oom_kill.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. * linux/mm/oom_kill.c
  3. *
  4. * Copyright (C) 1998,2000 Rik van Riel
  5. * Thanks go out to Claus Fischer for some serious inspiration and
  6. * for goading me into coding this file...
  7. *
  8. * The routines in this file are used to kill a process when
  9. * we're seriously out of memory. This gets called from __alloc_pages()
  10. * in mm/page_alloc.c when we really run out of memory.
  11. *
  12. * Since we won't call these routines often (on a well-configured
  13. * machine) this file will double as a 'coding guide' and a signpost
  14. * for newbie kernel hackers. It features several pointers to major
  15. * kernel subsystems and hints as to where to find out what things do.
  16. */
  17. #include <linux/oom.h>
  18. #include <linux/mm.h>
  19. #include <linux/err.h>
  20. #include <linux/gfp.h>
  21. #include <linux/sched.h>
  22. #include <linux/swap.h>
  23. #include <linux/timex.h>
  24. #include <linux/jiffies.h>
  25. #include <linux/cpuset.h>
  26. #include <linux/module.h>
  27. #include <linux/notifier.h>
  28. #include <linux/memcontrol.h>
  29. #include <linux/security.h>
  30. int sysctl_panic_on_oom;
  31. int sysctl_oom_kill_allocating_task;
  32. int sysctl_oom_dump_tasks;
  33. static DEFINE_SPINLOCK(zone_scan_lock);
  34. /* #define DEBUG */
  35. /*
  36. * Is all threads of the target process nodes overlap ours?
  37. */
  38. static int has_intersects_mems_allowed(struct task_struct *tsk)
  39. {
  40. struct task_struct *t;
  41. t = tsk;
  42. do {
  43. if (cpuset_mems_allowed_intersects(current, t))
  44. return 1;
  45. t = next_thread(t);
  46. } while (t != tsk);
  47. return 0;
  48. }
  49. /**
  50. * badness - calculate a numeric value for how bad this task has been
  51. * @p: task struct of which task we should calculate
  52. * @uptime: current uptime in seconds
  53. *
  54. * The formula used is relatively simple and documented inline in the
  55. * function. The main rationale is that we want to select a good task
  56. * to kill when we run out of memory.
  57. *
  58. * Good in this context means that:
  59. * 1) we lose the minimum amount of work done
  60. * 2) we recover a large amount of memory
  61. * 3) we don't kill anything innocent of eating tons of memory
  62. * 4) we want to kill the minimum amount of processes (one)
  63. * 5) we try to kill the process the user expects us to kill, this
  64. * algorithm has been meticulously tuned to meet the principle
  65. * of least surprise ... (be careful when you change it)
  66. */
  67. unsigned long badness(struct task_struct *p, unsigned long uptime)
  68. {
  69. unsigned long points, cpu_time, run_time;
  70. struct mm_struct *mm;
  71. struct task_struct *child;
  72. int oom_adj = p->signal->oom_adj;
  73. struct task_cputime task_time;
  74. unsigned long utime;
  75. unsigned long stime;
  76. if (oom_adj == OOM_DISABLE)
  77. return 0;
  78. task_lock(p);
  79. mm = p->mm;
  80. if (!mm) {
  81. task_unlock(p);
  82. return 0;
  83. }
  84. /*
  85. * The memory size of the process is the basis for the badness.
  86. */
  87. points = mm->total_vm;
  88. /*
  89. * After this unlock we can no longer dereference local variable `mm'
  90. */
  91. task_unlock(p);
  92. /*
  93. * swapoff can easily use up all memory, so kill those first.
  94. */
  95. if (p->flags & PF_OOM_ORIGIN)
  96. return ULONG_MAX;
  97. /*
  98. * Processes which fork a lot of child processes are likely
  99. * a good choice. We add half the vmsize of the children if they
  100. * have an own mm. This prevents forking servers to flood the
  101. * machine with an endless amount of children. In case a single
  102. * child is eating the vast majority of memory, adding only half
  103. * to the parents will make the child our kill candidate of choice.
  104. */
  105. list_for_each_entry(child, &p->children, sibling) {
  106. task_lock(child);
  107. if (child->mm != mm && child->mm)
  108. points += child->mm->total_vm/2 + 1;
  109. task_unlock(child);
  110. }
  111. /*
  112. * CPU time is in tens of seconds and run time is in thousands
  113. * of seconds. There is no particular reason for this other than
  114. * that it turned out to work very well in practice.
  115. */
  116. thread_group_cputime(p, &task_time);
  117. utime = cputime_to_jiffies(task_time.utime);
  118. stime = cputime_to_jiffies(task_time.stime);
  119. cpu_time = (utime + stime) >> (SHIFT_HZ + 3);
  120. if (uptime >= p->start_time.tv_sec)
  121. run_time = (uptime - p->start_time.tv_sec) >> 10;
  122. else
  123. run_time = 0;
  124. if (cpu_time)
  125. points /= int_sqrt(cpu_time);
  126. if (run_time)
  127. points /= int_sqrt(int_sqrt(run_time));
  128. /*
  129. * Niced processes are most likely less important, so double
  130. * their badness points.
  131. */
  132. if (task_nice(p) > 0)
  133. points *= 2;
  134. /*
  135. * Superuser processes are usually more important, so we make it
  136. * less likely that we kill those.
  137. */
  138. if (has_capability_noaudit(p, CAP_SYS_ADMIN) ||
  139. has_capability_noaudit(p, CAP_SYS_RESOURCE))
  140. points /= 4;
  141. /*
  142. * We don't want to kill a process with direct hardware access.
  143. * Not only could that mess up the hardware, but usually users
  144. * tend to only have this flag set on applications they think
  145. * of as important.
  146. */
  147. if (has_capability_noaudit(p, CAP_SYS_RAWIO))
  148. points /= 4;
  149. /*
  150. * If p's nodes don't overlap ours, it may still help to kill p
  151. * because p may have allocated or otherwise mapped memory on
  152. * this node before. However it will be less likely.
  153. */
  154. if (!has_intersects_mems_allowed(p))
  155. points /= 8;
  156. /*
  157. * Adjust the score by oom_adj.
  158. */
  159. if (oom_adj) {
  160. if (oom_adj > 0) {
  161. if (!points)
  162. points = 1;
  163. points <<= oom_adj;
  164. } else
  165. points >>= -(oom_adj);
  166. }
  167. #ifdef DEBUG
  168. printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
  169. p->pid, p->comm, points);
  170. #endif
  171. return points;
  172. }
  173. /*
  174. * Determine the type of allocation constraint.
  175. */
  176. #ifdef CONFIG_NUMA
  177. static enum oom_constraint constrained_alloc(struct zonelist *zonelist,
  178. gfp_t gfp_mask, nodemask_t *nodemask)
  179. {
  180. struct zone *zone;
  181. struct zoneref *z;
  182. enum zone_type high_zoneidx = gfp_zone(gfp_mask);
  183. /*
  184. * Reach here only when __GFP_NOFAIL is used. So, we should avoid
  185. * to kill current.We have to random task kill in this case.
  186. * Hopefully, CONSTRAINT_THISNODE...but no way to handle it, now.
  187. */
  188. if (gfp_mask & __GFP_THISNODE)
  189. return CONSTRAINT_NONE;
  190. /*
  191. * The nodemask here is a nodemask passed to alloc_pages(). Now,
  192. * cpuset doesn't use this nodemask for its hardwall/softwall/hierarchy
  193. * feature. mempolicy is an only user of nodemask here.
  194. * check mempolicy's nodemask contains all N_HIGH_MEMORY
  195. */
  196. if (nodemask && !nodes_subset(node_states[N_HIGH_MEMORY], *nodemask))
  197. return CONSTRAINT_MEMORY_POLICY;
  198. /* Check this allocation failure is caused by cpuset's wall function */
  199. for_each_zone_zonelist_nodemask(zone, z, zonelist,
  200. high_zoneidx, nodemask)
  201. if (!cpuset_zone_allowed_softwall(zone, gfp_mask))
  202. return CONSTRAINT_CPUSET;
  203. return CONSTRAINT_NONE;
  204. }
  205. #else
  206. static enum oom_constraint constrained_alloc(struct zonelist *zonelist,
  207. gfp_t gfp_mask, nodemask_t *nodemask)
  208. {
  209. return CONSTRAINT_NONE;
  210. }
  211. #endif
  212. /*
  213. * Simple selection loop. We chose the process with the highest
  214. * number of 'points'. We expect the caller will lock the tasklist.
  215. *
  216. * (not docbooked, we don't want this one cluttering up the manual)
  217. */
  218. static struct task_struct *select_bad_process(unsigned long *ppoints,
  219. struct mem_cgroup *mem)
  220. {
  221. struct task_struct *p;
  222. struct task_struct *chosen = NULL;
  223. struct timespec uptime;
  224. *ppoints = 0;
  225. do_posix_clock_monotonic_gettime(&uptime);
  226. for_each_process(p) {
  227. unsigned long points;
  228. /*
  229. * skip kernel threads and tasks which have already released
  230. * their mm.
  231. */
  232. if (!p->mm)
  233. continue;
  234. /* skip the init task */
  235. if (is_global_init(p))
  236. continue;
  237. if (mem && !task_in_mem_cgroup(p, mem))
  238. continue;
  239. /*
  240. * This task already has access to memory reserves and is
  241. * being killed. Don't allow any other task access to the
  242. * memory reserve.
  243. *
  244. * Note: this may have a chance of deadlock if it gets
  245. * blocked waiting for another task which itself is waiting
  246. * for memory. Is there a better alternative?
  247. */
  248. if (test_tsk_thread_flag(p, TIF_MEMDIE))
  249. return ERR_PTR(-1UL);
  250. /*
  251. * This is in the process of releasing memory so wait for it
  252. * to finish before killing some other task by mistake.
  253. *
  254. * However, if p is the current task, we allow the 'kill' to
  255. * go ahead if it is exiting: this will simply set TIF_MEMDIE,
  256. * which will allow it to gain access to memory reserves in
  257. * the process of exiting and releasing its resources.
  258. * Otherwise we could get an easy OOM deadlock.
  259. */
  260. if (p->flags & PF_EXITING) {
  261. if (p != current)
  262. return ERR_PTR(-1UL);
  263. chosen = p;
  264. *ppoints = ULONG_MAX;
  265. }
  266. if (p->signal->oom_adj == OOM_DISABLE)
  267. continue;
  268. points = badness(p, uptime.tv_sec);
  269. if (points > *ppoints || !chosen) {
  270. chosen = p;
  271. *ppoints = points;
  272. }
  273. }
  274. return chosen;
  275. }
  276. /**
  277. * dump_tasks - dump current memory state of all system tasks
  278. * @mem: target memory controller
  279. *
  280. * Dumps the current memory state of all system tasks, excluding kernel threads.
  281. * State information includes task's pid, uid, tgid, vm size, rss, cpu, oom_adj
  282. * score, and name.
  283. *
  284. * If the actual is non-NULL, only tasks that are a member of the mem_cgroup are
  285. * shown.
  286. *
  287. * Call with tasklist_lock read-locked.
  288. */
  289. static void dump_tasks(const struct mem_cgroup *mem)
  290. {
  291. struct task_struct *g, *p;
  292. printk(KERN_INFO "[ pid ] uid tgid total_vm rss cpu oom_adj "
  293. "name\n");
  294. do_each_thread(g, p) {
  295. struct mm_struct *mm;
  296. if (mem && !task_in_mem_cgroup(p, mem))
  297. continue;
  298. if (!thread_group_leader(p))
  299. continue;
  300. task_lock(p);
  301. mm = p->mm;
  302. if (!mm) {
  303. /*
  304. * total_vm and rss sizes do not exist for tasks with no
  305. * mm so there's no need to report them; they can't be
  306. * oom killed anyway.
  307. */
  308. task_unlock(p);
  309. continue;
  310. }
  311. printk(KERN_INFO "[%5d] %5d %5d %8lu %8lu %3d %3d %s\n",
  312. p->pid, __task_cred(p)->uid, p->tgid, mm->total_vm,
  313. get_mm_rss(mm), (int)task_cpu(p), p->signal->oom_adj,
  314. p->comm);
  315. task_unlock(p);
  316. } while_each_thread(g, p);
  317. }
  318. static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
  319. struct mem_cgroup *mem)
  320. {
  321. pr_warning("%s invoked oom-killer: gfp_mask=0x%x, order=%d, "
  322. "oom_adj=%d\n",
  323. current->comm, gfp_mask, order, current->signal->oom_adj);
  324. task_lock(current);
  325. cpuset_print_task_mems_allowed(current);
  326. task_unlock(current);
  327. dump_stack();
  328. mem_cgroup_print_oom_info(mem, p);
  329. show_mem();
  330. if (sysctl_oom_dump_tasks)
  331. dump_tasks(mem);
  332. }
  333. #define K(x) ((x) << (PAGE_SHIFT-10))
  334. /*
  335. * Send SIGKILL to the selected process irrespective of CAP_SYS_RAW_IO
  336. * flag though it's unlikely that we select a process with CAP_SYS_RAW_IO
  337. * set.
  338. */
  339. static void __oom_kill_task(struct task_struct *p, int verbose)
  340. {
  341. if (is_global_init(p)) {
  342. WARN_ON(1);
  343. printk(KERN_WARNING "tried to kill init!\n");
  344. return;
  345. }
  346. task_lock(p);
  347. if (!p->mm) {
  348. WARN_ON(1);
  349. printk(KERN_WARNING "tried to kill an mm-less task %d (%s)!\n",
  350. task_pid_nr(p), p->comm);
  351. task_unlock(p);
  352. return;
  353. }
  354. if (verbose)
  355. printk(KERN_ERR "Killed process %d (%s) "
  356. "vsz:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
  357. task_pid_nr(p), p->comm,
  358. K(p->mm->total_vm),
  359. K(get_mm_counter(p->mm, MM_ANONPAGES)),
  360. K(get_mm_counter(p->mm, MM_FILEPAGES)));
  361. task_unlock(p);
  362. /*
  363. * We give our sacrificial lamb high priority and access to
  364. * all the memory it needs. That way it should be able to
  365. * exit() and clear out its resources quickly...
  366. */
  367. p->rt.time_slice = HZ;
  368. set_tsk_thread_flag(p, TIF_MEMDIE);
  369. force_sig(SIGKILL, p);
  370. }
  371. static int oom_kill_task(struct task_struct *p)
  372. {
  373. /* WARNING: mm may not be dereferenced since we did not obtain its
  374. * value from get_task_mm(p). This is OK since all we need to do is
  375. * compare mm to q->mm below.
  376. *
  377. * Furthermore, even if mm contains a non-NULL value, p->mm may
  378. * change to NULL at any time since we do not hold task_lock(p).
  379. * However, this is of no concern to us.
  380. */
  381. if (!p->mm || p->signal->oom_adj == OOM_DISABLE)
  382. return 1;
  383. __oom_kill_task(p, 1);
  384. return 0;
  385. }
  386. static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
  387. unsigned long points, struct mem_cgroup *mem,
  388. const char *message)
  389. {
  390. struct task_struct *c;
  391. if (printk_ratelimit())
  392. dump_header(p, gfp_mask, order, mem);
  393. /*
  394. * If the task is already exiting, don't alarm the sysadmin or kill
  395. * its children or threads, just set TIF_MEMDIE so it can die quickly
  396. */
  397. if (p->flags & PF_EXITING) {
  398. __oom_kill_task(p, 0);
  399. return 0;
  400. }
  401. printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
  402. message, task_pid_nr(p), p->comm, points);
  403. /* Try to kill a child first */
  404. list_for_each_entry(c, &p->children, sibling) {
  405. if (c->mm == p->mm)
  406. continue;
  407. if (mem && !task_in_mem_cgroup(c, mem))
  408. continue;
  409. if (!oom_kill_task(c))
  410. return 0;
  411. }
  412. return oom_kill_task(p);
  413. }
  414. #ifdef CONFIG_CGROUP_MEM_RES_CTLR
  415. void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask)
  416. {
  417. unsigned long points = 0;
  418. struct task_struct *p;
  419. if (sysctl_panic_on_oom == 2)
  420. panic("out of memory(memcg). panic_on_oom is selected.\n");
  421. read_lock(&tasklist_lock);
  422. retry:
  423. p = select_bad_process(&points, mem);
  424. if (PTR_ERR(p) == -1UL)
  425. goto out;
  426. if (!p)
  427. p = current;
  428. if (oom_kill_process(p, gfp_mask, 0, points, mem,
  429. "Memory cgroup out of memory"))
  430. goto retry;
  431. out:
  432. read_unlock(&tasklist_lock);
  433. }
  434. #endif
  435. static BLOCKING_NOTIFIER_HEAD(oom_notify_list);
  436. int register_oom_notifier(struct notifier_block *nb)
  437. {
  438. return blocking_notifier_chain_register(&oom_notify_list, nb);
  439. }
  440. EXPORT_SYMBOL_GPL(register_oom_notifier);
  441. int unregister_oom_notifier(struct notifier_block *nb)
  442. {
  443. return blocking_notifier_chain_unregister(&oom_notify_list, nb);
  444. }
  445. EXPORT_SYMBOL_GPL(unregister_oom_notifier);
  446. /*
  447. * Try to acquire the OOM killer lock for the zones in zonelist. Returns zero
  448. * if a parallel OOM killing is already taking place that includes a zone in
  449. * the zonelist. Otherwise, locks all zones in the zonelist and returns 1.
  450. */
  451. int try_set_zone_oom(struct zonelist *zonelist, gfp_t gfp_mask)
  452. {
  453. struct zoneref *z;
  454. struct zone *zone;
  455. int ret = 1;
  456. spin_lock(&zone_scan_lock);
  457. for_each_zone_zonelist(zone, z, zonelist, gfp_zone(gfp_mask)) {
  458. if (zone_is_oom_locked(zone)) {
  459. ret = 0;
  460. goto out;
  461. }
  462. }
  463. for_each_zone_zonelist(zone, z, zonelist, gfp_zone(gfp_mask)) {
  464. /*
  465. * Lock each zone in the zonelist under zone_scan_lock so a
  466. * parallel invocation of try_set_zone_oom() doesn't succeed
  467. * when it shouldn't.
  468. */
  469. zone_set_flag(zone, ZONE_OOM_LOCKED);
  470. }
  471. out:
  472. spin_unlock(&zone_scan_lock);
  473. return ret;
  474. }
  475. /*
  476. * Clears the ZONE_OOM_LOCKED flag for all zones in the zonelist so that failed
  477. * allocation attempts with zonelists containing them may now recall the OOM
  478. * killer, if necessary.
  479. */
  480. void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_mask)
  481. {
  482. struct zoneref *z;
  483. struct zone *zone;
  484. spin_lock(&zone_scan_lock);
  485. for_each_zone_zonelist(zone, z, zonelist, gfp_zone(gfp_mask)) {
  486. zone_clear_flag(zone, ZONE_OOM_LOCKED);
  487. }
  488. spin_unlock(&zone_scan_lock);
  489. }
  490. /*
  491. * Must be called with tasklist_lock held for read.
  492. */
  493. static void __out_of_memory(gfp_t gfp_mask, int order)
  494. {
  495. struct task_struct *p;
  496. unsigned long points;
  497. if (sysctl_oom_kill_allocating_task)
  498. if (!oom_kill_process(current, gfp_mask, order, 0, NULL,
  499. "Out of memory (oom_kill_allocating_task)"))
  500. return;
  501. retry:
  502. /*
  503. * Rambo mode: Shoot down a process and hope it solves whatever
  504. * issues we may have.
  505. */
  506. p = select_bad_process(&points, NULL);
  507. if (PTR_ERR(p) == -1UL)
  508. return;
  509. /* Found nothing?!?! Either we hang forever, or we panic. */
  510. if (!p) {
  511. read_unlock(&tasklist_lock);
  512. dump_header(NULL, gfp_mask, order, NULL);
  513. panic("Out of memory and no killable processes...\n");
  514. }
  515. if (oom_kill_process(p, gfp_mask, order, points, NULL,
  516. "Out of memory"))
  517. goto retry;
  518. }
  519. /*
  520. * pagefault handler calls into here because it is out of memory but
  521. * doesn't know exactly how or why.
  522. */
  523. void pagefault_out_of_memory(void)
  524. {
  525. unsigned long freed = 0;
  526. blocking_notifier_call_chain(&oom_notify_list, 0, &freed);
  527. if (freed > 0)
  528. /* Got some memory back in the last second. */
  529. return;
  530. if (sysctl_panic_on_oom)
  531. panic("out of memory from page fault. panic_on_oom is selected.\n");
  532. read_lock(&tasklist_lock);
  533. __out_of_memory(0, 0); /* unknown gfp_mask and order */
  534. read_unlock(&tasklist_lock);
  535. /*
  536. * Give "p" a good chance of killing itself before we
  537. * retry to allocate memory.
  538. */
  539. if (!test_thread_flag(TIF_MEMDIE))
  540. schedule_timeout_uninterruptible(1);
  541. }
  542. /**
  543. * out_of_memory - kill the "best" process when we run out of memory
  544. * @zonelist: zonelist pointer
  545. * @gfp_mask: memory allocation flags
  546. * @order: amount of memory being requested as a power of 2
  547. *
  548. * If we run out of memory, we have the choice between either
  549. * killing a random task (bad), letting the system crash (worse)
  550. * OR try to be smart about which process to kill. Note that we
  551. * don't have to be perfect here, we just have to be good.
  552. */
  553. void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
  554. int order, nodemask_t *nodemask)
  555. {
  556. unsigned long freed = 0;
  557. enum oom_constraint constraint;
  558. blocking_notifier_call_chain(&oom_notify_list, 0, &freed);
  559. if (freed > 0)
  560. /* Got some memory back in the last second. */
  561. return;
  562. if (sysctl_panic_on_oom == 2) {
  563. dump_header(NULL, gfp_mask, order, NULL);
  564. panic("out of memory. Compulsory panic_on_oom is selected.\n");
  565. }
  566. /*
  567. * Check if there were limitations on the allocation (only relevant for
  568. * NUMA) that may require different handling.
  569. */
  570. constraint = constrained_alloc(zonelist, gfp_mask, nodemask);
  571. read_lock(&tasklist_lock);
  572. switch (constraint) {
  573. case CONSTRAINT_MEMORY_POLICY:
  574. oom_kill_process(current, gfp_mask, order, 0, NULL,
  575. "No available memory (MPOL_BIND)");
  576. break;
  577. case CONSTRAINT_NONE:
  578. if (sysctl_panic_on_oom) {
  579. dump_header(NULL, gfp_mask, order, NULL);
  580. panic("out of memory. panic_on_oom is selected\n");
  581. }
  582. /* Fall-through */
  583. case CONSTRAINT_CPUSET:
  584. __out_of_memory(gfp_mask, order);
  585. break;
  586. }
  587. read_unlock(&tasklist_lock);
  588. /*
  589. * Give "p" a good chance of killing itself before we
  590. * retry to allocate memory unless "p" is current
  591. */
  592. if (!test_thread_flag(TIF_MEMDIE))
  593. schedule_timeout_uninterruptible(1);
  594. }