linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PROC: Make proc_dir_entry::name a terminal array rather than a pointer
@ 2011-06-06 15:41 David Howells
  2011-06-07  5:50 ` Alexey Dobriyan
  2011-06-07  9:03 ` David Howells
  0 siblings, 2 replies; 5+ messages in thread
From: David Howells @ 2011-06-06 15:41 UTC (permalink / raw)
  To: adobriyan; +Cc: linux-fsdevel, David Howells

Since __proc_create() appends the name it is given to the end of the PDE
structure that it allocates, there isn't a need to store a name pointer.
Instead we can just replace the name pointer with a terminal char array of
_unspecified_ length (the compiler will simply append the string to statically
defined variables of PDE type and, unlike specifying an explicitly _zero_
length array, won't give a warning if you try to statically initialise it with
a string of more than zero length).

Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/proc/generic.c       |    3 +--
 fs/proc/proc_net.c      |    4 ++--
 fs/proc/root.c          |    2 +-
 include/linux/proc_fs.h |    2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index f1637f1..9d99131 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -620,8 +620,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
 	if (!ent) goto out;
 
 	memset(ent, 0, sizeof(struct proc_dir_entry));
-	memcpy(((char *) ent) + sizeof(struct proc_dir_entry), fn, len + 1);
-	ent->name = ((char *) ent) + sizeof(*ent);
+	memcpy(ent->name, fn, len + 1);
 	ent->namelen = len;
 	ent->mode = mode;
 	ent->nlink = nlink;
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
index 9020ac1..f738024 100644
--- a/fs/proc/proc_net.c
+++ b/fs/proc/proc_net.c
@@ -197,15 +197,15 @@ static __net_init int proc_net_ns_init(struct net *net)
 	int err;
 
 	err = -ENOMEM;
-	netd = kzalloc(sizeof(*netd), GFP_KERNEL);
+	netd = kzalloc(sizeof(*netd) + 4, GFP_KERNEL);
 	if (!netd)
 		goto out;
 
 	netd->data = net;
 	netd->nlink = 2;
-	netd->name = "net";
 	netd->namelen = 3;
 	netd->parent = &proc_root;
+	memcpy(netd->name, "net", 4);
 
 	err = -EEXIST;
 	net_statd = proc_net_mkdir(net, "stat", netd);
