Commit 2c85f51d222ccdd8c401d77a36b723a89156810d

Authored by Jan Beulich
Committed by Linus Torvalds
1 parent 3c1596efe1

mm: also use alloc_large_system_hash() for the PID hash table

This is being done by allowing boot time allocations to specify that they
may want a sub-page sized amount of memory.

Overall this seems more consistent with the other hash table allocations,
and allows making two supposedly mm-only variables really mm-only
(nr_{kernel,all}_pages).

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 16 additions and 17 deletions Side-by-side Diff

include/linux/bootmem.h
... ... @@ -132,9 +132,6 @@
132 132 }
133 133 #endif /* CONFIG_HAVE_ARCH_ALLOC_REMAP */
134 134  
135   -extern unsigned long __meminitdata nr_kernel_pages;
136   -extern unsigned long __meminitdata nr_all_pages;
137   -
138 135 extern void *alloc_large_system_hash(const char *tablename,
139 136 unsigned long bucketsize,
140 137 unsigned long numentries,
... ... @@ -145,6 +142,8 @@
145 142 unsigned long limit);
146 143  
147 144 #define HASH_EARLY 0x00000001 /* Allocating during early boot? */
  145 +#define HASH_SMALL 0x00000002 /* sub-page allocation allowed, min
  146 + * shift passed via *_hash_shift */
148 147  
149 148 /* Only NUMA needs hash distribution. 64bit NUMA architectures have
150 149 * sufficient vmalloc space.
... ... @@ -40,7 +40,7 @@
40 40 #define pid_hashfn(nr, ns) \
41 41 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
42 42 static struct hlist_head *pid_hash;
43   -static int pidhash_shift;
  43 +static unsigned int pidhash_shift = 4;
44 44 struct pid init_struct_pid = INIT_STRUCT_PID;
45 45  
46 46 int pid_max = PID_MAX_DEFAULT;
47 47  
48 48  
... ... @@ -499,19 +499,12 @@
499 499 void __init pidhash_init(void)
500 500 {
501 501 int i, pidhash_size;
502   - unsigned long megabytes = nr_kernel_pages >> (20 - PAGE_SHIFT);
503 502  
504   - pidhash_shift = max(4, fls(megabytes * 4));
505   - pidhash_shift = min(12, pidhash_shift);
  503 + pid_hash = alloc_large_system_hash("PID", sizeof(*pid_hash), 0, 18,
  504 + HASH_EARLY | HASH_SMALL,
  505 + &pidhash_shift, NULL, 4096);
506 506 pidhash_size = 1 << pidhash_shift;
507 507  
508   - printk("PID hash table entries: %d (order: %d, %Zd bytes)\n",
509   - pidhash_size, pidhash_shift,
510   - pidhash_size * sizeof(struct hlist_head));
511   -
512   - pid_hash = alloc_bootmem(pidhash_size * sizeof(*(pid_hash)));
513   - if (!pid_hash)
514   - panic("Could not alloc pidhash!\n");
515 508 for (i = 0; i < pidhash_size; i++)
516 509 INIT_HLIST_HEAD(&pid_hash[i]);
517 510 }
... ... @@ -124,8 +124,8 @@
124 124  
125 125 int min_free_kbytes = 1024;
126 126  
127   -unsigned long __meminitdata nr_kernel_pages;
128   -unsigned long __meminitdata nr_all_pages;
  127 +static unsigned long __meminitdata nr_kernel_pages;
  128 +static unsigned long __meminitdata nr_all_pages;
129 129 static unsigned long __meminitdata dma_reserve;
130 130  
131 131 #ifdef CONFIG_ARCH_POPULATES_NODE_MAP
... ... @@ -4821,7 +4821,14 @@
4821 4821 numentries <<= (PAGE_SHIFT - scale);
4822 4822  
4823 4823 /* Make sure we've got at least a 0-order allocation.. */
4824   - if (unlikely((numentries * bucketsize) < PAGE_SIZE))
  4824 + if (unlikely(flags & HASH_SMALL)) {
  4825 + /* Makes no sense without HASH_EARLY */
  4826 + WARN_ON(!(flags & HASH_EARLY));
  4827 + if (!(numentries >> *_hash_shift)) {
  4828 + numentries = 1UL << *_hash_shift;
  4829 + BUG_ON(!numentries);
  4830 + }
  4831 + } else if (unlikely((numentries * bucketsize) < PAGE_SIZE))
4825 4832 numentries = PAGE_SIZE / bucketsize;
4826 4833 }
4827 4834 numentries = roundup_pow_of_two(numentries);