Whamcloud - gitweb
LU-9679 osc: simplify osc_page_gang_lookup() 99/37599/2
authorNeilBrown <neilb@suse.com>
Mon, 17 Dec 2018 04:06:47 +0000 (15:06 +1100)
committerOleg Drokin <green@whamcloud.com>
Thu, 5 Mar 2020 22:35:27 +0000 (22:35 +0000)
osc_page_gang_lookup() has 4 values that it can receive from a
callback, and that it can return to the caller:
CLP_GANG_OKAY,
CLP_GANG_RESCHED,
CLP_GANG_AGAIN,
CLP_GANG_ABORT

"AGAIN" is never used.
"RESCHED" is not needed as a cond_resched() can safely be called at
the point this is returned, rather than returning it.
That leaves "OKAY" and "ABORT" which can simply by "true" and "false"
boolean values.

Internalizing the RESCHED case means the callers don't need to loop
themselves.  This simplifies calling patterns.

Linux-Commit: 1e8fd6f9806c ("lustre: osc_cache: simplify
osc_page_gang_lookup()")

Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Mr NeilBrown <neilb@suse.com>
Change-Id: I603963b72e4299bebcdaf4064428d6281fd12def
Reviewed-on: https://review.whamcloud.com/37599
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/cl_object.h
lustre/include/lustre_osc.h
lustre/mdc/mdc_dev.c
lustre/osc/osc_cache.c
lustre/osc/osc_io.c
lustre/osc/osc_lock.c

index 99d0a59..61f214a 100644 (file)
@@ -2148,14 +2148,6 @@ static inline int cl_object_refc(struct cl_object *clob)
 
 /** \defgroup cl_page cl_page
  * @{ */
-enum {
-        CLP_GANG_OKAY = 0,
-        CLP_GANG_RESCHED,
-        CLP_GANG_AGAIN,
-        CLP_GANG_ABORT
-};
-/* callback of cl_page_gang_lookup() */
-
 struct cl_page *cl_page_find        (const struct lu_env *env,
                                      struct cl_object *obj,
                                      pgoff_t idx, struct page *vmpage,
index 0837764..f9ab603 100644 (file)
@@ -614,13 +614,13 @@ static inline void osc_io_unplug(const struct lu_env *env,
        (void)osc_io_unplug0(env, cli, osc, 0);
 }
 
-typedef int (*osc_page_gang_cbt)(const struct lu_env *, struct cl_io *,
-                                struct osc_page *, void *);
-int osc_page_gang_lookup(const struct lu_env *env, struct cl_io *io,
-                       struct osc_object *osc, pgoff_t start, pgoff_t end,
-                       osc_page_gang_cbt cb, void *cbdata);
-int osc_discard_cb(const struct lu_env *env, struct cl_io *io,
-                  struct osc_page *ops, void *cbdata);
+typedef bool (*osc_page_gang_cbt)(const struct lu_env *, struct cl_io *,
+                                 struct osc_page *, void *);
+bool osc_page_gang_lookup(const struct lu_env *env, struct cl_io *io,
+                         struct osc_object *osc, pgoff_t start, pgoff_t end,
+                         osc_page_gang_cbt cb, void *cbdata);
+bool osc_discard_cb(const struct lu_env *env, struct cl_io *io,
+                   struct osc_page *ops, void *cbdata);
 
 /* osc_dev.c */
 int osc_device_init(const struct lu_env *env, struct lu_device *d,
index 6ab9bca..69d1f07 100644 (file)
@@ -172,8 +172,8 @@ again:
 /**
  * Check if page @page is covered by an extra lock or discard it.
  */
-static int mdc_check_and_discard_cb(const struct lu_env *env, struct cl_io *io,
-                                   struct osc_page *ops, void *cbdata)
+static bool mdc_check_and_discard_cb(const struct lu_env *env, struct cl_io *io,
+                                    struct osc_page *ops, void *cbdata)
 {
        struct osc_thread_info *info = osc_env_info(env);
        struct osc_object *osc = cbdata;
@@ -200,7 +200,7 @@ static int mdc_check_and_discard_cb(const struct lu_env *env, struct cl_io *io,
        }
 
        info->oti_next_index = index + 1;
-       return CLP_GANG_OKAY;
+       return true;
 }
 
 /**
@@ -219,7 +219,6 @@ static int mdc_lock_discard_pages(const struct lu_env *env,
        struct osc_thread_info *info = osc_env_info(env);
        struct cl_io *io = &info->oti_io;
        osc_page_gang_cbt cb;
-       int res;
        int result;
 
        ENTRY;
@@ -232,15 +231,9 @@ static int mdc_lock_discard_pages(const struct lu_env *env,
 
        cb = discard ? osc_discard_cb : mdc_check_and_discard_cb;
        info->oti_fn_index = info->oti_next_index = start;
-       do {
-               res = osc_page_gang_lookup(env, io, osc, info->oti_next_index,
-                                          end, cb, (void *)osc);
-               if (info->oti_next_index > end)
-                       break;
 
-               if (res == CLP_GANG_RESCHED)
-                       cond_resched();
-       } while (res != CLP_GANG_OKAY);
+       osc_page_gang_lookup(env, io, osc, info->oti_next_index,
+                            end, cb, (void *)osc);
 out:
        cl_io_fini(env, io);
        RETURN(result);
index 917ed96..9bb9896 100644 (file)
@@ -3045,18 +3045,14 @@ EXPORT_SYMBOL(osc_cache_writeback_range);
 /**
  * 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 osc_page_gang_lookup(const struct lu_env *env, struct cl_io *io,
-                       struct osc_object *osc, pgoff_t start, pgoff_t end,
-                       osc_page_gang_cbt cb, void *cbdata)
+bool osc_page_gang_lookup(const struct lu_env *env, struct cl_io *io,
+                         struct osc_object *osc, pgoff_t start, pgoff_t end,
+                         osc_page_gang_cbt cb, void *cbdata)
 {
        struct osc_page *ops;
        struct pagevec  *pagevec;
@@ -3065,7 +3061,7 @@ int osc_page_gang_lookup(const struct lu_env *env, struct cl_io *io,
        unsigned int    nr;
        unsigned int    i;
        unsigned int    j;
-       int             res = CLP_GANG_OKAY;
+       bool            res = true;
        bool            tree_lock = true;
        ENTRY;
 
@@ -3114,7 +3110,7 @@ int osc_page_gang_lookup(const struct lu_env *env, struct cl_io *io,
 
                for (i = 0; i < j; ++i) {
                        ops = pvec[i];
-                       if (res == CLP_GANG_OKAY)
+                       if (res)
                                res = (*cb)(env, io, ops, cbdata);
 
                        page = ops->ops_cl.cpl_page;
@@ -3126,10 +3122,10 @@ int osc_page_gang_lookup(const struct lu_env *env, struct cl_io *io,
                if (nr < OTI_PVEC_SIZE || end_of_region)
                        break;
 
-               if (res == CLP_GANG_OKAY && need_resched())
-                       res = CLP_GANG_RESCHED;
-               if (res != CLP_GANG_OKAY)
+               if (!res)
                        break;
+               if (need_resched())
+                       cond_resched();
 
                spin_lock(&osc->oo_tree_lock);
                tree_lock = true;
@@ -3143,7 +3139,7 @@ EXPORT_SYMBOL(osc_page_gang_lookup);
 /**
  * Check if page @page is covered by an extra lock or discard it.
  */
-static int check_and_discard_cb(const struct lu_env *env, struct cl_io *io,
+static bool check_and_discard_cb(const struct lu_env *env, struct cl_io *io,
                                struct osc_page *ops, void *cbdata)
 {
        struct osc_thread_info *info = osc_env_info(env);
@@ -3178,10 +3174,10 @@ static int check_and_discard_cb(const struct lu_env *env, struct cl_io *io,
        }
 
        info->oti_next_index = index + 1;
-       return CLP_GANG_OKAY;
+       return true;
 }
 
-int osc_discard_cb(const struct lu_env *env, struct cl_io *io,
+bool osc_discard_cb(const struct lu_env *env, struct cl_io *io,
                   struct osc_page *ops, void *cbdata)
 {
        struct osc_thread_info *info = osc_env_info(env);
@@ -3202,7 +3198,7 @@ int osc_discard_cb(const struct lu_env *env, struct cl_io *io,
                LASSERT(page->cp_state == CPS_FREEING);
        }
 
-       return CLP_GANG_OKAY;
+       return true;
 }
 EXPORT_SYMBOL(osc_discard_cb);
 
@@ -3220,7 +3216,6 @@ int osc_lock_discard_pages(const struct lu_env *env, struct osc_object *osc,
        struct osc_thread_info *info = osc_env_info(env);
        struct cl_io *io = osc_env_thread_io(env);
        osc_page_gang_cbt cb;
-       int res;
        int result;
 
        ENTRY;
@@ -3233,15 +3228,9 @@ int osc_lock_discard_pages(const struct lu_env *env, struct osc_object *osc,
 
        cb = discard ? osc_discard_cb : check_and_discard_cb;
        info->oti_fn_index = info->oti_next_index = start;
-       do {
-               res = osc_page_gang_lookup(env, io, osc,
-                                          info->oti_next_index, end, cb, osc);
-               if (info->oti_next_index > end)
-                       break;
 
-               if (res == CLP_GANG_RESCHED)
-                       cond_resched();
-       } while (res != CLP_GANG_OKAY);
+       osc_page_gang_lookup(env, io, osc,
+                            info->oti_next_index, end, cb, osc);
 out:
        cl_io_fini(env, io);
        RETURN(result);
index 03b4cf8..3ac6102 100644 (file)
@@ -498,7 +498,7 @@ static int osc_async_upcall(void *a, int rc)
 /**
  * Checks that there are no pages being written in the extent being truncated.
  */
-static int trunc_check_cb(const struct lu_env *env, struct cl_io *io,
+static bool trunc_check_cb(const struct lu_env *env, struct cl_io *io,
                          struct osc_page *ops , void *cbdata)
 {
        struct cl_page *page = ops->ops_cl.cpl_page;
@@ -515,7 +515,7 @@ static int trunc_check_cb(const struct lu_env *env, struct cl_io *io,
                CDEBUG(D_CACHE, "page %p index %lu locked for %d.\n",
                       ops, osc_index(ops), oap->oap_cmd & OBD_BRW_RWMASK);
 
-       return CLP_GANG_OKAY;
+       return true;
 }
 
 static void osc_trunc_check(const struct lu_env *env, struct cl_io *io,
index a639568..6ad53ce 100644 (file)
@@ -649,17 +649,17 @@ out:
 }
 EXPORT_SYMBOL(osc_ldlm_glimpse_ast);
 
-static int weigh_cb(const struct lu_env *env, struct cl_io *io,
-                   struct osc_page *ops, void *cbdata)
+static bool weigh_cb(const struct lu_env *env, struct cl_io *io,
+                    struct osc_page *ops, void *cbdata)
 {
        struct cl_page *page = ops->ops_cl.cpl_page;
 
        if (cl_page_is_vmlocked(env, page) || PageDirty(page->cp_vmpage) ||
            PageWriteback(page->cp_vmpage))
-               return CLP_GANG_ABORT;
+               return false;
 
        *(pgoff_t *)cbdata = osc_index(ops) + 1;
-       return CLP_GANG_OKAY;
+       return true;
 }
 
 static unsigned long osc_lock_weight(const struct lu_env *env,
@@ -680,18 +680,14 @@ static unsigned long osc_lock_weight(const struct lu_env *env,
                RETURN(result);
 
        page_index = cl_index(obj, start);
-       do {
-               result = osc_page_gang_lookup(env, io, oscobj,
-                                             page_index, cl_index(obj, end),
-                                             weigh_cb, (void *)&page_index);
-               if (result == CLP_GANG_ABORT)
-                       break;
-               if (result == CLP_GANG_RESCHED)
-                       cond_resched();
-       } while (result != CLP_GANG_OKAY);
+
+       if (!osc_page_gang_lookup(env, io, oscobj,
+                                 page_index, cl_index(obj, end),
+                                 weigh_cb, (void *)&page_index))
+               result = 1;
        cl_io_fini(env, io);
 
-       return result == CLP_GANG_ABORT ? 1 : 0;
+       return result;
 }
 
 /**