Skip to contentSkip to conversation

proc: make proc entry's len "unsigned int"

PATCH In review Alexey Dobriyan 3 participants 4 messages Nov 26, 2010 – Jan 5, 2011 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proc: make proc entry's len "unsigned int"

Space is not really conserved, because of natural alignment for the next field.

---

 fs/proc/generic.c       |    8 ++++----
 include/linux/proc_fs.h |    2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
fs/proc/generic.c +4 -4
@@ -28,7 +28,7 @@
 
 DEFINE_SPINLOCK(proc_subdir_lock);
 
-static int proc_match(int len, const char *name, struct proc_dir_entry *de)
+static int proc_match(unsigned int len, const char *name, struct proc_dir_entry *de)
 {
 	if (de->namelen != len)
 		return 0;
@@ -303,7 +303,7 @@ static int __xlate_proc_name(const char *name, struct proc_dir_entry **ret,
 {
 	const char     		*cp = name, *next;
 	struct proc_dir_entry	*de;
-	int			len;
+	unsigned int		len;
 
 	de = *ret;
 	if (!de)
@@ -605,7 +605,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
 {
 	struct proc_dir_entry *ent = NULL;
 	const char *fn = name;
-	int len;
+	unsigned int len;
 
 	/* make sure name is valid */
 	if (!name || !strlen(name)) goto out;
@@ -794,7 +794,7 @@ void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
 	struct proc_dir_entry **p;
 	struct proc_dir_entry *de = NULL;
 	const char *fn = name;
-	int len;
+	unsigned int len;
 
 	spin_lock(&proc_subdir_lock);
 	if (__xlate_proc_name(name, &parent, &fn) != 0) {
include/linux/proc_fs.h +1 -1
@@ -50,7 +50,7 @@ typedef	int (write_proc_t)(struct file *file, const char __user *buffer,
 
 struct proc_dir_entry {
 	unsigned int low_ino;
-	unsigned short namelen;
+	unsigned int namelen;
 	const char *name;
 	mode_t mode;
 	nlink_t nlink;
#1 lore raw
Quoted 1 line · Alexey Dobriyan

Space is not really conserved, because of natural alignment for the next field.

It can be. Depends on the arch.

Quoted 1 line

[]

include/linux/proc_fs.h typedef int (write_proc_t)(struct file *file, const char __user *buffer, · line 56

Quoted 11 lines
include/linux/proc_fs.h +1 -1
@@ -50,7 +50,7 @@ typedef	int (write_proc_t)(struct file *file, const char __user *buffer,
 
 struct proc_dir_entry {
 	unsigned int low_ino;
-	unsigned short namelen;
+	unsigned int namelen;
 	const char *name;
 	mode_t mode;
 	nlink_t nlink;

mode_t is unsigned short on many platforms.

Layout order in this struct should probably be:

	const char *name;
	unsigned short namelen;
	mode_t mode;
#2 lore raw
In reply to Alexey Dobriyan
Quoted 45 lines · On Fri, 26 Nov 2010 23:10:33 +0200 Alexey Dobriyan <[email protected]> wrote:

Space is not really conserved, because of natural alignment for the next field.

...

fs/proc/generic.c +4 -4
@@ -28,7 +28,7 @@
 
 DEFINE_SPINLOCK(proc_subdir_lock);
 
-static int proc_match(int len, const char *name, struct proc_dir_entry *de)
+static int proc_match(unsigned int len, const char *name, struct proc_dir_entry *de)
 {
 	if (de->namelen != len)
 		return 0;
@@ -303,7 +303,7 @@ static int __xlate_proc_name(const char *name, struct proc_dir_entry **ret,
 {
 	const char     		*cp = name, *next;
 	struct proc_dir_entry	*de;
-	int			len;
+	unsigned int		len;
 
 	de = *ret;
 	if (!de)
@@ -605,7 +605,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
 {
 	struct proc_dir_entry *ent = NULL;
 	const char *fn = name;
-	int len;
+	unsigned int len;
 
 	/* make sure name is valid */
 	if (!name || !strlen(name)) goto out;
@@ -794,7 +794,7 @@ void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
 	struct proc_dir_entry **p;
 	struct proc_dir_entry *de = NULL;
 	const char *fn = name;
-	int len;
+	unsigned int len;
 
 	spin_lock(&proc_subdir_lock);
 	if (__xlate_proc_name(name, &parent, &fn) != 0) {

include/linux/proc_fs.h typedef int (write_proc_t)(struct file *file, const char __user *buffer, · line 56

Quoted 8 lines
include/linux/proc_fs.h +1 -1
@@ -50,7 +50,7 @@ typedef	int (write_proc_t)(struct file *file, const char __user *buffer,
 
 struct proc_dir_entry {
 	unsigned int low_ino;
-	unsigned short namelen;
+	unsigned int namelen;
 	const char *name;
 	mode_t mode;
 	nlink_t nlink;

Well, if we _can_ save some space here then the returns would be appreciable.

akpm:/home/akpm# find /proc | wc -l
95543

(wtf?)

akpm:/home/akpm# find /proc/[0-9]* | wc -l
94212

(oh.)

Do all of those things have a proc_dir_entry? IIRC we changed things so they're somewhat allocate-on-demand.

#3 lore raw
Quoted 17 lines · Andrew Morton

include/linux/proc_fs.h typedef int (write_proc_t)(struct file *file, const char __user *buffer, · line 56

Quoted 7 lines · On Fri, 26 Nov 2010 23:10:33 +0200 Alexey Dobriyan <[email protected]> wrote:

struct proc_dir_entry {

include/linux/proc_fs.h +1 -1
 	unsigned int low_ino;
-	unsigned short namelen;
+	unsigned int namelen;
 	const char *name;
 	mode_t mode;
 	nlink_t nlink;

Well, if we _can_ save some space here then the returns would be appreciable.

akpm:/home/akpm# find /proc | wc -l
95543
Quoted 6 lines

(wtf?)

akpm:/home/akpm# find /proc/[0-9]* | wc -l
94212

(oh.)

Different number of processes?

Quoted 1 line

Do all of those things have a proc_dir_entry?

No!

Quoted 1 line

IIRC we changed things so they're somewhat allocate-on-demand.

Only /proc/$PID and /proc/sys/* are on-demand allocated. The rest has struct proc_dir_entry associated.