/net/sunrpc/sched.c

http://github.com/mirrors/linux · C · 1334 lines · 900 code · 161 blank · 273 comment · 125 complexity · 39674a12de2ba6faf73f0eddca0a9e89 MD5 · raw file

  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/net/sunrpc/sched.c
  4. *
  5. * Scheduling for synchronous and asynchronous RPC requests.
  6. *
  7. * Copyright (C) 1996 Olaf Kirch, <okir@monad.swb.de>
  8. *
  9. * TCP NFS related read + write fixes
  10. * (C) 1999 Dave Airlie, University of Limerick, Ireland <airlied@linux.ie>
  11. */
  12. #include <linux/module.h>
  13. #include <linux/sched.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/slab.h>
  16. #include <linux/mempool.h>
  17. #include <linux/smp.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/mutex.h>
  20. #include <linux/freezer.h>
  21. #include <linux/sched/mm.h>
  22. #include <linux/sunrpc/clnt.h>
  23. #include <linux/sunrpc/metrics.h>
  24. #include "sunrpc.h"
  25. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
  26. #define RPCDBG_FACILITY RPCDBG_SCHED
  27. #endif
  28. #define CREATE_TRACE_POINTS
  29. #include <trace/events/sunrpc.h>
  30. /*
  31. * RPC slabs and memory pools
  32. */
  33. #define RPC_BUFFER_MAXSIZE (2048)
  34. #define RPC_BUFFER_POOLSIZE (8)
  35. #define RPC_TASK_POOLSIZE (8)
  36. static struct kmem_cache *rpc_task_slabp __read_mostly;
  37. static struct kmem_cache *rpc_buffer_slabp __read_mostly;
  38. static mempool_t *rpc_task_mempool __read_mostly;
  39. static mempool_t *rpc_buffer_mempool __read_mostly;
  40. static void rpc_async_schedule(struct work_struct *);
  41. static void rpc_release_task(struct rpc_task *task);
  42. static void __rpc_queue_timer_fn(struct work_struct *);
  43. /*
  44. * RPC tasks sit here while waiting for conditions to improve.
  45. */
  46. static struct rpc_wait_queue delay_queue;
  47. /*
  48. * rpciod-related stuff
  49. */
  50. struct workqueue_struct *rpciod_workqueue __read_mostly;
  51. struct workqueue_struct *xprtiod_workqueue __read_mostly;
  52. EXPORT_SYMBOL_GPL(xprtiod_workqueue);
  53. unsigned long
  54. rpc_task_timeout(const struct rpc_task *task)
  55. {
  56. unsigned long timeout = READ_ONCE(task->tk_timeout);
  57. if (timeout != 0) {
  58. unsigned long now = jiffies;
  59. if (time_before(now, timeout))
  60. return timeout - now;
  61. }
  62. return 0;
  63. }
  64. EXPORT_SYMBOL_GPL(rpc_task_timeout);
  65. /*
  66. * Disable the timer for a given RPC task. Should be called with
  67. * queue->lock and bh_disabled in order to avoid races within
  68. * rpc_run_timer().
  69. */
  70. static void
  71. __rpc_disable_timer(struct rpc_wait_queue *queue, struct rpc_task *task)
  72. {
  73. if (list_empty(&task->u.tk_wait.timer_list))
  74. return;
  75. dprintk("RPC: %5u disabling timer\n", task->tk_pid);
  76. task->tk_timeout = 0;
  77. list_del(&task->u.tk_wait.timer_list);
  78. if (list_empty(&queue->timer_list.list))
  79. cancel_delayed_work(&queue->timer_list.dwork);
  80. }
  81. static void
  82. rpc_set_queue_timer(struct rpc_wait_queue *queue, unsigned long expires)
  83. {
  84. unsigned long now = jiffies;
  85. queue->timer_list.expires = expires;
  86. if (time_before_eq(expires, now))
  87. expires = 0;
  88. else
  89. expires -= now;
  90. mod_delayed_work(rpciod_workqueue, &queue->timer_list.dwork, expires);
  91. }
  92. /*
  93. * Set up a timer for the current task.
  94. */
  95. static void
  96. __rpc_add_timer(struct rpc_wait_queue *queue, struct rpc_task *task,
  97. unsigned long timeout)
  98. {
  99. dprintk("RPC: %5u setting alarm for %u ms\n",
  100. task->tk_pid, jiffies_to_msecs(timeout - jiffies));
  101. task->tk_timeout = timeout;
  102. if (list_empty(&queue->timer_list.list) || time_before(timeout, queue->timer_list.expires))
  103. rpc_set_queue_timer(queue, timeout);
  104. list_add(&task->u.tk_wait.timer_list, &queue->timer_list.list);
  105. }
  106. static void rpc_set_waitqueue_priority(struct rpc_wait_queue *queue, int priority)
  107. {
  108. if (queue->priority != priority) {
  109. queue->priority = priority;
  110. queue->nr = 1U << priority;
  111. }
  112. }
  113. static void rpc_reset_waitqueue_priority(struct rpc_wait_queue *queue)
  114. {
  115. rpc_set_waitqueue_priority(queue, queue->maxpriority);
  116. }
  117. /*
  118. * Add a request to a queue list
  119. */
  120. static void
  121. __rpc_list_enqueue_task(struct list_head *q, struct rpc_task *task)
  122. {
  123. struct rpc_task *t;
  124. list_for_each_entry(t, q, u.tk_wait.list) {
  125. if (t->tk_owner == task->tk_owner) {
  126. list_add_tail(&task->u.tk_wait.links,
  127. &t->u.tk_wait.links);
  128. /* Cache the queue head in task->u.tk_wait.list */
  129. task->u.tk_wait.list.next = q;
  130. task->u.tk_wait.list.prev = NULL;
  131. return;
  132. }
  133. }
  134. INIT_LIST_HEAD(&task->u.tk_wait.links);
  135. list_add_tail(&task->u.tk_wait.list, q);
  136. }
  137. /*
  138. * Remove request from a queue list
  139. */
  140. static void
  141. __rpc_list_dequeue_task(struct rpc_task *task)
  142. {
  143. struct list_head *q;
  144. struct rpc_task *t;
  145. if (task->u.tk_wait.list.prev == NULL) {
  146. list_del(&task->u.tk_wait.links);
  147. return;
  148. }
  149. if (!list_empty(&task->u.tk_wait.links)) {
  150. t = list_first_entry(&task->u.tk_wait.links,
  151. struct rpc_task,
  152. u.tk_wait.links);
  153. /* Assume __rpc_list_enqueue_task() cached the queue head */
  154. q = t->u.tk_wait.list.next;
  155. list_add_tail(&t->u.tk_wait.list, q);
  156. list_del(&task->u.tk_wait.links);
  157. }
  158. list_del(&task->u.tk_wait.list);
  159. }
  160. /*
  161. * Add new request to a priority queue.
  162. */
  163. static void __rpc_add_wait_queue_priority(struct rpc_wait_queue *queue,
  164. struct rpc_task *task,
  165. unsigned char queue_priority)
  166. {
  167. if (unlikely(queue_priority > queue->maxpriority))
  168. queue_priority = queue->maxpriority;
  169. __rpc_list_enqueue_task(&queue->tasks[queue_priority], task);
  170. }
  171. /*
  172. * Add new request to wait queue.
  173. *
  174. * Swapper tasks always get inserted at the head of the queue.
  175. * This should avoid many nasty memory deadlocks and hopefully
  176. * improve overall performance.
  177. * Everyone else gets appended to the queue to ensure proper FIFO behavior.
  178. */
  179. static void __rpc_add_wait_queue(struct rpc_wait_queue *queue,
  180. struct rpc_task *task,
  181. unsigned char queue_priority)
  182. {
  183. INIT_LIST_HEAD(&task->u.tk_wait.timer_list);
  184. if (RPC_IS_PRIORITY(queue))
  185. __rpc_add_wait_queue_priority(queue, task, queue_priority);
  186. else if (RPC_IS_SWAPPER(task))
  187. list_add(&task->u.tk_wait.list, &queue->tasks[0]);
  188. else
  189. list_add_tail(&task->u.tk_wait.list, &queue->tasks[0]);
  190. task->tk_waitqueue = queue;
  191. queue->qlen++;
  192. /* barrier matches the read in rpc_wake_up_task_queue_locked() */
  193. smp_wmb();
  194. rpc_set_queued(task);
  195. dprintk("RPC: %5u added to queue %p \"%s\"\n",
  196. task->tk_pid, queue, rpc_qname(queue));
  197. }
  198. /*
  199. * Remove request from a priority queue.
  200. */
  201. static void __rpc_remove_wait_queue_priority(struct rpc_task *task)
  202. {
  203. __rpc_list_dequeue_task(task);
  204. }
  205. /*
  206. * Remove request from queue.
  207. * Note: must be called with spin lock held.
  208. */
  209. static void __rpc_remove_wait_queue(struct rpc_wait_queue *queue, struct rpc_task *task)
  210. {
  211. __rpc_disable_timer(queue, task);
  212. if (RPC_IS_PRIORITY(queue))
  213. __rpc_remove_wait_queue_priority(task);
  214. else
  215. list_del(&task->u.tk_wait.list);
  216. queue->qlen--;
  217. dprintk("RPC: %5u removed from queue %p \"%s\"\n",
  218. task->tk_pid, queue, rpc_qname(queue));
  219. }
  220. static void __rpc_init_priority_wait_queue(struct rpc_wait_queue *queue, const char *qname, unsigned char nr_queues)
  221. {
  222. int i;
  223. spin_lock_init(&queue->lock);
  224. for (i = 0; i < ARRAY_SIZE(queue->tasks); i++)
  225. INIT_LIST_HEAD(&queue->tasks[i]);
  226. queue->maxpriority = nr_queues - 1;
  227. rpc_reset_waitqueue_priority(queue);
  228. queue->qlen = 0;
  229. queue->timer_list.expires = 0;
  230. INIT_DELAYED_WORK(&queue->timer_list.dwork, __rpc_queue_timer_fn);
  231. INIT_LIST_HEAD(&queue->timer_list.list);
  232. rpc_assign_waitqueue_name(queue, qname);
  233. }
  234. void rpc_init_priority_wait_queue(struct rpc_wait_queue *queue, const char *qname)
  235. {
  236. __rpc_init_priority_wait_queue(queue, qname, RPC_NR_PRIORITY);
  237. }
  238. EXPORT_SYMBOL_GPL(rpc_init_priority_wait_queue);
  239. void rpc_init_wait_queue(struct rpc_wait_queue *queue, const char *qname)
  240. {
  241. __rpc_init_priority_wait_queue(queue, qname, 1);
  242. }
  243. EXPORT_SYMBOL_GPL(rpc_init_wait_queue);
  244. void rpc_destroy_wait_queue(struct rpc_wait_queue *queue)
  245. {
  246. cancel_delayed_work_sync(&queue->timer_list.dwork);
  247. }
  248. EXPORT_SYMBOL_GPL(rpc_destroy_wait_queue);
  249. static int rpc_wait_bit_killable(struct wait_bit_key *key, int mode)
  250. {
  251. freezable_schedule_unsafe();
  252. if (signal_pending_state(mode, current))
  253. return -ERESTARTSYS;
  254. return 0;
  255. }
  256. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) || IS_ENABLED(CONFIG_TRACEPOINTS)
  257. static void rpc_task_set_debuginfo(struct rpc_task *task)
  258. {
  259. static atomic_t rpc_pid;
  260. task->tk_pid = atomic_inc_return(&rpc_pid);
  261. }
  262. #else
  263. static inline void rpc_task_set_debuginfo(struct rpc_task *task)
  264. {
  265. }
  266. #endif
  267. static void rpc_set_active(struct rpc_task *task)
  268. {
  269. rpc_task_set_debuginfo(task);
  270. set_bit(RPC_TASK_ACTIVE, &task->tk_runstate);
  271. trace_rpc_task_begin(task, NULL);
  272. }
  273. /*
  274. * Mark an RPC call as having completed by clearing the 'active' bit
  275. * and then waking up all tasks that were sleeping.
  276. */
  277. static int rpc_complete_task(struct rpc_task *task)
  278. {
  279. void *m = &task->tk_runstate;
  280. wait_queue_head_t *wq = bit_waitqueue(m, RPC_TASK_ACTIVE);
  281. struct wait_bit_key k = __WAIT_BIT_KEY_INITIALIZER(m, RPC_TASK_ACTIVE);
  282. unsigned long flags;
  283. int ret;
  284. trace_rpc_task_complete(task, NULL);
  285. spin_lock_irqsave(&wq->lock, flags);
  286. clear_bit(RPC_TASK_ACTIVE, &task->tk_runstate);
  287. ret = atomic_dec_and_test(&task->tk_count);
  288. if (waitqueue_active(wq))
  289. __wake_up_locked_key(wq, TASK_NORMAL, &k);
  290. spin_unlock_irqrestore(&wq->lock, flags);
  291. return ret;
  292. }
  293. /*
  294. * Allow callers to wait for completion of an RPC call
  295. *
  296. * Note the use of out_of_line_wait_on_bit() rather than wait_on_bit()
  297. * to enforce taking of the wq->lock and hence avoid races with
  298. * rpc_complete_task().
  299. */
  300. int __rpc_wait_for_completion_task(struct rpc_task *task, wait_bit_action_f *action)
  301. {
  302. if (action == NULL)
  303. action = rpc_wait_bit_killable;
  304. return out_of_line_wait_on_bit(&task->tk_runstate, RPC_TASK_ACTIVE,
  305. action, TASK_KILLABLE);
  306. }
  307. EXPORT_SYMBOL_GPL(__rpc_wait_for_completion_task);
  308. /*
  309. * Make an RPC task runnable.
  310. *
  311. * Note: If the task is ASYNC, and is being made runnable after sitting on an
  312. * rpc_wait_queue, this must be called with the queue spinlock held to protect
  313. * the wait queue operation.
  314. * Note the ordering of rpc_test_and_set_running() and rpc_clear_queued(),
  315. * which is needed to ensure that __rpc_execute() doesn't loop (due to the
  316. * lockless RPC_IS_QUEUED() test) before we've had a chance to test
  317. * the RPC_TASK_RUNNING flag.
  318. */
  319. static void rpc_make_runnable(struct workqueue_struct *wq,
  320. struct rpc_task *task)
  321. {
  322. bool need_wakeup = !rpc_test_and_set_running(task);
  323. rpc_clear_queued(task);
  324. if (!need_wakeup)
  325. return;
  326. if (RPC_IS_ASYNC(task)) {
  327. INIT_WORK(&task->u.tk_work, rpc_async_schedule);
  328. queue_work(wq, &task->u.tk_work);
  329. } else
  330. wake_up_bit(&task->tk_runstate, RPC_TASK_QUEUED);
  331. }
  332. /*
  333. * Prepare for sleeping on a wait queue.
  334. * By always appending tasks to the list we ensure FIFO behavior.
  335. * NB: An RPC task will only receive interrupt-driven events as long
  336. * as it's on a wait queue.
  337. */
  338. static void __rpc_do_sleep_on_priority(struct rpc_wait_queue *q,
  339. struct rpc_task *task,
  340. unsigned char queue_priority)
  341. {
  342. dprintk("RPC: %5u sleep_on(queue \"%s\" time %lu)\n",
  343. task->tk_pid, rpc_qname(q), jiffies);
  344. trace_rpc_task_sleep(task, q);
  345. __rpc_add_wait_queue(q, task, queue_priority);
  346. }
  347. static void __rpc_sleep_on_priority(struct rpc_wait_queue *q,
  348. struct rpc_task *task,
  349. unsigned char queue_priority)
  350. {
  351. if (WARN_ON_ONCE(RPC_IS_QUEUED(task)))
  352. return;
  353. __rpc_do_sleep_on_priority(q, task, queue_priority);
  354. }
  355. static void __rpc_sleep_on_priority_timeout(struct rpc_wait_queue *q,
  356. struct rpc_task *task, unsigned long timeout,
  357. unsigned char queue_priority)
  358. {
  359. if (WARN_ON_ONCE(RPC_IS_QUEUED(task)))
  360. return;
  361. if (time_is_after_jiffies(timeout)) {
  362. __rpc_do_sleep_on_priority(q, task, queue_priority);
  363. __rpc_add_timer(q, task, timeout);
  364. } else
  365. task->tk_status = -ETIMEDOUT;
  366. }
  367. static void rpc_set_tk_callback(struct rpc_task *task, rpc_action action)
  368. {
  369. if (action && !WARN_ON_ONCE(task->tk_callback != NULL))
  370. task->tk_callback = action;
  371. }
  372. static bool rpc_sleep_check_activated(struct rpc_task *task)
  373. {
  374. /* We shouldn't ever put an inactive task to sleep */
  375. if (WARN_ON_ONCE(!RPC_IS_ACTIVATED(task))) {
  376. task->tk_status = -EIO;
  377. rpc_put_task_async(task);
  378. return false;
  379. }
  380. return true;
  381. }
  382. void rpc_sleep_on_timeout(struct rpc_wait_queue *q, struct rpc_task *task,
  383. rpc_action action, unsigned long timeout)
  384. {
  385. if (!rpc_sleep_check_activated(task))
  386. return;
  387. rpc_set_tk_callback(task, action);
  388. /*
  389. * Protect the queue operations.
  390. */
  391. spin_lock(&q->lock);
  392. __rpc_sleep_on_priority_timeout(q, task, timeout, task->tk_priority);
  393. spin_unlock(&q->lock);
  394. }
  395. EXPORT_SYMBOL_GPL(rpc_sleep_on_timeout);
  396. void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task,
  397. rpc_action action)
  398. {
  399. if (!rpc_sleep_check_activated(task))
  400. return;
  401. rpc_set_tk_callback(task, action);
  402. WARN_ON_ONCE(task->tk_timeout != 0);
  403. /*
  404. * Protect the queue operations.
  405. */
  406. spin_lock(&q->lock);
  407. __rpc_sleep_on_priority(q, task, task->tk_priority);
  408. spin_unlock(&q->lock);
  409. }
  410. EXPORT_SYMBOL_GPL(rpc_sleep_on);
  411. void rpc_sleep_on_priority_timeout(struct rpc_wait_queue *q,
  412. struct rpc_task *task, unsigned long timeout, int priority)
  413. {
  414. if (!rpc_sleep_check_activated(task))
  415. return;
  416. priority -= RPC_PRIORITY_LOW;
  417. /*
  418. * Protect the queue operations.
  419. */
  420. spin_lock(&q->lock);
  421. __rpc_sleep_on_priority_timeout(q, task, timeout, priority);
  422. spin_unlock(&q->lock);
  423. }
  424. EXPORT_SYMBOL_GPL(rpc_sleep_on_priority_timeout);
  425. void rpc_sleep_on_priority(struct rpc_wait_queue *q, struct rpc_task *task,
  426. int priority)
  427. {
  428. if (!rpc_sleep_check_activated(task))
  429. return;
  430. WARN_ON_ONCE(task->tk_timeout != 0);
  431. priority -= RPC_PRIORITY_LOW;
  432. /*
  433. * Protect the queue operations.
  434. */
  435. spin_lock(&q->lock);
  436. __rpc_sleep_on_priority(q, task, priority);
  437. spin_unlock(&q->lock);
  438. }
  439. EXPORT_SYMBOL_GPL(rpc_sleep_on_priority);
  440. /**
  441. * __rpc_do_wake_up_task_on_wq - wake up a single rpc_task
  442. * @wq: workqueue on which to run task
  443. * @queue: wait queue
  444. * @task: task to be woken up
  445. *
  446. * Caller must hold queue->lock, and have cleared the task queued flag.
  447. */
  448. static void __rpc_do_wake_up_task_on_wq(struct workqueue_struct *wq,
  449. struct rpc_wait_queue *queue,
  450. struct rpc_task *task)
  451. {
  452. dprintk("RPC: %5u __rpc_wake_up_task (now %lu)\n",
  453. task->tk_pid, jiffies);
  454. /* Has the task been executed yet? If not, we cannot wake it up! */
  455. if (!RPC_IS_ACTIVATED(task)) {
  456. printk(KERN_ERR "RPC: Inactive task (%p) being woken up!\n", task);
  457. return;
  458. }
  459. trace_rpc_task_wakeup(task, queue);
  460. __rpc_remove_wait_queue(queue, task);
  461. rpc_make_runnable(wq, task);
  462. dprintk("RPC: __rpc_wake_up_task done\n");
  463. }
  464. /*
  465. * Wake up a queued task while the queue lock is being held
  466. */
  467. static struct rpc_task *
  468. rpc_wake_up_task_on_wq_queue_action_locked(struct workqueue_struct *wq,
  469. struct rpc_wait_queue *queue, struct rpc_task *task,
  470. bool (*action)(struct rpc_task *, void *), void *data)
  471. {
  472. if (RPC_IS_QUEUED(task)) {
  473. smp_rmb();
  474. if (task->tk_waitqueue == queue) {
  475. if (action == NULL || action(task, data)) {
  476. __rpc_do_wake_up_task_on_wq(wq, queue, task);
  477. return task;
  478. }
  479. }
  480. }
  481. return NULL;
  482. }
  483. /*
  484. * Wake up a queued task while the queue lock is being held
  485. */
  486. static void rpc_wake_up_task_queue_locked(struct rpc_wait_queue *queue,
  487. struct rpc_task *task)
  488. {
  489. rpc_wake_up_task_on_wq_queue_action_locked(rpciod_workqueue, queue,
  490. task, NULL, NULL);
  491. }
  492. /*
  493. * Wake up a task on a specific queue
  494. */
  495. void rpc_wake_up_queued_task(struct rpc_wait_queue *queue, struct rpc_task *task)
  496. {
  497. if (!RPC_IS_QUEUED(task))
  498. return;
  499. spin_lock(&queue->lock);
  500. rpc_wake_up_task_queue_locked(queue, task);
  501. spin_unlock(&queue->lock);
  502. }
  503. EXPORT_SYMBOL_GPL(rpc_wake_up_queued_task);
  504. static bool rpc_task_action_set_status(struct rpc_task *task, void *status)
  505. {
  506. task->tk_status = *(int *)status;
  507. return true;
  508. }
  509. static void
  510. rpc_wake_up_task_queue_set_status_locked(struct rpc_wait_queue *queue,
  511. struct rpc_task *task, int status)
  512. {
  513. rpc_wake_up_task_on_wq_queue_action_locked(rpciod_workqueue, queue,
  514. task, rpc_task_action_set_status, &status);
  515. }
  516. /**
  517. * rpc_wake_up_queued_task_set_status - wake up a task and set task->tk_status
  518. * @queue: pointer to rpc_wait_queue
  519. * @task: pointer to rpc_task
  520. * @status: integer error value
  521. *
  522. * If @task is queued on @queue, then it is woken up, and @task->tk_status is
  523. * set to the value of @status.
  524. */
  525. void
  526. rpc_wake_up_queued_task_set_status(struct rpc_wait_queue *queue,
  527. struct rpc_task *task, int status)
  528. {
  529. if (!RPC_IS_QUEUED(task))
  530. return;
  531. spin_lock(&queue->lock);
  532. rpc_wake_up_task_queue_set_status_locked(queue, task, status);
  533. spin_unlock(&queue->lock);
  534. }
  535. /*
  536. * Wake up the next task on a priority queue.
  537. */
  538. static struct rpc_task *__rpc_find_next_queued_priority(struct rpc_wait_queue *queue)
  539. {
  540. struct list_head *q;
  541. struct rpc_task *task;
  542. /*
  543. * Service a batch of tasks from a single owner.
  544. */
  545. q = &queue->tasks[queue->priority];
  546. if (!list_empty(q) && --queue->nr) {
  547. task = list_first_entry(q, struct rpc_task, u.tk_wait.list);
  548. goto out;
  549. }
  550. /*
  551. * Service the next queue.
  552. */
  553. do {
  554. if (q == &queue->tasks[0])
  555. q = &queue->tasks[queue->maxpriority];
  556. else
  557. q = q - 1;
  558. if (!list_empty(q)) {
  559. task = list_first_entry(q, struct rpc_task, u.tk_wait.list);
  560. goto new_queue;
  561. }
  562. } while (q != &queue->tasks[queue->priority]);
  563. rpc_reset_waitqueue_priority(queue);
  564. return NULL;
  565. new_queue:
  566. rpc_set_waitqueue_priority(queue, (unsigned int)(q - &queue->tasks[0]));
  567. out:
  568. return task;
  569. }
  570. static struct rpc_task *__rpc_find_next_queued(struct rpc_wait_queue *queue)
  571. {
  572. if (RPC_IS_PRIORITY(queue))
  573. return __rpc_find_next_queued_priority(queue);
  574. if (!list_empty(&queue->tasks[0]))
  575. return list_first_entry(&queue->tasks[0], struct rpc_task, u.tk_wait.list);
  576. return NULL;
  577. }
  578. /*
  579. * Wake up the first task on the wait queue.
  580. */
  581. struct rpc_task *rpc_wake_up_first_on_wq(struct workqueue_struct *wq,
  582. struct rpc_wait_queue *queue,
  583. bool (*func)(struct rpc_task *, void *), void *data)
  584. {
  585. struct rpc_task *task = NULL;
  586. dprintk("RPC: wake_up_first(%p \"%s\")\n",
  587. queue, rpc_qname(queue));
  588. spin_lock(&queue->lock);
  589. task = __rpc_find_next_queued(queue);
  590. if (task != NULL)
  591. task = rpc_wake_up_task_on_wq_queue_action_locked(wq, queue,
  592. task, func, data);
  593. spin_unlock(&queue->lock);
  594. return task;
  595. }
  596. /*
  597. * Wake up the first task on the wait queue.
  598. */
  599. struct rpc_task *rpc_wake_up_first(struct rpc_wait_queue *queue,
  600. bool (*func)(struct rpc_task *, void *), void *data)
  601. {
  602. return rpc_wake_up_first_on_wq(rpciod_workqueue, queue, func, data);
  603. }
  604. EXPORT_SYMBOL_GPL(rpc_wake_up_first);
  605. static bool rpc_wake_up_next_func(struct rpc_task *task, void *data)
  606. {
  607. return true;
  608. }
  609. /*
  610. * Wake up the next task on the wait queue.
  611. */
  612. struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *queue)
  613. {
  614. return rpc_wake_up_first(queue, rpc_wake_up_next_func, NULL);
  615. }
  616. EXPORT_SYMBOL_GPL(rpc_wake_up_next);
  617. /**
  618. * rpc_wake_up - wake up all rpc_tasks
  619. * @queue: rpc_wait_queue on which the tasks are sleeping
  620. *
  621. * Grabs queue->lock
  622. */
  623. void rpc_wake_up(struct rpc_wait_queue *queue)
  624. {
  625. struct list_head *head;
  626. spin_lock(&queue->lock);
  627. head = &queue->tasks[queue->maxpriority];
  628. for (;;) {
  629. while (!list_empty(head)) {
  630. struct rpc_task *task;
  631. task = list_first_entry(head,
  632. struct rpc_task,
  633. u.tk_wait.list);
  634. rpc_wake_up_task_queue_locked(queue, task);
  635. }
  636. if (head == &queue->tasks[0])
  637. break;
  638. head--;
  639. }
  640. spin_unlock(&queue->lock);
  641. }
  642. EXPORT_SYMBOL_GPL(rpc_wake_up);
  643. /**
  644. * rpc_wake_up_status - wake up all rpc_tasks and set their status value.
  645. * @queue: rpc_wait_queue on which the tasks are sleeping
  646. * @status: status value to set
  647. *
  648. * Grabs queue->lock
  649. */
  650. void rpc_wake_up_status(struct rpc_wait_queue *queue, int status)
  651. {
  652. struct list_head *head;
  653. spin_lock(&queue->lock);
  654. head = &queue->tasks[queue->maxpriority];
  655. for (;;) {
  656. while (!list_empty(head)) {
  657. struct rpc_task *task;
  658. task = list_first_entry(head,
  659. struct rpc_task,
  660. u.tk_wait.list);
  661. task->tk_status = status;
  662. rpc_wake_up_task_queue_locked(queue, task);
  663. }
  664. if (head == &queue->tasks[0])
  665. break;
  666. head--;
  667. }
  668. spin_unlock(&queue->lock);
  669. }
  670. EXPORT_SYMBOL_GPL(rpc_wake_up_status);
  671. static void __rpc_queue_timer_fn(struct work_struct *work)
  672. {
  673. struct rpc_wait_queue *queue = container_of(work,
  674. struct rpc_wait_queue,
  675. timer_list.dwork.work);
  676. struct rpc_task *task, *n;
  677. unsigned long expires, now, timeo;
  678. spin_lock(&queue->lock);
  679. expires = now = jiffies;
  680. list_for_each_entry_safe(task, n, &queue->timer_list.list, u.tk_wait.timer_list) {
  681. timeo = task->tk_timeout;
  682. if (time_after_eq(now, timeo)) {
  683. dprintk("RPC: %5u timeout\n", task->tk_pid);
  684. task->tk_status = -ETIMEDOUT;
  685. rpc_wake_up_task_queue_locked(queue, task);
  686. continue;
  687. }
  688. if (expires == now || time_after(expires, timeo))
  689. expires = timeo;
  690. }
  691. if (!list_empty(&queue->timer_list.list))
  692. rpc_set_queue_timer(queue, expires);
  693. spin_unlock(&queue->lock);
  694. }
  695. static void __rpc_atrun(struct rpc_task *task)
  696. {
  697. if (task->tk_status == -ETIMEDOUT)
  698. task->tk_status = 0;
  699. }
  700. /*
  701. * Run a task at a later time
  702. */
  703. void rpc_delay(struct rpc_task *task, unsigned long delay)
  704. {
  705. rpc_sleep_on_timeout(&delay_queue, task, __rpc_atrun, jiffies + delay);
  706. }
  707. EXPORT_SYMBOL_GPL(rpc_delay);
  708. /*
  709. * Helper to call task->tk_ops->rpc_call_prepare
  710. */
  711. void rpc_prepare_task(struct rpc_task *task)
  712. {
  713. task->tk_ops->rpc_call_prepare(task, task->tk_calldata);
  714. }
  715. static void
  716. rpc_init_task_statistics(struct rpc_task *task)
  717. {
  718. /* Initialize retry counters */
  719. task->tk_garb_retry = 2;
  720. task->tk_cred_retry = 2;
  721. task->tk_rebind_retry = 2;
  722. /* starting timestamp */
  723. task->tk_start = ktime_get();
  724. }
  725. static void
  726. rpc_reset_task_statistics(struct rpc_task *task)
  727. {
  728. task->tk_timeouts = 0;
  729. task->tk_flags &= ~(RPC_CALL_MAJORSEEN|RPC_TASK_SENT);
  730. rpc_init_task_statistics(task);
  731. }
  732. /*
  733. * Helper that calls task->tk_ops->rpc_call_done if it exists
  734. */
  735. void rpc_exit_task(struct rpc_task *task)
  736. {
  737. trace_rpc_task_end(task, task->tk_action);
  738. task->tk_action = NULL;
  739. if (task->tk_ops->rpc_count_stats)
  740. task->tk_ops->rpc_count_stats(task, task->tk_calldata);
  741. else if (task->tk_client)
  742. rpc_count_iostats(task, task->tk_client->cl_metrics);
  743. if (task->tk_ops->rpc_call_done != NULL) {
  744. task->tk_ops->rpc_call_done(task, task->tk_calldata);
  745. if (task->tk_action != NULL) {
  746. /* Always release the RPC slot and buffer memory */
  747. xprt_release(task);
  748. rpc_reset_task_statistics(task);
  749. }
  750. }
  751. }
  752. void rpc_signal_task(struct rpc_task *task)
  753. {
  754. struct rpc_wait_queue *queue;
  755. if (!RPC_IS_ACTIVATED(task))
  756. return;
  757. trace_rpc_task_signalled(task, task->tk_action);
  758. set_bit(RPC_TASK_SIGNALLED, &task->tk_runstate);
  759. smp_mb__after_atomic();
  760. queue = READ_ONCE(task->tk_waitqueue);
  761. if (queue)
  762. rpc_wake_up_queued_task_set_status(queue, task, -ERESTARTSYS);
  763. }
  764. void rpc_exit(struct rpc_task *task, int status)
  765. {
  766. task->tk_status = status;
  767. task->tk_action = rpc_exit_task;
  768. rpc_wake_up_queued_task(task->tk_waitqueue, task);
  769. }
  770. EXPORT_SYMBOL_GPL(rpc_exit);
  771. void rpc_release_calldata(const struct rpc_call_ops *ops, void *calldata)
  772. {
  773. if (ops->rpc_release != NULL)
  774. ops->rpc_release(calldata);
  775. }
  776. /*
  777. * This is the RPC `scheduler' (or rather, the finite state machine).
  778. */
  779. static void __rpc_execute(struct rpc_task *task)
  780. {
  781. struct rpc_wait_queue *queue;
  782. int task_is_async = RPC_IS_ASYNC(task);
  783. int status = 0;
  784. dprintk("RPC: %5u __rpc_execute flags=0x%x\n",
  785. task->tk_pid, task->tk_flags);
  786. WARN_ON_ONCE(RPC_IS_QUEUED(task));
  787. if (RPC_IS_QUEUED(task))
  788. return;
  789. for (;;) {
  790. void (*do_action)(struct rpc_task *);
  791. /*
  792. * Perform the next FSM step or a pending callback.
  793. *
  794. * tk_action may be NULL if the task has been killed.
  795. * In particular, note that rpc_killall_tasks may
  796. * do this at any time, so beware when dereferencing.
  797. */
  798. do_action = task->tk_action;
  799. if (task->tk_callback) {
  800. do_action = task->tk_callback;
  801. task->tk_callback = NULL;
  802. }
  803. if (!do_action)
  804. break;
  805. trace_rpc_task_run_action(task, do_action);
  806. do_action(task);
  807. /*
  808. * Lockless check for whether task is sleeping or not.
  809. */
  810. if (!RPC_IS_QUEUED(task))
  811. continue;
  812. /*
  813. * Signalled tasks should exit rather than sleep.
  814. */
  815. if (RPC_SIGNALLED(task)) {
  816. task->tk_rpc_status = -ERESTARTSYS;
  817. rpc_exit(task, -ERESTARTSYS);
  818. }
  819. /*
  820. * The queue->lock protects against races with
  821. * rpc_make_runnable().
  822. *
  823. * Note that once we clear RPC_TASK_RUNNING on an asynchronous
  824. * rpc_task, rpc_make_runnable() can assign it to a
  825. * different workqueue. We therefore cannot assume that the
  826. * rpc_task pointer may still be dereferenced.
  827. */
  828. queue = task->tk_waitqueue;
  829. spin_lock(&queue->lock);
  830. if (!RPC_IS_QUEUED(task)) {
  831. spin_unlock(&queue->lock);
  832. continue;
  833. }
  834. rpc_clear_running(task);
  835. spin_unlock(&queue->lock);
  836. if (task_is_async)
  837. return;
  838. /* sync task: sleep here */
  839. dprintk("RPC: %5u sync task going to sleep\n", task->tk_pid);
  840. status = out_of_line_wait_on_bit(&task->tk_runstate,
  841. RPC_TASK_QUEUED, rpc_wait_bit_killable,
  842. TASK_KILLABLE);
  843. if (status < 0) {
  844. /*
  845. * When a sync task receives a signal, it exits with
  846. * -ERESTARTSYS. In order to catch any callbacks that
  847. * clean up after sleeping on some queue, we don't
  848. * break the loop here, but go around once more.
  849. */
  850. trace_rpc_task_signalled(task, task->tk_action);
  851. set_bit(RPC_TASK_SIGNALLED, &task->tk_runstate);
  852. task->tk_rpc_status = -ERESTARTSYS;
  853. rpc_exit(task, -ERESTARTSYS);
  854. }
  855. dprintk("RPC: %5u sync task resuming\n", task->tk_pid);
  856. }
  857. dprintk("RPC: %5u return %d, status %d\n", task->tk_pid, status,
  858. task->tk_status);
  859. /* Release all resources associated with the task */
  860. rpc_release_task(task);
  861. }
  862. /*
  863. * User-visible entry point to the scheduler.
  864. *
  865. * This may be called recursively if e.g. an async NFS task updates
  866. * the attributes and finds that dirty pages must be flushed.
  867. * NOTE: Upon exit of this function the task is guaranteed to be
  868. * released. In particular note that tk_release() will have
  869. * been called, so your task memory may have been freed.
  870. */
  871. void rpc_execute(struct rpc_task *task)
  872. {
  873. bool is_async = RPC_IS_ASYNC(task);
  874. rpc_set_active(task);
  875. rpc_make_runnable(rpciod_workqueue, task);
  876. if (!is_async)
  877. __rpc_execute(task);
  878. }
  879. static void rpc_async_schedule(struct work_struct *work)
  880. {
  881. unsigned int pflags = memalloc_nofs_save();
  882. __rpc_execute(container_of(work, struct rpc_task, u.tk_work));
  883. memalloc_nofs_restore(pflags);
  884. }
  885. /**
  886. * rpc_malloc - allocate RPC buffer resources
  887. * @task: RPC task
  888. *
  889. * A single memory region is allocated, which is split between the
  890. * RPC call and RPC reply that this task is being used for. When
  891. * this RPC is retired, the memory is released by calling rpc_free.
  892. *
  893. * To prevent rpciod from hanging, this allocator never sleeps,
  894. * returning -ENOMEM and suppressing warning if the request cannot
  895. * be serviced immediately. The caller can arrange to sleep in a
  896. * way that is safe for rpciod.
  897. *
  898. * Most requests are 'small' (under 2KiB) and can be serviced from a
  899. * mempool, ensuring that NFS reads and writes can always proceed,
  900. * and that there is good locality of reference for these buffers.
  901. */
  902. int rpc_malloc(struct rpc_task *task)
  903. {
  904. struct rpc_rqst *rqst = task->tk_rqstp;
  905. size_t size = rqst->rq_callsize + rqst->rq_rcvsize;
  906. struct rpc_buffer *buf;
  907. gfp_t gfp = GFP_NOFS;
  908. if (RPC_IS_SWAPPER(task))
  909. gfp = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN;
  910. size += sizeof(struct rpc_buffer);
  911. if (size <= RPC_BUFFER_MAXSIZE)
  912. buf = mempool_alloc(rpc_buffer_mempool, gfp);
  913. else
  914. buf = kmalloc(size, gfp);
  915. if (!buf)
  916. return -ENOMEM;
  917. buf->len = size;
  918. dprintk("RPC: %5u allocated buffer of size %zu at %p\n",
  919. task->tk_pid, size, buf);
  920. rqst->rq_buffer = buf->data;
  921. rqst->rq_rbuffer = (char *)rqst->rq_buffer + rqst->rq_callsize;
  922. return 0;
  923. }
  924. EXPORT_SYMBOL_GPL(rpc_malloc);
  925. /**
  926. * rpc_free - free RPC buffer resources allocated via rpc_malloc
  927. * @task: RPC task
  928. *
  929. */
  930. void rpc_free(struct rpc_task *task)
  931. {
  932. void *buffer = task->tk_rqstp->rq_buffer;
  933. size_t size;
  934. struct rpc_buffer *buf;
  935. buf = container_of(buffer, struct rpc_buffer, data);
  936. size = buf->len;
  937. dprintk("RPC: freeing buffer of size %zu at %p\n",
  938. size, buf);
  939. if (size <= RPC_BUFFER_MAXSIZE)
  940. mempool_free(buf, rpc_buffer_mempool);
  941. else
  942. kfree(buf);
  943. }
  944. EXPORT_SYMBOL_GPL(rpc_free);
  945. /*
  946. * Creation and deletion of RPC task structures
  947. */
  948. static void rpc_init_task(struct rpc_task *task, const struct rpc_task_setup *task_setup_data)
  949. {
  950. memset(task, 0, sizeof(*task));
  951. atomic_set(&task->tk_count, 1);
  952. task->tk_flags = task_setup_data->flags;
  953. task->tk_ops = task_setup_data->callback_ops;
  954. task->tk_calldata = task_setup_data->callback_data;
  955. INIT_LIST_HEAD(&task->tk_task);
  956. task->tk_priority = task_setup_data->priority - RPC_PRIORITY_LOW;
  957. task->tk_owner = current->tgid;
  958. /* Initialize workqueue for async tasks */
  959. task->tk_workqueue = task_setup_data->workqueue;
  960. task->tk_xprt = rpc_task_get_xprt(task_setup_data->rpc_client,
  961. xprt_get(task_setup_data->rpc_xprt));
  962. task->tk_op_cred = get_rpccred(task_setup_data->rpc_op_cred);
  963. if (task->tk_ops->rpc_call_prepare != NULL)
  964. task->tk_action = rpc_prepare_task;
  965. rpc_init_task_statistics(task);
  966. dprintk("RPC: new task initialized, procpid %u\n",
  967. task_pid_nr(current));
  968. }
  969. static struct rpc_task *
  970. rpc_alloc_task(void)
  971. {
  972. return (struct rpc_task *)mempool_alloc(rpc_task_mempool, GFP_NOFS);
  973. }
  974. /*
  975. * Create a new task for the specified client.
  976. */
  977. struct rpc_task *rpc_new_task(const struct rpc_task_setup *setup_data)
  978. {
  979. struct rpc_task *task = setup_data->task;
  980. unsigned short flags = 0;
  981. if (task == NULL) {
  982. task = rpc_alloc_task();
  983. flags = RPC_TASK_DYNAMIC;
  984. }
  985. rpc_init_task(task, setup_data);
  986. task->tk_flags |= flags;
  987. dprintk("RPC: allocated task %p\n", task);
  988. return task;
  989. }
  990. /*
  991. * rpc_free_task - release rpc task and perform cleanups
  992. *
  993. * Note that we free up the rpc_task _after_ rpc_release_calldata()
  994. * in order to work around a workqueue dependency issue.
  995. *
  996. * Tejun Heo states:
  997. * "Workqueue currently considers two work items to be the same if they're
  998. * on the same address and won't execute them concurrently - ie. it
  999. * makes a work item which is queued again while being executed wait
  1000. * for the previous execution to complete.
  1001. *
  1002. * If a work function frees the work item, and then waits for an event
  1003. * which should be performed by another work item and *that* work item
  1004. * recycles the freed work item, it can create a false dependency loop.
  1005. * There really is no reliable way to detect this short of verifying
  1006. * every memory free."
  1007. *
  1008. */
  1009. static void rpc_free_task(struct rpc_task *task)
  1010. {
  1011. unsigned short tk_flags = task->tk_flags;
  1012. put_rpccred(task->tk_op_cred);
  1013. rpc_release_calldata(task->tk_ops, task->tk_calldata);
  1014. if (tk_flags & RPC_TASK_DYNAMIC) {
  1015. dprintk("RPC: %5u freeing task\n", task->tk_pid);
  1016. mempool_free(task, rpc_task_mempool);
  1017. }
  1018. }
  1019. static void rpc_async_release(struct work_struct *work)
  1020. {
  1021. unsigned int pflags = memalloc_nofs_save();
  1022. rpc_free_task(container_of(work, struct rpc_task, u.tk_work));
  1023. memalloc_nofs_restore(pflags);
  1024. }
  1025. static void rpc_release_resources_task(struct rpc_task *task)
  1026. {
  1027. xprt_release(task);
  1028. if (task->tk_msg.rpc_cred) {
  1029. if (!(task->tk_flags & RPC_TASK_CRED_NOREF))
  1030. put_cred(task->tk_msg.rpc_cred);
  1031. task->tk_msg.rpc_cred = NULL;
  1032. }
  1033. rpc_task_release_client(task);
  1034. }
  1035. static void rpc_final_put_task(struct rpc_task *task,
  1036. struct workqueue_struct *q)
  1037. {
  1038. if (q != NULL) {
  1039. INIT_WORK(&task->u.tk_work, rpc_async_release);
  1040. queue_work(q, &task->u.tk_work);
  1041. } else
  1042. rpc_free_task(task);
  1043. }
  1044. static void rpc_do_put_task(struct rpc_task *task, struct workqueue_struct *q)
  1045. {
  1046. if (atomic_dec_and_test(&task->tk_count)) {
  1047. rpc_release_resources_task(task);
  1048. rpc_final_put_task(task, q);
  1049. }
  1050. }
  1051. void rpc_put_task(struct rpc_task *task)
  1052. {
  1053. rpc_do_put_task(task, NULL);
  1054. }
  1055. EXPORT_SYMBOL_GPL(rpc_put_task);
  1056. void rpc_put_task_async(struct rpc_task *task)
  1057. {
  1058. rpc_do_put_task(task, task->tk_workqueue);
  1059. }
  1060. EXPORT_SYMBOL_GPL(rpc_put_task_async);
  1061. static void rpc_release_task(struct rpc_task *task)
  1062. {
  1063. dprintk("RPC: %5u release task\n", task->tk_pid);
  1064. WARN_ON_ONCE(RPC_IS_QUEUED(task));
  1065. rpc_release_resources_task(task);
  1066. /*
  1067. * Note: at this point we have been removed from rpc_clnt->cl_tasks,
  1068. * so it should be safe to use task->tk_count as a test for whether
  1069. * or not any other processes still hold references to our rpc_task.
  1070. */
  1071. if (atomic_read(&task->tk_count) != 1 + !RPC_IS_ASYNC(task)) {
  1072. /* Wake up anyone who may be waiting for task completion */
  1073. if (!rpc_complete_task(task))
  1074. return;
  1075. } else {
  1076. if (!atomic_dec_and_test(&task->tk_count))
  1077. return;
  1078. }
  1079. rpc_final_put_task(task, task->tk_workqueue);
  1080. }
  1081. int rpciod_up(void)
  1082. {
  1083. return try_module_get(THIS_MODULE) ? 0 : -EINVAL;
  1084. }
  1085. void rpciod_down(void)
  1086. {
  1087. module_put(THIS_MODULE);
  1088. }
  1089. /*
  1090. * Start up the rpciod workqueue.
  1091. */
  1092. static int rpciod_start(void)
  1093. {
  1094. struct workqueue_struct *wq;
  1095. /*
  1096. * Create the rpciod thread and wait for it to start.
  1097. */
  1098. dprintk("RPC: creating workqueue rpciod\n");
  1099. wq = alloc_workqueue("rpciod", WQ_MEM_RECLAIM | WQ_UNBOUND, 0);
  1100. if (!wq)
  1101. goto out_failed;
  1102. rpciod_workqueue = wq;
  1103. /* Note: highpri because network receive is latency sensitive */
  1104. wq = alloc_workqueue("xprtiod", WQ_UNBOUND|WQ_MEM_RECLAIM|WQ_HIGHPRI, 0);
  1105. if (!wq)
  1106. goto free_rpciod;
  1107. xprtiod_workqueue = wq;
  1108. return 1;
  1109. free_rpciod:
  1110. wq = rpciod_workqueue;
  1111. rpciod_workqueue = NULL;
  1112. destroy_workqueue(wq);
  1113. out_failed:
  1114. return 0;
  1115. }
  1116. static void rpciod_stop(void)
  1117. {
  1118. struct workqueue_struct *wq = NULL;
  1119. if (rpciod_workqueue == NULL)
  1120. return;
  1121. dprintk("RPC: destroying workqueue rpciod\n");
  1122. wq = rpciod_workqueue;
  1123. rpciod_workqueue = NULL;
  1124. destroy_workqueue(wq);
  1125. wq = xprtiod_workqueue;
  1126. xprtiod_workqueue = NULL;
  1127. destroy_workqueue(wq);
  1128. }
  1129. void
  1130. rpc_destroy_mempool(void)
  1131. {
  1132. rpciod_stop();
  1133. mempool_destroy(rpc_buffer_mempool);
  1134. mempool_destroy(rpc_task_mempool);
  1135. kmem_cache_destroy(rpc_task_slabp);
  1136. kmem_cache_destroy(rpc_buffer_slabp);
  1137. rpc_destroy_wait_queue(&delay_queue);
  1138. }
  1139. int
  1140. rpc_init_mempool(void)
  1141. {
  1142. /*
  1143. * The following is not strictly a mempool initialisation,
  1144. * but there is no harm in doing it here
  1145. */
  1146. rpc_init_wait_queue(&delay_queue, "delayq");
  1147. if (!rpciod_start())
  1148. goto err_nomem;
  1149. rpc_task_slabp = kmem_cache_create("rpc_tasks",
  1150. sizeof(struct rpc_task),
  1151. 0, SLAB_HWCACHE_ALIGN,
  1152. NULL);
  1153. if (!rpc_task_slabp)
  1154. goto err_nomem;
  1155. rpc_buffer_slabp = kmem_cache_create("rpc_buffers",
  1156. RPC_BUFFER_MAXSIZE,
  1157. 0, SLAB_HWCACHE_ALIGN,
  1158. NULL);
  1159. if (!rpc_buffer_slabp)
  1160. goto err_nomem;
  1161. rpc_task_mempool = mempool_create_slab_pool(RPC_TASK_POOLSIZE,
  1162. rpc_task_slabp);
  1163. if (!rpc_task_mempool)
  1164. goto err_nomem;
  1165. rpc_buffer_mempool = mempool_create_slab_pool(RPC_BUFFER_POOLSIZE,
  1166. rpc_buffer_slabp);
  1167. if (!rpc_buffer_mempool)
  1168. goto err_nomem;
  1169. return 0;
  1170. err_nomem:
  1171. rpc_destroy_mempool();
  1172. return -ENOMEM;
  1173. }