diff options
Diffstat (limited to 'mm/oom_kill.c')
| -rw-r--r-- | mm/oom_kill.c | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 492c98624fc1..f52481b1c1e5 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c | |||
| @@ -196,27 +196,46 @@ unsigned long badness(struct task_struct *p, unsigned long uptime) | |||
| 196 | /* | 196 | /* |
| 197 | * Determine the type of allocation constraint. | 197 | * Determine the type of allocation constraint. |
| 198 | */ | 198 | */ |
| 199 | static inline enum oom_constraint constrained_alloc(struct zonelist *zonelist, | ||
| 200 | gfp_t gfp_mask) | ||
| 201 | { | ||
| 202 | #ifdef CONFIG_NUMA | 199 | #ifdef CONFIG_NUMA |
| 200 | static enum oom_constraint constrained_alloc(struct zonelist *zonelist, | ||
| 201 | gfp_t gfp_mask, nodemask_t *nodemask) | ||
| 202 | { | ||
| 203 | struct zone *zone; | 203 | struct zone *zone; |
| 204 | struct zoneref *z; | 204 | struct zoneref *z; |
| 205 | enum zone_type high_zoneidx = gfp_zone(gfp_mask); | 205 | enum zone_type high_zoneidx = gfp_zone(gfp_mask); |
| 206 | nodemask_t nodes = node_states[N_HIGH_MEMORY]; | ||
| 207 | 206 | ||
| 208 | for_each_zone_zonelist(zone, z, zonelist, high_zoneidx) | 207 | /* |
| 209 | if (cpuset_zone_allowed_softwall(zone, gfp_mask)) | 208 | * Reach here only when __GFP_NOFAIL is used. So, we should avoid |
| 210 | node_clear(zone_to_nid(zone), nodes); | 209 | * to kill current.We have to random task kill in this case. |
| 211 | else | 210 | * Hopefully, CONSTRAINT_THISNODE...but no way to handle it, now. |
| 212 | return CONSTRAINT_CPUSET; | 211 | */ |
| 212 | if (gfp_mask & __GFP_THISNODE) | ||
| 213 | return CONSTRAINT_NONE; | ||
| 213 | 214 | ||
| 214 | if (!nodes_empty(nodes)) | 215 | /* |
| 216 | * The nodemask here is a nodemask passed to alloc_pages(). Now, | ||
| 217 | * cpuset doesn't use this nodemask for its hardwall/softwall/hierarchy | ||
| 218 | * feature. mempolicy is an only user of nodemask here. | ||
| 219 | * check mempolicy's nodemask contains all N_HIGH_MEMORY | ||
| 220 | */ | ||
| 221 | if (nodemask && !nodes_subset(node_states[N_HIGH_MEMORY], *nodemask)) | ||
| 215 | return CONSTRAINT_MEMORY_POLICY; | 222 | return CONSTRAINT_MEMORY_POLICY; |
| 216 | #endif | 223 | |
| 224 | /* Check this allocation failure is caused by cpuset's wall function */ | ||
| 225 | for_each_zone_zonelist_nodemask(zone, z, zonelist, | ||
| 226 | high_zoneidx, nodemask) | ||
| 227 | if (!cpuset_zone_allowed_softwall(zone, gfp_mask)) | ||
| 228 | return CONSTRAINT_CPUSET; | ||
| 217 | 229 | ||
| 218 | return CONSTRAINT_NONE; | 230 | return CONSTRAINT_NONE; |
| 219 | } | 231 | } |
| 232 | #else | ||
| 233 | static enum oom_constraint constrained_alloc(struct zonelist *zonelist, | ||
| 234 | gfp_t gfp_mask, nodemask_t *nodemask) | ||
| 235 | { | ||
| 236 | return CONSTRAINT_NONE; | ||
| 237 | } | ||
| 238 | #endif | ||
| 220 | 239 | ||
| 221 | /* | 240 | /* |
| 222 | * Simple selection loop. We chose the process with the highest | 241 | * Simple selection loop. We chose the process with the highest |
| @@ -337,7 +356,8 @@ static void dump_tasks(const struct mem_cgroup *mem) | |||
| 337 | } while_each_thread(g, p); | 356 | } while_each_thread(g, p); |
| 338 | } | 357 | } |
| 339 | 358 | ||
| 340 | static void dump_header(gfp_t gfp_mask, int order, struct mem_cgroup *mem) | 359 | static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order, |
| 360 | struct mem_cgroup *mem) | ||
| 341 | { | 361 | { |
| 342 | pr_warning("%s invoked oom-killer: gfp_mask=0x%x, order=%d, " | 362 | pr_warning("%s invoked oom-killer: gfp_mask=0x%x, order=%d, " |
| 343 | "oom_adj=%d\n", | 363 | "oom_adj=%d\n", |
| @@ -346,12 +366,14 @@ static void dump_header(gfp_t gfp_mask, int order, struct mem_cgroup *mem) | |||
| 346 | cpuset_print_task_mems_allowed(current); | 366 | cpuset_print_task_mems_allowed(current); |
| 347 | task_unlock(current); | 367 | task_unlock(current); |
| 348 | dump_stack(); | 368 | dump_stack(); |
| 349 | mem_cgroup_print_oom_info(mem, current); | 369 | mem_cgroup_print_oom_info(mem, p); |
| 350 | show_mem(); | 370 | show_mem(); |
| 351 | if (sysctl_oom_dump_tasks) | 371 | if (sysctl_oom_dump_tasks) |
| 352 | dump_tasks(mem); | 372 | dump_tasks(mem); |
| 353 | } | 373 | } |
| 354 | 374 | ||
| 375 | #define K(x) ((x) << (PAGE_SHIFT-10)) | ||
| 376 | |||
| 355 | /* | 377 | /* |
| 356 | * Send SIGKILL to the selected process irrespective of CAP_SYS_RAW_IO | 378 | * Send SIGKILL to the selected process irrespective of CAP_SYS_RAW_IO |
| 357 | * flag though it's unlikely that we select a process with CAP_SYS_RAW_IO | 379 | * flag though it's unlikely that we select a process with CAP_SYS_RAW_IO |
| @@ -365,15 +387,23 @@ static void __oom_kill_task(struct task_struct *p, int verbose) | |||
| 365 | return; | 387 | return; |
| 366 | } | 388 | } |
| 367 | 389 | ||
| 390 | task_lock(p); | ||
| 368 | if (!p->mm) { | 391 | if (!p->mm) { |
| 369 | WARN_ON(1); | 392 | WARN_ON(1); |
| 370 | printk(KERN_WARNING "tried to kill an mm-less task!\n"); | 393 | printk(KERN_WARNING "tried to kill an mm-less task %d (%s)!\n", |
| 394 | task_pid_nr(p), p->comm); | ||
| 395 | task_unlock(p); | ||
| 371 | return; | 396 | return; |
| 372 | } | 397 | } |
| 373 | 398 | ||
| 374 | if (verbose) | 399 | if (verbose) |
| 375 | printk(KERN_ERR "Killed process %d (%s)\n", | 400 | printk(KERN_ERR "Killed process %d (%s) " |
| 376 | task_pid_nr(p), p->comm); | 401 | "vsz:%lukB, anon-rss:%lukB, file-rss:%lukB\n", |
| 402 | task_pid_nr(p), p->comm, | ||
| 403 | K(p->mm->total_vm), | ||
| 404 | K(get_mm_counter(p->mm, anon_rss)), | ||
| 405 | K(get_mm_counter(p->mm, file_rss))); | ||
| 406 | task_unlock(p); | ||
| 377 | 407 | ||
| 378 | /* | 408 | /* |
| 379 | * We give our sacrificial lamb high priority and access to | 409 | * We give our sacrificial lamb high priority and access to |
| @@ -411,7 +441,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, | |||
| 411 | struct task_struct *c; | 441 | struct task_struct *c; |
| 412 | 442 | ||
| 413 | if (printk_ratelimit()) | 443 | if (printk_ratelimit()) |
| 414 | dump_header(gfp_mask, order, mem); | 444 | dump_header(p, gfp_mask, order, mem); |
| 415 | 445 | ||
| 416 | /* | 446 | /* |
| 417 | * If the task is already exiting, don't alarm the sysadmin or kill | 447 | * If the task is already exiting, don't alarm the sysadmin or kill |
| @@ -547,7 +577,7 @@ retry: | |||
| 547 | /* Found nothing?!?! Either we hang forever, or we panic. */ | 577 | /* Found nothing?!?! Either we hang forever, or we panic. */ |
| 548 | if (!p) { | 578 | if (!p) { |
| 549 | read_unlock(&tasklist_lock); | 579 | read_unlock(&tasklist_lock); |
| 550 | dump_header(gfp_mask, order, NULL); | 580 | dump_header(NULL, gfp_mask, order, NULL); |
| 551 | panic("Out of memory and no killable processes...\n"); | 581 | panic("Out of memory and no killable processes...\n"); |
| 552 | } | 582 | } |
| 553 | 583 | ||
| @@ -603,7 +633,8 @@ rest_and_return: | |||
| 603 | * OR try to be smart about which process to kill. Note that we | 633 | * OR try to be smart about which process to kill. Note that we |
| 604 | * don't have to be perfect here, we just have to be good. | 634 | * don't have to be perfect here, we just have to be good. |
| 605 | */ | 635 | */ |
| 606 | void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order) | 636 | void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, |
| 637 | int order, nodemask_t *nodemask) | ||
| 607 | { | 638 | { |
| 608 | unsigned long freed = 0; | 639 | unsigned long freed = 0; |
| 609 | enum oom_constraint constraint; | 640 | enum oom_constraint constraint; |
| @@ -614,7 +645,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order) | |||
| 614 | return; | 645 | return; |
| 615 | 646 | ||
| 616 | if (sysctl_panic_on_oom == 2) { | 647 | if (sysctl_panic_on_oom == 2) { |
| 617 | dump_header(gfp_mask, order, NULL); | 648 | dump_header(NULL, gfp_mask, order, NULL); |
| 618 | panic("out of memory. Compulsory panic_on_oom is selected.\n"); | 649 | panic("out of memory. Compulsory panic_on_oom is selected.\n"); |
| 619 | } | 650 | } |
| 620 | 651 | ||
| @@ -622,7 +653,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order) | |||
| 622 | * Check if there were limitations on the allocation (only relevant for | 653 | * Check if there were limitations on the allocation (only relevant for |
| 623 | * NUMA) that may require different handling. | 654 | * NUMA) that may require different handling. |
| 624 | */ | 655 | */ |
| 625 | constraint = constrained_alloc(zonelist, gfp_mask); | 656 | constraint = constrained_alloc(zonelist, gfp_mask, nodemask); |
| 626 | read_lock(&tasklist_lock); | 657 | read_lock(&tasklist_lock); |
| 627 | 658 | ||
| 628 | switch (constraint) { | 659 | switch (constraint) { |
| @@ -633,7 +664,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order) | |||
| 633 | 664 | ||
| 634 | case CONSTRAINT_NONE: | 665 | case CONSTRAINT_NONE: |
| 635 | if (sysctl_panic_on_oom) { | 666 | if (sysctl_panic_on_oom) { |
| 636 | dump_header(gfp_mask, order, NULL); | 667 | dump_header(NULL, gfp_mask, order, NULL); |
| 637 | panic("out of memory. panic_on_oom is selected\n"); | 668 | panic("out of memory. panic_on_oom is selected\n"); |
| 638 | } | 669 | } |
| 639 | /* Fall-through */ | 670 | /* Fall-through */ |
