linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] proc: Make inline name size calculation automatic
@ 2018-06-14 20:09 Alexey Dobriyan
  2018-06-14 20:30 ` David Howells
  0 siblings, 1 reply; 10+ messages in thread
From: Alexey Dobriyan @ 2018-06-14 20:09 UTC (permalink / raw)
  To: dhowells; +Cc: viro, linux-fsdevel, linux-kernel

> Require a minimum inline name size of 33+1 to allow for names that look
> like two hex numbers with a dash between.

Hi, David.

Why 34? /proc will fallback to separate allocation for name anyway.

I sent nearly identical patch earlier.
https://marc.info/?l=linux-kernel&m=152667374404900&w=4

If you compare, the differences are:

* no BUILD_BUG_ON,
* 64 bytes is too litle even on 32-bit,
* 512 bytes is probably too much even on 64-bit.

> -	.name		= proc_root.inline_name,
> -	.inline_name	= "/proc",
> +	.name		= "/proc",

This will "uninline" 5 bytes wasting space.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] proc: Make inline name size calculation automatic
  2018-06-14 20:09 [PATCH] proc: Make inline name size calculation automatic Alexey Dobriyan
@ 2018-06-14 20:30 ` David Howells
  2018-06-15 17:15   ` Alexey Dobriyan
  2018-06-17 21:57   ` [PATCH] proc: fixup PDE allocation bloat Alexey Dobriyan
  0 siblings, 2 replies; 10+ messages in thread
From: David Howells @ 2018-06-14 20:30 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: dhowells, viro, linux-fsdevel, linux-kernel

Alexey Dobriyan <adobriyan@gmail.com> wrote:

> > Require a minimum inline name size of 33+1 to allow for names that look
> > like two hex numbers with a dash between.
> 
> Why 34? /proc will fallback to separate allocation for name anyway.

See above comment.  I ran find on /proc and there were a bunch of files whose
names were "<hex>-<hex>".  Allow for 16-char hex addresses and add a NUL char
to that and you get 34.

David

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] proc: Make inline name size calculation automatic
  2018-06-14 20:30 ` David Howells
@ 2018-06-15 17:15   ` Alexey Dobriyan
  2018-06-17 21:57   ` [PATCH] proc: fixup PDE allocation bloat Alexey Dobriyan
  1 sibling, 0 replies; 10+ messages in thread
From: Alexey Dobriyan @ 2018-06-15 17:15 UTC (permalink / raw)
  To: David Howells; +Cc: viro, linux-fsdevel, linux-kernel

On Thu, Jun 14, 2018 at 09:30:42PM +0100, David Howells wrote:
> Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 
> > > Require a minimum inline name size of 33+1 to allow for names that look
> > > like two hex numbers with a dash between.
> > 
> > Why 34? /proc will fallback to separate allocation for name anyway.
> 
> See above comment.  I ran find on /proc and there were a bunch of files whose
> names were "<hex>-<hex>".  Allow for 16-char hex addresses and add a NUL char
> to that and you get 34.

Those must be /proc/*/map_files symlinks. If that's the case,
they don't have PDEs allocated.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] proc: fixup PDE allocation bloat
  2018-06-14 20:30 ` David Howells
  2018-06-15 17:15   ` Alexey Dobriyan
@ 2018-06-17 21:57   ` Alexey Dobriyan
  2018-07-20  0:06     ` Shakeel Butt
  1 sibling, 1 reply; 10+ messages in thread
From: Alexey Dobriyan @ 2018-06-17 21:57 UTC (permalink / raw)
  To: dhowells, viro, akpm; +Cc: linux-fsdevel, linux-kernel

commit 24074a35c5c975c94cd9691ae962855333aac47f
("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 is gotten out of control.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 fs/proc/inode.c    |    6 ++++--
 fs/proc/internal.h |   17 +++++++----------
 2 files changed, 11 insertions(+), 12 deletions(-)

--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -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)
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -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)
+#ifdef CONFIG_64BIT
+#define SIZEOF_PDE	(sizeof(spinlock_t) <= 4 ? 192 : 256)
+#else
+#define SIZEOF_PDE	(sizeof(spinlock_t) <= 4 ? 128 : 192)
+#endif
+
+#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);

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] proc: fixup PDE allocation bloat
  2018-06-17 21:57   ` [PATCH] proc: fixup PDE allocation bloat Alexey Dobriyan
@ 2018-07-20  0:06     ` Shakeel Butt
  2018-08-17 13:28       ` Alexey Dobriyan
  0 siblings, 1 reply; 10+ messages in thread
