From: Manfred Spraul <manfred@colorfullife.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] speed up get_tgid_list
Date: Tue, 06 Jan 2004 11:05:02 +0100 [thread overview]
Message-ID: <3FFA884E.1040203@colorfullife.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 652 bytes --]
get_tgid_list(n,) should lookup the next few valid pids after the nth
task in the task list. The current implementation scans through the task
list to find the nth task.
What about the attached patch? filp->f_version is indented for readdir
implementations to store the current position. The patch stores the next
pid in that field. If filp->f_version is not 0 (i.e. no lseek/seekdir)
and the task is still found by find_task_by_pid, then get_tgid_list
starts immediately from that position.
It's just a speed up, the worst case
(fd=open("/proc");lseek(fd,1000000,SEEK_SET);readdir()) still walks
through the whole task list.
--
Manfred
[-- Attachment #2: patch-tgid_lookup --]
[-- Type: text/plain, Size: 1289 bytes --]
--- 2.6/fs/proc/base.c 2003-12-20 09:19:13.000000000 +0100
+++ build-2.6/fs/proc/base.c 2004-01-06 10:50:35.000000000 +0100
@@ -1631,14 +1631,23 @@
* tasklist lock while doing this, and we must release it before
* we actually do the filldir itself, so we use a temp buffer..
*/
-static int get_tgid_list(int index, unsigned int *tgids)
+static int get_tgid_list(int index, unsigned long version, unsigned int *tgids)
{
struct task_struct *p;
int nr_tgids = 0;
index--;
read_lock(&tasklist_lock);
- for_each_process(p) {
+ p = NULL;
+ if (version)
+ p = find_task_by_pid(version);
+
+ if (p)
+ index = 0;
+ else
+ p = next_task(&init_task);
+
+ for ( ; p != &init_task; p = next_task(p)) {
int tgid = p->pid;
if (!pid_alive(p))
continue;
@@ -1701,7 +1710,7 @@
nr++;
}
- nr_tgids = get_tgid_list(nr, tgid_array);
+ nr_tgids = get_tgid_list(nr, filp->f_version, tgid_array);
for (i = 0; i < nr_tgids; i++) {
int tgid = tgid_array[i];
@@ -1710,8 +1719,10 @@
do buf[--j] = '0' + (tgid % 10); while (tgid/=10);
- if (filldir(dirent, buf+j, PROC_NUMBUF-j, filp->f_pos, ino, DT_DIR) < 0)
+ if (filldir(dirent, buf+j, PROC_NUMBUF-j, filp->f_pos, ino, DT_DIR) < 0) {
+ filp->f_version = tgid;
break;
+ }
filp->f_pos++;
}
return 0;
reply other threads:[~2004-01-06 10:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=3FFA884E.1040203@colorfullife.com \
--to=manfred@colorfullife.com \
--cc=linux-kernel@vger.kernel.org \
/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
Powered by JetHome