Skip to content

Commit 4f11343

Browse files
Alexey Dobriyantorvalds
authored andcommitted
proc: use slower rb_first()
In a typical for /proc "open+read+close" usecase, dentry is looked up successfully on open only to be killed in dput() on close. In fact dentries which aren't /proc/*/... and /proc/sys/* were almost NEVER CACHED. Simple printk in proc_lookup_de() shows that. Now that ->delete hook intelligently picks which dentries should live in dcache and which should not, rbtree caching is not necessary as dcache does it job, at last! As a side effect, struct proc_dir_entry shrinks by one pointer which can go into inline name. Link: http://lkml.kernel.org/r/20180314231032.GA15854@avx2 Signed-off-by: Alexey Dobriyan <[email protected]> Acked-by: Davidlohr Bueso <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Al Viro <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 05c3f29 commit 4f11343

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

fs/proc/generic.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static int proc_match(const char *name, struct proc_dir_entry *de, unsigned int
5252

5353
static struct proc_dir_entry *pde_subdir_first(struct proc_dir_entry *dir)
5454
{
55-
return rb_entry_safe(rb_first_cached(&dir->subdir),
56-
struct proc_dir_entry, subdir_node);
55+
return rb_entry_safe(rb_first(&dir->subdir), struct proc_dir_entry,
56+
subdir_node);
5757
}
5858

5959
static struct proc_dir_entry *pde_subdir_next(struct proc_dir_entry *dir)
@@ -66,7 +66,7 @@ static struct proc_dir_entry *pde_subdir_find(struct proc_dir_entry *dir,
6666
const char *name,
6767
unsigned int len)
6868
{
69-
struct rb_node *node = dir->subdir.rb_root.rb_node;
69+
struct rb_node *node = dir->subdir.rb_node;
7070

7171
while (node) {
7272
struct proc_dir_entry *de = rb_entry(node,
@@ -87,9 +87,8 @@ static struct proc_dir_entry *pde_subdir_find(struct proc_dir_entry *dir,
8787
static bool pde_subdir_insert(struct proc_dir_entry *dir,
8888
struct proc_dir_entry *de)
8989
{
90-
struct rb_root_cached *root = &dir->subdir;
91-
struct rb_node **new = &root->rb_root.rb_node, *parent = NULL;
92-
bool leftmost = true;
90+
struct rb_root *root = &dir->subdir;
91+
struct rb_node **new = &root->rb_node, *parent = NULL;
9392

9493
/* Figure out where to put new node */
9594
while (*new) {
@@ -101,16 +100,15 @@ static bool pde_subdir_insert(struct proc_dir_entry *dir,
101100
parent = *new;
102101
if (result < 0)
103102
new = &(*new)->rb_left;
104-
else if (result > 0) {
103+
else if (result > 0)
105104
new = &(*new)->rb_right;
106-
leftmost = false;
107-
} else
105+
else
108106
return false;
109107
}
110108

111109
/* Add new node and rebalance tree. */
112110
rb_link_node(&de->subdir_node, parent, new);
113-
rb_insert_color_cached(&de->subdir_node, root, leftmost);
111+
rb_insert_color(&de->subdir_node, root);
114112
return true;
115113
}
116114

@@ -401,7 +399,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
401399
ent->namelen = qstr.len;
402400
ent->mode = mode;
403401
ent->nlink = nlink;
404-
ent->subdir = RB_ROOT_CACHED;
402+
ent->subdir = RB_ROOT;
405403
refcount_set(&ent->refcnt, 1);
406404
spin_lock_init(&ent->pde_unload_lock);
407405
INIT_LIST_HEAD(&ent->pde_openers);
@@ -577,7 +575,7 @@ void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
577575

578576
de = pde_subdir_find(parent, fn, len);
579577
if (de)
580-
rb_erase_cached(&de->subdir_node, &parent->subdir);
578+
rb_erase(&de->subdir_node, &parent->subdir);
581579
write_unlock(&proc_subdir_lock);
582580
if (!de) {
583581
WARN(1, "name '%s'\n", name);
@@ -614,13 +612,13 @@ int remove_proc_subtree(const char *name, struct proc_dir_entry *parent)
614612
write_unlock(&proc_subdir_lock);
615613
return -ENOENT;
616614
}
617-
rb_erase_cached(&root->subdir_node, &parent->subdir);
615+
rb_erase(&root->subdir_node, &parent->subdir);
618616

619617
de = root;
620618
while (1) {
621619
next = pde_subdir_first(de);
622620
if (next) {
623-
rb_erase_cached(&next->subdir_node, &de->subdir);
621+
rb_erase(&next->subdir_node, &de->subdir);
624622
de = next;
625623
continue;
626624
}

fs/proc/internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ struct proc_dir_entry {
5151
kgid_t gid;
5252
loff_t size;
5353
struct proc_dir_entry *parent;
54-
struct rb_root_cached subdir;
54+
struct rb_root subdir;
5555
struct rb_node subdir_node;
5656
char *name;
5757
umode_t mode;
5858
u8 namelen;
5959
#ifdef CONFIG_64BIT
60-
#define SIZEOF_PDE_INLINE_NAME (192-147)
60+
#define SIZEOF_PDE_INLINE_NAME (192-139)
6161
#else
62-
#define SIZEOF_PDE_INLINE_NAME (128-91)
62+
#define SIZEOF_PDE_INLINE_NAME (128-87)
6363
#endif
6464
char inline_name[SIZEOF_PDE_INLINE_NAME];
6565
} __randomize_layout;

fs/proc/proc_net.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static __net_init int proc_net_ns_init(struct net *net)
196196
if (!netd)
197197
goto out;
198198

199-
netd->subdir = RB_ROOT_CACHED;
199+
netd->subdir = RB_ROOT;
200200
netd->data = net;
201201
netd->nlink = 2;
202202
netd->namelen = 3;

fs/proc/root.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct proc_dir_entry proc_root = {
203203
.proc_iops = &proc_root_inode_operations,
204204
.proc_fops = &proc_root_operations,
205205
.parent = &proc_root,
206-
.subdir = RB_ROOT_CACHED,
206+
.subdir = RB_ROOT,
207207
.name = proc_root.inline_name,
208208
.inline_name = "/proc",
209209
};

0 commit comments

Comments
 (0)