slow-work.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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. * Worker thread culling algorithm
  288. */
  289. static bool slow_work_cull_thread(void)
  290. {
  291. unsigned long flags;
  292. bool do_cull = false;
  293. spin_lock_irqsave(&slow_work_queue_lock, flags);
  294. if (slow_work_cull) {
  295. slow_work_cull = false;
  296. if (list_empty(&slow_work_queue) &&
  297. list_empty(&vslow_work_queue) &&
  298. atomic_read(&slow_work_thread_count) >
  299. slow_work_min_threads) {
  300. mod_timer(&slow_work_cull_timer,
  301. jiffies + SLOW_WORK_CULL_TIMEOUT);
  302. do_cull = true;
  303. }
  304. }
  305. spin_unlock_irqrestore(&slow_work_queue_lock, flags);
  306. return do_cull;
  307. }
  308. /*
  309. * Determine if there is slow work available for dispatch
  310. */
  311. static inline bool slow_work_available(int vsmax)
  312. {
  313. return !list_empty(&slow_work_queue) ||
  314. (!list_empty(&vslow_work_queue) &&
  315. atomic_read(&vslow_work_executing_count) < vsmax);
  316. }
  317. /*
  318. * Worker thread dispatcher
  319. */
  320. static int slow_work_thread(void *_data)
  321. {
  322. int vsmax;
  323. DEFINE_WAIT(wait);
  324. set_freezable();
  325. set_user_nice(current, -5);
  326. for (;;) {
  327. vsmax = vslow_work_proportion;
  328. vsmax *= atomic_read(&slow_work_thread_count);
  329. vsmax /= 100;
  330. prepare_to_wait(&slow_work_thread_wq, &wait,
  331. TASK_INTERRUPTIBLE);
  332. if (!freezing(current) &&
  333. !slow_work_threads_should_exit &&
  334. !slow_work_available(vsmax) &&
  335. !slow_work_cull)
  336. schedule();
  337. finish_wait(&slow_work_thread_wq, &wait);
  338. try_to_freeze();
  339. vsmax = vslow_work_proportion;
  340. vsmax *= atomic_read(&slow_work_thread_count);
  341. vsmax /= 100;
  342. if (slow_work_available(vsmax) && slow_work_execute()) {
  343. cond_resched();
  344. if (list_empty(&slow_work_queue) &&
  345. list_empty(&vslow_work_queue) &&
  346. atomic_read(&slow_work_thread_count) >
  347. slow_work_min_threads)
  348. mod_timer(&slow_work_cull_timer,
  349. jiffies + SLOW_WORK_CULL_TIMEOUT);
  350. continue;
  351. }
  352. if (slow_work_threads_should_exit)
  353. break;
  354. if (slow_work_cull && slow_work_cull_thread())
  355. break;
  356. }
  357. if (atomic_dec_and_test(&slow_work_thread_count))
  358. complete_and_exit(&slow_work_last_thread_exited, 0);
  359. return 0;
  360. }
  361. /*
  362. * Handle thread cull timer expiration
  363. */
  364. static void slow_work_cull_timeout(unsigned long data)
  365. {
  366. slow_work_cull = true;
  367. wake_up(&slow_work_thread_wq);
  368. }
  369. /*
  370. * Get a reference on slow work thread starter
  371. */
  372. static int slow_work_new_thread_get_ref(struct slow_work *work)
  373. {
  374. return 0;
  375. }
  376. /*
  377. * Drop a reference on slow work thread starter
  378. */
  379. static void slow_work_new_thread_put_ref(struct slow_work *work)
  380. {
  381. }
  382. /*
  383. * Start a new slow work thread
  384. */
  385. static void slow_work_new_thread_execute(struct slow_work *work)
  386. {
  387. struct task_struct *p;
  388. if (slow_work_threads_should_exit)
  389. return;
  390. if (atomic_read(&slow_work_thread_count) >= slow_work_max_threads)
  391. return;
  392. if (!mutex_trylock(&slow_work_user_lock))
  393. return;
  394. slow_work_may_not_start_new_thread = true;
  395. atomic_inc(&slow_work_thread_count);
  396. p = kthread_run(slow_work_thread, NULL, "kslowd");
  397. if (IS_ERR(p)) {
  398. printk(KERN_DEBUG "Slow work thread pool: OOM\n");
  399. if (atomic_dec_and_test(&slow_work_thread_count))
  400. BUG(); /* we're running on a slow work thread... */
  401. mod_timer(&slow_work_oom_timer,
  402. jiffies + SLOW_WORK_OOM_TIMEOUT);
  403. } else {
  404. /* ratelimit the starting of new threads */
  405. mod_timer(&slow_work_oom_timer, jiffies + 1);
  406. }
  407. mutex_unlock(&slow_work_user_lock);
  408. }
  409. static const struct slow_work_ops slow_work_new_thread_ops = {
  410. .get_ref = slow_work_new_thread_get_ref,
  411. .put_ref = slow_work_new_thread_put_ref,
  412. .execute = slow_work_new_thread_execute,
  413. };
  414. /*
  415. * post-OOM new thread start suppression expiration
  416. */
  417. static void slow_work_oom_timeout(unsigned long data)
  418. {
  419. slow_work_may_not_start_new_thread = false;
  420. }
  421. #ifdef CONFIG_SYSCTL
  422. /*
  423. * Handle adjustment of the minimum number of threads
  424. */
  425. static int slow_work_min_threads_sysctl(struct ctl_table *table, int write,
  426. struct file *filp, void __user *buffer,
  427. size_t *lenp, loff_t *ppos)
  428. {
  429. int ret = proc_dointvec_minmax(table, write, filp, buffer, lenp, ppos);
  430. int n;
  431. if (ret == 0) {
  432. mutex_lock(&slow_work_user_lock);
  433. if (slow_work_user_count > 0) {
  434. /* see if we need to start or stop threads */
  435. n = atomic_read(&slow_work_thread_count) -
  436. slow_work_min_threads;
  437. if (n < 0 && !slow_work_may_not_start_new_thread)
  438. slow_work_enqueue(&slow_work_new_thread);
  439. else if (n > 0)
  440. mod_timer(&slow_work_cull_timer,
  441. jiffies + SLOW_WORK_CULL_TIMEOUT);
  442. }
  443. mutex_unlock(&slow_work_user_lock);
  444. }
  445. return ret;
  446. }
  447. /*
  448. * Handle adjustment of the maximum number of threads
  449. */
  450. static int slow_work_max_threads_sysctl(struct ctl_table *table, int write,
  451. struct file *filp, void __user *buffer,
  452. size_t *lenp, loff_t *ppos)
  453. {
  454. int ret = proc_dointvec_minmax(table, write, filp, buffer, lenp, ppos);
  455. int n;
  456. if (ret == 0) {
  457. mutex_lock(&slow_work_user_lock);
  458. if (slow_work_user_count > 0) {
  459. /* see if we need to stop threads */
  460. n = slow_work_max_threads -
  461. atomic_read(&slow_work_thread_count);
  462. if (n < 0)
  463. mod_timer(&slow_work_cull_timer,
  464. jiffies + SLOW_WORK_CULL_TIMEOUT);
  465. }
  466. mutex_unlock(&slow_work_user_lock);
  467. }
  468. return ret;
  469. }
  470. #endif /* CONFIG_SYSCTL */
  471. /**
  472. * slow_work_register_user - Register a user of the facility
  473. *
  474. * Register a user of the facility, starting up the initial threads if there
  475. * aren't any other users at this point. This will return 0 if successful, or
  476. * an error if not.
  477. */
  478. int slow_work_register_user(void)
  479. {
  480. struct task_struct *p;
  481. int loop;
  482. mutex_lock(&slow_work_user_lock);
  483. if (slow_work_user_count == 0) {
  484. printk(KERN_NOTICE "Slow work thread pool: Starting up\n");
  485. init_completion(&slow_work_last_thread_exited);
  486. slow_work_threads_should_exit = false;
  487. slow_work_init(&slow_work_new_thread,
  488. &slow_work_new_thread_ops);
  489. slow_work_may_not_start_new_thread = false;
  490. slow_work_cull = false;
  491. /* start the minimum number of threads */
  492. for (loop = 0; loop < slow_work_min_threads; loop++) {
  493. atomic_inc(&slow_work_thread_count);
  494. p = kthread_run(slow_work_thread, NULL, "kslowd");
  495. if (IS_ERR(p))
  496. goto error;
  497. }
  498. printk(KERN_NOTICE "Slow work thread pool: Ready\n");
  499. }
  500. slow_work_user_count++;
  501. mutex_unlock(&slow_work_user_lock);
  502. return 0;
  503. error:
  504. if (atomic_dec_and_test(&slow_work_thread_count))
  505. complete(&slow_work_last_thread_exited);
  506. if (loop > 0) {
  507. printk(KERN_ERR "Slow work thread pool:"
  508. " Aborting startup on ENOMEM\n");
  509. slow_work_threads_should_exit = true;
  510. wake_up_all(&slow_work_thread_wq);
  511. wait_for_completion(&slow_work_last_thread_exited);
  512. printk(KERN_ERR "Slow work thread pool: Aborted\n");
  513. }
  514. mutex_unlock(&slow_work_user_lock);
  515. return PTR_ERR(p);
  516. }
  517. EXPORT_SYMBOL(slow_work_register_user);
  518. /**
  519. * slow_work_unregister_user - Unregister a user of the facility
  520. *
  521. * Unregister a user of the facility, killing all the threads if this was the
  522. * last one.
  523. */
  524. void slow_work_unregister_user(void)
  525. {
  526. mutex_lock(&slow_work_user_lock);
  527. BUG_ON(slow_work_user_count <= 0);
  528. slow_work_user_count--;
  529. if (slow_work_user_count == 0) {
  530. printk(KERN_NOTICE "Slow work thread pool: Shutting down\n");
  531. slow_work_threads_should_exit = true;
  532. wake_up_all(&slow_work_thread_wq);
  533. wait_for_completion(&slow_work_last_thread_exited);
  534. printk(KERN_NOTICE "Slow work thread pool:"
  535. " Shut down complete\n");
  536. }
  537. del_timer_sync(&slow_work_cull_timer);
  538. mutex_unlock(&slow_work_user_lock);
  539. }
  540. EXPORT_SYMBOL(slow_work_unregister_user);
  541. /*
  542. * Initialise the slow work facility
  543. */
  544. static int __init init_slow_work(void)
  545. {
  546. unsigned nr_cpus = num_possible_cpus();
  547. if (slow_work_max_threads < nr_cpus)
  548. slow_work_max_threads = nr_cpus;
  549. #ifdef CONFIG_SYSCTL
  550. if (slow_work_max_max_threads < nr_cpus * 2)
  551. slow_work_max_max_threads = nr_cpus * 2;
  552. #endif
  553. return 0;
  554. }
  555. subsys_initcall(init_slow_work);