proc: spread likely/unlikely a bit

"Linux Kernel Mailing List" <[email protected]>
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/15b158b4e6274351fc3cf652cbabc57104efb547
Commit:     15b158b4e6274351fc3cf652cbabc57104efb547
Parent:     efb1a57d90cae6af1ddd32f1b920c924a711aba5
Refname:    refs/heads/master
Author:     Alexey Dobriyan <[email protected]>
AuthorDate: Tue Feb 6 15:37:28 2018 -0800
Committer:  Linus Torvalds <[email protected]>
CommitDate: Tue Feb 6 18:32:43 2018 -0800

    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 <[email protected]>
    Signed-off-by: Andrew Morton <[email protected]>
    Signed-off-by: Linus Torvalds <[email protected]>
---
 fs/proc/inode.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index c5c8e7af5520..6e8724958116 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -129,12 +129,12 @@ enum {BIAS = -1U<<31};
 
 static inline int use_pde(struct proc_dir_entry *pde)
 {
-	return atomic_inc_unless_negative(&pde->in_use);
+	return likely(atomic_inc_unless_negative(&pde->in_use));
 }
 
 static void unuse_pde(struct proc_dir_entry *pde)
 {
-	if (atomic_dec_return(&pde->in_use) == BIAS)
+	if (unlikely(atomic_dec_return(&pde->in_use) == BIAS))
 		complete(pde->pde_unload_completion);
 }
 
@@ -167,7 +167,7 @@ static void close_pdeo(struct proc_dir_entry *pde, struct pde_opener *pdeo)
 		spin_lock(&pde->pde_unload_lock);
 		/* After ->release. */
 		list_del(&pdeo->lh);
-		if (pdeo->c)
+		if (unlikely(pdeo->c))
 			complete(pdeo->c);
 		kfree(pdeo);
 	}
@@ -421,7 +421,7 @@ static const char *proc_get_link(struct dentry *dentry,
 				 struct delayed_call *done)
 {
 	struct proc_dir_entry *pde = PDE(inode);
-	if (unlikely(!use_pde(pde)))
+	if (!use_pde(pde))
 		return ERR_PTR(-EINVAL);
 	set_delayed_call(done, proc_put_link, pde);
 	return pde->data;
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.