From c29cf72acd431e65f0438804561e7c30feef0366 Mon Sep 17 00:00:00 2001 From: Li Xi Date: Tue, 13 Sep 2016 23:16:08 -0400 Subject: [PATCH] LU-4931 ofd: use thread buffer for ladvise 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 Change-Id: I34015ea0658cb116b3348f8cab67128645718cac Reviewed-on: http://review.whamcloud.com/22489 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/include/obd.h | 4 +++ lustre/ofd/ofd_dev.c | 61 ++++++++++++++++++++++---------------------- lustre/target/tgt_internal.h | 4 --- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/lustre/include/obd.h b/lustre/include/obd.h index 76afcd1..81b958d 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -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" diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index a4a8756..b5d8e74 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -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: diff --git a/lustre/target/tgt_internal.h b/lustre/target/tgt_internal.h index 2a2aa36..3cc6979 100644 --- a/lustre/target/tgt_internal.h +++ b/lustre/target/tgt_internal.h @@ -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); -- 1.8.3.1