slow-work.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /* Worker thread pool for slow items, such as filesystem lookups or mkdirs
  2. *
  3. * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. *
  11. * See Documentation/slow-work.txt
  12. */
  13. #include <linux/module.h>
  14. #include <linux/slow-work.h>
  15. #include <linux/kthread.h>
  16. #include <linux/freezer.h>
  17. #include <linux/wait.h>
  18. #define SLOW_WORK_CULL_TIMEOUT (5 * HZ) /* cull threads 5s after running out of
  19. * things to do */
  20. #define SLOW_WORK_OOM_TIMEOUT (5 * HZ) /* can't start new threads for 5s after
  21. * OOM */
  22. static void slow_work_cull_timeout(unsigned long);
  23. static void slow_work_oom_timeout(unsigned long);
  24. #ifdef CONFIG_SYSCTL
  25. static int slow_work_min_threads_sysctl(struct ctl_table *, int, struct file *,
  26. void __user *, size_t *, loff_t *);
  27. static int slow_work_max_threads_sysctl(struct ctl_table *, int , struct file *,
  28. void __user *, size_t *, loff_t *);
  29. #endif
  30. /*
  31. * The pool of threads has at least min threads in it as long as someone is
  32. * using the facility, and may have as many as max.
  33. *
  34. * A portion of the pool may be processing very slow operations.
  35. */
  36. static unsigned slow_work_min_threads = 2;
  37. static unsigned slow_work_max_threads = 4;
  38. static unsigned vslow_work_proportion = 50; /* % of threads that may process
  39. * very slow work */
  40. #ifdef CONFIG_SYSCTL
  41. static const int slow_work_min_min_threads = 2;
  42. static int slow_work_max_max_threads = 255;
  43. static const int slow_work_min_vslow = 1;
  44. static const int slow_work_max_vslow = 99;
  45. ctl_table slow_work_sysctls[] = {
  46. {
  47. .ctl_name = CTL_UNNUMBERED,
  48. .procname = "min-threads",
  49. .data = &slow_work_min_threads,
  50. .maxlen = sizeof(unsigned),
  51. .mode = 0644,
  52. .proc_handler = slow_work_min_threads_sysctl,
  53. .extra1 = (void *) &slow_work_min_min_threads,
  54. .extra2 = &slow_work_max_threads,
  55. },
  56. {
  57. .ctl_name = CTL_UNNUMBERED,
  58. .procname = "max-threads",
  59. .data = &slow_work_max_threads,
  60. .maxlen = sizeof(unsigned),
  61. .mode = 0644,
  62. .proc_handler = slow_work_max_threads_sysctl,
  63. .extra1 = &slow_work_min_threads,
  64. .extra2 = (void *) &slow_work_max_max_threads,
  65. },
  66. {
  67. .ctl_name = CTL_UNNUMBERED,
  68. .procname = "vslow-percentage",
  69. .data = &vslow_work_proportion,
  70. .maxlen = sizeof(unsigned),
  71. .mode = 0644,
  72. .proc_handler = &proc_dointvec_minmax,
  73. .extra1 = (void *) &slow_work_min_vslow,
  74. .extra2 = (void *) &slow_work_max_vslow,
  75. },
  76. { .ctl_name = 0 }
  77. };
  78. #endif
  79. /*
  80. * The active state of the thread pool
  81. */
  82. static atomic_t slow_work_thread_count;
  83. static atomic_t vslow_work_executing_count;
  84. static bool slow_work_may_not_start_new_thread;
  85. static bool slow_work_cull; /* cull a thread due to lack of activity */
  86. static DEFINE_TIMER(slow_work_cull_timer, slow_work_cull_timeout, 0, 0);
  87. static DEFINE_TIMER(slow_work_oom_timer, slow_work_oom_timeout, 0, 0);
  88. static struct slow_work slow_work_new_thread; /* new thread starter */
  89. /*
  90. * The queues of work items and the lock governing access to them. These are
  91. * shared between all the CPUs. It doesn't make sense to have per-CPU queues
  92. * as the number of threads bears no relation to the number of CPUs.
  93. *
  94. * There are two queues of work items: one for slow work items, and one for
  95. * very slow work items.
  96. */
  97. static LIST_HEAD(slow_work_queue);
  98. static LIST_HEAD(vslow_work_queue);
  99. static DEFINE_SPINLOCK(slow_work_queue_lock);
  100. /*
  101. * The thread controls. A variable used to signal to the threads that they
  102. * should exit when the queue is empty, a waitqueue used by the threads to wait
  103. * for signals, and a completion set by the last thread to exit.
  104. */
  105. static bool slow_work_threads_should_exit;
  106. static DECLARE_WAIT_QUEUE_HEAD(slow_work_thread_wq);
  107. static DECLARE_COMPLETION(slow_work_last_thread_exited);
  108. /*
  109. * The number of users of the thread pool and its lock. Whilst this is zero we
  110. * have no threads hanging around, and when this reaches zero, we wait for all
  111. * active or queued work items to complete and kill all the threads we do have.
  112. */
  113. static int slow_work_user_count;
  114. static DEFINE_MUTEX(slow_work_user_lock);
  115. /*
  116. * Calculate the maximum number of active threads in the pool that are
  117. * permitted to process very slow work items.
  118. *
  119. * The answer is rounded up to at least 1, but may not equal or exceed the
  120. * maximum number of the threads in the pool. This means we always have at
  121. * least one thread that can process slow work items, and we always have at
  122. * least one thread that won't get tied up doing so.
  123. */
  124. static unsigned slow_work_calc_vsmax(void)
  125. {
  126. unsigned vsmax;
  127. vsmax = atomic_read(&slow_work_thread_count) * vslow_work_proportion;
  128. vsmax /= 100;
  129. vsmax = max(vsmax, 1U);
  130. return min(vsmax, slow_work_max_threads - 1);
  131. }
  132. /*
  133. * Attempt to execute stuff queued on a slow thread. Return true if we managed
  134. * it, false if there was nothing to do.
  135. */
  136. static bool slow_work_execute(void)
  137. {
  138. struct slow_work *work = NULL;
  139. unsigned vsmax;
  140. bool very_slow;
  141. vsmax = slow_work_calc_vsmax();
  142. /* see if we can schedule a new thread to be started if we're not
  143. * keeping up with the work */
  144. if (!waitqueue_active(&slow_work_thread_wq) &&
  145. (!list_empty(&slow_work_queue) || !list_empty(&vslow_work_queue)) &&
  146. atomic_read(&slow_work_thread_count) < slow_work_max_threads &&
  147. !slow_work_may_not_start_new_thread)
  148. slow_work_enqueue(&slow_work_new_thread);
  149. /* find something to execute */
  150. spin_lock_irq(&slow_work_queue_lock);
  151. if (!list_empty(&vslow_work_queue) &&
  152. atomic_read(&vslow_work_executing_count) < vsmax) {
  153. work = list_entry(vslow_work_queue.next,
  154. struct slow_work, link);
  155. if (test_and_set_bit_lock(SLOW_WORK_EXECUTING, &work->flags))
  156. BUG();
  157. list_del_init(&work->link);
  158. atomic_inc(&vslow_work_executing_count);
  159. very_slow = true;
  160. } else if (!list_empty(&slow_work_queue)) {
  161. work = list_entry(slow_work_queue.next,
  162. struct slow_work, link);
  163. if (test_and_set_bit_lock(SLOW_WORK_EXECUTING, &work->flags))
  164. BUG();
  165. list_del_init(&work->link);
  166. very_slow = false;
  167. } else {
  168. very_slow = false; /* avoid the compiler warning */
  169. }
  170. spin_unlock_irq(&slow_work_queue_lock);
  171. if (!work)
  172. return false;
  173. if (!test_and_clear_bit(SLOW_WORK_PENDING, &work->flags))
  174. BUG();
  175. work->ops->execute(work);
  176. if (very_slow)
  177. atomic_dec(&vslow_work_executing_count);
  178. clear_bit_unlock(SLOW_WORK_EXECUTING, &work->flags);
  179. /* if someone tried to enqueue the item whilst we were executing it,
  180. * then it'll be left unenqueued to avoid multiple threads trying to
  181. * execute it simultaneously
  182. *
  183. * there is, however, a race between us testing the pending flag and
  184. * getting the spinlock, and between the enqueuer setting the pending
  185. * flag and getting the spinlock, so we use a deferral bit to tell us
  186. * if the enqueuer got there first
  187. */
  188. if (test_bit(SLOW_WORK_PENDING, &work->flags)) {
  189. spin_lock_irq(&slow_work_queue_lock);
  190. if (!test_bit(SLOW_WORK_EXECUTING, &work->flags) &&
  191. test_and_clear_bit(SLOW_WORK_ENQ_DEFERRED, &work->flags))
  192. goto auto_requeue;
  193. spin_unlock_irq(&slow_work_queue_lock);
  194. }
  195. work->ops->put_ref(work);
  196. return true;
  197. auto_requeue:
  198. /* we must complete the enqueue operation
  199. * - we transfer our ref on the item back to the appropriate queue
  200. * - don't wake another thread up as we're awake already
  201. */
  202. if (test_bit(SLOW_WORK_VERY_SLOW, &work->flags))
  203. list_add_tail(&work->link, &vslow_work_queue);
  204. else
  205. list_add_tail(&work->link, &slow_work_queue);
  206. spin_unlock_irq(&slow_work_queue_lock);
  207. return true;
  208. }
  209. /**
  210. * slow_work_enqueue - Schedule a slow work item for processing
  211. * @work: The work item to queue
  212. *
  213. * Schedule a slow work item for processing. If the item is already undergoing
  214. * execution, this guarantees not to re-enter the execution routine until the
  215. * first execution finishes.
  216. *
  217. * The item is pinned by this function as it retains a reference to it, managed
  218. * through the item operations. The item is unpinned once it has been
  219. * executed.
  220. *
  221. * An item may hog the thread that is running it for a relatively large amount
  222. * of time, sufficient, for example, to perform several lookup, mkdir, create
  223. * and setxattr operations. It may sleep on I/O and may sleep to obtain locks.
  224. *
  225. * Conversely, if a number of items are awaiting processing, it may take some
  226. * time before any given item is given attention. The number of threads in the
  227. * pool may be increased to deal with demand, but only up to a limit.
  228. *
  229. * If SLOW_WORK_VERY_SLOW is set on the work item, then it will be placed in
  230. * the very slow queue, from which only a portion of the threads will be
  231. * allowed to pick items to execute. This ensures that very slow items won't
  232. * overly block ones that are just ordinarily slow.
  233. *
  234. * Returns 0 if successful, -EAGAIN if not.
  235. */
  236. int slow_work_enqueue(struct slow_work *work)
  237. {
  238. unsigned long flags;
  239. BUG_ON(slow_work_user_count <= 0);
  240. BUG_ON(!work);
  241. BUG_ON(!work->ops);
  242. BUG_ON(!work->ops->get_ref);
  243. /* when honouring an enqueue request, we only promise that we will run
  244. * the work function in the future; we do not promise to run it once
  245. * per enqueue request
  246. *
  247. * we use the PENDING bit to merge together repeat requests without
  248. * having to disable IRQs and take the spinlock, whilst still
  249. * maintaining our promise
  250. */
  251. if (!test_and_set_bit_lock(SLOW_WORK_PENDING, &work->flags)) {
  252. spin_lock_irqsave(&slow_work_queue_lock, flags);
  253. /* we promise that we will not attempt to execute the work
  254. * function in more than one thread simultaneously
  255. *
  256. * this, however, leaves us with a problem if we're asked to
  257. * enqueue the work whilst someone is executing the work
  258. * function as simply queueing the work immediately means that
  259. * another thread may try executing it whilst it is already
  260. * under execution
  261. *
  262. * to deal with this, we set the ENQ_DEFERRED bit instead of
  263. * enqueueing, and the thread currently executing the work
  264. * function will enqueue the work item when the work function
  265. * returns and it has cleared the EXECUTING bit
  266. */
  267. if (test_bit(SLOW_WORK_EXECUTING, &work->flags)) {
  268. set_bit(SLOW_WORK_ENQ_DEFERRED, &work->flags);
  269. } else {
  270. if (work->ops->get_ref(work) < 0)
  271. goto cant_get_ref;
  272. if (test_bit(SLOW_WORK_VERY_SLOW, &work->flags))
  273. list_add_tail(&work->link, &vslow_work_queue);
  274. else
  275. list_add_tail(&work->link, &slow_work_queue);
  276. wake_up(&slow_work_thread_wq);
  277. }
  278. spin_unlock_irqrestore(&slow_work_queue_lock, flags);
  279. }
  280. return 0;
  281. cant_get_ref:
  282. spin_unlock_irqrestore(&slow_work_queue_lock, flags);
  283. return -EAGAIN;
  284. }
  285. EXPORT_SYMBOL(slow_work_enqueue);
  286. /*
  287. * Schedule a cull of the thread pool at some time in the near future
  288. */
  289. static void slow_work_schedule_cull(void)
  290. {
  291. mod_timer(&slow_work_cull_timer,
  292. round_jiffies(jiffies + SLOW_WORK_CULL_TIMEOUT));
  293. }
  294. /*
  295. * Worker thread culling algorithm
  296. */
  297. static bool slow_work_cull_thread(void)
  298. {
  299. unsigned long flags;
  300. bool do_cull = false;
  301. spin_lock_irqsave(&slow_work_queue_lock, flags);
  302. if (slow_work_cull) {
  303. slow_work_cull = false;
  304. if (list_empty(&slow_work_queue) &&
  305. list_empty(&vslow_work_queue) &&
  306. atomic_read(&slow_work_thread_count) >
  307. slow_work_min_threads) {
  308. slow_work_schedule_cull();
  309. do_cull = true;
  310. }
  311. }
  312. spin_unlock_irqrestore(&slow_work_queue_lock, flags);
  313. return do_cull;
  314. }
  315. /*
  316. * Determine if there is slow work available for dispatch
  317. */
  318. static inline bool slow_work_available(int vsmax)
  319. {
  320. return !list_empty(&slow_work_queue) ||
  321. (!list_empty(&vslow_work_queue) &&
  322. atomic_read(&vslow_work_executing_count) < vsmax);
  323. }
  324. /*
  325. * Worker thread dispatcher
  326. */
  327. static int slow_work_thread(void *_data)
  328. {
  329. int vsmax;
  330. DEFINE_WAIT(wait);
  331. set_freezable();
  332. set_user_nice(current, -5);
  333. for (;;) {
  334. vsmax = vslow_work_proportion;
  335. vsmax *= atomic_read(&slow_work_thread_count);
  336. vsmax /= 100;
  337. prepare_to_wait_exclusive(&slow_work_thread_wq, &wait,
  338. TASK_INTERRUPTIBLE);
  339. if (!freezing(current) &&
  340. !slow_work_threads_should_exit &&
  341. !slow_work_available(vsmax) &&
  342. !slow_work_cull)
  343. schedule();
  344. finish_wait(&slow_work_thread_wq, &wait);
  345. try_to_freeze();
  346. vsmax = vslow_work_proportion;
  347. vsmax *= atomic_read(&slow_work_thread_count);
  348. vsmax /= 100;
  349. if (slow_work_available(vsmax) && slow_work_execute()) {
  350. cond_resched();
  351. if (list_empty(&slow_work_queue) &&
  352. list_empty(&vslow_work_queue) &&
  353. atomic_read(&slow_work_thread_count) >
  354. slow_work_min_threads)
  355. slow_work_schedule_cull();
  356. continue;
  357. }
  358. if (slow_work_threads_should_exit)
  359. break;
  360. if (slow_work_cull && slow_work_cull_thread())
  361. break;
  362. }
  363. if (atomic_dec_and_test(&slow_work_thread_count))
  364. complete_and_exit(&slow_work_last_thread_exited, 0);
  365. return 0;
  366. }
  367. /*
  368. * Handle thread cull timer expiration
  369. */
  370. static void slow_work_cull_timeout(unsigned long data)
  371. {
  372. slow_work_cull = true;
  373. wake_up(&slow_work_thread_wq);
  374. }
  375. /*
  376. * Get a reference on slow work thread starter
  377. */
  378. static int slow_work_new_thread_get_ref(struct slow_work *work)
  379. {
  380. return 0;
  381. }
  382. /*
  383. * Drop a reference on slow work thread starter
  384. */
  385. static void slow_work_new_thread_put_ref(struct slow_work *work)
  386. {
  387. }
  388. /*
  389. * Start a new slow work thread
  390. */
  391. static void slow_work_new_thread_execute(struct slow_work *work)
  392. {
  393. struct task_struct *p;
  394. if (slow_work_threads_should_exit)
  395. return;
  396. if (atomic_read(&slow_work_thread_count) >= slow_work_max_threads)
  397. return;
  398. if (!mutex_trylock(&slow_work_user_lock))
  399. return;
  400. slow_work_may_not_start_new_thread = true;
  401. atomic_inc(&slow_work_thread_count);
  402. p = kthread_run(slow_work_thread, NULL, "kslowd");
  403. if (IS_ERR(p)) {
  404. printk(KERN_DEBUG "Slow work thread pool: OOM\n");
  405. if (atomic_dec_and_test(&slow_work_thread_count))
  406. BUG(); /* we're running on a slow work thread... */
  407. mod_timer(&slow_work_oom_timer,
  408. round_jiffies(jiffies + SLOW_WORK_OOM_TIMEOUT));
  409. } else {
  410. /* ratelimit the starting of new threads */
  411. mod_timer(&slow_work_oom_timer, jiffies + 1);
  412. }
  413. mutex_unlock(&slow_work_user_lock);
  414. }
  415. static const struct slow_work_ops slow_work_new_thread_ops = {
  416. .get_ref = slow_work_new_thread_get_ref,
  417. .put_ref = slow_work_new_thread_put_ref,
  418. .execute = slow_work_new_thread_execute,
  419. };
  420. /*
  421. * post-OOM new thread start suppression expiration
  422. */
  423. static void slow_work_oom_timeout(unsigned long data)
  424. {
  425. slow_work_may_not_start_new_thread = false;
  426. }
  427. #ifdef CONFIG_SYSCTL
  428. /*
  429. * Handle adjustment of the minimum number of threads
  430. */
  431. static int slow_work_min_threads_sysctl(struct ctl_table *table, int write,
  432. struct file *filp, void __user *buffer,
  433. size_t *lenp, loff_t *ppos)
  434. {
  435. int ret = proc_dointvec_minmax(table, write, filp, buffer, lenp, ppos);
  436. int n;
  437. if (ret == 0) {
  438. mutex_lock(&slow_work_user_lock);
  439. if (slow_work_user_count > 0) {
  440. /* see if we need to start or stop threads */
  441. n = atomic_read(&slow_work_thread_count) -
  442. slow_work_min_threads;
  443. if (n < 0 && !slow_work_may_not_start_new_thread)
  444. slow_work_enqueue(&slow_work_new_thread);
  445. else if (n > 0)
  446. slow_work_schedule_cull();
  447. }
  448. mutex_unlock(&slow_work_user_lock);
  449. }
  450. return ret;
  451. }
  452. /*
  453. * Handle adjustment of the maximum number of threads
  454. */
  455. static int slow_work_max_threads_sysctl(struct ctl_table *table, int write,
  456. struct file *filp, void __user *buffer,
  457. size_t *lenp, loff_t *ppos)
  458. {
  459. int ret = proc_dointvec_minmax(table, write, filp, buffer, lenp, ppos);
  460. int n;
  461. if (ret == 0) {
  462. mutex_lock(&slow_work_user_lock);
  463. if (slow_work_user_count > 0) {
  464. /* see if we need to stop threads */
  465. n = slow_work_max_threads -
  466. atomic_read(&slow_work_thread_count);
  467. if (n < 0)
  468. slow_work_schedule_cull();
  469. }
  470. mutex_unlock(&slow_work_user_lock);
  471. }
  472. return ret;
  473. }
  474. #endif /* CONFIG_SYSCTL */
  475. /**
  476. * slow_work_register_user - Register a user of the facility
  477. *
  478. * Register a user of the facility, starting up the initial threads if there
  479. * aren't any other users at this point. This will return 0 if successful, or
  480. * an error if not.
  481. */
  482. int slow_work_register_user(void)
  483. {
  484. struct task_struct *p;
  485. int loop;
  486. mutex_lock(&slow_work_user_lock);
  487. if (slow_work_user_count == 0) {
  488. printk(KERN_NOTICE "Slow work thread pool: Starting up\n");
  489. init_completion(&slow_work_last_thread_exited);
  490. slow_work_threads_should_exit = false;
  491. slow_work_init(&slow_work_new_thread,
  492. &slow_work_new_thread_ops);
  493. slow_work_may_not_start_new_thread = false;
  494. slow_work_cull = false;
  495. /* start the minimum number of threads */
  496. for (loop = 0; loop < slow_work_min_threads; loop++) {
  497. atomic_inc(&slow_work_thread_count);
  498. p = kthread_run(slow_work_thread, NULL, "kslowd");
  499. if (IS_ERR(p))
  500. goto error;
  501. }
  502. printk(KERN_NOTICE "Slow work thread pool: Ready\n");
  503. }
  504. slow_work_user_count++;
  505. mutex_unlock(&slow_work_user_lock);
  506. return 0;
  507. error:
  508. if (atomic_dec_and_test(&slow_work_thread_count))
  509. complete(&slow_work_last_thread_exited);
  510. if (loop > 0) {
  511. printk(KERN_ERR "Slow work thread pool:"
  512. " Aborting startup on ENOMEM\n");
  513. slow_work_threads_should_exit = true;
  514. wake_up_all(&slow_work_thread_wq);
  515. wait_for_completion(&slow_work_last_thread_exited);
  516. printk(KERN_ERR "Slow work thread pool: Aborted\n");
  517. }
  518. mutex_unlock(&slow_work_user_lock);
  519. return PTR_ERR(p);
  520. }
  521. EXPORT_SYMBOL(slow_work_register_user);
  522. /**
  523. * slow_work_unregister_user - Unregister a user of the facility
  524. *
  525. * Unregister a user of the facility, killing all the threads if this was the
  526. * last one.
  527. */
  528. void slow_work_unregister_user(void)
  529. {
  530. mutex_lock(&slow_work_user_lock);
  531. BUG_ON(slow_work_user_count <= 0);
  532. slow_work_user_count--;
  533. if (slow_work_user_count == 0) {
  534. printk(KERN_NOTICE "Slow work thread pool: Shutting down\n");
  535. slow_work_threads_should_exit = true;
  536. del_timer_sync(&slow_work_cull_timer);
  537. del_timer_sync(&slow_work_oom_timer);
  538. wake_up_all(&slow_work_thread_wq);
  539. wait_for_completion(&slow_work_last_thread_exited);
  540. printk(KERN_NOTICE "Slow work thread pool:"
  541. " Shut down complete\n");
  542. }
  543. mutex_unlock(&slow_work_user_lock);
  544. }
  545. EXPORT_SYMBOL(slow_work_unregister_user);
  546. /*
  547. * Initialise the slow work facility
  548. */
  549. static int __init init_slow_work(void)
  550. {
  551. unsigned nr_cpus = num_possible_cpus();
  552. if (slow_work_max_threads < nr_cpus)
  553. slow_work_max_threads = nr_cpus;
  554. #ifdef CONFIG_SYSCTL
  555. if (slow_work_max_max_threads < nr_cpus * 2)
  556. slow_work_max_max_threads = nr_cpus * 2;
  557. #endif
  558. return 0;
  559. }
  560. subsys_initcall(init_slow_work);