From: Shakeel Butt @ 2018-07-20  0:06 UTC (permalink / raw)
  To: adobriyan; +Cc: dhowells, Alexander Viro, Andrew Morton, linux-fsdevel, LKML

On Sun, Jun 17, 2018 at 2:57 PM Alexey Dobriyan <adobriyan@gmail.com> wrote:
>
> commit 24074a35c5c975c94cd9691ae962855333aac47f
> ("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 is gotten out of control.
>
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
>
>  fs/proc/inode.c    |    6 ++++--
>  fs/proc/internal.h |   17 +++++++----------
>  2 files changed, 11 insertions(+), 12 deletions(-)
>
> --- a/fs/proc/inode.c
> +++ b/fs/proc/inode.c
> @@ -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,

Hi Alexey, can you comment if proc_dir_entry_cache should or shouldn't
have SLAB_ACCOUNT flag?

Shakeel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] proc: fixup PDE allocation bloat
  2018-07-20  0:06     ` Shakeel Butt
@ 2018-08-17 13:28       ` Alexey Dobriyan
  0 siblings, 0 replies; 10+ messages in thread
From: Alexey Dobriyan @ 2018-08-17 13:28 UTC (permalink / raw)
  To: Shakeel Butt; +Cc: dhowells, Alexander Viro, Andrew Morton, linux-fsdevel, LKML

