Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / lustre / obdclass / cl_object.c
index c2e045b..e3bc29f 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * Client Lustre Object.
  *
 
 #include <linux/list.h>
 #include <libcfs/libcfs.h>
-/* class_put_type() */
 #include <obd_class.h>
 #include <obd_support.h>
 #include <lustre_fid.h>
-#include <libcfs/libcfs_hash.h> /* for cfs_hash stuff */
 #include <cl_object.h>
 #include <lu_object.h>
 #include "cl_internal.h"
 
 static struct kmem_cache *cl_env_kmem;
+struct kmem_cache *cl_dio_aio_kmem;
+struct kmem_cache *cl_sub_dio_kmem;
+struct kmem_cache *cl_page_kmem_array[16];
+unsigned short cl_page_kmem_size_array[16];
 
 /** Lock class of cl_object_header::coh_attr_guard */
 static struct lock_class_key cl_attr_guard_class;
@@ -201,18 +198,16 @@ EXPORT_SYMBOL(cl_object_attr_unlock);
  * top-to-bottom to fill in parts of \a attr that this layer is responsible
  * for.
  */
-int cl_object_attr_get(const struct lu_env *env, struct cl_object *obj,
+int cl_object_attr_get(const struct lu_env *env, struct cl_object *top,
                        struct cl_attr *attr)
 {
-       struct lu_object_header *top;
-       int result;
+       struct cl_object *obj;
+       int result = 0;
 
-       assert_spin_locked(cl_object_attr_guard(obj));
+       assert_spin_locked(cl_object_attr_guard(top));
        ENTRY;
 
-       top = obj->co_lu.lo_header;
-       result = 0;
-       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
+       cl_object_for_each(obj, top) {
                if (obj->co_ops->coo_attr_get != NULL) {
                        result = obj->co_ops->coo_attr_get(env, obj, attr);
                        if (result != 0) {
@@ -233,18 +228,16 @@ EXPORT_SYMBOL(cl_object_attr_get);
  * updated. Calls cl_object_operations::coo_upd_attr() on every layer, bottom
  * to top.
  */
-int cl_object_attr_update(const struct lu_env *env, struct cl_object *obj,
+int cl_object_attr_update(const struct lu_env *env, struct cl_object *top,
                          const struct cl_attr *attr, unsigned v)
 {
-       struct lu_object_header *top;
-       int result;
+       struct cl_object *obj;
+       int result = 0;
 
-       assert_spin_locked(cl_object_attr_guard(obj));
+       assert_spin_locked(cl_object_attr_guard(top));
        ENTRY;
 
-       top = obj->co_lu.lo_header;
-       result = 0;
-       list_for_each_entry_reverse(obj, &top->loh_layers, co_lu.lo_linkage) {
+       cl_object_for_each_reverse(obj, top) {
                if (obj->co_ops->coo_attr_update != NULL) {
                        result = obj->co_ops->coo_attr_update(env, obj, attr,
                                                              v);
@@ -260,6 +253,25 @@ int cl_object_attr_update(const struct lu_env *env, struct cl_object *obj,
 EXPORT_SYMBOL(cl_object_attr_update);
 
 /**
+ * Mark the inode as dirty when the inode has uncommitted (unstable) pages.
+ * Thus when the system is under momory pressure, it will trigger writeback
+ * on background to commit and unpin the pages.
+ */
+void cl_object_dirty_for_sync(const struct lu_env *env, struct cl_object *top)
+{
+       struct cl_object *obj;
+
+       ENTRY;
+
+       cl_object_for_each(obj, top) {
+               if (obj->co_ops->coo_dirty_for_sync != NULL)
+                       obj->co_ops->coo_dirty_for_sync(env, obj);
+       }
+       EXIT;
+}
+EXPORT_SYMBOL(cl_object_dirty_for_sync);
+
+/**
  * Notifies layers (bottom-to-top) that glimpse AST was received.
  *
  * Layers have to fill \a lvb fields with information that will be shipped
@@ -267,70 +279,63 @@ EXPORT_SYMBOL(cl_object_attr_update);
  *
  * \see cl_lock_operations::clo_glimpse()
  */
-int cl_object_glimpse(const struct lu_env *env, struct cl_object *obj,
-                      struct ost_lvb *lvb)
+int cl_object_glimpse(const struct lu_env *env, struct cl_object *top,
+                     struct ost_lvb *lvb)
 {
-        struct lu_object_header *top;
-        int result;
+       struct cl_object *obj;
+       int result = 0;
 
-        ENTRY;
-        top = obj->co_lu.lo_header;
-        result = 0;
-       list_for_each_entry_reverse(obj, &top->loh_layers, co_lu.lo_linkage) {
-                if (obj->co_ops->coo_glimpse != NULL) {
-                        result = obj->co_ops->coo_glimpse(env, obj, lvb);
-                        if (result != 0)
-                                break;
-                }
-        }
-        LU_OBJECT_HEADER(D_DLMTRACE, env, lu_object_top(top),
+       ENTRY;
+       cl_object_for_each_reverse(obj, top) {
+               if (obj->co_ops->coo_glimpse != NULL) {
+                       result = obj->co_ops->coo_glimpse(env, obj, lvb);
+                       if (result != 0)
+                               break;
+               }
+       }
+       LU_OBJECT_HEADER(D_DLMTRACE, env, lu_object_top(top->co_lu.lo_header),
                         "size: %llu mtime: %llu atime: %llu "
                         "ctime: %llu blocks: %llu\n",
-                         lvb->lvb_size, lvb->lvb_mtime, lvb->lvb_atime,
-                         lvb->lvb_ctime, lvb->lvb_blocks);
-        RETURN(result);
+                        lvb->lvb_size, lvb->lvb_mtime, lvb->lvb_atime,
+                        lvb->lvb_ctime, lvb->lvb_blocks);
+       RETURN(result);
 }
 EXPORT_SYMBOL(cl_object_glimpse);
 
 /**
  * Updates a configuration of an object \a obj.
  */
-int cl_conf_set(const struct lu_env *env, struct cl_object *obj,
-                const struct cl_object_conf *conf)
+int cl_conf_set(const struct lu_env *env, struct cl_object *top,
+               const struct cl_object_conf *conf)
 {
-        struct lu_object_header *top;
-        int result;
+       struct cl_object *obj;
+       int result = 0;
 
-        ENTRY;
-        top = obj->co_lu.lo_header;
-        result = 0;
-       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-                if (obj->co_ops->coo_conf_set != NULL) {
-                        result = obj->co_ops->coo_conf_set(env, obj, conf);
-                        if (result != 0)
-                                break;
-                }
-        }
-        RETURN(result);
+       ENTRY;
+       cl_object_for_each(obj, top) {
+               if (obj->co_ops->coo_conf_set != NULL) {
+                       result = obj->co_ops->coo_conf_set(env, obj, conf);
+                       if (result)
+                               break;
+               }
+       }
+       RETURN(result);
 }
 EXPORT_SYMBOL(cl_conf_set);
 
 /**
  * Prunes caches of pages and locks for this object.
  */
-int cl_object_prune(const struct lu_env *env, struct cl_object *obj)
+int cl_object_prune(const struct lu_env *env, struct cl_object *top)
 {
-       struct lu_object_header *top;
-       struct cl_object *o;
-       int result;
+       struct cl_object *obj;
+       int result = 0;
        ENTRY;
 
-       top = obj->co_lu.lo_header;
-       result = 0;
-       list_for_each_entry(o, &top->loh_layers, co_lu.lo_linkage) {
-               if (o->co_ops->coo_prune != NULL) {
-                       result = o->co_ops->coo_prune(env, o);
-                       if (result != 0)
+       cl_object_for_each(obj, top) {
+               if (obj->co_ops->coo_prune != NULL) {
+                       result = obj->co_ops->coo_prune(env, obj);
+                       if (result)
                                break;
                }
        }
@@ -342,18 +347,18 @@ EXPORT_SYMBOL(cl_object_prune);
 /**
  * Get stripe information of this object.
  */
-int cl_object_getstripe(const struct lu_env *env, struct cl_object *obj,
-                       struct lov_user_md __user *uarg)
+int cl_object_getstripe(const struct lu_env *env, struct cl_object *top,
+                       struct lov_user_md __user *uarg, size_t size)
 {
-       struct lu_object_header *top;
-       int                     result = 0;
+       struct cl_object *obj;
+       int result = 0;
        ENTRY;
 
-       top = obj->co_lu.lo_header;
-       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-               if (obj->co_ops->coo_getstripe != NULL) {
-                       result = obj->co_ops->coo_getstripe(env, obj, uarg);
-                       if (result != 0)
+       cl_object_for_each(obj, top) {
+               if (obj->co_ops->coo_getstripe) {
+                       result = obj->co_ops->coo_getstripe(env, obj, uarg,
+                                                           size);
+                       if (result)
                                break;
                }
        }
@@ -373,20 +378,19 @@ EXPORT_SYMBOL(cl_object_getstripe);
  * \retval 0   success
  * \retval < 0 error
  */
-int cl_object_fiemap(const struct lu_env *env, struct cl_object *obj,
+int cl_object_fiemap(const struct lu_env *env, struct cl_object *top,
                     struct ll_fiemap_info_key *key,
                     struct fiemap *fiemap, size_t *buflen)
 {
-       struct lu_object_header *top;
-       int                     result = 0;
+       struct cl_object *obj;
+       int result = 0;
        ENTRY;
 
-       top = obj->co_lu.lo_header;
-       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-               if (obj->co_ops->coo_fiemap != NULL) {
+       cl_object_for_each(obj, top) {
+               if (obj->co_ops->coo_fiemap) {
                        result = obj->co_ops->coo_fiemap(env, obj, key, fiemap,
                                                         buflen);
-                       if (result != 0)
+                       if (result)
                                break;
                }
        }
@@ -394,14 +398,14 @@ int cl_object_fiemap(const struct lu_env *env, struct cl_object *obj,
 }
 EXPORT_SYMBOL(cl_object_fiemap);
 
-int cl_object_layout_get(const struct lu_env *env, struct cl_object *obj,
+int cl_object_layout_get(const struct lu_env *env, struct cl_object *top,
                         struct cl_layout *cl)
 {
-       struct lu_object_header *top = obj->co_lu.lo_header;
+       struct cl_object *obj;
        ENTRY;
 
-       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-               if (obj->co_ops->coo_layout_get != NULL)
+       cl_object_for_each(obj, top) {
+               if (obj->co_ops->coo_layout_get)
                        return obj->co_ops->coo_layout_get(env, obj, cl);
        }
 
@@ -409,14 +413,14 @@ int cl_object_layout_get(const struct lu_env *env, struct cl_object *obj,
 }
 EXPORT_SYMBOL(cl_object_layout_get);
 
-loff_t cl_object_maxbytes(struct cl_object *obj)
+loff_t cl_object_maxbytes(struct cl_object *top)
 {
-       struct lu_object_header *top = obj->co_lu.lo_header;
+       struct cl_object *obj;
        loff_t maxbytes = LLONG_MAX;
        ENTRY;
 
-       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-               if (obj->co_ops->coo_maxbytes != NULL)
+       cl_object_for_each(obj, top) {
+               if (obj->co_ops->coo_maxbytes)
                        maxbytes = min_t(loff_t, obj->co_ops->coo_maxbytes(obj),
                                         maxbytes);
        }
@@ -425,6 +429,43 @@ loff_t cl_object_maxbytes(struct cl_object *obj)
 }
 EXPORT_SYMBOL(cl_object_maxbytes);
 
+int cl_object_flush(const struct lu_env *env, struct cl_object *top,
+                        struct ldlm_lock *lock)
+{
+       struct cl_object *obj;
+       int rc = 0;
+       ENTRY;
+
+       cl_object_for_each(obj, top) {
+               if (obj->co_ops->coo_object_flush) {
+                       rc = obj->co_ops->coo_object_flush(env, obj, lock);
+                       if (rc)
+                               break;
+               }
+       }
+       RETURN(rc);
+}
+EXPORT_SYMBOL(cl_object_flush);
+
+int cl_object_inode_ops(const struct lu_env *env, struct cl_object *top,
+                       enum coo_inode_opc opc, void *data)
+{
+       struct cl_object *obj;
+       int rc = 0;
+
+       ENTRY;
+
+       cl_object_for_each(obj, top) {
+               if (obj->co_ops->coo_inode_ops) {
+                       rc = obj->co_ops->coo_inode_ops(env, obj, opc, data);
+                       if (rc)
+                               break;
+               }
+       }
+       RETURN(rc);
+}
+EXPORT_SYMBOL(cl_object_inode_ops);
+
 /**
  * Helper function removing all object locks, and marking object for
  * deletion. All object pages must have been deleted at this point.
@@ -517,7 +558,7 @@ static struct cache_stats cl_env_stats = {
  */
 int cl_site_stats_print(const struct cl_site *site, struct seq_file *m)
 {
-       static const char *pstate[] = {
+       static const char *const pstate[] = {
                [CPS_CACHED]    = "c",
                [CPS_OWNED]     = "o",
                [CPS_PAGEOUT]   = "w",
@@ -551,24 +592,6 @@ EXPORT_SYMBOL(cl_site_stats_print);
  *
  */
 
-/**
- * The most efficient way is to store cl_env pointer in task specific
- * structures. On Linux, it wont' be easy to use task_struct->journal_info
- * because Lustre code may call into other fs which has certain assumptions
- * about journal_info. Currently following fields in task_struct are identified
- * can be used for this purpose:
- *  - cl_env: for liblustre.
- *  - tux_info: ony on RedHat kernel.
- *  - ...
- * \note As long as we use task_struct to store cl_env, we assume that once
- * called into Lustre, we'll never call into the other part of the kernel
- * which will use those fields in task_struct without explicitly exiting
- * Lustre.
- *
- * If there's no space in task_struct is available, hash will be used.
- * bz20044, bz22683.
- */
-
 static unsigned cl_envs_cached_max = 32; /* XXX: prototype: arbitrary limit
                                          * for now. */
 static struct cl_env_cache {
@@ -598,17 +621,20 @@ struct cl_env {
         void             *ce_debug;
 };
 
+static void cl_env_inc(enum cache_stats_item item)
+{
+#ifdef CONFIG_DEBUG_PAGESTATE_TRACKING
+       atomic_inc(&cl_env_stats.cs_stats[item]);
+#endif
+}
+
+static void cl_env_dec(enum cache_stats_item item)
+{
 #ifdef CONFIG_DEBUG_PAGESTATE_TRACKING
-#define CL_ENV_INC(counter) atomic_inc(&cl_env_stats.cs_stats[CS_##counter])
-
-#define CL_ENV_DEC(counter) do {                                              \
-       LASSERT(atomic_read(&cl_env_stats.cs_stats[CS_##counter]) > 0);   \
-       atomic_dec(&cl_env_stats.cs_stats[CS_##counter]);                 \
-} while (0)
-#else
-#define CL_ENV_INC(counter)
-#define CL_ENV_DEC(counter)
+       LASSERT(atomic_read(&cl_env_stats.cs_stats[item]) > 0);
+       atomic_dec(&cl_env_stats.cs_stats[item]);
 #endif
+}
 
 static void cl_env_init0(struct cl_env *cle, void *debug)
 {
@@ -618,7 +644,7 @@ static void cl_env_init0(struct cl_env *cle, void *debug)
 
        cle->ce_ref = 1;
        cle->ce_debug = debug;
-       CL_ENV_INC(busy);
+       cl_env_inc(CS_busy);
 }
 
 static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug)
@@ -648,8 +674,8 @@ static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug)
                        OBD_SLAB_FREE_PTR(cle, cl_env_kmem);
                        env = ERR_PTR(rc);
                } else {
-                       CL_ENV_INC(create);
-                       CL_ENV_INC(total);
+                       cl_env_inc(CS_create);
+                       cl_env_inc(CS_total);
                }
        } else
                env = ERR_PTR(-ENOMEM);
@@ -658,12 +684,15 @@ static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug)
 
 static void cl_env_fini(struct cl_env *cle)
 {
-        CL_ENV_DEC(total);
-        lu_context_fini(&cle->ce_lu.le_ctx);
-        lu_context_fini(&cle->ce_ses);
-        OBD_SLAB_FREE_PTR(cle, cl_env_kmem);
+       cl_env_dec(CS_total);
+       lu_context_fini(&cle->ce_lu.le_ctx);
+       lu_context_fini(&cle->ce_ses);
+       OBD_SLAB_FREE_PTR(cle, cl_env_kmem);
 }
 
+/* Get a cl_env, either from the per-CPU cache for the current CPU, or by
+ * allocating a new one.
+ */
 static struct lu_env *cl_env_obtain(void *debug)
 {
        struct cl_env *cle;
@@ -710,10 +739,14 @@ static inline struct cl_env *cl_env_container(struct lu_env *env)
 }
 
 /**
- * Returns lu_env: if there already is an environment associated with the
- * current thread, it is returned, otherwise, new environment is allocated.
+ * Returns an lu_env.
+ *
+ * No link to thread, this returns an env from the cache or
+ * allocates a new one.
  *
- * Allocations are amortized through the global cache of environments.
+ * If you need to get the specific environment you created for this thread,
+ * you must either pass the pointer directly or store it in the file/inode
+ * private data and retrieve it from there using ll_cl_add/ll_cl_find.
  *
  * \param refcheck pointer to a counter used to detect environment leaks. In
  * the usual case cl_env_get() and cl_env_put() are called in the same lexical
@@ -801,8 +834,8 @@ EXPORT_SYMBOL(cl_env_cache_purge);
  * Release an environment.
  *
  * Decrement \a env reference counter. When counter drops to 0, nothing in
- * this thread is using environment and it is returned to the allocation
- * cache, or freed straight away, if cache is large enough.
+ * this thread is using environment and it is returned to the per-CPU cache or
+ * freed immediately if the cache is full.
  */
 void cl_env_put(struct lu_env *env, __u16 *refcheck)
 {
@@ -817,18 +850,18 @@ void cl_env_put(struct lu_env *env, __u16 *refcheck)
         if (--cle->ce_ref == 0) {
                int cpu = get_cpu();
 
-                CL_ENV_DEC(busy);
-                cle->ce_debug = NULL;
-                cl_env_exit(cle);
-                /*
-                 * Don't bother to take a lock here.
-                 *
-                 * Return environment to the cache only when it was allocated
-                 * with the standard tags.
-                 */
+               cl_env_dec(CS_busy);
+               cle->ce_debug = NULL;
+               cl_env_exit(cle);
+               /*
+                * Don't bother to take a lock here.
+                *
+                * Return environment to the cache only when it was allocated
+                * with the standard tags.
+                */
                if (cl_envs[cpu].cec_count < cl_envs_cached_max &&
-                   (env->le_ctx.lc_tags & ~LCT_HAS_EXIT) == LCT_CL_THREAD &&
-                   (env->le_ses->lc_tags & ~LCT_HAS_EXIT) == LCT_SESSION) {
+                   (env->le_ctx.lc_tags & ~LCT_HAS_EXIT) == lu_context_tags_default &&
+                   (env->le_ses->lc_tags & ~LCT_HAS_EXIT) == lu_session_tags_default) {
                        read_lock(&cl_envs[cpu].cec_guard);
                        list_add(&cle->ce_linkage, &cl_envs[cpu].cec_envs);
                        cl_envs[cpu].cec_count++;
@@ -847,13 +880,11 @@ EXPORT_SYMBOL(cl_env_put);
  */
 void cl_attr2lvb(struct ost_lvb *lvb, const struct cl_attr *attr)
 {
-        ENTRY;
         lvb->lvb_size   = attr->cat_size;
         lvb->lvb_mtime  = attr->cat_mtime;
         lvb->lvb_atime  = attr->cat_atime;
         lvb->lvb_ctime  = attr->cat_ctime;
         lvb->lvb_blocks = attr->cat_blocks;
-        EXIT;
 }
 
 /**
@@ -863,17 +894,16 @@ void cl_attr2lvb(struct ost_lvb *lvb, const struct cl_attr *attr)
  */
 void cl_lvb2attr(struct cl_attr *attr, const struct ost_lvb *lvb)
 {
-        ENTRY;
         attr->cat_size   = lvb->lvb_size;
         attr->cat_mtime  = lvb->lvb_mtime;
         attr->cat_atime  = lvb->lvb_atime;
         attr->cat_ctime  = lvb->lvb_ctime;
         attr->cat_blocks = lvb->lvb_blocks;
-        EXIT;
 }
 EXPORT_SYMBOL(cl_lvb2attr);
 
 static struct cl_env cl_env_percpu[NR_CPUS];
+static DEFINE_MUTEX(cl_env_percpu_mutex);
 
 static int cl_env_percpu_init(void)
 {
@@ -938,8 +968,10 @@ static void cl_env_percpu_refill(void)
 {
        int i;
 
+       mutex_lock(&cl_env_percpu_mutex);
        for_each_possible_cpu(i)
                lu_env_refill(&cl_env_percpu[i].ce_lu);
+       mutex_unlock(&cl_env_percpu_mutex);
 }
 
 void cl_env_percpu_put(struct lu_env *env)
@@ -954,14 +986,14 @@ void cl_env_percpu_put(struct lu_env *env)
        cle->ce_ref--;
        LASSERT(cle->ce_ref == 0);
 
-       CL_ENV_DEC(busy);
+       cl_env_dec(CS_busy);
        cle->ce_debug = NULL;
 
        put_cpu();
 }
 EXPORT_SYMBOL(cl_env_percpu_put);
 
-struct lu_env *cl_env_percpu_get()
+struct lu_env *cl_env_percpu_get(void)
 {
        struct cl_env *cle;
 
@@ -1026,20 +1058,8 @@ struct cl_thread_info *cl_env_info(const struct lu_env *env)
         return lu_context_key_get(&env->le_ctx, &cl_key);
 }
 
-/* defines cl0_key_{init,fini}() */
-LU_KEY_INIT_FINI(cl0, struct cl_thread_info);
-
-static void *cl_key_init(const struct lu_context *ctx,
-                         struct lu_context_key *key)
-{
-       return cl0_key_init(ctx, key);
-}
-
-static void cl_key_fini(const struct lu_context *ctx,
-                        struct lu_context_key *key, void *data)
-{
-       cl0_key_fini(ctx, key, data);
-}
+/* defines cl_key_{init,fini}() */
+LU_KEY_INIT_FINI(cl, struct cl_thread_info);
 
 static struct lu_context_key cl_key = {
         .lct_tags = LCT_CL_THREAD,
@@ -1048,14 +1068,24 @@ static struct lu_context_key cl_key = {
 };
 
 static struct lu_kmem_descr cl_object_caches[] = {
-        {
-                .ckd_cache = &cl_env_kmem,
-                .ckd_name  = "cl_env_kmem",
-                .ckd_size  = sizeof (struct cl_env)
-        },
-        {
-                .ckd_cache = NULL
-        }
+       {
+               .ckd_cache = &cl_env_kmem,
+               .ckd_name  = "cl_env_kmem",
+               .ckd_size  = sizeof(struct cl_env)
+       },
+       {
+               .ckd_cache = &cl_dio_aio_kmem,
+               .ckd_name  = "cl_dio_aio_kmem",
+               .ckd_size  = sizeof(struct cl_dio_aio)
+       },
+       {
+               .ckd_cache = &cl_sub_dio_kmem,
+               .ckd_name  = "cl_sub_dio_kmem",
+               .ckd_size  = sizeof(struct cl_sub_dio)
+       },
+       {
+               .ckd_cache = NULL
+       }
 };
 
 /**
@@ -1068,7 +1098,7 @@ int cl_global_init(void)
 {
        int result;
 
-       OBD_ALLOC(cl_envs, sizeof(*cl_envs) * num_possible_cpus());
+       OBD_ALLOC_PTR_ARRAY(cl_envs, num_possible_cpus());
        if (cl_envs == NULL)
                GOTO(out, result = -ENOMEM);
 
@@ -1092,7 +1122,7 @@ out_keys:
 out_kmem:
        lu_kmem_fini(cl_object_caches);
 out_envs:
-       OBD_FREE(cl_envs, sizeof(*cl_envs) * num_possible_cpus());
+       OBD_FREE_PTR_ARRAY(cl_envs, num_possible_cpus());
 out:
        return result;
 }
@@ -1102,8 +1132,16 @@ out:
  */
 void cl_global_fini(void)
 {
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(cl_page_kmem_array); i++) {
+               if (cl_page_kmem_array[i]) {
+                       kmem_cache_destroy(cl_page_kmem_array[i]);
+                       cl_page_kmem_array[i] = NULL;
+               }
+       }
        cl_env_percpu_fini();
        lu_context_key_degister(&cl_key);
        lu_kmem_fini(cl_object_caches);
-       OBD_FREE(cl_envs, sizeof(*cl_envs) * num_possible_cpus());
+       OBD_FREE_PTR_ARRAY(cl_envs, num_possible_cpus());
 }