Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs/file.c: replace alloc_fdmem() with kvmalloc() alternative

There is no real reason to duplicate kvmalloc* helpers so drop
alloc_fdmem and replace it with the appropriate library function.

Link: http://lkml.kernel.org/r/20170531155145.17111-2-mhocko@kernel.org
Signed-off-by: Michal Hocko <mhocko@suse.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Michal Hocko and committed by
Linus Torvalds
c823bd92 b74271e4

+4 -18
+4 -18
fs/file.c
··· 30 30 unsigned int sysctl_nr_open_max = 31 31 __const_min(INT_MAX, ~(size_t)0/sizeof(void *)) & -BITS_PER_LONG; 32 32 33 - static void *alloc_fdmem(size_t size) 34 - { 35 - /* 36 - * Very large allocations can stress page reclaim, so fall back to 37 - * vmalloc() if the allocation size will be considered "large" by the VM. 38 - */ 39 - if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) { 40 - void *data = kmalloc(size, GFP_KERNEL_ACCOUNT | 41 - __GFP_NOWARN | __GFP_NORETRY); 42 - if (data != NULL) 43 - return data; 44 - } 45 - return __vmalloc(size, GFP_KERNEL_ACCOUNT, PAGE_KERNEL); 46 - } 47 - 48 33 static void __free_fdtable(struct fdtable *fdt) 49 34 { 50 35 kvfree(fdt->fd); ··· 116 131 if (!fdt) 117 132 goto out; 118 133 fdt->max_fds = nr; 119 - data = alloc_fdmem(nr * sizeof(struct file *)); 134 + data = kvmalloc_array(nr, sizeof(struct file *), GFP_KERNEL_ACCOUNT); 120 135 if (!data) 121 136 goto out_fdt; 122 137 fdt->fd = data; 123 138 124 - data = alloc_fdmem(max_t(size_t, 125 - 2 * nr / BITS_PER_BYTE + BITBIT_SIZE(nr), L1_CACHE_BYTES)); 139 + data = kvmalloc(max_t(size_t, 140 + 2 * nr / BITS_PER_BYTE + BITBIT_SIZE(nr), L1_CACHE_BYTES), 141 + GFP_KERNEL_ACCOUNT); 126 142 if (!data) 127 143 goto out_arr; 128 144 fdt->open_fds = data;