On Thu, Jul 19, 2018 at 05:06:55PM -0700, Shakeel Butt wrote:
> On Sun, Jun 17, 2018 at 2:57 PM Alexey Dobriyan <adobriyan@gmail.com> wrote:
> >
> > commit 24074a35c5c975c94cd9691ae962855333aac47f
> > ("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 is gotten out of control.
> >
> > Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> > ---
> >
> >  fs/proc/inode.c    |    6 ++++--
> >  fs/proc/internal.h |   17 +++++++----------
> >  2 files changed, 11 insertions(+), 12 deletions(-)
> >
> > --- a/fs/proc/inode.c
> > +++ b/fs/proc/inode.c
> > @@ -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,
> 
> Hi Alexey, can you comment if proc_dir_entry_cache should or shouldn't
> have SLAB_ACCOUNT flag?

It should not (but see below):

SLAB_ACCOUNT is for allocations which can be done by userspace directly:
open(2) directly allocates "struct file".

But /proc entries aren't like that: say, /proc/cpuinfo is created by kernel
and userspace can't do anything about it.

Some subsystems create /proc entries based on userspace actions and
those aren't related to hardware (example: xt_hashlimit.c) but those are
few so kernel doesn't bother accounting those.

Or in other words: user can't mkdir(1) and touch(1) and ln(1) inside /proc
at will and therefore PDEs aren't accounted.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] proc: Make inline name size calculation automatic
  2018-06-19  8:01 ` David Howells
@ 2018-06-19 21:59   ` Andrew Morton
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2018-06-19 21:59 UTC (permalink / raw)
  To: David Howells; +Cc: viro, linux-fsdevel, linux-kernel, Alexey Dobriyan

On Tue, 19 Jun 2018 09:01:01 +0100 David Howells <dhowells@redhat.com> wrote:

> Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> > Please cc Alexey on /proc patches.
> 
> If Alexey is responsible for procfs he should declare this in MAINTAINERS.

oop.  I thought we did that but it isn't there.

> > What are the user-visible runtime effects of this change?
> 
> Memory usage only.

Please always include such info in changelogs.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] proc: Make inline name size calculation automatic
  2018-06-13 18:43 [PATCH] proc: Make inline name size calculation automatic David Howells
  2018-06-19  0:42 ` Andrew Morton
@ 2018-06-19  8:01 ` David Howells
  2018-06-19 21:59   ` Andrew Morton
  1 sibling, 1 reply; 10+ messages in thread
From: David Howells @ 2018-06-19  8:01 UTC (permalink / raw)
  To: Andrew Morton
  Cc: dhowells, viro, linux-fsdevel, linux-kernel, Alexey Dobriyan

Andrew Morton <akpm@linux-foundation.org> wrote:

> Please cc Alexey on /proc patches.

If Alexey is responsible for procfs he should declare this in MAINTAINERS.

> What are the user-visible runtime effects of this change?

Memory usage only.

David

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] proc: Make inline name size calculation automatic
  2018-06-13 18:43 [PATCH] proc: Make inline name size calculation automatic David Howells
@ 2018-06-19  0:42 ` Andrew Morton
  2018-06-19  8:01 ` David Howells
  1 sibling, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2018-06-19  0:42 UTC (permalink / raw)
  To: David Howells; +Cc: viro, linux-fsdevel, linux-kernel, Alexey Dobriyan

On Wed, 13 Jun 2018 19:43:19 +0100 David Howells <dhowells@redhat.com> wrote:

> Make calculation of the size of the inline name in struct proc_dir_entry
> automatic, rather than having to manually encode the numbers and failing to
> allow for lockdep.
> 
> Require a minimum inline name size of 33+1 to allow for names that look
> like two hex numbers with a dash between.

Please cc Alexey on /proc patches.

What are the user-visible runtime effects of this change?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] proc: Make inline name size calculation automatic
@ 2018-06-13 18:43 David Howells
  2018-06-19  0:42 ` Andrew Morton
  2018-06-19  8:01 ` David Howells
  0 siblings, 2 replies; 10+ messages in thread
From: David Howells @ 2018-06-13 18:43 UTC (permalink / raw)
  To: viro; +Cc: dhowells, linux-fsdevel, linux-kernel

Make calculation of the size of the inline name in struct proc_dir_entry
automatic, rather than having to manually encode the numbers and failing to
allow for lockdep.

Require a minimum inline name size of 33+1 to allow for names that look
like two hex numbers with a dash between.

Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/proc/generic.c  |    2 +-
 fs/proc/inode.c    |    5 ++---
 fs/proc/internal.h |   18 ++++++++++++------
 fs/proc/root.c     |    3 +--
 4 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index fa5b28f0a3a3..6ac1c92997ea 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -409,7 +409,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
 	if (!ent)
 		goto out;
 
-	if (qstr.len + 1 <= sizeof(ent->inline_name)) {
+	if (qstr.len + 1 <= SIZEOF_PDE_INLINE_NAME) {
 		ent->name = ent->inline_name;
 	} else {
 		ent->name = kmalloc(qstr.len + 1, GFP_KERNEL);
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 7aa86dd65ba8..38155bec4a54 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -104,9 +104,8 @@ 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(struct proc_dir_entry), 0, SLAB_PANIC,
-		offsetof(struct proc_dir_entry, inline_name),
-		sizeof_field(struct proc_dir_entry, inline_name), NULL);
+		"proc_dir_entry", SIZEOF_PDE_SLOT, 0, SLAB_PANIC,
+		OFFSETOF_PDE_NAME, SIZEOF_PDE_INLINE_NAME, NULL);
 }
 
 static int proc_show_options(struct seq_file *seq, struct dentry *root)
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 0644b29e53b7..539c6566752a 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -62,14 +62,20 @@ struct proc_dir_entry {
 	char *name;
 	umode_t mode;
 	u8 namelen;
-#ifdef CONFIG_64BIT
-#define SIZEOF_PDE_INLINE_NAME	(192-155)
-#else
-#define SIZEOF_PDE_INLINE_NAME	(128-95)
-#endif
-	char inline_name[SIZEOF_PDE_INLINE_NAME];
+	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)
+
 extern struct kmem_cache *proc_dir_entry_cache;
 void pde_free(struct proc_dir_entry *pde);
 
diff --git a/fs/proc/root.c b/fs/proc/root.c
index a379edccd880..efbdc08a3c86 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -288,8 +288,7 @@ struct proc_dir_entry proc_root = {
 	.proc_fops	= &proc_root_operations,
 	.parent		= &proc_root,
 	.subdir		= RB_ROOT,
-	.name		= proc_root.inline_name,
-	.inline_name	= "/proc",
+	.name		= "/proc",
 };
 
 int pid_ns_prepare_proc(struct pid_namespace *ns)

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-08-17 16:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-14 20:09 [PATCH] proc: Make inline name size calculation automatic Alexey Dobriyan
2018-06-14 20:30 ` David Howells
2018-06-15 17:15   ` Alexey Dobriyan
2018-06-17 21:57   ` [PATCH] proc: fixup PDE allocation bloat Alexey Dobriyan
2018-07-20  0:06     ` Shakeel Butt
2018-08-17 13:28       ` Alexey Dobriyan
  -- strict thread matches above, loose matches on Subject: below --
2018-06-13 18:43 [PATCH] proc: Make inline name size calculation automatic David Howells
2018-06-19  0:42 ` Andrew Morton
2018-06-19  8:01 ` David Howells
2018-06-19 21:59   ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).