4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/ptlrpc/ptlrpcd.c
35 /** \defgroup ptlrpcd PortalRPC daemon
37 * ptlrpcd is a special thread with its own set where other user might add
38 * requests when they don't want to wait for their completion.
39 * PtlRPCD will take care of sending such requests and then processing their
40 * replies and calling completion callbacks as necessary.
41 * The callbacks are called directly from ptlrpcd context.
42 * It is important to never significantly block (esp. on RPCs!) within such
43 * completion handler or a deadlock might occur where ptlrpcd enters some
44 * callback that attempts to send another RPC and wait for it to return,
45 * during which time ptlrpcd is completely blocked, so e.g. if import
46 * fails, recovery cannot progress because connection requests are also
52 #define DEBUG_SUBSYSTEM S_RPC
54 #include <linux/kthread.h>
55 #include <libcfs/libcfs.h>
56 #include <lustre_net.h>
57 #include <lustre_lib.h>
58 #include <lustre_ha.h>
59 #include <obd_class.h> /* for obd_zombie */
60 #include <obd_support.h> /* for OBD_FAIL_CHECK */
61 #include <cl_object.h> /* cl_env_{get,put}() */
62 #include <lprocfs_status.h>
64 #include "ptlrpc_internal.h"
66 /* One of these per CPT. */
74 struct ptlrpcd_ctl pd_threads[0];
78 * max_ptlrpcds is obsolete, but retained to ensure that the kernel
79 * module will load on a system where it has been tuned.
80 * A value other than 0 implies it was tuned, in which case the value
81 * is used to derive a setting for ptlrpcd_per_cpt_max.
83 static int max_ptlrpcds;
84 module_param(max_ptlrpcds, int, 0644);
85 MODULE_PARM_DESC(max_ptlrpcds,
86 "Max ptlrpcd thread count to be started (obsolete).");
89 * ptlrpcd_bind_policy is obsolete, but retained to ensure that
90 * the kernel module will load on a system where it has been tuned.
91 * A value other than 0 implies it was tuned, in which case the value
92 * is used to derive a setting for ptlrpcd_partner_group_size.
94 static int ptlrpcd_bind_policy;
95 module_param(ptlrpcd_bind_policy, int, 0644);
96 MODULE_PARM_DESC(ptlrpcd_bind_policy,
97 "Ptlrpcd threads binding mode (obsolete).");
100 * ptlrpcd_per_cpt_max: The maximum number of ptlrpcd threads to run
103 static int ptlrpcd_per_cpt_max;
104 module_param(ptlrpcd_per_cpt_max, int, 0644);
105 MODULE_PARM_DESC(ptlrpcd_per_cpt_max,
106 "Max ptlrpcd thread count to be started per CPT.");
109 * ptlrpcd_partner_group_size: The desired number of threads in each
110 * ptlrpcd partner thread group. Default is 2, corresponding to the
111 * old PDB_POLICY_PAIR. A negative value makes all ptlrpcd threads in
112 * a CPT partners of each other.
114 static int ptlrpcd_partner_group_size;
115 module_param(ptlrpcd_partner_group_size, int, 0644);
116 MODULE_PARM_DESC(ptlrpcd_partner_group_size,
117 "Number of ptlrpcd threads in a partner group.");
120 * ptlrpcd_cpts: A CPT string describing the CPU partitions that
121 * ptlrpcd threads should run on. Used to make ptlrpcd threads run on
122 * a subset of all CPTs.
126 * run ptlrpcd threads only on CPT 2.
130 * run ptlrpcd threads on CPTs 0, 1, 2, and 3.
132 * ptlrpcd_cpts=[0-3,5,7]
133 * run ptlrpcd threads on CPTS 0, 1, 2, 3, 5, and 7.
135 static char *ptlrpcd_cpts;
136 module_param(ptlrpcd_cpts, charp, 0644);
137 MODULE_PARM_DESC(ptlrpcd_cpts,
138 "CPU partitions ptlrpcd threads should run in");
140 /* ptlrpcds_cpt_idx maps cpt numbers to an index in the ptlrpcds array. */
141 static int *ptlrpcds_cpt_idx;
143 /* ptlrpcds_num is the number of entries in the ptlrpcds array. */
144 static int ptlrpcds_num;
145 static struct ptlrpcd **ptlrpcds;
148 * In addition to the regular thread pool above, there is a single
149 * global recovery thread. Recovery isn't critical for performance,
150 * and doesn't block, but must always be able to proceed, and it is
151 * possible that all normal ptlrpcd threads are blocked. Hence the
152 * need for a dedicated thread.
154 static struct ptlrpcd_ctl ptlrpcd_rcv;
156 struct mutex ptlrpcd_mutex;
157 static int ptlrpcd_users = 0;
159 void ptlrpcd_wake(struct ptlrpc_request *req)
161 struct ptlrpc_request_set *set = req->rq_set;
163 LASSERT(set != NULL);
164 wake_up(&set->set_waitq);
166 EXPORT_SYMBOL(ptlrpcd_wake);
168 static struct ptlrpcd_ctl *
169 ptlrpcd_select_pc(struct ptlrpc_request *req)
175 if (req != NULL && req->rq_send_state != LUSTRE_IMP_FULL)
178 cpt = cfs_cpt_current(cfs_cpt_tab, 1);
179 if (ptlrpcds_cpt_idx == NULL)
182 idx = ptlrpcds_cpt_idx[cpt];
185 /* We do not care whether it is strict load balance. */
187 if (++idx == pd->pd_nthreads)
191 return &pd->pd_threads[idx];
195 * Move all request from an existing request set to the ptlrpcd queue.
196 * All requests from the set must be in phase RQ_PHASE_NEW.
198 void ptlrpcd_add_rqset(struct ptlrpc_request_set *set)
200 struct list_head *tmp, *pos;
201 struct ptlrpcd_ctl *pc;
202 struct ptlrpc_request_set *new;
205 pc = ptlrpcd_select_pc(NULL);
208 list_for_each_safe(pos, tmp, &set->set_requests) {
209 struct ptlrpc_request *req =
210 list_entry(pos, struct ptlrpc_request,
213 LASSERT(req->rq_phase == RQ_PHASE_NEW);
215 req->rq_queued_time = ktime_get_seconds();
218 spin_lock(&new->set_new_req_lock);
219 list_splice_init(&set->set_requests, &new->set_new_requests);
220 i = atomic_read(&set->set_remaining);
221 count = atomic_add_return(i, &new->set_new_count);
222 atomic_set(&set->set_remaining, 0);
223 spin_unlock(&new->set_new_req_lock);
225 wake_up(&new->set_waitq);
228 * XXX: It maybe unnecessary to wakeup all the partners. But to
229 * guarantee the async RPC can be processed ASAP, we have
230 * no other better choice. It maybe fixed in future.
232 for (i = 0; i < pc->pc_npartners; i++)
233 wake_up(&pc->pc_partners[i]->pc_set->set_waitq);
238 * Return transferred RPCs count.
240 static int ptlrpcd_steal_rqset(struct ptlrpc_request_set *des,
241 struct ptlrpc_request_set *src)
243 struct ptlrpc_request *req, *tmp;
246 spin_lock(&src->set_new_req_lock);
247 if (likely(!list_empty(&src->set_new_requests))) {
248 list_for_each_entry_safe(req, tmp, &src->set_new_requests,
252 list_splice_init(&src->set_new_requests,
254 rc = atomic_read(&src->set_new_count);
255 atomic_add(rc, &des->set_remaining);
256 atomic_set(&src->set_new_count, 0);
258 spin_unlock(&src->set_new_req_lock);
263 * Requests that are added to the ptlrpcd queue are sent via
264 * ptlrpcd_check->ptlrpc_check_set().
266 void ptlrpcd_add_req(struct ptlrpc_request *req)
268 struct ptlrpcd_ctl *pc;
271 lustre_msg_set_jobid(req->rq_reqmsg, NULL);
273 spin_lock(&req->rq_lock);
274 if (req->rq_invalid_rqset) {
275 req->rq_invalid_rqset = 0;
276 spin_unlock(&req->rq_lock);
277 if (wait_event_idle_timeout(req->rq_set_waitq,
279 cfs_time_seconds(5)) == 0)
280 l_wait_event_abortable(req->rq_set_waitq,
281 req->rq_set == NULL);
282 } else if (req->rq_set) {
284 * If we have a vaid "rq_set", just reuse it to avoid double
287 LASSERT(req->rq_phase == RQ_PHASE_NEW);
288 LASSERT(req->rq_send_state == LUSTRE_IMP_REPLAY);
290 /* ptlrpc_check_set will decrease the count */
291 atomic_inc(&req->rq_set->set_remaining);
292 spin_unlock(&req->rq_lock);
293 wake_up(&req->rq_set->set_waitq);
296 spin_unlock(&req->rq_lock);
299 pc = ptlrpcd_select_pc(req);
301 DEBUG_REQ(D_INFO, req, "add req [%p] to pc [%s+%d]",
302 req, pc->pc_name, pc->pc_index);
304 ptlrpc_set_add_new_req(pc, req);
306 EXPORT_SYMBOL(ptlrpcd_add_req);
308 static inline void ptlrpc_reqset_get(struct ptlrpc_request_set *set)
310 atomic_inc(&set->set_refcount);
314 * Check if there is more work to do on ptlrpcd set.
317 static int ptlrpcd_check(struct lu_env *env, struct ptlrpcd_ctl *pc)
319 struct ptlrpc_request *req, *tmp;
320 struct ptlrpc_request_set *set = pc->pc_set;
326 if (atomic_read(&set->set_new_count)) {
327 spin_lock(&set->set_new_req_lock);
328 if (likely(!list_empty(&set->set_new_requests))) {
329 list_splice_init(&set->set_new_requests,
331 atomic_add(atomic_read(&set->set_new_count),
332 &set->set_remaining);
333 atomic_set(&set->set_new_count, 0);
335 * Need to calculate its timeout.
339 spin_unlock(&set->set_new_req_lock);
343 * We should call lu_env_refill() before handling new requests to make
344 * sure that env key the requests depending on really exists.
346 rc2 = lu_env_refill(env);
349 * XXX This is very awkward situation, because
350 * execution can neither continue (request
351 * interpreters assume that env is set up), nor repeat
352 * the loop (as this potentially results in a tight
353 * loop of -ENOMEM's).
355 * Fortunately, refill only ever does something when
356 * new modules are loaded, i.e., early during boot up.
358 CERROR("Failure to refill session: %d\n", rc2);
362 if (atomic_read(&set->set_remaining))
363 rc |= ptlrpc_check_set(env, set);
366 * NB: ptlrpc_check_set has already moved complted request at the
367 * head of seq::set_requests
369 list_for_each_entry_safe(req, tmp, &set->set_requests, rq_set_chain) {
370 if (req->rq_phase != RQ_PHASE_COMPLETE)
373 list_del_init(&req->rq_set_chain);
375 ptlrpc_req_finished(req);
380 * If new requests have been added, make sure to wake up.
382 rc = atomic_read(&set->set_new_count);
385 * If we have nothing to do, check whether we can take some
386 * work from our partner threads.
388 if (rc == 0 && pc->pc_npartners > 0) {
389 struct ptlrpcd_ctl *partner;
390 struct ptlrpc_request_set *ps;
391 int first = pc->pc_cursor;
394 partner = pc->pc_partners[pc->pc_cursor++];
395 if (pc->pc_cursor >= pc->pc_npartners)
400 spin_lock(&partner->pc_lock);
401 ps = partner->pc_set;
403 spin_unlock(&partner->pc_lock);
407 ptlrpc_reqset_get(ps);
408 spin_unlock(&partner->pc_lock);
410 if (atomic_read(&ps->set_new_count)) {
411 rc = ptlrpcd_steal_rqset(set, ps);
414 "transfer %d async RPCs [%d->%d]\n",
415 rc, partner->pc_index,
418 ptlrpc_reqset_put(ps);
419 } while (rc == 0 && pc->pc_cursor != first);
423 RETURN(rc || test_bit(LIOD_STOP, &pc->pc_flags));
427 * Main ptlrpcd thread.
428 * ptlrpc's code paths like to execute in process context, so we have this
429 * thread which spins on a set which contains the rpcs and sends them.
431 static int ptlrpcd(void *arg)
433 struct ptlrpcd_ctl *pc = arg;
434 struct ptlrpc_request_set *set;
435 struct lu_context ses = { 0 };
436 struct lu_env env = { .le_ses = &ses };
441 if (cfs_cpt_bind(cfs_cpt_tab, pc->pc_cpt) != 0)
442 CWARN("Failed to bind %s on CPT %d\n", pc->pc_name, pc->pc_cpt);
445 * Allocate the request set after the thread has been bound
446 * above. This is safe because no requests will be queued
447 * until all ptlrpcd threads have confirmed that they have
448 * successfully started.
450 set = ptlrpc_prep_set();
452 GOTO(failed, rc = -ENOMEM);
453 spin_lock(&pc->pc_lock);
455 spin_unlock(&pc->pc_lock);
457 /* Both client and server (MDT/OST) may use the environment. */
458 rc = lu_context_init(&env.le_ctx, LCT_MD_THREAD |
465 rc = lu_context_init(env.le_ses, LCT_SESSION |
469 lu_context_fini(&env.le_ctx);
473 complete(&pc->pc_starting);
476 * This mainloop strongly resembles ptlrpc_set_wait() except that our
477 * set never completes. ptlrpcd_check() calls ptlrpc_check_set() when
478 * there are requests in the set. New requests come in on the set's
479 * new_req_list and ptlrpcd_check() moves them into the set.
484 timeout = ptlrpc_set_next_timeout(set);
486 lu_context_enter(&env.le_ctx);
487 lu_context_enter(env.le_ses);
489 wait_event_idle(set->set_waitq,
490 ptlrpcd_check(&env, pc));
491 else if (wait_event_idle_timeout(set->set_waitq,
492 ptlrpcd_check(&env, pc),
493 cfs_time_seconds(timeout))
495 ptlrpc_expired_set(set);
496 lu_context_exit(&env.le_ctx);
497 lu_context_exit(env.le_ses);
500 * Abort inflight rpcs for forced stop case.
502 if (test_bit(LIOD_STOP, &pc->pc_flags)) {
503 if (test_bit(LIOD_FORCE, &pc->pc_flags))
504 ptlrpc_abort_set(set);
509 * Let's make one more loop to make sure that ptlrpcd_check()
510 * copied all raced new rpcs into the set so we can kill them.
515 * Wait for inflight requests to drain.
517 if (!list_empty(&set->set_requests))
518 ptlrpc_set_wait(&env, set);
519 lu_context_fini(&env.le_ctx);
520 lu_context_fini(env.le_ses);
522 complete(&pc->pc_finishing);
528 complete(&pc->pc_starting);
532 static void ptlrpcd_ctl_init(struct ptlrpcd_ctl *pc, int index, int cpt)
536 pc->pc_index = index;
538 init_completion(&pc->pc_starting);
539 init_completion(&pc->pc_finishing);
540 spin_lock_init(&pc->pc_lock);
543 /* Recovery thread. */
544 snprintf(pc->pc_name, sizeof(pc->pc_name), "ptlrpcd_rcv");
546 /* Regular thread. */
547 snprintf(pc->pc_name, sizeof(pc->pc_name),
548 "ptlrpcd_%02d_%02d", cpt, index);
554 /* XXX: We want multiple CPU cores to share the async RPC load. So we
555 * start many ptlrpcd threads. We also want to reduce the ptlrpcd
556 * overhead caused by data transfer cross-CPU cores. So we bind
557 * all ptlrpcd threads to a CPT, in the expectation that CPTs
558 * will be defined in a way that matches these boundaries. Within
559 * a CPT a ptlrpcd thread can be scheduled on any available core.
561 * Each ptlrpcd thread has its own request queue. This can cause
562 * response delay if the thread is already busy. To help with
563 * this we define partner threads: these are other threads bound
564 * to the same CPT which will check for work in each other's
565 * request queues if they have no work to do.
567 * The desired number of partner threads can be tuned by setting
568 * ptlrpcd_partner_group_size. The default is to create pairs of
571 static int ptlrpcd_partners(struct ptlrpcd *pd, int index)
573 struct ptlrpcd_ctl *pc;
574 struct ptlrpcd_ctl **ppc;
581 LASSERT(index >= 0 && index < pd->pd_nthreads);
582 pc = &pd->pd_threads[index];
583 pc->pc_npartners = pd->pd_groupsize - 1;
585 if (pc->pc_npartners <= 0)
588 OBD_CPT_ALLOC(pc->pc_partners, cfs_cpt_tab, pc->pc_cpt,
589 sizeof(struct ptlrpcd_ctl *) * pc->pc_npartners);
590 if (pc->pc_partners == NULL) {
591 pc->pc_npartners = 0;
592 GOTO(out, rc = -ENOMEM);
595 first = index - index % pd->pd_groupsize;
596 ppc = pc->pc_partners;
597 for (i = first; i < first + pd->pd_groupsize; i++) {
599 *ppc++ = &pd->pd_threads[i];
605 int ptlrpcd_start(struct ptlrpcd_ctl *pc)
607 struct task_struct *task;
613 * Do not allow starting a second thread for one pc.
615 if (test_and_set_bit(LIOD_START, &pc->pc_flags)) {
616 CWARN("Starting second thread (%s) for same pc %p\n",
621 task = kthread_run(ptlrpcd, pc, "%s", pc->pc_name);
623 GOTO(out_set, rc = PTR_ERR(task));
625 wait_for_completion(&pc->pc_starting);
633 if (pc->pc_set != NULL) {
634 struct ptlrpc_request_set *set = pc->pc_set;
636 spin_lock(&pc->pc_lock);
638 spin_unlock(&pc->pc_lock);
639 ptlrpc_set_destroy(set);
641 clear_bit(LIOD_START, &pc->pc_flags);
645 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force)
649 if (!test_bit(LIOD_START, &pc->pc_flags)) {
650 CWARN("Thread for pc %p was not started\n", pc);
654 set_bit(LIOD_STOP, &pc->pc_flags);
656 set_bit(LIOD_FORCE, &pc->pc_flags);
657 wake_up(&pc->pc_set->set_waitq);
663 void ptlrpcd_free(struct ptlrpcd_ctl *pc)
665 struct ptlrpc_request_set *set = pc->pc_set;
669 if (!test_bit(LIOD_START, &pc->pc_flags)) {
670 CWARN("Thread for pc %p was not started\n", pc);
674 wait_for_completion(&pc->pc_finishing);
676 spin_lock(&pc->pc_lock);
678 spin_unlock(&pc->pc_lock);
679 ptlrpc_set_destroy(set);
681 clear_bit(LIOD_START, &pc->pc_flags);
682 clear_bit(LIOD_STOP, &pc->pc_flags);
683 clear_bit(LIOD_FORCE, &pc->pc_flags);
686 if (pc->pc_npartners > 0) {
687 LASSERT(pc->pc_partners != NULL);
689 OBD_FREE_PTR_ARRAY(pc->pc_partners, pc->pc_npartners);
690 pc->pc_partners = NULL;
692 pc->pc_npartners = 0;
697 static void ptlrpcd_fini(void)
705 if (ptlrpcds != NULL) {
706 for (i = 0; i < ptlrpcds_num; i++) {
707 if (ptlrpcds[i] == NULL)
709 for (j = 0; j < ptlrpcds[i]->pd_nthreads; j++)
710 ptlrpcd_stop(&ptlrpcds[i]->pd_threads[j], 0);
711 for (j = 0; j < ptlrpcds[i]->pd_nthreads; j++)
712 ptlrpcd_free(&ptlrpcds[i]->pd_threads[j]);
713 OBD_FREE(ptlrpcds[i], ptlrpcds[i]->pd_size);
716 OBD_FREE_PTR_ARRAY(ptlrpcds, ptlrpcds_num);
720 ptlrpcd_stop(&ptlrpcd_rcv, 0);
721 ptlrpcd_free(&ptlrpcd_rcv);
723 if (ptlrpcds_cpt_idx != NULL) {
724 ncpts = cfs_cpt_number(cfs_cpt_tab);
725 OBD_FREE_PTR_ARRAY(ptlrpcds_cpt_idx, ncpts);
726 ptlrpcds_cpt_idx = NULL;
732 static int ptlrpcd_init(void)
740 struct cfs_cpt_table *cptable;
749 * Determine the CPTs that ptlrpcd threads will run on.
751 cptable = cfs_cpt_tab;
752 ncpts = cfs_cpt_number(cptable);
753 if (ptlrpcd_cpts != NULL) {
754 struct cfs_expr_list *el;
756 size = ncpts * sizeof(ptlrpcds_cpt_idx[0]);
757 OBD_ALLOC(ptlrpcds_cpt_idx, size);
758 if (ptlrpcds_cpt_idx == NULL)
759 GOTO(out, rc = -ENOMEM);
761 rc = cfs_expr_list_parse(ptlrpcd_cpts,
762 strlen(ptlrpcd_cpts),
765 CERROR("%s: invalid CPT pattern string: %s",
766 "ptlrpcd_cpts", ptlrpcd_cpts);
767 GOTO(out, rc = -EINVAL);
770 rc = cfs_expr_list_values(el, ncpts, &cpts);
771 cfs_expr_list_free(el);
773 CERROR("%s: failed to parse CPT array %s: %d\n",
774 "ptlrpcd_cpts", ptlrpcd_cpts, rc);
781 * Create the cpt-to-index map. When there is no match
782 * in the cpt table, pick a cpt at random. This could
783 * be changed to take the topology of the system into
786 for (cpt = 0; cpt < ncpts; cpt++) {
787 for (i = 0; i < rc; i++)
792 ptlrpcds_cpt_idx[cpt] = i;
795 cfs_expr_list_values_free(cpts, rc);
798 ptlrpcds_num = ncpts;
800 size = ncpts * sizeof(ptlrpcds[0]);
801 OBD_ALLOC(ptlrpcds, size);
802 if (ptlrpcds == NULL)
803 GOTO(out, rc = -ENOMEM);
806 * The max_ptlrpcds parameter is obsolete, but do something
807 * sane if it has been tuned, and complain if
808 * ptlrpcd_per_cpt_max has also been tuned.
810 if (max_ptlrpcds != 0) {
811 CWARN("max_ptlrpcds is obsolete.\n");
812 if (ptlrpcd_per_cpt_max == 0) {
813 ptlrpcd_per_cpt_max = max_ptlrpcds / ncpts;
814 /* Round up if there is a remainder. */
815 if (max_ptlrpcds % ncpts != 0)
816 ptlrpcd_per_cpt_max++;
817 CWARN("Setting ptlrpcd_per_cpt_max = %d\n",
818 ptlrpcd_per_cpt_max);
820 CWARN("ptlrpd_per_cpt_max is also set!\n");
825 * The ptlrpcd_bind_policy parameter is obsolete, but do
826 * something sane if it has been tuned, and complain if
827 * ptlrpcd_partner_group_size is also tuned.
829 if (ptlrpcd_bind_policy != 0) {
830 CWARN("ptlrpcd_bind_policy is obsolete.\n");
831 if (ptlrpcd_partner_group_size == 0) {
832 switch (ptlrpcd_bind_policy) {
833 case 1: /* PDB_POLICY_NONE */
834 case 2: /* PDB_POLICY_FULL */
835 ptlrpcd_partner_group_size = 1;
837 case 3: /* PDB_POLICY_PAIR */
838 ptlrpcd_partner_group_size = 2;
840 case 4: /* PDB_POLICY_NEIGHBOR */
842 ptlrpcd_partner_group_size = -1; /* CPT */
844 ptlrpcd_partner_group_size = 3; /* Triplets */
847 default: /* Illegal value, use the default. */
848 ptlrpcd_partner_group_size = 2;
851 CWARN("Setting ptlrpcd_partner_group_size = %d\n",
852 ptlrpcd_partner_group_size);
854 CWARN("ptlrpcd_partner_group_size is also set!\n");
858 if (ptlrpcd_partner_group_size == 0)
859 ptlrpcd_partner_group_size = 2;
860 else if (ptlrpcd_partner_group_size < 0)
861 ptlrpcd_partner_group_size = -1;
862 else if (ptlrpcd_per_cpt_max > 0 &&
863 ptlrpcd_partner_group_size > ptlrpcd_per_cpt_max)
864 ptlrpcd_partner_group_size = ptlrpcd_per_cpt_max;
867 * Start the recovery thread first.
869 set_bit(LIOD_RECOVERY, &ptlrpcd_rcv.pc_flags);
870 ptlrpcd_ctl_init(&ptlrpcd_rcv, -1, CFS_CPT_ANY);
871 rc = ptlrpcd_start(&ptlrpcd_rcv);
875 for (i = 0; i < ncpts; i++) {
881 nthreads = cfs_cpt_weight(cptable, cpt);
882 if (ptlrpcd_per_cpt_max > 0 && ptlrpcd_per_cpt_max < nthreads)
883 nthreads = ptlrpcd_per_cpt_max;
887 if (ptlrpcd_partner_group_size <= 0) {
888 groupsize = nthreads;
889 } else if (nthreads <= ptlrpcd_partner_group_size) {
890 groupsize = nthreads;
892 groupsize = ptlrpcd_partner_group_size;
893 if (nthreads % groupsize != 0)
894 nthreads += groupsize - (nthreads % groupsize);
897 size = offsetof(struct ptlrpcd, pd_threads[nthreads]);
898 OBD_CPT_ALLOC(pd, cptable, cpt, size);
901 GOTO(out, rc = -ENOMEM);
906 pd->pd_nthreads = nthreads;
907 pd->pd_groupsize = groupsize;
911 * The ptlrpcd threads in a partner group can access
912 * each other's struct ptlrpcd_ctl, so these must be
913 * initialized before any thead is started.
915 for (j = 0; j < nthreads; j++) {
916 ptlrpcd_ctl_init(&pd->pd_threads[j], j, cpt);
917 rc = ptlrpcd_partners(pd, j);
922 /* XXX: We start nthreads ptlrpc daemons on this cpt.
923 * Each of them can process any non-recovery
924 * async RPC to improve overall async RPC
927 * But there are some issues with async I/O RPCs
928 * and async non-I/O RPCs processed in the same
929 * set under some cases. The ptlrpcd may be
930 * blocked by some async I/O RPC(s), then will
931 * cause other async non-I/O RPC(s) can not be
934 * Maybe we should distinguish blocked async RPCs
935 * from non-blocked async RPCs, and process them
936 * in different ptlrpcd sets to avoid unnecessary
937 * dependency. But how to distribute async RPCs
938 * load among all the ptlrpc daemons becomes
941 for (j = 0; j < nthreads; j++) {
942 rc = ptlrpcd_start(&pd->pd_threads[j]);
954 int ptlrpcd_addref(void)
960 mutex_lock(&ptlrpcd_mutex);
961 if (++ptlrpcd_users == 1) {
966 mutex_unlock(&ptlrpcd_mutex);
969 EXPORT_SYMBOL(ptlrpcd_addref);
971 void ptlrpcd_decref(void)
973 mutex_lock(&ptlrpcd_mutex);
974 if (--ptlrpcd_users == 0)
976 mutex_unlock(&ptlrpcd_mutex);
978 EXPORT_SYMBOL(ptlrpcd_decref);