lkml.org 
[lkml]   [2015]   [May]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH RFC 05/13] fs: Refactoring in get_children_pid()
From
Date
This will be used in next patches. No functionality change.

Signed-off-by: Kirill Tkhai <ktkhai@odin.com>
---
fs/proc/array.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index fd02a9e..e2f21c0 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -576,9 +576,7 @@ get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
struct task_struct *start, *task;
struct pid *pid = NULL;

- read_lock(&tasklist_lock);
-
- start = pid_task(proc_pid(inode), PIDTYPE_PID);
+ start = get_pid_task(proc_pid(inode), PIDTYPE_PID);
if (!start)
goto out;

@@ -586,18 +584,21 @@ get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
* Lets try to continue searching first, this gives
* us significant speedup on children-rich processes.
*/
- if (pid_prev) {
- task = pid_task(pid_prev, PIDTYPE_PID);
- if (task && task->real_parent == start &&
- !(list_empty(&task->sibling))) {
- if (list_is_last(&task->sibling, &start->children))
- goto out;
+ task = get_pid_task(pid_prev, PIDTYPE_PID);
+ if (!task)
+ goto put_start;
+
+ read_lock(&tasklist_lock);
+ if (task->real_parent == start && !(list_empty(&task->sibling))) {
+ put_task_struct(task);
+ if (!list_is_last(&task->sibling, &start->children)) {
task = list_first_entry(&task->sibling,
- struct task_struct, sibling);
+ struct task_struct, sibling);
pid = get_pid(task_pid(task));
- goto out;
}
+ goto unlock;
}
+ put_task_struct(task);

/*
* Slow search case.
@@ -621,8 +622,11 @@ get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
}
}

-out:
+unlock:
read_unlock(&tasklist_lock);
+put_start:
+ put_task_struct(start);
+out:
return pid;
}





\
 
 \ /
  Last update: 2015-05-25 20:21    [W:0.044 / U:0.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site