oom_kill.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/mm/oom_kill.c
  4. *
  5. * Copyright (C) 1998,2000 Rik van Riel
  6. * Thanks go out to Claus Fischer for some serious inspiration and
  7. * for goading me into coding this file...
  8. * Copyright (C) 2010 Google, Inc.
  9. * Rewritten by David Rientjes
  10. *
  11. * The routines in this file are used to kill a process when
  12. * we're seriously out of memory. This gets called from __alloc_pages()
  13. * in mm/page_alloc.c when we really run out of memory.
  14. *
  15. * Since we won't call these routines often (on a well-configured
  16. * machine) this file will double as a 'coding guide' and a signpost
  17. * for newbie kernel hackers. It features several pointers to major
  18. * kernel subsystems and hints as to where to find out what things do.
  19. */
  20. #include <linux/oom.h>
  21. #include <linux/mm.h>
  22. #include <linux/err.h>
  23. #include <linux/gfp.h>
  24. #include <linux/sched.h>
  25. #include <linux/sched/mm.h>
  26. #include <linux/sched/coredump.h>
  27. #include <linux/sched/task.h>
  28. #include <linux/sched/debug.h>
  29. #include <linux/swap.h>
  30. #include <linux/syscalls.h>
  31. #include <linux/timex.h>
  32. #include <linux/jiffies.h>
  33. #include <linux/cpuset.h>
  34. #include <linux/export.h>
  35. #include <linux/notifier.h>
  36. #include <linux/memcontrol.h>
  37. #include <linux/mempolicy.h>
  38. #include <linux/security.h>
  39. #include <linux/ptrace.h>
  40. #include <linux/freezer.h>
  41. #include <linux/ftrace.h>
  42. #include <linux/ratelimit.h>
  43. #include <linux/kthread.h>
  44. #include <linux/init.h>
  45. #include <linux/mmu_notifier.h>
  46. #include <linux/cred.h>
  47. #include <linux/nmi.h>
  48. #include <asm/tlb.h>
  49. #include "internal.h"
  50. #include "slab.h"
  51. #define CREATE_TRACE_POINTS
  52. #include <trace/events/oom.h>
  53. static int sysctl_panic_on_oom;
  54. static int sysctl_oom_kill_allocating_task;
  55. static int sysctl_oom_dump_tasks = 1;
  56. /*
  57. * Serializes oom killer invocations (out_of_memory()) from all contexts to
  58. * prevent from over eager oom killing (e.g. when the oom killer is invoked
  59. * from different domains).
  60. *
  61. * oom_killer_disable() relies on this lock to stabilize oom_killer_disabled
  62. * and mark_oom_victim
  63. */
  64. DEFINE_MUTEX(oom_lock);
  65. /* Serializes oom_score_adj and oom_score_adj_min updates */
  66. DEFINE_MUTEX(oom_adj_mutex);
  67. static inline bool is_memcg_oom(struct oom_control *oc)
  68. {
  69. return oc->memcg != NULL;
  70. }
  71. #ifdef CONFIG_NUMA
  72. /**
  73. * oom_cpuset_eligible() - check task eligibility for kill
  74. * @start: task struct of which task to consider
  75. * @oc: pointer to struct oom_control
  76. *
  77. * Task eligibility is determined by whether or not a candidate task, @tsk,
  78. * shares the same mempolicy nodes as current if it is bound by such a policy
  79. * and whether or not it has the same set of allowed cpuset nodes.
  80. *
  81. * This function is assuming oom-killer context and 'current' has triggered
  82. * the oom-killer.
  83. */
  84. static bool oom_cpuset_eligible(struct task_struct *start,
  85. struct oom_control *oc)
  86. {
  87. struct task_struct *tsk;
  88. bool ret = false;
  89. const nodemask_t *mask = oc->nodemask;
  90. rcu_read_lock();
  91. for_each_thread(start, tsk) {
  92. if (mask) {
  93. /*
  94. * If this is a mempolicy constrained oom, tsk's
  95. * cpuset is irrelevant. Only return true if its
  96. * mempolicy intersects current, otherwise it may be
  97. * needlessly killed.
  98. */
  99. ret = mempolicy_in_oom_domain(tsk, mask);
  100. } else {
  101. /*
  102. * This is not a mempolicy constrained oom, so only
  103. * check the mems of tsk's cpuset.
  104. */
  105. ret = cpuset_mems_allowed_intersects(current, tsk);
  106. }
  107. if (ret)
  108. break;
  109. }
  110. rcu_read_unlock();
  111. return ret;
  112. }
  113. #else
  114. static bool oom_cpuset_eligible(struct task_struct *tsk, struct oom_control *oc)
  115. {
  116. return true;
  117. }
  118. #endif /* CONFIG_NUMA */
  119. /*
  120. * The process p may have detached its own ->mm while exiting or through
  121. * kthread_use_mm(), but one or more of its subthreads may still have a valid
  122. * pointer. Return p, or any of its subthreads with a valid ->mm, with
  123. * task_lock() held.
  124. */
  125. struct task_struct *find_lock_task_mm(struct task_struct *p)
  126. {
  127. struct task_struct *t;
  128. rcu_read_lock();
  129. for_each_thread(p, t) {
  130. task_lock(t);
  131. if (likely(t->mm))
  132. goto found;
  133. task_unlock(t);
  134. }
  135. t = NULL;
  136. found:
  137. rcu_read_unlock();
  138. return t;
  139. }
  140. /*
  141. * order == -1 means the oom kill is required by sysrq, otherwise only
  142. * for display purposes.
  143. */
  144. static inline bool is_sysrq_oom(struct oom_control *oc)
  145. {
  146. return oc->order == -1;
  147. }
  148. /* return true if the task is not adequate as candidate victim task. */
  149. static bool oom_unkillable_task(struct task_struct *p)
  150. {
  151. if (is_global_init(p))
  152. return true;
  153. if (p->flags & PF_KTHREAD)
  154. return true;
  155. return false;
  156. }
  157. /*
  158. * Check whether unreclaimable slab amount is greater than
  159. * all user memory(LRU pages).
  160. * dump_unreclaimable_slab() could help in the case that
  161. * oom due to too much unreclaimable slab used by kernel.
  162. */
  163. static bool should_dump_unreclaim_slab(void)
  164. {
  165. unsigned long nr_lru;
  166. nr_lru = global_node_page_state(NR_ACTIVE_ANON) +
  167. global_node_page_state(NR_INACTIVE_ANON) +
  168. global_node_page_state(NR_ACTIVE_FILE) +
  169. global_node_page_state(NR_INACTIVE_FILE) +
  170. global_node_page_state(NR_ISOLATED_ANON) +
  171. global_node_page_state(NR_ISOLATED_FILE) +
  172. global_node_page_state(NR_UNEVICTABLE);
  173. return (global_node_page_state_pages(NR_SLAB_UNRECLAIMABLE_B) > nr_lru);
  174. }
  175. /**
  176. * oom_badness - heuristic function to determine which candidate task to kill
  177. * @p: task struct of which task we should calculate
  178. * @totalpages: total present RAM allowed for page allocation
  179. *
  180. * The heuristic for determining which task to kill is made to be as simple and
  181. * predictable as possible. The goal is to return the highest value for the
  182. * task consuming the most memory to avoid subsequent oom failures.
  183. */
  184. long oom_badness(struct task_struct *p, unsigned long totalpages)
  185. {
  186. long points;
  187. long adj;
  188. if (oom_unkillable_task(p))
  189. return LONG_MIN;
  190. p = find_lock_task_mm(p);
  191. if (!p)
  192. return LONG_MIN;
  193. /*
  194. * Do not even consider tasks which are explicitly marked oom
  195. * unkillable or have been already oom reaped or the are in
  196. * the middle of vfork
  197. */
  198. adj = (long)p->signal->oom_score_adj;
  199. if (adj == OOM_SCORE_ADJ_MIN ||
  200. test_bit(MMF_OOM_SKIP, &p->mm->flags) ||
  201. in_vfork(p)) {
  202. task_unlock(p);
  203. return LONG_MIN;
  204. }
  205. /*
  206. * The baseline for the badness score is the proportion of RAM that each
  207. * task's rss, pagetable and swap space use.
  208. */
  209. points = get_mm_rss(p->mm) + get_mm_counter(p->mm, MM_SWAPENTS) +
  210. mm_pgtables_bytes(p->mm) / PAGE_SIZE;
  211. task_unlock(p);
  212. /* Normalize to oom_score_adj units */
  213. adj *= totalpages / 1000;
  214. points += adj;
  215. return points;
  216. }
  217. static const char * const oom_constraint_text[] = {
  218. [CONSTRAINT_NONE] = "CONSTRAINT_NONE",
  219. [CONSTRAINT_CPUSET] = "CONSTRAINT_CPUSET",
  220. [CONSTRAINT_MEMORY_POLICY] = "CONSTRAINT_MEMORY_POLICY",
  221. [CONSTRAINT_MEMCG] = "CONSTRAINT_MEMCG",
  222. };
  223. /*
  224. * Determine the type of allocation constraint.
  225. */
  226. static enum oom_constraint constrained_alloc(struct oom_control *oc)
  227. {
  228. struct zone *zone;
  229. struct zoneref *z;
  230. enum zone_type highest_zoneidx = gfp_zone(oc->gfp_mask);
  231. bool cpuset_limited = false;
  232. int nid;
  233. if (is_memcg_oom(oc)) {
  234. oc->totalpages = mem_cgroup_get_max(oc->memcg) ?: 1;
  235. return CONSTRAINT_MEMCG;
  236. }
  237. /* Default to all available memory */
  238. oc->totalpages = totalram_pages() + total_swap_pages;
  239. if (!IS_ENABLED(CONFIG_NUMA))
  240. return CONSTRAINT_NONE;
  241. if (!oc->zonelist)
  242. return CONSTRAINT_NONE;
  243. /*
  244. * Reach here only when __GFP_NOFAIL is used. So, we should avoid
  245. * to kill current.We have to random task kill in this case.
  246. * Hopefully, CONSTRAINT_THISNODE...but no way to handle it, now.
  247. */
  248. if (oc->gfp_mask & __GFP_THISNODE)
  249. return CONSTRAINT_NONE;
  250. /*
  251. * This is not a __GFP_THISNODE allocation, so a truncated nodemask in
  252. * the page allocator means a mempolicy is in effect. Cpuset policy
  253. * is enforced in get_page_from_freelist().
  254. */
  255. if (oc->nodemask &&
  256. !nodes_subset(node_states[N_MEMORY], *oc->nodemask)) {
  257. oc->totalpages = total_swap_pages;
  258. for_each_node_mask(nid, *oc->nodemask)
  259. oc->totalpages += node_present_pages(nid);
  260. return CONSTRAINT_MEMORY_POLICY;
  261. }
  262. /* Check this allocation failure is caused by cpuset's wall function */
  263. for_each_zone_zonelist_nodemask(zone, z, oc->zonelist,
  264. highest_zoneidx, oc->nodemask)
  265. if (!cpuset_zone_allowed(zone, oc->gfp_mask))
  266. cpuset_limited = true;
  267. if (cpuset_limited) {
  268. oc->totalpages = total_swap_pages;
  269. for_each_node_mask(nid, cpuset_current_mems_allowed)
  270. oc->totalpages += node_present_pages(nid);
  271. return CONSTRAINT_CPUSET;
  272. }
  273. return CONSTRAINT_NONE;
  274. }
  275. static int oom_evaluate_task(struct task_struct *task, void *arg)
  276. {
  277. struct oom_control *oc = arg;
  278. long points;
  279. if (oom_unkillable_task(task))
  280. goto next;
  281. /* p may not have freeable memory in nodemask */
  282. if (!is_memcg_oom(oc) && !oom_cpuset_eligible(task, oc))
  283. goto next;
  284. /*
  285. * This task already has access to memory reserves and is being killed.
  286. * Don't allow any other task to have access to the reserves unless
  287. * the task has MMF_OOM_SKIP because chances that it would release
  288. * any memory is quite low.
  289. */
  290. if (!is_sysrq_oom(oc) && tsk_is_oom_victim(task)) {
  291. if (test_bit(MMF_OOM_SKIP, &task->signal->oom_mm->flags))
  292. goto next;
  293. goto abort;
  294. }
  295. /*
  296. * If task is allocating a lot of memory and has been marked to be
  297. * killed first if it triggers an oom, then select it.
  298. */
  299. if (oom_task_origin(task)) {
  300. points = LONG_MAX;
  301. goto select;
  302. }
  303. points = oom_badness(task, oc->totalpages);
  304. if (points == LONG_MIN || points < oc->chosen_points)
  305. goto next;
  306. select:
  307. if (oc->chosen)
  308. put_task_struct(oc->chosen);
  309. get_task_struct(task);
  310. oc->chosen = task;
  311. oc->chosen_points = points;
  312. next:
  313. return 0;
  314. abort:
  315. if (oc->chosen)
  316. put_task_struct(oc->chosen);
  317. oc->chosen = (void *)-1UL;
  318. return 1;
  319. }
  320. /*
  321. * Simple selection loop. We choose the process with the highest number of
  322. * 'points'. In case scan was aborted, oc->chosen is set to -1.
  323. */
  324. static void select_bad_process(struct oom_control *oc)
  325. {
  326. oc->chosen_points = LONG_MIN;
  327. if (is_memcg_oom(oc))
  328. mem_cgroup_scan_tasks(oc->memcg, oom_evaluate_task, oc);
  329. else {
  330. struct task_struct *p;
  331. rcu_read_lock();
  332. for_each_process(p)
  333. if (oom_evaluate_task(p, oc))
  334. break;
  335. rcu_read_unlock();
  336. }
  337. }
  338. static int dump_task(struct task_struct *p, void *arg)
  339. {
  340. struct oom_control *oc = arg;
  341. struct task_struct *task;
  342. if (oom_unkillable_task(p))
  343. return 0;
  344. /* p may not have freeable memory in nodemask */
  345. if (!is_memcg_oom(oc) && !oom_cpuset_eligible(p, oc))
  346. return 0;
  347. task = find_lock_task_mm(p);
  348. if (!task) {
  349. /*
  350. * All of p's threads have already detached their mm's. There's
  351. * no need to report them; they can't be oom killed anyway.
  352. */
  353. return 0;
  354. }
  355. pr_info("[%7d] %5d %5d %8lu %8lu %8lu %8lu %9lu %8ld %8lu %5hd %s\n",
  356. task->pid, from_kuid(&init_user_ns, task_uid(task)),
  357. task->tgid, task->mm->total_vm, get_mm_rss(task->mm),
  358. get_mm_counter(task->mm, MM_ANONPAGES), get_mm_counter(task->mm, MM_FILEPAGES),
  359. get_mm_counter(task->mm, MM_SHMEMPAGES), mm_pgtables_bytes(task->mm),
  360. get_mm_counter(task->mm, MM_SWAPENTS),
  361. task->signal->oom_score_adj, task->comm);
  362. task_unlock(task);
  363. return 0;
  364. }
  365. /**
  366. * dump_tasks - dump current memory state of all system tasks
  367. * @oc: pointer to struct oom_control
  368. *
  369. * Dumps the current memory state of all eligible tasks. Tasks not in the same
  370. * memcg, not in the same cpuset, or bound to a disjoint set of mempolicy nodes
  371. * are not shown.
  372. * State information includes task's pid, uid, tgid, vm size, rss,
  373. * pgtables_bytes, swapents, oom_score_adj value, and name.
  374. */
  375. static void dump_tasks(struct oom_control *oc)
  376. {
  377. pr_info("Tasks state (memory values in pages):\n");
  378. pr_info("[ pid ] uid tgid total_vm rss rss_anon rss_file rss_shmem pgtables_bytes swapents oom_score_adj name\n");
  379. if (is_memcg_oom(oc))
  380. mem_cgroup_scan_tasks(oc->memcg, dump_task, oc);
  381. else {
  382. struct task_struct *p;
  383. int i = 0;
  384. rcu_read_lock();
  385. for_each_process(p) {
  386. /* Avoid potential softlockup warning */
  387. if ((++i & 1023) == 0)
  388. touch_softlockup_watchdog();
  389. dump_task(p, oc);
  390. }
  391. rcu_read_unlock();
  392. }
  393. }
  394. static void dump_oom_victim(struct oom_control *oc, struct task_struct *victim)
  395. {
  396. /* one line summary of the oom killer context. */
  397. pr_info("oom-kill:constraint=%s,nodemask=%*pbl",
  398. oom_constraint_text[oc->constraint],
  399. nodemask_pr_args(oc->nodemask));
  400. cpuset_print_current_mems_allowed();
  401. mem_cgroup_print_oom_context(oc->memcg, victim);
  402. pr_cont(",task=%s,pid=%d,uid=%d\n", victim->comm, victim->pid,
  403. from_kuid(&init_user_ns, task_uid(victim)));
  404. }
  405. static void dump_header(struct oom_control *oc)
  406. {
  407. pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%hd\n",
  408. current->comm, oc->gfp_mask, &oc->gfp_mask, oc->order,
  409. current->signal->oom_score_adj);
  410. if (!IS_ENABLED(CONFIG_COMPACTION) && oc->order)
  411. pr_warn("COMPACTION is disabled!!!\n");
  412. dump_stack();
  413. if (is_memcg_oom(oc))
  414. mem_cgroup_print_oom_meminfo(oc->memcg);
  415. else {
  416. __show_mem(SHOW_MEM_FILTER_NODES, oc->nodemask, gfp_zone(oc->gfp_mask));
  417. if (should_dump_unreclaim_slab())
  418. dump_unreclaimable_slab();
  419. }
  420. if (sysctl_oom_dump_tasks)
  421. dump_tasks(oc);
  422. }
  423. /*
  424. * Number of OOM victims in flight
  425. */
  426. static atomic_t oom_victims = ATOMIC_INIT(0);
  427. static DECLARE_WAIT_QUEUE_HEAD(oom_victims_wait);
  428. static bool oom_killer_disabled __read_mostly;
  429. /*
  430. * task->mm can be NULL if the task is the exited group leader. So to
  431. * determine whether the task is using a particular mm, we examine all the
  432. * task's threads: if one of those is using this mm then this task was also
  433. * using it.
  434. */
  435. bool process_shares_mm(struct task_struct *p, struct mm_struct *mm)
  436. {
  437. struct task_struct *t;
  438. for_each_thread(p, t) {
  439. struct mm_struct *t_mm = READ_ONCE(t->mm);
  440. if (t_mm)
  441. return t_mm == mm;
  442. }
  443. return false;
  444. }
  445. #ifdef CONFIG_MMU
  446. /*
  447. * OOM Reaper kernel thread which tries to reap the memory used by the OOM
  448. * victim (if that is possible) to help the OOM killer to move on.
  449. */
  450. static struct task_struct *oom_reaper_th;
  451. static DECLARE_WAIT_QUEUE_HEAD(oom_reaper_wait);
  452. static struct task_struct *oom_reaper_list;
  453. static DEFINE_SPINLOCK(oom_reaper_lock);
  454. static bool __oom_reap_task_mm(struct mm_struct *mm)
  455. {
  456. struct vm_area_struct *vma;
  457. bool ret = true;
  458. VMA_ITERATOR(vmi, mm, 0);
  459. /*
  460. * Tell all users of get_user/copy_from_user etc... that the content
  461. * is no longer stable. No barriers really needed because unmapping
  462. * should imply barriers already and the reader would hit a page fault
  463. * if it stumbled over a reaped memory.
  464. */
  465. set_bit(MMF_UNSTABLE, &mm->flags);
  466. for_each_vma(vmi, vma) {
  467. if (vma->vm_flags & (VM_HUGETLB|VM_PFNMAP))
  468. continue;
  469. /*
  470. * Only anonymous pages have a good chance to be dropped
  471. * without additional steps which we cannot afford as we
  472. * are OOM already.
  473. *
  474. * We do not even care about fs backed pages because all
  475. * which are reclaimable have already been reclaimed and
  476. * we do not want to block exit_mmap by keeping mm ref
  477. * count elevated without a good reason.
  478. */
  479. if (vma_is_anonymous(vma) || !(vma->vm_flags & VM_SHARED)) {
  480. struct mmu_notifier_range range;
  481. struct mmu_gather tlb;
  482. mmu_notifier_range_init(&range, MMU_NOTIFY_UNMAP, 0,
  483. mm, vma->vm_start,
  484. vma->vm_end);
  485. tlb_gather_mmu(&tlb, mm);
  486. if (mmu_notifier_invalidate_range_start_nonblock(&range)) {
  487. tlb_finish_mmu(&tlb);
  488. ret = false;
  489. continue;
  490. }
  491. unmap_page_range(&tlb, vma, range.start, range.end, NULL);
  492. mmu_notifier_invalidate_range_end(&range);
  493. tlb_finish_mmu(&tlb);
  494. }
  495. }
  496. return ret;
  497. }
  498. /*
  499. * Reaps the address space of the give task.
  500. *
  501. * Returns true on success and false if none or part of the address space
  502. * has been reclaimed and the caller should retry later.
  503. */
  504. static bool oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm)
  505. {
  506. bool ret = true;
  507. if (!mmap_read_trylock(mm)) {
  508. trace_skip_task_reaping(tsk->pid);
  509. return false;
  510. }
  511. /*
  512. * MMF_OOM_SKIP is set by exit_mmap when the OOM reaper can't
  513. * work on the mm anymore. The check for MMF_OOM_SKIP must run
  514. * under mmap_lock for reading because it serializes against the
  515. * mmap_write_lock();mmap_write_unlock() cycle in exit_mmap().
  516. */
  517. if (test_bit(MMF_OOM_SKIP, &mm->flags)) {
  518. trace_skip_task_reaping(tsk->pid);
  519. goto out_unlock;
  520. }
  521. trace_start_task_reaping(tsk->pid);
  522. /* failed to reap part of the address space. Try again later */
  523. ret = __oom_reap_task_mm(mm);
  524. if (!ret)
  525. goto out_finish;
  526. pr_info("oom_reaper: reaped process %d (%s), now anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB\n",
  527. task_pid_nr(tsk), tsk->comm,
  528. K(get_mm_counter(mm, MM_ANONPAGES)),
  529. K(get_mm_counter(mm, MM_FILEPAGES)),
  530. K(get_mm_counter(mm, MM_SHMEMPAGES)));
  531. out_finish:
  532. trace_finish_task_reaping(tsk->pid);
  533. out_unlock:
  534. mmap_read_unlock(mm);
  535. return ret;
  536. }
  537. #define MAX_OOM_REAP_RETRIES 10
  538. static void oom_reap_task(struct task_struct *tsk)
  539. {
  540. int attempts = 0;
  541. struct mm_struct *mm = tsk->signal->oom_mm;
  542. /* Retry the mmap_read_trylock(mm) a few times */
  543. while (attempts++ < MAX_OOM_REAP_RETRIES && !oom_reap_task_mm(tsk, mm))
  544. schedule_timeout_idle(HZ/10);
  545. if (attempts <= MAX_OOM_REAP_RETRIES ||
  546. test_bit(MMF_OOM_SKIP, &mm->flags))
  547. goto done;
  548. pr_info("oom_reaper: unable to reap pid:%d (%s)\n",
  549. task_pid_nr(tsk), tsk->comm);
  550. sched_show_task(tsk);
  551. debug_show_all_locks();
  552. done:
  553. tsk->oom_reaper_list = NULL;
  554. /*
  555. * Hide this mm from OOM killer because it has been either reaped or
  556. * somebody can't call mmap_write_unlock(mm).
  557. */
  558. set_bit(MMF_OOM_SKIP, &mm->flags);
  559. /* Drop a reference taken by queue_oom_reaper */
  560. put_task_struct(tsk);
  561. }
  562. static int oom_reaper(void *unused)
  563. {
  564. set_freezable();
  565. while (true) {
  566. struct task_struct *tsk = NULL;
  567. wait_event_freezable(oom_reaper_wait, oom_reaper_list != NULL);
  568. spin_lock_irq(&oom_reaper_lock);
  569. if (oom_reaper_list != NULL) {
  570. tsk = oom_reaper_list;
  571. oom_reaper_list = tsk->oom_reaper_list;
  572. }
  573. spin_unlock_irq(&oom_reaper_lock);
  574. if (tsk)
  575. oom_reap_task(tsk);
  576. }
  577. return 0;
  578. }
  579. static void wake_oom_reaper(struct timer_list *timer)
  580. {
  581. struct task_struct *tsk = container_of(timer, struct task_struct,
  582. oom_reaper_timer);
  583. struct mm_struct *mm = tsk->signal->oom_mm;
  584. unsigned long flags;
  585. /* The victim managed to terminate on its own - see exit_mmap */
  586. if (test_bit(MMF_OOM_SKIP, &mm->flags)) {
  587. put_task_struct(tsk);
  588. return;
  589. }
  590. spin_lock_irqsave(&oom_reaper_lock, flags);
  591. tsk->oom_reaper_list = oom_reaper_list;
  592. oom_reaper_list = tsk;
  593. spin_unlock_irqrestore(&oom_reaper_lock, flags);
  594. trace_wake_reaper(tsk->pid);
  595. wake_up(&oom_reaper_wait);
  596. }
  597. /*
  598. * Give the OOM victim time to exit naturally before invoking the oom_reaping.
  599. * The timers timeout is arbitrary... the longer it is, the longer the worst
  600. * case scenario for the OOM can take. If it is too small, the oom_reaper can
  601. * get in the way and release resources needed by the process exit path.
  602. * e.g. The futex robust list can sit in Anon|Private memory that gets reaped
  603. * before the exit path is able to wake the futex waiters.
  604. */
  605. #define OOM_REAPER_DELAY (2*HZ)
  606. static void queue_oom_reaper(struct task_struct *tsk)
  607. {
  608. /* mm is already queued? */
  609. if (test_and_set_bit(MMF_OOM_REAP_QUEUED, &tsk->signal->oom_mm->flags))
  610. return;
  611. get_task_struct(tsk);
  612. timer_setup(&tsk->oom_reaper_timer, wake_oom_reaper, 0);
  613. tsk->oom_reaper_timer.expires = jiffies + OOM_REAPER_DELAY;
  614. add_timer(&tsk->oom_reaper_timer);
  615. }
  616. #ifdef CONFIG_SYSCTL
  617. static struct ctl_table vm_oom_kill_table[] = {
  618. {
  619. .procname = "panic_on_oom",
  620. .data = &sysctl_panic_on_oom,
  621. .maxlen = sizeof(sysctl_panic_on_oom),
  622. .mode = 0644,
  623. .proc_handler = proc_dointvec_minmax,
  624. .extra1 = SYSCTL_ZERO,
  625. .extra2 = SYSCTL_TWO,
  626. },
  627. {
  628. .procname = "oom_kill_allocating_task",
  629. .data = &sysctl_oom_kill_allocating_task,
  630. .maxlen = sizeof(sysctl_oom_kill_allocating_task),
  631. .mode = 0644,
  632. .proc_handler = proc_dointvec,
  633. },
  634. {
  635. .procname = "oom_dump_tasks",
  636. .data = &sysctl_oom_dump_tasks,
  637. .maxlen = sizeof(sysctl_oom_dump_tasks),
  638. .mode = 0644,
  639. .proc_handler = proc_dointvec,
  640. },
  641. };
  642. #endif
  643. static int __init oom_init(void)
  644. {
  645. oom_reaper_th = kthread_run(oom_reaper, NULL, "oom_reaper");
  646. #ifdef CONFIG_SYSCTL
  647. register_sysctl_init("vm", vm_oom_kill_table);
  648. #endif
  649. return 0;
  650. }
  651. subsys_initcall(oom_init)
  652. #else
  653. static inline void queue_oom_reaper(struct task_struct *tsk)
  654. {
  655. }
  656. #endif /* CONFIG_MMU */
  657. /**
  658. * mark_oom_victim - mark the given task as OOM victim
  659. * @tsk: task to mark
  660. *
  661. * Has to be called with oom_lock held and never after
  662. * oom has been disabled already.
  663. *
  664. * tsk->mm has to be non NULL and caller has to guarantee it is stable (either
  665. * under task_lock or operate on the current).
  666. */
  667. static void mark_oom_victim(struct task_struct *tsk)
  668. {
  669. const struct cred *cred;
  670. struct mm_struct *mm = tsk->mm;
  671. WARN_ON(oom_killer_disabled);
  672. /* OOM killer might race with memcg OOM */
  673. if (test_and_set_tsk_thread_flag(tsk, TIF_MEMDIE))
  674. return;
  675. /* oom_mm is bound to the signal struct life time. */
  676. if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm))
  677. mmgrab(tsk->signal->oom_mm);
  678. /*
  679. * Make sure that the task is woken up from uninterruptible sleep
  680. * if it is frozen because OOM killer wouldn't be able to free
  681. * any memory and livelock. freezing_slow_path will tell the freezer
  682. * that TIF_MEMDIE tasks should be ignored.
  683. */
  684. __thaw_task(tsk);
  685. atomic_inc(&oom_victims);
  686. cred = get_task_cred(tsk);
  687. trace_mark_victim(tsk, cred->uid.val);
  688. put_cred(cred);
  689. }
  690. /**
  691. * exit_oom_victim - note the exit of an OOM victim
  692. */
  693. void exit_oom_victim(void)
  694. {
  695. clear_thread_flag(TIF_MEMDIE);
  696. if (!atomic_dec_return(&oom_victims))
  697. wake_up_all(&oom_victims_wait);
  698. }
  699. /**
  700. * oom_killer_enable - enable OOM killer
  701. */
  702. void oom_killer_enable(void)
  703. {
  704. oom_killer_disabled = false;
  705. pr_info("OOM killer enabled.\n");
  706. }
  707. /**
  708. * oom_killer_disable - disable OOM killer
  709. * @timeout: maximum timeout to wait for oom victims in jiffies
  710. *
  711. * Forces all page allocations to fail rather than trigger OOM killer.
  712. * Will block and wait until all OOM victims are killed or the given
  713. * timeout expires.
  714. *
  715. * The function cannot be called when there are runnable user tasks because
  716. * the userspace would see unexpected allocation failures as a result. Any
  717. * new usage of this function should be consulted with MM people.
  718. *
  719. * Returns true if successful and false if the OOM killer cannot be
  720. * disabled.
  721. */
  722. bool oom_killer_disable(signed long timeout)
  723. {
  724. signed long ret;
  725. /*
  726. * Make sure to not race with an ongoing OOM killer. Check that the
  727. * current is not killed (possibly due to sharing the victim's memory).
  728. */
  729. if (mutex_lock_killable(&oom_lock))
  730. return false;
  731. oom_killer_disabled = true;
  732. mutex_unlock(&oom_lock);
  733. ret = wait_event_interruptible_timeout(oom_victims_wait,
  734. !atomic_read(&oom_victims), timeout);
  735. if (ret <= 0) {
  736. oom_killer_enable();
  737. return false;
  738. }
  739. pr_info("OOM killer disabled.\n");
  740. return true;
  741. }
  742. static inline bool __task_will_free_mem(struct task_struct *task)
  743. {
  744. struct signal_struct *sig = task->signal;
  745. /*
  746. * A coredumping process may sleep for an extended period in
  747. * coredump_task_exit(), so the oom killer cannot assume that
  748. * the process will promptly exit and release memory.
  749. */
  750. if (sig->core_state)
  751. return false;
  752. if (sig->flags & SIGNAL_GROUP_EXIT)
  753. return true;
  754. if (thread_group_empty(task) && (task->flags & PF_EXITING))
  755. return true;
  756. return false;
  757. }
  758. /*
  759. * Checks whether the given task is dying or exiting and likely to
  760. * release its address space. This means that all threads and processes
  761. * sharing the same mm have to be killed or exiting.
  762. * Caller has to make sure that task->mm is stable (hold task_lock or
  763. * it operates on the current).
  764. */
  765. static bool task_will_free_mem(struct task_struct *task)
  766. {
  767. struct mm_struct *mm = task->mm;
  768. struct task_struct *p;
  769. bool ret = true;
  770. /*
  771. * Skip tasks without mm because it might have passed its exit_mm and
  772. * exit_oom_victim. oom_reaper could have rescued that but do not rely
  773. * on that for now. We can consider find_lock_task_mm in future.
  774. */
  775. if (!mm)
  776. return false;
  777. if (!__task_will_free_mem(task))
  778. return false;
  779. /*
  780. * This task has already been drained by the oom reaper so there are
  781. * only small chances it will free some more
  782. */
  783. if (test_bit(MMF_OOM_SKIP, &mm->flags))
  784. return false;
  785. if (atomic_read(&mm->mm_users) <= 1)
  786. return true;
  787. /*
  788. * Make sure that all tasks which share the mm with the given tasks
  789. * are dying as well to make sure that a) nobody pins its mm and
  790. * b) the task is also reapable by the oom reaper.
  791. */
  792. rcu_read_lock();
  793. for_each_process(p) {
  794. if (!process_shares_mm(p, mm))
  795. continue;
  796. if (same_thread_group(task, p))
  797. continue;
  798. ret = __task_will_free_mem(p);
  799. if (!ret)
  800. break;
  801. }
  802. rcu_read_unlock();
  803. return ret;
  804. }
  805. static void __oom_kill_process(struct task_struct *victim, const char *message)
  806. {
  807. struct task_struct *p;
  808. struct mm_struct *mm;
  809. bool can_oom_reap = true;
  810. p = find_lock_task_mm(victim);
  811. if (!p) {
  812. pr_info("%s: OOM victim %d (%s) is already exiting. Skip killing the task\n",
  813. message, task_pid_nr(victim), victim->comm);
  814. put_task_struct(victim);
  815. return;
  816. } else if (victim != p) {
  817. get_task_struct(p);
  818. put_task_struct(victim);
  819. victim = p;
  820. }
  821. /* Get a reference to safely compare mm after task_unlock(victim) */
  822. mm = victim->mm;
  823. mmgrab(mm);
  824. /* Raise event before sending signal: task reaper must see this */
  825. count_vm_event(OOM_KILL);
  826. memcg_memory_event_mm(mm, MEMCG_OOM_KILL);
  827. /*
  828. * We should send SIGKILL before granting access to memory reserves
  829. * in order to prevent the OOM victim from depleting the memory
  830. * reserves from the user space under its control.
  831. */
  832. do_send_sig_info(SIGKILL, SEND_SIG_PRIV, victim, PIDTYPE_TGID);
  833. mark_oom_victim(victim);
  834. pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%hd\n",
  835. message, task_pid_nr(victim), victim->comm, K(mm->total_vm),
  836. K(get_mm_counter(mm, MM_ANONPAGES)),
  837. K(get_mm_counter(mm, MM_FILEPAGES)),
  838. K(get_mm_counter(mm, MM_SHMEMPAGES)),
  839. from_kuid(&init_user_ns, task_uid(victim)),
  840. mm_pgtables_bytes(mm) >> 10, victim->signal->oom_score_adj);
  841. task_unlock(victim);
  842. /*
  843. * Kill all user processes sharing victim->mm in other thread groups, if
  844. * any. They don't get access to memory reserves, though, to avoid
  845. * depletion of all memory. This prevents mm->mmap_lock livelock when an
  846. * oom killed thread cannot exit because it requires the semaphore and
  847. * its contended by another thread trying to allocate memory itself.
  848. * That thread will now get access to memory reserves since it has a
  849. * pending fatal signal.
  850. */
  851. rcu_read_lock();
  852. for_each_process(p) {
  853. if (!process_shares_mm(p, mm))
  854. continue;
  855. if (same_thread_group(p, victim))
  856. continue;
  857. if (is_global_init(p)) {
  858. can_oom_reap = false;
  859. set_bit(MMF_OOM_SKIP, &mm->flags);
  860. pr_info("oom killer %d (%s) has mm pinned by %d (%s)\n",
  861. task_pid_nr(victim), victim->comm,
  862. task_pid_nr(p), p->comm);
  863. continue;
  864. }
  865. /*
  866. * No kthread_use_mm() user needs to read from the userspace so
  867. * we are ok to reap it.
  868. */
  869. if (unlikely(p->flags & PF_KTHREAD))
  870. continue;
  871. do_send_sig_info(SIGKILL, SEND_SIG_PRIV, p, PIDTYPE_TGID);
  872. }
  873. rcu_read_unlock();
  874. if (can_oom_reap)
  875. queue_oom_reaper(victim);
  876. mmdrop(mm);
  877. put_task_struct(victim);
  878. }
  879. /*
  880. * Kill provided task unless it's secured by setting
  881. * oom_score_adj to OOM_SCORE_ADJ_MIN.
  882. */
  883. static int oom_kill_memcg_member(struct task_struct *task, void *message)
  884. {
  885. if (task->signal->oom_score_adj != OOM_SCORE_ADJ_MIN &&
  886. !is_global_init(task)) {
  887. get_task_struct(task);
  888. __oom_kill_process(task, message);
  889. }
  890. return 0;
  891. }
  892. static void oom_kill_process(struct oom_control *oc, const char *message)
  893. {
  894. struct task_struct *victim = oc->chosen;
  895. struct mem_cgroup *oom_group;
  896. static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL,
  897. DEFAULT_RATELIMIT_BURST);
  898. /*
  899. * If the task is already exiting, don't alarm the sysadmin or kill
  900. * its children or threads, just give it access to memory reserves
  901. * so it can die quickly
  902. */
  903. task_lock(victim);
  904. if (task_will_free_mem(victim)) {
  905. mark_oom_victim(victim);
  906. queue_oom_reaper(victim);
  907. task_unlock(victim);
  908. put_task_struct(victim);
  909. return;
  910. }
  911. task_unlock(victim);
  912. if (__ratelimit(&oom_rs)) {
  913. dump_header(oc);
  914. dump_oom_victim(oc, victim);
  915. }
  916. /*
  917. * Do we need to kill the entire memory cgroup?
  918. * Or even one of the ancestor memory cgroups?
  919. * Check this out before killing the victim task.
  920. */
  921. oom_group = mem_cgroup_get_oom_group(victim, oc->memcg);
  922. __oom_kill_process(victim, message);
  923. /*
  924. * If necessary, kill all tasks in the selected memory cgroup.
  925. */
  926. if (oom_group) {
  927. memcg_memory_event(oom_group, MEMCG_OOM_GROUP_KILL);
  928. mem_cgroup_print_oom_group(oom_group);
  929. mem_cgroup_scan_tasks(oom_group, oom_kill_memcg_member,
  930. (void *)message);
  931. mem_cgroup_put(oom_group);
  932. }
  933. }
  934. /*
  935. * Determines whether the kernel must panic because of the panic_on_oom sysctl.
  936. */
  937. static void check_panic_on_oom(struct oom_control *oc)
  938. {
  939. if (likely(!sysctl_panic_on_oom))
  940. return;
  941. if (sysctl_panic_on_oom != 2) {
  942. /*
  943. * panic_on_oom == 1 only affects CONSTRAINT_NONE, the kernel
  944. * does not panic for cpuset, mempolicy, or memcg allocation
  945. * failures.
  946. */
  947. if (oc->constraint != CONSTRAINT_NONE)
  948. return;
  949. }
  950. /* Do not panic for oom kills triggered by sysrq */
  951. if (is_sysrq_oom(oc))
  952. return;
  953. dump_header(oc);
  954. panic("Out of memory: %s panic_on_oom is enabled\n",
  955. sysctl_panic_on_oom == 2 ? "compulsory" : "system-wide");
  956. }
  957. static BLOCKING_NOTIFIER_HEAD(oom_notify_list);
  958. int register_oom_notifier(struct notifier_block *nb)
  959. {
  960. return blocking_notifier_chain_register(&oom_notify_list, nb);
  961. }
  962. EXPORT_SYMBOL_GPL(register_oom_notifier);
  963. int unregister_oom_notifier(struct notifier_block *nb)
  964. {
  965. return blocking_notifier_chain_unregister(&oom_notify_list, nb);
  966. }
  967. EXPORT_SYMBOL_GPL(unregister_oom_notifier);
  968. /**
  969. * out_of_memory - kill the "best" process when we run out of memory
  970. * @oc: pointer to struct oom_control
  971. *
  972. * If we run out of memory, we have the choice between either
  973. * killing a random task (bad), letting the system crash (worse)
  974. * OR try to be smart about which process to kill. Note that we
  975. * don't have to be perfect here, we just have to be good.
  976. */
  977. bool out_of_memory(struct oom_control *oc)
  978. {
  979. unsigned long freed = 0;
  980. if (oom_killer_disabled)
  981. return false;
  982. if (!is_memcg_oom(oc)) {
  983. blocking_notifier_call_chain(&oom_notify_list, 0, &freed);
  984. if (freed > 0 && !is_sysrq_oom(oc))
  985. /* Got some memory back in the last second. */
  986. return true;
  987. }
  988. /*
  989. * If current has a pending SIGKILL or is exiting, then automatically
  990. * select it. The goal is to allow it to allocate so that it may
  991. * quickly exit and free its memory.
  992. */
  993. if (task_will_free_mem(current)) {
  994. mark_oom_victim(current);
  995. queue_oom_reaper(current);
  996. return true;
  997. }
  998. /*
  999. * The OOM killer does not compensate for IO-less reclaim.
  1000. * But mem_cgroup_oom() has to invoke the OOM killer even
  1001. * if it is a GFP_NOFS allocation.
  1002. */
  1003. if (!(oc->gfp_mask & __GFP_FS) && !is_memcg_oom(oc))
  1004. return true;
  1005. /*
  1006. * Check if there were limitations on the allocation (only relevant for
  1007. * NUMA and memcg) that may require different handling.
  1008. */
  1009. oc->constraint = constrained_alloc(oc);
  1010. if (oc->constraint != CONSTRAINT_MEMORY_POLICY)
  1011. oc->nodemask = NULL;
  1012. check_panic_on_oom(oc);
  1013. if (!is_memcg_oom(oc) && sysctl_oom_kill_allocating_task &&
  1014. current->mm && !oom_unkillable_task(current) &&
  1015. oom_cpuset_eligible(current, oc) &&
  1016. current->signal->oom_score_adj != OOM_SCORE_ADJ_MIN) {
  1017. get_task_struct(current);
  1018. oc->chosen = current;
  1019. oom_kill_process(oc, "Out of memory (oom_kill_allocating_task)");
  1020. return true;
  1021. }
  1022. select_bad_process(oc);
  1023. /* Found nothing?!?! */
  1024. if (!oc->chosen) {
  1025. dump_header(oc);
  1026. pr_warn("Out of memory and no killable processes...\n");
  1027. /*
  1028. * If we got here due to an actual allocation at the
  1029. * system level, we cannot survive this and will enter
  1030. * an endless loop in the allocator. Bail out now.
  1031. */
  1032. if (!is_sysrq_oom(oc) && !is_memcg_oom(oc))
  1033. panic("System is deadlocked on memory\n");
  1034. }
  1035. if (oc->chosen && oc->chosen != (void *)-1UL)
  1036. oom_kill_process(oc, !is_memcg_oom(oc) ? "Out of memory" :
  1037. "Memory cgroup out of memory");
  1038. return !!oc->chosen;
  1039. }
  1040. /*
  1041. * The pagefault handler calls here because some allocation has failed. We have
  1042. * to take care of the memcg OOM here because this is the only safe context without
  1043. * any locks held but let the oom killer triggered from the allocation context care
  1044. * about the global OOM.
  1045. */
  1046. void pagefault_out_of_memory(void)
  1047. {
  1048. static DEFINE_RATELIMIT_STATE(pfoom_rs, DEFAULT_RATELIMIT_INTERVAL,
  1049. DEFAULT_RATELIMIT_BURST);
  1050. if (mem_cgroup_oom_synchronize(true))
  1051. return;
  1052. if (fatal_signal_pending(current))
  1053. return;
  1054. if (__ratelimit(&pfoom_rs))
  1055. pr_warn("Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF\n");
  1056. }
  1057. SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags)
  1058. {
  1059. #ifdef CONFIG_MMU
  1060. struct mm_struct *mm = NULL;
  1061. struct task_struct *task;
  1062. struct task_struct *p;
  1063. unsigned int f_flags;
  1064. bool reap = false;
  1065. long ret = 0;
  1066. if (flags)
  1067. return -EINVAL;
  1068. task = pidfd_get_task(pidfd, &f_flags);
  1069. if (IS_ERR(task))
  1070. return PTR_ERR(task);
  1071. /*
  1072. * Make sure to choose a thread which still has a reference to mm
  1073. * during the group exit
  1074. */
  1075. p = find_lock_task_mm(task);
  1076. if (!p) {
  1077. ret = -ESRCH;
  1078. goto put_task;
  1079. }
  1080. mm = p->mm;
  1081. mmgrab(mm);
  1082. if (task_will_free_mem(p))
  1083. reap = true;
  1084. else {
  1085. /* Error only if the work has not been done already */
  1086. if (!test_bit(MMF_OOM_SKIP, &mm->flags))
  1087. ret = -EINVAL;
  1088. }
  1089. task_unlock(p);
  1090. if (!reap)
  1091. goto drop_mm;
  1092. if (mmap_read_lock_killable(mm)) {
  1093. ret = -EINTR;
  1094. goto drop_mm;
  1095. }
  1096. /*
  1097. * Check MMF_OOM_SKIP again under mmap_read_lock protection to ensure
  1098. * possible change in exit_mmap is seen
  1099. */
  1100. if (!test_bit(MMF_OOM_SKIP, &mm->flags) && !__oom_reap_task_mm(mm))
  1101. ret = -EAGAIN;
  1102. mmap_read_unlock(mm);
  1103. drop_mm:
  1104. mmdrop(mm);
  1105. put_task:
  1106. put_task_struct(task);
  1107. return ret;
  1108. #else
  1109. return -ENOSYS;
  1110. #endif /* CONFIG_MMU */
  1111. }