diff --git a/fs/proc/root.c b/fs/proc/root.c
index a9000e9..3f7474d 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -185,13 +185,13 @@ static const struct inode_operations proc_root_inode_operations = {
 struct proc_dir_entry proc_root = {
 	.low_ino	= PROC_ROOT_INO, 
 	.namelen	= 5, 
-	.name		= "/proc",
 	.mode		= S_IFDIR | S_IRUGO | S_IXUGO, 
 	.nlink		= 2, 
 	.count		= ATOMIC_INIT(1),
 	.proc_iops	= &proc_root_inode_operations, 
 	.proc_fops	= &proc_root_operations,
 	.parent		= &proc_root,
+	.name		= "/proc",
 };
 
 int pid_ns_prepare_proc(struct pid_namespace *ns)
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index e7576cf..e9705c8 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -51,7 +51,6 @@ typedef	int (write_proc_t)(struct file *file, const char __user *buffer,
 struct proc_dir_entry {
 	unsigned int low_ino;
 	unsigned int namelen;
-	const char *name;
 	mode_t mode;
 	nlink_t nlink;
 	uid_t uid;
@@ -76,6 +75,7 @@ struct proc_dir_entry {
 	spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
 	struct completion *pde_unload_completion;
 	struct list_head pde_openers;	/* who did ->open, but not ->release */
+	char name[];
 };
 
 enum kcore_type {


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

* Re: [PATCH] PROC: Make proc_dir_entry::name a terminal array rather than a pointer
  2011-06-06 15:41 [PATCH] PROC: Make proc_dir_entry::name a terminal array rather than a pointer David Howells
@ 2011-06-07  5:50 ` Alexey Dobriyan
  2011-06-07  9:03 ` David Howells
  1 sibling, 0 replies; 5+ messages in thread
From: Alexey Dobriyan @ 2011-06-07  5:50 UTC (permalink / raw)
  To: David Howells; +Cc: linux-fsdevel

On Mon, Jun 06, 2011 at 04:41:39PM +0100, David Howells wrote:

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

Might as well move "namelen" next to the end.

>  struct proc_dir_entry {
>  	unsigned int low_ino;
>  	unsigned int namelen;
> -	const char *name;
>  	mode_t mode;
>  	nlink_t nlink;
>  	uid_t uid;
> @@ -76,6 +75,7 @@ struct proc_dir_entry {
>  	spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
>  	struct completion *pde_unload_completion;
>  	struct list_head pde_openers;	/* who did ->open, but not ->release */
> +	char name[];
>  };

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

* Re: [PATCH] PROC: Make proc_dir_entry::name a terminal array rather than a pointer
  2011-06-06 15:41 [PATCH] PROC: Make proc_dir_entry::name a terminal array rather than a pointer David Howells
  2011-06-07  5:50 ` Alexey Dobriyan
@ 2011-06-07  9:03 ` David Howells
  2011-06-07  9:18   ` Alexey Dobriyan
  2011-06-07  9:58   ` David Howells
  1 sibling, 2 replies; 5+ messages in thread
From: David Howells @ 2011-06-07  9:03 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: dhowells, linux-fsdevel

Alexey Dobriyan <adobriyan@gmail.com> wrote:

> Might as well move "namelen" next to the end.

Good point.  Before:

	(gdb) p &(((struct proc_dir_entry*)0)->name)
	$1 = (char (*)[]) 0xc0

After:

	(gdb) p &(((struct proc_dir_entry*)0)->name)
	$2 = (char (*)[]) 0xbc

The size is 192 in either case; the name just overlaps the hole at the end of
the structure.

Also, whilst I'm at it:

 (1) pde_unload_lock can be put two places later, so that if it's just a
     32-bit word, there won't be a hole left in the struct on a 64-bit
     machine.

 (2) namelen doesn't need to be a 32-bit word, but can be an 8-bit value as it
     doesn't have to exceed NAME_MAX.

David

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

* Re: [PATCH] PROC: Make proc_dir_entry::name a terminal array rather than a pointer
  2011-06-07  9:03 ` David Howells
@ 2011-06-07  9:18   ` Alexey Dobriyan
  2011-06-07  9:58   ` David Howells
  1 sibling, 0 replies; 5+ messages in thread
From: Alexey Dobriyan @ 2011-06-07  9:18 UTC (permalink / raw)
  To: David Howells; +Cc: linux-fsdevel

On Tue, Jun 07, 2011 at 10:03:49AM +0100, David Howells wrote:
>  (2) namelen doesn't need to be a 32-bit word, but can be an 8-bit value as it
>      doesn't have to exceed NAME_MAX.

It can be removed as well, dunno why we're keeping it.

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

* Re: [PATCH] PROC: Make proc_dir_entry::name a terminal array rather than a pointer
  2011-06-07  9:03 ` David Howells
  2011-06-07  9:18   ` Alexey Dobriyan
@ 2011-06-07  9:58   ` David Howells
  1 sibling, 0 replies; 5+ messages in thread
From: David Howells @ 2011-06-07  9:58 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: dhowells, linux-fsdevel

Alexey Dobriyan <adobriyan@gmail.com> wrote:

> It can be removed as well, dunno why we're keeping it.

It speeds up name comparisons.

David

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

end of thread, other threads:[~2011-06-07  9:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-06 15:41 [PATCH] PROC: Make proc_dir_entry::name a terminal array rather than a pointer David Howells
2011-06-07  5:50 ` Alexey Dobriyan
2011-06-07  9:03 ` David Howells
2011-06-07  9:18   ` Alexey Dobriyan
2011-06-07  9:58   ` David Howells

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).