Whamcloud - gitweb
LU-3321 clio: collapse layer of cl_page
[fs/lustre-release.git] / lustre / obdclass / cl_page.c
index 9e57e09..a8f46ea 100644 (file)
@@ -36,6 +36,7 @@
  * Client Lustre Page.
  *
  *   Author: Nikita Danilov <nikita.danilov@sun.com>
+ *   Author: Jinshan Xiong <jinshan.xiong@intel.com>
  */
 
 #define DEBUG_SUBSYSTEM S_CLASS
@@ -48,8 +49,7 @@
 #include <cl_object.h>
 #include "cl_internal.h"
 
-static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg,
-                            int radix);
+static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg);
 
 #ifdef LIBCFS_DEBUG
 # define PASSERT(env, page, expr)                                       \
@@ -111,8 +111,7 @@ static struct cl_page *cl_page_top_trusted(struct cl_page *page)
  *
  * This function can be used to obtain initial reference to previously
  * unreferenced cached object. It can be called only if concurrent page
- * reclamation is somehow prevented, e.g., by locking page radix-tree
- * (cl_object_header::hdr->coh_page_guard), or by keeping a lock on a VM page,
+ * reclamation is somehow prevented, e.g., by keeping a lock on a VM page,
  * associated with \a page.
  *
  * Use with care! Not exported.
@@ -147,132 +146,6 @@ cl_page_at_trusted(const struct cl_page *page,
         RETURN(NULL);
 }
 
