Whamcloud - gitweb
LU-5548 ptlrpc: avoid list scan in ptlrpcd_check 65/12265/3
authorLiang Zhen <liang.zhen@intel.com>
Tue, 19 Aug 2014 02:55:04 +0000 (10:55 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 1 Dec 2014 04:21:03 +0000 (04:21 +0000)
ptlrpcd_check() always scan all requests on ptlrpc_request_set
and try to finish completed requests, this is low efficiency.
Even worse, l_wait_event() always checks condition for twice
before sleeping and one more time after waking up, which means
it will call ptlrpcd_check() for three times in each loop.

This patch will move completed requests at the head of list
in ptlrpc_check_set(), with this change ptlrpcd_check doesn't
need to scan all requests anymore.

Signed-off-by: Liang Zhen <liang.zhen@intel.com>
Signed-off-by: Mikhail Pershin <mike.pershin@intel.com>
Change-Id: I770016d4a2bcd51603b390b41427eb64ff52f71c
Reviewed-on: http://review.whamcloud.com/12265
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/ptlrpc/client.c
lustre/ptlrpc/ptlrpcd.c

index d2924de..f3793ca 100644 (file)
@@ -1518,13 +1518,15 @@ static inline int ptlrpc_set_producer(struct ptlrpc_request_set *set)
  */
 int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
 {
-        cfs_list_t *tmp, *next;
+       cfs_list_t *tmp, *next;
+       cfs_list_t  comp_reqs;
         int force_timer_recalc = 0;
         ENTRY;
 
         if (cfs_atomic_read(&set->set_remaining) == 0)
                 RETURN(1);
 
+       CFS_INIT_LIST_HEAD(&comp_reqs);
         cfs_list_for_each_safe(tmp, next, &set->set_requests) {
                 struct ptlrpc_request *req =
                         cfs_list_entry(tmp, struct ptlrpc_request,
@@ -1599,8 +1601,10 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
                         ptlrpc_rqphase_move(req, req->rq_next_phase);
                 }
 
-                if (req->rq_phase == RQ_PHASE_COMPLETE)
+                if (req->rq_phase == RQ_PHASE_COMPLETE) {
+                       cfs_list_move_tail(&req->rq_set_chain, &comp_reqs);
                         continue;
+               }
 
                 if (req->rq_phase == RQ_PHASE_INTERPRET)
                         GOTO(interpret, req->rq_status);
@@ -1885,9 +1889,14 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
                        if (req->rq_status != 0)
                                set->set_rc = req->rq_status;
                        ptlrpc_req_finished(req);
+               } else {
+                       cfs_list_move_tail(&req->rq_set_chain, &comp_reqs);
                }
         }
 
+       /* move completed request at the head of list so it's easier for
+        * caller to find them */
+       cfs_list_splice(&comp_reqs, &set->set_requests);
         /* If we hit an error, we want to recover promptly. */
         RETURN(cfs_atomic_read(&set->set_remaining) == 0 || force_timer_recalc);
 }
index ecebfc9..d058510 100644 (file)
@@ -330,22 +330,17 @@ static int ptlrpcd_check(struct lu_env *env, struct ptlrpcd_ctl *pc)
         if (cfs_atomic_read(&set->set_remaining))
                 rc |= ptlrpc_check_set(env, set);
 
-        if (!cfs_list_empty(&set->set_requests)) {
-                /*
-                 * XXX: our set never completes, so we prune the completed
-                 * reqs after each iteration. boy could this be smarter.
-                 */
-                cfs_list_for_each_safe(pos, tmp, &set->set_requests) {
-                        req = cfs_list_entry(pos, struct ptlrpc_request,
-                                             rq_set_chain);
-                        if (req->rq_phase != RQ_PHASE_COMPLETE)
-                                continue;
-
-                        cfs_list_del_init(&req->rq_set_chain);
-                        req->rq_set = NULL;
-                        ptlrpc_req_finished(req);
-                }
-        }
+       /* NB: ptlrpc_check_set has already moved completed request at the
+        * head of seq::set_requests */
+       cfs_list_for_each_safe(pos, tmp, &set->set_requests) {
+               req = cfs_list_entry(pos, struct ptlrpc_request, rq_set_chain);
+               if (req->rq_phase != RQ_PHASE_COMPLETE)
+                       break;
+
+               cfs_list_del_init(&req->rq_set_chain);
+               req->rq_set = NULL;
+               ptlrpc_req_finished(req);
+       }
 
         if (rc == 0) {
                 /*