Whamcloud - gitweb
LU-4931 ofd: use thread buffer for ladvise 89/22489/4
authorLi Xi <lixi@ddn.com>
Wed, 14 Sep 2016 03:16:08 +0000 (23:16 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 8 Oct 2016 16:38:52 +0000 (16:38 +0000)
A buffer is allocated everytime when handling willread advice.
This is not efficient, so replace it by using thread buffer
instead.

Signed-off-by: Li Xi <lixi@ddn.com>
Change-Id: I34015ea0658cb116b3348f8cab67128645718cac
Reviewed-on: http://review.whamcloud.com/22489
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/obd.h
lustre/ofd/ofd_dev.c
lustre/target/tgt_internal.h

index 76afcd1..81b958d 100644 (file)
@@ -435,6 +435,10 @@ struct niobuf_local {
        void            *lnb_data;
 };
 
+struct tgt_thread_big_cache {
+       struct niobuf_local     local[PTLRPC_MAX_BRW_PAGES];
+};
+
 #define LUSTRE_FLD_NAME         "fld"
 #define LUSTRE_SEQ_NAME         "seq"
 
index a4a8756..b5d8e74 100644 (file)
@@ -2107,22 +2107,18 @@ out:
 
 static int ofd_ladvise_prefetch(const struct lu_env *env,
                                struct ofd_object *fo,
+                               struct niobuf_local *lnb,
                                __u64 start, __u64 end)
 {
        struct ofd_thread_info  *info = ofd_info(env);
        pgoff_t                  start_index, end_index, pages;
        struct niobuf_remote     rnb;
        unsigned long            nr_local;
-       struct niobuf_local     *lnb;
        int                      rc = 0;
 
        if (end <= start)
                RETURN(-EINVAL);
 
-       OBD_ALLOC_LARGE(lnb, sizeof(*lnb) * PTLRPC_MAX_BRW_PAGES);
-       if (lnb == NULL)
-               RETURN(-ENOMEM);
-
        ofd_read_lock(env, fo);
        if (!ofd_object_exists(fo))
                GOTO(out_unlock, rc = -ENOENT);
@@ -2160,7 +2156,6 @@ static int ofd_ladvise_prefetch(const struct lu_env *env,
 
 out_unlock:
        ofd_read_unlock(env, fo);
-       OBD_FREE_LARGE(lnb, sizeof(*lnb) * PTLRPC_MAX_BRW_PAGES);
        RETURN(rc);
 }
 
@@ -2176,22 +2171,26 @@ out_unlock:
  */
 static int ofd_ladvise_hdl(struct tgt_session_info *tsi)
 {
-       struct ptlrpc_request   *req = tgt_ses_req(tsi);
-       struct obd_export       *exp = tsi->tsi_exp;
-       struct ofd_device       *ofd = ofd_exp(exp);
-       struct ost_body         *body, *repbody;
-       struct ofd_thread_info  *info;
-       struct ofd_object       *fo;
-       const struct lu_env     *env = req->rq_svc_thread->t_env;
-       int                      rc = 0;
-       struct lu_ladvise       *ladvise;
-       int                      num_advise;
-       struct ladvise_hdr      *ladvise_hdr;
-       struct obd_ioobj         ioo;
-       struct lustre_handle     lockh = { 0 };
-       __u64                    flags = 0;
-       int                      i;
-       struct dt_object        *dob;
+       struct ptlrpc_request *req = tgt_ses_req(tsi);
+       struct obd_export *exp = tsi->tsi_exp;
+       struct ofd_device *ofd = ofd_exp(exp);
+       struct ost_body *body, *repbody;
+       struct ofd_thread_info *info;
+       struct ofd_object *fo;
+       struct ptlrpc_thread *svc_thread = req->rq_svc_thread;
+       const struct lu_env *env = svc_thread->t_env;
+       struct tgt_thread_big_cache *tbc = svc_thread->t_data;
+       int rc = 0;
+       struct lu_ladvise *ladvise;
+       int num_advise;
+       struct ladvise_hdr *ladvise_hdr;
+       struct obd_ioobj ioo;
+       struct lustre_handle lockh = { 0 };
+       __u64 flags = 0;
+       int i;
+       struct dt_object *dob;
+       __u64 start;
+       __u64 end;
        ENTRY;
 
        CFS_FAIL_TIMEOUT(OBD_FAIL_OST_LADVISE_PAUSE, cfs_fail_val);
@@ -2241,7 +2240,9 @@ static int ofd_ladvise_hdl(struct tgt_session_info *tsi)
        dob = ofd_object_child(fo);
 
        for (i = 0; i < num_advise; i++, ladvise++) {
-               if (ladvise->lla_end <= ladvise->lla_start) {
+               start = ladvise->lla_start;
+               end = ladvise->lla_end;
+               if (end <= start) {
                        rc = err_serious(-EPROTO);
                        break;
                }
@@ -2252,20 +2253,20 @@ static int ofd_ladvise_hdl(struct tgt_session_info *tsi)
                        rc = -ENOTSUPP;
                        break;
                case LU_LADVISE_WILLREAD:
+                       if (tbc == NULL)
+                               RETURN(-ENOMEM);
+
                        ioo.ioo_oid = body->oa.o_oi;
                        ioo.ioo_bufcnt = 1;
                        rc = tgt_extent_lock(exp->exp_obd->obd_namespace,
-                                            &tsi->tsi_resid,
-                                            ladvise->lla_start,
-                                            ladvise->lla_end - 1,
+                                            &tsi->tsi_resid, start, end - 1,
                                             &lockh, LCK_PR, &flags);
                        if (rc != 0)
                                break;
 
-                       req->rq_status = ofd_ladvise_prefetch(env,
-                               fo,
-                               ladvise->lla_start,
-                               ladvise->lla_end);
+                       req->rq_status = ofd_ladvise_prefetch(env, fo,
+                                                             tbc->local,
+                                                             start, end);
                        tgt_extent_unlock(&lockh, LCK_PR);
                        break;
                case LU_LADVISE_DONTNEED:
index 2a2aa36..3cc6979 100644 (file)
@@ -238,10 +238,6 @@ const char *update_op_str(__u16 opcode);
 
 extern struct page *tgt_page_to_corrupt;
 
-struct tgt_thread_big_cache {
-       struct niobuf_local     local[PTLRPC_MAX_BRW_PAGES];
-};
-
 int tgt_server_data_init(const struct lu_env *env, struct lu_target *tgt);
 int tgt_txn_start_cb(const struct lu_env *env, struct thandle *th,
                     void *cookie);