-/**
- * Returns a page with given index in the given object, or NULL if no page is
- * found. Acquires a reference on \a page.
- *
- * Locking: called under cl_object_header::coh_page_guard spin-lock.
- */
-struct cl_page *cl_page_lookup(struct cl_object_header *hdr, pgoff_t index)
-{
-       struct cl_page *page;
-
-       LASSERT(spin_is_locked(&hdr->coh_page_guard));
-
-       page = radix_tree_lookup(&hdr->coh_tree, index);
-       if (page != NULL)
-               cl_page_get_trust(page);
-       return page;
-}
-EXPORT_SYMBOL(cl_page_lookup);
-
-/**
- * Returns a list of pages by a given [start, end] of \a obj.
- *
- * \param resched If not NULL, then we give up before hogging CPU for too
- * long and set *resched = 1, in that case caller should implement a retry
- * logic.
- *
- * Gang tree lookup (radix_tree_gang_lookup()) optimization is absolutely
- * crucial in the face of [offset, EOF] locks.
- *
- * Return at least one page in @queue unless there is no covered page.
- */
-int cl_page_gang_lookup(const struct lu_env *env, struct cl_object *obj,
-                       struct cl_io *io, pgoff_t start, pgoff_t end,
-                       cl_page_gang_cb_t cb, void *cbdata)
-{
-        struct cl_object_header *hdr;
-        struct cl_page          *page;
-        struct cl_page         **pvec;
-        const struct cl_page_slice  *slice;
-        const struct lu_device_type *dtype;
-        pgoff_t                  idx;
-        unsigned int             nr;
-        unsigned int             i;
-        unsigned int             j;
-        int                      res = CLP_GANG_OKAY;
-        int                      tree_lock = 1;
-        ENTRY;
-
-        idx = start;
-        hdr = cl_object_header(obj);
-        pvec = cl_env_info(env)->clt_pvec;
-        dtype = cl_object_top(obj)->co_lu.lo_dev->ld_type;
-       spin_lock(&hdr->coh_page_guard);
-        while ((nr = radix_tree_gang_lookup(&hdr->coh_tree, (void **)pvec,
-                                            idx, CLT_PVEC_SIZE)) > 0) {
-                int end_of_region = 0;
-                idx = pvec[nr - 1]->cp_index + 1;
-                for (i = 0, j = 0; i < nr; ++i) {
-                        page = pvec[i];
-                        pvec[i] = NULL;
-
-                        LASSERT(page->cp_type == CPT_CACHEABLE);
-                        if (page->cp_index > end) {
-                                end_of_region = 1;
-                                break;
-                        }
-                        if (page->cp_state == CPS_FREEING)
-                                continue;
-
-                        slice = cl_page_at_trusted(page, dtype);
-                        /*
-                         * Pages for lsm-less file has no underneath sub-page
-                         * for osc, in case of ...
-                         */
-                        PASSERT(env, page, slice != NULL);
-
-                       page = slice->cpl_page;
-                       /*
-                        * Can safely call cl_page_get_trust() under
-                        * radix-tree spin-lock.
-                        *
-                        * XXX not true, because @page is from object another
-                        * than @hdr and protected by different tree lock.
-                        */
-                       cl_page_get_trust(page);
-                       lu_ref_add_atomic(&page->cp_reference,
-                                         "gang_lookup", current);
-                       pvec[j++] = page;
-               }
-
-               /*
-                * Here a delicate locking dance is performed. Current thread
-                * holds a reference to a page, but has to own it before it
-                * can be placed into queue. Owning implies waiting, so
-                * radix-tree lock is to be released. After a wait one has to
-                * check that pages weren't truncated (cl_page_own() returns
-                * error in the latter case).
-                */
-               spin_unlock(&hdr->coh_page_guard);
-               tree_lock = 0;
-
-               for (i = 0; i < j; ++i) {
-                       page = pvec[i];
-                       if (res == CLP_GANG_OKAY)
-                               res = (*cb)(env, io, page, cbdata);
-                       lu_ref_del(&page->cp_reference,
-                                  "gang_lookup", current);
-                       cl_page_put(env, page);
-               }
-               if (nr < CLT_PVEC_SIZE || end_of_region)
-                       break;
-
-               if (res == CLP_GANG_OKAY && need_resched())
-                       res = CLP_GANG_RESCHED;
-               if (res != CLP_GANG_OKAY)
-                       break;
-
-               spin_lock(&hdr->coh_page_guard);
-               tree_lock = 1;
-       }
-       if (tree_lock)
-               spin_unlock(&hdr->coh_page_guard);
-       RETURN(res);
-}
-EXPORT_SYMBOL(cl_page_gang_lookup);
-
 static void cl_page_free(const struct lu_env *env, struct cl_page *page)
 {
         struct cl_object *obj  = page->cp_obj;
@@ -314,7 +187,7 @@ static inline void cl_page_state_set_trust(struct cl_page *page,
         *(enum cl_page_state *)&page->cp_state = state;
 }
 
-static struct cl_page *cl_page_alloc(const struct lu_env *env,
+struct cl_page *cl_page_alloc(const struct lu_env *env,
                struct cl_object *o, pgoff_t ind, struct page *vmpage,
                enum cl_page_type type)
 {
@@ -327,8 +200,6 @@ static struct cl_page *cl_page_alloc(const struct lu_env *env,
        if (page != NULL) {
                int result = 0;
                cfs_atomic_set(&page->cp_ref, 1);
-               if (type == CPT_CACHEABLE) /* for radix tree */
-                       cfs_atomic_inc(&page->cp_ref);
                page->cp_obj = o;
                cl_object_get(o);
                lu_object_ref_add_at(&o->co_lu, &page->cp_obj_ref, "cl_page",
@@ -348,7 +219,7 @@ static struct cl_page *cl_page_alloc(const struct lu_env *env,
                                result = o->co_ops->coo_page_init(env, o,
                                                                  page, vmpage);
                                if (result != 0) {
-                                       cl_page_delete0(env, page, 0);
+                                       cl_page_delete0(env, page);
                                        cl_page_free(env, page);
                                        page = ERR_PTR(result);
                                        break;
@@ -365,6 +236,7 @@ static struct cl_page *cl_page_alloc(const struct lu_env *env,
        }
        RETURN(page);
 }
+EXPORT_SYMBOL(cl_page_alloc);
 
 /**
  * Returns a cl_page with index \a idx at the object \a o, and associated with
@@ -377,16 +249,13 @@ static struct cl_page *cl_page_alloc(const struct lu_env *env,
  *
  * \see cl_object_find(), cl_lock_find()
  */
-static struct cl_page *cl_page_find0(const struct lu_env *env,
-                                     struct cl_object *o,
-                                     pgoff_t idx, struct page *vmpage,
-                                     enum cl_page_type type,
-                                     struct cl_page *parent)
+struct cl_page *cl_page_find(const struct lu_env *env,
+                            struct cl_object *o,
+                            pgoff_t idx, struct page *vmpage,
+                            enum cl_page_type type)
 {
        struct cl_page          *page = NULL;
-       struct cl_page          *ghost = NULL;
        struct cl_object_header *hdr;
-       int err;
 
        LASSERT(type == CPT_CACHEABLE || type == CPT_TRANSIENT);
        might_sleep();
@@ -413,93 +282,20 @@ static struct cl_page *cl_page_find0(const struct lu_env *env,
                  *       reference on it.
                  */
                 page = cl_vmpage_page(vmpage, o);
-                PINVRNT(env, page,
-                        ergo(page != NULL,
-                             cl_page_vmpage(env, page) == vmpage &&
-                             (void *)radix_tree_lookup(&hdr->coh_tree,
-                                                       idx) == page));
-        }
-
-        if (page != NULL) {
-               CS_PAGE_INC(o, hit);
-                RETURN(page);
+               if (page != NULL) {
+                       CS_PAGE_INC(o, hit);
+                       RETURN(page);
+               }
         }
 
         /* allocate and initialize cl_page */
         page = cl_page_alloc(env, o, idx, vmpage, type);
-        if (IS_ERR(page))
-                RETURN(page);
-
-        if (type == CPT_TRANSIENT) {
-                if (parent) {
-                        LASSERT(page->cp_parent == NULL);
-                        page->cp_parent = parent;
-                        parent->cp_child = page;
-                }
-                RETURN(page);
-        }
-
-        /*
-         * XXX optimization: use radix_tree_preload() here, and change tree
-         * gfp mask to GFP_KERNEL in cl_object_header_init().
-         */
-       spin_lock(&hdr->coh_page_guard);
-        err = radix_tree_insert(&hdr->coh_tree, idx, page);
-        if (err != 0) {
-                ghost = page;
-                /*
-                 * Noted by Jay: a lock on \a vmpage protects cl_page_find()
-                 * from this race, but
-                 *
-                 *     0. it's better to have cl_page interface "locally
-                 *     consistent" so that its correctness can be reasoned
-                 *     about without appealing to the (obscure world of) VM
-                 *     locking.
-                 *
-                 *     1. handling this race allows ->coh_tree to remain
-                 *     consistent even when VM locking is somehow busted,
-                 *     which is very useful during diagnosing and debugging.
-                 */
-                page = ERR_PTR(err);
-                CL_PAGE_DEBUG(D_ERROR, env, ghost,
-                              "fail to insert into radix tree: %d\n", err);
-        } else {
-                if (parent) {
-                        LASSERT(page->cp_parent == NULL);
-                        page->cp_parent = parent;
-                        parent->cp_child = page;
-                }
-                hdr->coh_pages++;
-        }
-       spin_unlock(&hdr->coh_page_guard);
-
-        if (unlikely(ghost != NULL)) {
-                cl_page_delete0(env, ghost, 0);
-                cl_page_free(env, ghost);
-        }
-        RETURN(page);
-}
-
-struct cl_page *cl_page_find(const struct lu_env *env, struct cl_object *o,
-                             pgoff_t idx, struct page *vmpage,
-                             enum cl_page_type type)
-{
-        return cl_page_find0(env, o, idx, vmpage, type, NULL);
+       RETURN(page);
 }
 EXPORT_SYMBOL(cl_page_find);
 
-
-struct cl_page *cl_page_find_sub(const struct lu_env *env, struct cl_object *o,
-                                 pgoff_t idx, struct page *vmpage,
-                                 struct cl_page *parent)
-{
-        return cl_page_find0(env, o, idx, vmpage, parent->cp_type, parent);
-}
-EXPORT_SYMBOL(cl_page_find_sub);
-
 static inline int cl_page_invariant(const struct cl_page *pg)
 {
-        struct cl_object_header *header;
         struct cl_page          *parent;
         struct cl_page          *child;
         struct cl_io            *owner;
@@ -509,7 +305,6 @@ static inline int cl_page_invariant(const struct cl_page *pg)
          */
         LINVRNT(cl_page_is_vmlocked(NULL, pg));
 
-        header = cl_object_header(pg->cp_obj);
         parent = pg->cp_parent;
         child  = pg->cp_child;
         owner  = pg->cp_owner;
@@ -522,15 +317,7 @@ static inline int cl_page_invariant(const struct cl_page *pg)
                 ergo(owner != NULL && parent != NULL,
                      parent->cp_owner == pg->cp_owner->ci_parent) &&
                 ergo(owner != NULL && child != NULL,
-                     child->cp_owner->ci_parent == owner) &&
-                /*
-                 * Either page is early in initialization (has neither child
-                 * nor parent yet), or it is in the object radix tree.
-                 */
-                ergo(pg->cp_state < CPS_FREEING && pg->cp_type == CPT_CACHEABLE,
-                     (void *)radix_tree_lookup(&header->coh_tree,
-                                               pg->cp_index) == pg ||
-                     (child == NULL && parent == NULL));
+                     child->cp_owner->ci_parent == owner);
 }
 
 static void cl_page_state_set0(const struct lu_env *env,
@@ -1081,10 +868,8 @@ EXPORT_SYMBOL(cl_page_discard);
  * pages, e.g,. in a error handling cl_page_find()->cl_page_delete0()
  * path. Doesn't check page invariant.
  */
-static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg,
-                            int radix)
+static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg)
 {
-        struct cl_page *tmp = pg;
         ENTRY;
 
         PASSERT(env, pg, pg == cl_page_top(pg));
@@ -1095,42 +880,11 @@ static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg,
          */
         cl_page_owner_clear(pg);
 
-        /* 
-         * unexport the page firstly before freeing it so that
-         * the page content is considered to be invalid.
-         * We have to do this because a CPS_FREEING cl_page may
-         * be NOT under the protection of a cl_lock.
-         * Afterwards, if this page is found by other threads, then this
-         * page will be forced to reread.
-         */
-        cl_page_export(env, pg, 0);
         cl_page_state_set0(env, pg, CPS_FREEING);
 
-        CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_delete),
+        CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(cpo_delete),
                        (const struct lu_env *, const struct cl_page_slice *));
 
-        if (tmp->cp_type == CPT_CACHEABLE) {
-                if (!radix)
-                        /* !radix means that @pg is not yet in the radix tree,
-                         * skip removing it.
-                         */
-                        tmp = pg->cp_child;
-                for (; tmp != NULL; tmp = tmp->cp_child) {
-                        void                    *value;
-                        struct cl_object_header *hdr;
-
-                        hdr = cl_object_header(tmp->cp_obj);
-                       spin_lock(&hdr->coh_page_guard);
-                       value = radix_tree_delete(&hdr->coh_tree,
-                                                 tmp->cp_index);
-                       PASSERT(env, tmp, value == tmp);
-                       PASSERT(env, tmp, hdr->coh_pages > 0);
-                       hdr->coh_pages--;
-                       spin_unlock(&hdr->coh_page_guard);
-                       cl_page_put(env, tmp);
-                }
-        }
-
         EXIT;
 }
 
@@ -1161,33 +915,14 @@ static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg,
  */
 void cl_page_delete(const struct lu_env *env, struct cl_page *pg)
 {
-        PINVRNT(env, pg, cl_page_invariant(pg));
-        ENTRY;
-        cl_page_delete0(env, pg, 1);
-        EXIT;
+       PINVRNT(env, pg, cl_page_invariant(pg));
+       ENTRY;
+       cl_page_delete0(env, pg);
+       EXIT;
 }
 EXPORT_SYMBOL(cl_page_delete);
 
 /**
- * Unmaps page from user virtual memory.
- *
- * Calls cl_page_operations::cpo_unmap() through all layers top-to-bottom. The
- * layer responsible for VM interaction has to unmap page from user space
- * virtual memory.
- *
- * \see cl_page_operations::cpo_unmap()
- */
-int cl_page_unmap(const struct lu_env *env,
-                  struct cl_io *io, struct cl_page *pg)
-{
-        PINVRNT(env, pg, cl_page_is_owned(pg, io));
-        PINVRNT(env, pg, cl_page_invariant(pg));
-
-        return cl_page_invoke(env, io, pg, CL_PAGE_OP(cpo_unmap));
-}
-EXPORT_SYMBOL(cl_page_unmap);
-
-/**
  * Marks page up-to-date.
  *
  * Call cl_page_operations::cpo_export() through all layers top-to-bottom. The
@@ -1460,54 +1195,6 @@ int cl_page_is_under_lock(const struct lu_env *env, struct cl_io *io,
 }
 EXPORT_SYMBOL(cl_page_is_under_lock);
 
-static int page_prune_cb(const struct lu_env *env, struct cl_io *io,
-                         struct cl_page *page, void *cbdata)
-{
-        cl_page_own(env, io, page);
-        cl_page_unmap(env, io, page);
-        cl_page_discard(env, io, page);
-        cl_page_disown(env, io, page);
-        return CLP_GANG_OKAY;
-}
-
-/**
- * Purges all cached pages belonging to the object \a obj.
- */
-int cl_pages_prune(const struct lu_env *env, struct cl_object *clobj)
-{
-       struct cl_thread_info   *info;
-       struct cl_object        *obj = cl_object_top(clobj);
-       struct cl_io            *io;
-       int                      result;
-
-       ENTRY;
-       info  = cl_env_info(env);
-       io    = &info->clt_io;
-
-       /*
-        * initialize the io. This is ugly since we never do IO in this
-        * function, we just make cl_page_list functions happy. -jay
-        */
-       io->ci_obj = obj;
-       io->ci_ignore_layout = 1;
-       result = cl_io_init(env, io, CIT_MISC, obj);
-       if (result != 0) {
-               cl_io_fini(env, io);
-               RETURN(io->ci_result);
-       }
-
-       do {
-               result = cl_page_gang_lookup(env, obj, io, 0, CL_PAGE_EOF,
-                                            page_prune_cb, NULL);
-               if (result == CLP_GANG_RESCHED)
-                       cond_resched();
-       } while (result != CLP_GANG_OKAY);
-
-       cl_io_fini(env, io);
-       RETURN(result);
-}
-EXPORT_SYMBOL(cl_pages_prune);
-
 /**
  * Tells transfer engine that only part of a page is to be transmitted.
  *