linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: viro@zeniv.linux.org.uk, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] proc: faster /proc/$PID lookup
Date: Fri, 13 Jun 2014 23:03:38 +0300	[thread overview]
Message-ID: <20140613200338.GA2149@p183.telecom.by> (raw)

Use first character as a hint for /proc/$PID lookup.

Currently it takes one spinlock and search through dozens of
misc proc entries which can not match /proc/$PID.

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

 fs/proc/root.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -199,10 +199,17 @@ static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
 
 static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry, unsigned int flags)
 {
-	if (!proc_lookup(dir, dentry, flags))
-		return NULL;
-	
-	return proc_pid_lookup(dir, dentry, flags);
+	const char c = dentry->d_name.name[0];
+	struct dentry *rv;
+
+	if ('0' <= c && c <= '9') {
+		rv = proc_pid_lookup(dir, dentry, flags);
+		if (rv)
+			rv = proc_lookup(dir, dentry, flags);
+	} else {
+		rv = proc_lookup(dir, dentry, flags);
+	}
+	return rv;
 }
 
 static int proc_root_readdir(struct file *file, struct dir_context *ctx)

             reply	other threads:[~2014-06-13 20:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-13 20:03 Alexey Dobriyan [this message]
2014-06-13 20:34 ` [PATCH] proc: faster /proc/$PID lookup Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140613200338.GA2149@p183.telecom.by \
    --to=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).