Skip to content

Commit 15b158b

Browse files
Alexey Dobriyantorvalds
authored andcommitted
proc: spread likely/unlikely a bit
use_pde() is used at every open/read/write/... of every random /proc file. Negative refcount happens only if PDE is being deleted by module (read: never). So it gets "likely". unuse_pde() gets "unlikely" for the same reason. close_pdeo() gets unlikely as the completion is filled only if there is a race between PDE removal and close() (read: never ever). It even saves code on x86_64 defconfig: add/remove: 0/0 grow/shrink: 1/2 up/down: 2/-20 (-18) Function old new delta close_pdeo 183 185 +2 proc_reg_get_unmapped_area 119 111 -8 proc_reg_poll 85 73 -12 Link: http://lkml.kernel.org/r/20180104175657.GA5204@avx2 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent efb1a57 commit 15b158b

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎fs/proc/inode.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ enum {BIAS = -1U<<31};
129129

130130
static inline int use_pde(struct proc_dir_entry *pde)
131131
{
132-
return atomic_inc_unless_negative(&pde->in_use);
132+
return likely(atomic_inc_unless_negative(&pde->in_use));
133133
}
134134

135135
static void unuse_pde(struct proc_dir_entry *pde)
136136
{
137-
if (atomic_dec_return(&pde->in_use) == BIAS)
137+
if (unlikely(atomic_dec_return(&pde->in_use) == BIAS))
138138
complete(pde->pde_unload_completion);
139139
}
140140

@@ -167,7 +167,7 @@ static void close_pdeo(struct proc_dir_entry *pde, struct pde_opener *pdeo)
167167
spin_lock(&pde->pde_unload_lock);
168168
/* After ->release. */
169169
list_del(&pdeo->lh);
170-
if (pdeo->c)
170+
if (unlikely(pdeo->c))
171171
complete(pdeo->c);
172172
kfree(pdeo);
173173
}
@@ -421,7 +421,7 @@ static const char *proc_get_link(struct dentry *dentry,
421421
struct delayed_call *done)
422422
{
423423
struct proc_dir_entry *pde = PDE(inode);
424-
if (unlikely(!use_pde(pde)))
424+
if (!use_pde(pde))
425425
return ERR_PTR(-EINVAL);
426426
set_delayed_call(done, proc_put_link, pde);
427427
return pde->data;

0 commit comments

Comments
 (0)