diff options
author | Pavel Tatashin <pasha.tatashin@oracle.com> | 2017-07-06 18:39:08 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-06 19:24:33 -0400 |
commit | 3749a8f008eac3355a9e50b366ba08317a7e9cf8 (patch) | |
tree | 448dc6eaf19a3838cdc2ab497c529729168def2b /mm/page_alloc.c | |
parent | f7fb506fef6e8701bdb0ea7bb4f01148efd7416c (diff) |
mm: zero hash tables in allocator
Add a new flag HASH_ZERO which when provided grantees that the hash
table that is returned by alloc_large_system_hash() is zeroed. In most
cases that is what is needed by the caller. Use page level allocator's
__GFP_ZERO flags to zero the memory. It is using memset() which is
efficient method to zero memory and is optimized for most platforms.
Link: http://lkml.kernel.org/r/1488432825-92126-3-git-send-email-pasha.tatashin@oracle.com
Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com>
Reviewed-by: Babu Moger <babu.moger@oracle.com>
Cc: David Miller <davem@davemloft.net>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/page_alloc.c')
-rw-r--r-- | mm/page_alloc.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 387f20db217c..34240e2a0583 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c | |||
@@ -7198,6 +7198,7 @@ void *__init alloc_large_system_hash(const char *tablename, | |||
7198 | unsigned long long max = high_limit; | 7198 | unsigned long long max = high_limit; |
7199 | unsigned long log2qty, size; | 7199 | unsigned long log2qty, size; |
7200 | void *table = NULL; | 7200 | void *table = NULL; |
7201 | gfp_t gfp_flags; | ||
7201 | 7202 | ||
7202 | /* allow the kernel cmdline to have a say */ | 7203 | /* allow the kernel cmdline to have a say */ |
7203 | if (!numentries) { | 7204 | if (!numentries) { |
@@ -7242,12 +7243,17 @@ void *__init alloc_large_system_hash(const char *tablename, | |||
7242 | 7243 | ||
7243 | log2qty = ilog2(numentries); | 7244 | log2qty = ilog2(numentries); |
7244 | 7245 | ||
7246 | /* | ||
7247 | * memblock allocator returns zeroed memory already, so HASH_ZERO is | ||
7248 | * currently not used when HASH_EARLY is specified. | ||
7249 | */ | ||
7250 | gfp_flags = (flags & HASH_ZERO) ? GFP_ATOMIC | __GFP_ZERO : GFP_ATOMIC; | ||
7245 | do { | 7251 | do { |
7246 | size = bucketsize << log2qty; | 7252 | size = bucketsize << log2qty; |
7247 | if (flags & HASH_EARLY) | 7253 | if (flags & HASH_EARLY) |
7248 | table = memblock_virt_alloc_nopanic(size, 0); | 7254 | table = memblock_virt_alloc_nopanic(size, 0); |
7249 | else if (hashdist) | 7255 | else if (hashdist) |
7250 | table = __vmalloc(size, GFP_ATOMIC, PAGE_KERNEL); | 7256 | table = __vmalloc(size, gfp_flags, PAGE_KERNEL); |
7251 | else { | 7257 | else { |
7252 | /* | 7258 | /* |
7253 | * If bucketsize is not a power-of-two, we may free | 7259 | * If bucketsize is not a power-of-two, we may free |
@@ -7255,8 +7261,8 @@ void *__init alloc_large_system_hash(const char *tablename, | |||
7255 | * alloc_pages_exact() automatically does | 7261 | * alloc_pages_exact() automatically does |
7256 | */ | 7262 | */ |
7257 | if (get_order(size) < MAX_ORDER) { | 7263 | if (get_order(size) < MAX_ORDER) { |
7258 | table = alloc_pages_exact(size, GFP_ATOMIC); | 7264 | table = alloc_pages_exact(size, gfp_flags); |
7259 | kmemleak_alloc(table, size, 1, GFP_ATOMIC); | 7265 | kmemleak_alloc(table, size, 1, gfp_flags); |
7260 | } | 7266 | } |
7261 | } | 7267 | } |
7262 | } while (!table && size > PAGE_SIZE && --log2qty); | 7268 | } while (!table && size > PAGE_SIZE && --log2qty); |