Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751229AbbEYRpO (ORCPT ); Mon, 25 May 2015 13:45:14 -0400 Received: from relay.parallels.com ([195.214.232.42]:44113 "EHLO relay.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750903AbbEYRpK (ORCPT ); Mon, 25 May 2015 13:45:10 -0400 Message-ID: <1432575905.6866.37.camel@odin.com> Subject: [PATCH RFC 05/13] fs: Refactoring in get_children_pid() From: Kirill Tkhai To: CC: Oleg Nesterov , Andrew Morton , Ingo Molnar , "Peter Zijlstra" , Michal Hocko , "Rik van Riel" , Ionut Alexa , Peter Hurley , Kirill Tkhai Date: Mon, 25 May 2015 20:45:05 +0300 In-Reply-To: <20150525162722.5171.15901.stgit@pro> References: <20150525162722.5171.15901.stgit@pro> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.9-1+b1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.30.16.109] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2053 Lines: 73 This will be used in next patches. No functionality change. Signed-off-by: Kirill Tkhai --- 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; } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/