Whamcloud - gitweb
LU-1757 brw: add short io osc/ost transfer.
[fs/lustre-release.git] / lustre / osc / osc_page.c
index ce87082..e929211 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
  */
@@ -27,7 +23,7 @@
  * 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, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -40,8 +36,9 @@
  */
 
 #define DEBUG_SUBSYSTEM S_OSC
+#include <lustre_osc.h>
 
-#include "osc_cl_internal.h"
+#include "osc_internal.h"
 
 static void osc_lru_del(struct client_obd *cli, struct osc_page *opg);
 static void osc_lru_use(struct client_obd *cli, struct osc_page *opg);
@@ -53,115 +50,7 @@ static int osc_lru_alloc(const struct lu_env *env, struct client_obd *cli,
  */
 
 /*
- * Comment out osc_page_protected because it may sleep inside the
- * the client_obd_list_lock.
- * client_obd_list_lock -> osc_ap_completion -> osc_completion ->
- *   -> osc_page_protected -> osc_page_is_dlocked -> osc_match_base
- *   -> ldlm_lock_match -> sptlrpc_import_check_ctx -> sleep.
- */
-#if 0
-static int osc_page_is_dlocked(const struct lu_env *env,
-                               const struct osc_page *opg,
-                               enum cl_lock_mode mode, int pending, int unref)
-{
-       struct cl_page         *page;
-       struct osc_object      *obj;
-       struct osc_thread_info *info;
-       struct ldlm_res_id     *resname;
-       struct lustre_handle   *lockh;
-       union ldlm_policy_data *policy;
-       enum ldlm_mode          dlmmode;
-       __u64                   flags;
-
-       might_sleep();
-
-       info = osc_env_info(env);
-       resname = &info->oti_resname;
-       policy = &info->oti_policy;
-       lockh = &info->oti_handle;
-       page = opg->ops_cl.cpl_page;
-       obj = cl2osc(opg->ops_cl.cpl_obj);
-
-       flags = LDLM_FL_TEST_LOCK | LDLM_FL_BLOCK_GRANTED;
-       if (pending)
-               flags |= LDLM_FL_CBPENDING;
-
-       dlmmode = osc_cl_lock2ldlm(mode) | LCK_PW;
-       osc_lock_build_res(env, obj, resname);
-       osc_index2policy(policy, page->cp_obj, osc_index(opg), osc_index(opg));
-       return osc_match_base(osc_export(obj), resname, LDLM_EXTENT, policy,
-                             dlmmode, &flags, NULL, lockh, unref);
-}
-
-/**
- * Checks an invariant that a page in the cache is covered by a lock, as
- * needed.
- */
-static int osc_page_protected(const struct lu_env *env,
-                              const struct osc_page *opg,
-                              enum cl_lock_mode mode, int unref)
-{
-        struct cl_object_header *hdr;
-        struct cl_lock          *scan;
-        struct cl_page          *page;
-        struct cl_lock_descr    *descr;
-        int result;
-
-        LINVRNT(!opg->ops_temp);
-
-        page = opg->ops_cl.cpl_page;
-        if (page->cp_owner != NULL &&
-            cl_io_top(page->cp_owner)->ci_lockreq == CILR_NEVER)
-                /*
-                 * If IO is done without locks (liblustre, or lloop), lock is
-                 * not required.
-                 */
-                result = 1;
-        else
-                /* otherwise check for a DLM lock */
-        result = osc_page_is_dlocked(env, opg, mode, 1, unref);
-        if (result == 0) {
-                /* maybe this page is a part of a lockless io? */
-                hdr = cl_object_header(opg->ops_cl.cpl_obj);
-                descr = &osc_env_info(env)->oti_descr;
-                descr->cld_mode = mode;
-               descr->cld_start = osc_index(opg);
-               descr->cld_end   = osc_index(opg);
-               spin_lock(&hdr->coh_lock_guard);
-               list_for_each_entry(scan, &hdr->coh_locks, cll_linkage) {
-                        /*
-                         * Lock-less sub-lock has to be either in HELD state
-                         * (when io is actively going on), or in CACHED state,
-                         * when top-lock is being unlocked:
-                         * cl_io_unlock()->cl_unuse()->...->lov_lock_unuse().
-                         */
-                        if ((scan->cll_state == CLS_HELD ||
-                             scan->cll_state == CLS_CACHED) &&
-                            cl_lock_ext_match(&scan->cll_descr, descr)) {
-                                struct osc_lock *olck;
-
-                                olck = osc_lock_at(scan);
-                                result = osc_lock_is_lockless(olck);
-                                break;
-                        }
-                }
-               spin_unlock(&hdr->coh_lock_guard);
-        }
-        return result;
-}
-#else
-static int osc_page_protected(const struct lu_env *env,
-                              const struct osc_page *opg,
-                              enum cl_lock_mode mode, int unref)
-{
-        return 1;
-}
-#endif
-
-/*****************************************************************************
- *
  * Page operations.
- *
  */
 static void osc_page_transfer_get(struct osc_page *opg, const char *label)
 {
@@ -207,8 +96,6 @@ int osc_page_cache_add(const struct lu_env *env,
        int result;
        ENTRY;
 
-       LINVRNT(osc_page_protected(env, opg, CLM_WRITE, 0));
-
        osc_page_transfer_get(opg, "transfer\0cache");
        result = osc_queue_async_io(env, io, opg);
        if (result != 0)
@@ -251,7 +138,7 @@ static int osc_page_print(const struct lu_env *env,
 
        return (*printer)(env, cookie, LUSTRE_OSC_NAME"-page@%p %lu: "
                          "1< %#x %d %u %s %s > "
-                         "2< "LPD64" %u %u %#x %#x | %p %p %p > "
+                         "2< %lld %u %u %#x %#x | %p %p %p > "
                          "3< %d %lu %d > "
                          "4< %d %d %d %lu %s | %s %s %s %s > "
                          "5< %s %s %s %s | %d %s | %d %s %s>\n",
@@ -290,17 +177,15 @@ static int osc_page_print(const struct lu_env *env,
 }
 
 static void osc_page_delete(const struct lu_env *env,
-                            const struct cl_page_slice *slice)
+                           const struct cl_page_slice *slice)
 {
        struct osc_page   *opg = cl2osc_page(slice);
        struct osc_object *obj = cl2osc(opg->ops_cl.cpl_obj);
-        int rc;
-
-        LINVRNT(opg->ops_temp || osc_page_protected(env, opg, CLM_READ, 1));
+       int rc;
 
-        ENTRY;
-        CDEBUG(D_TRACE, "%p\n", opg);
-        osc_page_transfer_put(env, opg);
+       ENTRY;
+       CDEBUG(D_TRACE, "%p\n", opg);
+       osc_page_transfer_put(env, opg);
        rc = osc_teardown_async_page(env, obj, opg);
        if (rc) {
                CL_PAGE_DEBUG(D_ERROR, env, slice->cpl_page,
@@ -329,33 +214,29 @@ static void osc_page_clip(const struct lu_env *env,
                          const struct cl_page_slice *slice,
                          int from, int to)
 {
-        struct osc_page       *opg = cl2osc_page(slice);
-        struct osc_async_page *oap = &opg->ops_oap;
-
-        LINVRNT(osc_page_protected(env, opg, CLM_READ, 0));
+       struct osc_page       *opg = cl2osc_page(slice);
+       struct osc_async_page *oap = &opg->ops_oap;
 
-        opg->ops_from = from;
-        opg->ops_to   = to;
+       opg->ops_from = from;
+       opg->ops_to   = to;
        spin_lock(&oap->oap_lock);
        oap->oap_async_flags |= ASYNC_COUNT_STABLE;
        spin_unlock(&oap->oap_lock);
 }
 
 static int osc_page_cancel(const struct lu_env *env,
-                           const struct cl_page_slice *slice)
+                          const struct cl_page_slice *slice)
 {
        struct osc_page *opg = cl2osc_page(slice);
-        int rc = 0;
-
-        LINVRNT(osc_page_protected(env, opg, CLM_READ, 0));
+       int rc = 0;
 
-        /* Check if the transferring against this page
-         * is completed, or not even queued. */
-        if (opg->ops_transfer_pinned)
-                /* FIXME: may not be interrupted.. */
+       /* Check if the transferring against this page
+        * is completed, or not even queued. */
+       if (opg->ops_transfer_pinned)
+               /* FIXME: may not be interrupted.. */
                rc = osc_cancel_async_page(env, opg);
-        LASSERT(ergo(rc == 0, opg->ops_transfer_pinned == 0));
-        return rc;
+       LASSERT(ergo(rc == 0, opg->ops_transfer_pinned == 0));
+       return rc;
 }
 
 static int osc_page_flush(const struct lu_env *env,
@@ -382,38 +263,39 @@ int osc_page_init(const struct lu_env *env, struct cl_object *obj,
 {
        struct osc_object *osc = cl2osc(obj);
        struct osc_page   *opg = cl_object_page_slice(obj, page);
+       struct osc_io *oio = osc_env_io(env);
        int result;
 
        opg->ops_from = 0;
-       opg->ops_to   = PAGE_CACHE_SIZE;
+       opg->ops_to   = PAGE_SIZE;
+
+       INIT_LIST_HEAD(&opg->ops_lru);
 
        result = osc_prep_async_page(osc, opg, page->cp_vmpage,
                                     cl_offset(obj, index));
-       if (result == 0) {
-               struct osc_io *oio = osc_env_io(env);
-               opg->ops_srvlock = osc_io_srvlock(oio);
-               cl_page_slice_add(page, &opg->ops_cl, obj, index,
-                                 &osc_page_ops);
-       }
-       /*
-        * Cannot assert osc_page_protected() here as read-ahead
-        * creates temporary pages outside of a lock.
-        */
-#ifdef CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK
-       opg->ops_temp = !osc_page_protected(env, opg, CLM_READ, 1);
-#endif
-       INIT_LIST_HEAD(&opg->ops_lru);
+       if (result != 0)
+               return result;
+
+       opg->ops_srvlock = osc_io_srvlock(oio);
+       cl_page_slice_add(page, &opg->ops_cl, obj, index,
+                         &osc_page_ops);
+
 
        /* reserve an LRU space for this page */
-       if (page->cp_type == CPT_CACHEABLE && result == 0) {
+       if (page->cp_type == CPT_CACHEABLE) {
                result = osc_lru_alloc(env, osc_cli(osc), opg);
                if (result == 0) {
-                       spin_lock(&osc->oo_tree_lock);
-                       result = radix_tree_insert(&osc->oo_tree, index, opg);
-                       if (result == 0)
-                               ++osc->oo_npages;
-                       spin_unlock(&osc->oo_tree_lock);
-                       LASSERT(result == 0);
+                       result = radix_tree_preload(GFP_NOFS);
+                       if (result == 0) {
+                               spin_lock(&osc->oo_tree_lock);
+                               result = radix_tree_insert(&osc->oo_tree,
+                                                          index, opg);
+                               if (result == 0)
+                                       ++osc->oo_npages;
+                               spin_unlock(&osc->oo_tree_lock);
+
+                               radix_tree_preload_end();
+                       }
                }
        }
 
@@ -429,9 +311,6 @@ void osc_page_submit(const struct lu_env *env, struct osc_page *opg,
 {
        struct osc_async_page *oap = &opg->ops_oap;
 
-       LINVRNT(osc_page_protected(env, opg,
-                                  crt == CRT_WRITE ? CLM_WRITE : CLM_READ, 1));
-
        LASSERTF(oap->oap_magic == OAP_MAGIC, "Bad oap magic: oap %p, "
                 "magic 0x%x\n", oap, oap->oap_magic);
        LASSERT(oap->oap_async_flags & ASYNC_READY);
@@ -506,11 +385,18 @@ static int osc_cache_too_much(struct client_obd *cli)
                else if (pages >= budget / 2)
                        return lru_shrink_min(cli);
        } else {
-               int duration = cfs_time_current_sec() - cli->cl_lru_last_used;
+               time64_t duration = ktime_get_real_seconds();
+               long timediff;
 
                /* knock out pages by duration of no IO activity */
-               duration >>= 6; /* approximately 1 minute */
-               if (duration > 0 && pages >= budget / duration)
+               duration -= cli->cl_lru_last_used;
+               /*
+                * The difference shouldn't be more than 70 years
+                * so we can safely case to a long. Round to
+                * approximately 1 minute.
+                */
+               timediff = (long)(duration >> 6);
+               if (timediff > 0 && pages >= budget / timediff)
                        return lru_shrink_min(cli);
        }
        return 0;
@@ -559,7 +445,7 @@ void osc_lru_add_batch(struct client_obd *cli, struct list_head *plist)
                list_splice_tail(&lru, &cli->cl_lru_list);
                atomic_long_sub(npages, &cli->cl_lru_busy);
                atomic_long_add(npages, &cli->cl_lru_in_list);
-               cli->cl_lru_last_used = cfs_time_current_sec();
+               cli->cl_lru_last_used = ktime_get_real_seconds();
                spin_unlock(&cli->cl_lru_list_lock);
 
                if (waitqueue_active(&osc_lru_waitq))
@@ -605,17 +491,19 @@ static void osc_lru_del(struct client_obd *cli, struct osc_page *opg)
 }
 
 /**
- * Delete page from LRUlist for redirty.
+ * Delete page from LRU list for redirty.
  */
 static void osc_lru_use(struct client_obd *cli, struct osc_page *opg)
 {
        /* If page is being transferred for the first time,
         * ops_lru should be empty */
-       if (opg->ops_in_lru && !list_empty(&opg->ops_lru)) {
+       if (opg->ops_in_lru) {
                spin_lock(&cli->cl_lru_list_lock);
-               __osc_lru_del(cli, opg);
+               if (!list_empty(&opg->ops_lru)) {
+                       __osc_lru_del(cli, opg);
+                       atomic_long_inc(&cli->cl_lru_busy);
+               }
                spin_unlock(&cli->cl_lru_list_lock);
-               atomic_long_inc(&cli->cl_lru_busy);
        }
 }
 
@@ -986,17 +874,27 @@ void osc_lru_unreserve(struct client_obd *cli, unsigned long npages)
  * are likely from the same page zone.
  */
 static inline void unstable_page_accounting(struct ptlrpc_bulk_desc *desc,
+                                           struct osc_brw_async_args *aa,
                                            int factor)
 {
-       int page_count = desc->bd_iov_count;
+       int page_count;
        void *zone = NULL;
        int count = 0;
        int i;
 
-       LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
+       if (desc != NULL) {
+               LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
+               page_count = desc->bd_iov_count;
+       } else {
+               page_count = aa->aa_page_count;
+       }
 
        for (i = 0; i < page_count; i++) {
-               void *pz = page_zone(BD_GET_KIOV(desc, i).kiov_page);
+               void *pz;
+               if (desc)
+                       pz = page_zone(BD_GET_KIOV(desc, i).kiov_page);
+               else
+                       pz = page_zone(aa->aa_ppga[i]->pg);
 
                if (likely(pz == zone)) {
                        ++count;
@@ -1015,14 +913,16 @@ static inline void unstable_page_accounting(struct ptlrpc_bulk_desc *desc,
                mod_zone_page_state(zone, NR_UNSTABLE_NFS, factor * count);
 }
 
-static inline void add_unstable_page_accounting(struct ptlrpc_bulk_desc *desc)
+static inline void add_unstable_page_accounting(struct ptlrpc_bulk_desc *desc,
+                                               struct osc_brw_async_args *aa)
 {
-       unstable_page_accounting(desc, 1);
+       unstable_page_accounting(desc, aa, 1);
 }
 
-static inline void dec_unstable_page_accounting(struct ptlrpc_bulk_desc *desc)
+static inline void dec_unstable_page_accounting(struct ptlrpc_bulk_desc *desc,
+                                               struct osc_brw_async_args *aa)
 {
-       unstable_page_accounting(desc, -1);
+       unstable_page_accounting(desc, aa, -1);
 }
 
 /**
@@ -1039,12 +939,19 @@ static inline void dec_unstable_page_accounting(struct ptlrpc_bulk_desc *desc)
 void osc_dec_unstable_pages(struct ptlrpc_request *req)
 {
        struct ptlrpc_bulk_desc *desc       = req->rq_bulk;
+       struct osc_brw_async_args *aa = (void *)&req->rq_async_args;
        struct client_obd       *cli        = &req->rq_import->imp_obd->u.cli;
-       int                      page_count = desc->bd_iov_count;
+       int                      page_count;
        long                     unstable_count;
 
+       if (desc)
+               page_count = desc->bd_iov_count;
+       else
+               page_count = aa->aa_page_count;
+
        LASSERT(page_count >= 0);
-       dec_unstable_page_accounting(desc);
+
+       dec_unstable_page_accounting(desc, aa);
 
        unstable_count = atomic_long_sub_return(page_count,
                                                &cli->cl_unstable_count);
@@ -1066,14 +973,20 @@ void osc_dec_unstable_pages(struct ptlrpc_request *req)
 void osc_inc_unstable_pages(struct ptlrpc_request *req)
 {
        struct ptlrpc_bulk_desc *desc = req->rq_bulk;
+       struct osc_brw_async_args *aa = (void *)&req->rq_async_args;
        struct client_obd       *cli  = &req->rq_import->imp_obd->u.cli;
-       long                     page_count = desc->bd_iov_count;
+       long                     page_count;
 
        /* No unstable page tracking */
        if (cli->cl_cache == NULL || !cli->cl_cache->ccc_unstable_check)
                return;
 
-       add_unstable_page_accounting(desc);
+       if (desc)
+               page_count = desc->bd_iov_count;
+       else
+               page_count = aa->aa_page_count;
+
+       add_unstable_page_accounting(desc, aa);
        atomic_long_add(page_count, &cli->cl_unstable_count);
        atomic_long_add(page_count, &cli->cl_cache->ccc_unstable_nr);