diff options
author | David Rientjes <rientjes@google.com> | 2009-12-14 20:58:38 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-15 11:53:13 -0500 |
commit | bad44b5be84cf3bb1ff900bec02ee61e1993328c (patch) | |
tree | edd9a9cc2f482ca8684c9e64abe4b977a5525615 /include/linux/nodemask.h | |
parent | 39da08cb074cf19cb249832a2a955dfb28837e65 (diff) |
mm: add gfp flags for NODEMASK_ALLOC slab allocations
Objects passed to NODEMASK_ALLOC() are relatively small in size and are
backed by slab caches that are not of large order, traditionally never
greater than PAGE_ALLOC_COSTLY_ORDER.
Thus, using GFP_KERNEL for these allocations on large machines when
CONFIG_NODES_SHIFT > 8 will cause the page allocator to loop endlessly in
the allocation attempt, each time invoking both direct reclaim or the oom
killer.
This is of particular interest when using NODEMASK_ALLOC() from a
mempolicy context (either directly in mm/mempolicy.c or the mempolicy
constrained hugetlb allocations) since the oom killer always kills current
when allocations are constrained by mempolicies. So for all present use
cases in the kernel, current would end up being oom killed when direct
reclaim fails. That would allow the NODEMASK_ALLOC() to succeed but
current would have sacrificed itself upon returning.
This patch adds gfp flags to NODEMASK_ALLOC() to pass to kmalloc() on
CONFIG_NODES_SHIFT > 8; this parameter is a nop on other configurations.
All current use cases either directly from hugetlb code or indirectly via
NODEMASK_SCRATCH() union __GFP_NORETRY to avoid direct reclaim and the oom
killer when the slab allocator needs to allocate additional pages.
The side-effect of this change is that all current use cases of either
NODEMASK_ALLOC() or NODEMASK_SCRATCH() need appropriate -ENOMEM handling
when the allocation fails (never for CONFIG_NODES_SHIFT <= 8). All
current use cases were audited and do have appropriate error handling at
this time.
Signed-off-by: David Rientjes <rientjes@google.com>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Nishanth Aravamudan <nacc@us.ibm.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Adam Litke <agl@us.ibm.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Eric Whitney <eric.whitney@hp.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/nodemask.h')
-rw-r--r-- | include/linux/nodemask.h | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index cbd521a03127..454997cccbd8 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h | |||
@@ -485,15 +485,17 @@ static inline int num_node_state(enum node_states state) | |||
485 | #define for_each_online_node(node) for_each_node_state(node, N_ONLINE) | 485 | #define for_each_online_node(node) for_each_node_state(node, N_ONLINE) |
486 | 486 | ||
487 | /* | 487 | /* |
488 | * For nodemask scrach area.(See CPUMASK_ALLOC() in cpumask.h) | 488 | * For nodemask scrach area. |
489 | * NODEMASK_ALLOC(x, m) allocates an object of type 'x' with the name 'm'. | 489 | * NODEMASK_ALLOC(type, name) allocates an object with a specified type and |
490 | * name. | ||
490 | */ | 491 | */ |
491 | #if NODES_SHIFT > 8 /* nodemask_t > 64 bytes */ | 492 | #if NODES_SHIFT > 8 /* nodemask_t > 256 bytes */ |
492 | #define NODEMASK_ALLOC(x, m) x *m = kmalloc(sizeof(*m), GFP_KERNEL) | 493 | #define NODEMASK_ALLOC(type, name, gfp_flags) \ |
493 | #define NODEMASK_FREE(m) kfree(m) | 494 | type *name = kmalloc(sizeof(*name), gfp_flags) |
495 | #define NODEMASK_FREE(m) kfree(m) | ||
494 | #else | 496 | #else |
495 | #define NODEMASK_ALLOC(x, m) x _m, *m = &_m | 497 | #define NODEMASK_ALLOC(type, name, gfp_flags) type _name, *name = &_name |
496 | #define NODEMASK_FREE(m) do {} while (0) | 498 | #define NODEMASK_FREE(m) do {} while (0) |
497 | #endif | 499 | #endif |
498 | 500 | ||
499 | /* A example struture for using NODEMASK_ALLOC, used in mempolicy. */ | 501 | /* A example struture for using NODEMASK_ALLOC, used in mempolicy. */ |
@@ -502,8 +504,9 @@ struct nodemask_scratch { | |||
502 | nodemask_t mask2; | 504 | nodemask_t mask2; |
503 | }; | 505 | }; |
504 | 506 | ||
505 | #define NODEMASK_SCRATCH(x) \ | 507 | #define NODEMASK_SCRATCH(x) \ |
506 | NODEMASK_ALLOC(struct nodemask_scratch, x) | 508 | NODEMASK_ALLOC(struct nodemask_scratch, x, \ |
509 | GFP_KERNEL | __GFP_NORETRY) | ||
507 | #define NODEMASK_SCRATCH_FREE(x) NODEMASK_FREE(x) | 510 | #define NODEMASK_SCRATCH_FREE(x) NODEMASK_FREE(x) |
508 | 511 | ||
509 | 512 | ||