proc: fixup PDE allocation bloat
authorAlexey Dobriyan <adobriyan@gmail.com>
Wed, 22 Aug 2018 04:54:09 +0000 (21:54 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 22 Aug 2018 17:52:45 +0000 (10:52 -0700)
24074a35c5c975 ("proc: Make inline name size calculation automatic")
started to put PDE allocations into kmalloc-256 which is unnecessary as
~40 character names are very rare.

Put allocation back into kmalloc-192 cache for 64-bit non-debug builds.

Put BUILD_BUG_ON to know when PDE size has gotten out of control.

[adobriyan@gmail.com: fix BUILD_BUG_ON breakage on powerpc64]
Link: http://lkml.kernel.org/r/20180703191602.GA25521@avx2
Link: http://lkml.kernel.org/r/20180617215732.GA24688@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/proc/inode.c
fs/proc/internal.h

index 85ffbd27f2883a8e6fb3dfe8275c2e1a36ac3ffe..fc5306a31a1d8b489dc16483d79cf83b6445f387 100644 (file)
@@ -105,8 +105,10 @@ void __init proc_init_kmemcache(void)
                kmem_cache_create("pde_opener", sizeof(struct pde_opener), 0,
                                  SLAB_ACCOUNT|SLAB_PANIC, NULL);
        proc_dir_entry_cache = kmem_cache_create_usercopy(
-               "proc_dir_entry", SIZEOF_PDE_SLOT, 0, SLAB_PANIC,
-               OFFSETOF_PDE_NAME, SIZEOF_PDE_INLINE_NAME, NULL);
+               "proc_dir_entry", SIZEOF_PDE, 0, SLAB_PANIC,
+               offsetof(struct proc_dir_entry, inline_name),
+               SIZEOF_PDE_INLINE_NAME, NULL);
+       BUILD_BUG_ON(sizeof(struct proc_dir_entry) >= SIZEOF_PDE);
 }
 
 static int proc_show_options(struct seq_file *seq, struct dentry *root)
index f5b75d258d22640cf0af1f8421cce6efe67973ad..c9d97818a421671fef51c66a5711bc187d5dba93 100644 (file)
@@ -65,16 +65,13 @@ struct proc_dir_entry {
        char inline_name[];
 } __randomize_layout;
 
-#define OFFSETOF_PDE_NAME offsetof(struct proc_dir_entry, inline_name)
-#define SIZEOF_PDE_SLOT                                        \
-       (OFFSETOF_PDE_NAME + 34 <= 64 ? 64 :            \
-        OFFSETOF_PDE_NAME + 34 <= 128 ? 128 :          \
-        OFFSETOF_PDE_NAME + 34 <= 192 ? 192 :          \
-        OFFSETOF_PDE_NAME + 34 <= 256 ? 256 :          \
-        OFFSETOF_PDE_NAME + 34 <= 512 ? 512 :          \
-        0)
-
-#define SIZEOF_PDE_INLINE_NAME (SIZEOF_PDE_SLOT - OFFSETOF_PDE_NAME)
+#define SIZEOF_PDE     (                               \
+       sizeof(struct proc_dir_entry) < 128 ? 128 :     \
+       sizeof(struct proc_dir_entry) < 192 ? 192 :     \
+       sizeof(struct proc_dir_entry) < 256 ? 256 :     \
+       sizeof(struct proc_dir_entry) < 512 ? 512 :     \
+       0)
+#define SIZEOF_PDE_INLINE_NAME (SIZEOF_PDE - sizeof(struct proc_dir_entry))
 
 extern struct kmem_cache *proc_dir_entry_cache;
 void pde_free(struct proc_dir_entry *pde);