提交 128fb956 编写于 作者: O Oleg Nesterov 提交者: Linus Torvalds

[PATCH] taskstats_exit_alloc: optimize/simplify

If there are no listeners, every task does unneeded kmem_cache alloc/free on
exit. We don't need listeners->sem for 'if (!list_empty())' check. Yes, we may
have a false positive, but this doesn't differ from the case when the listener
is unregistered after we drop the semaphore. So we don't need to do allocation
beforehand.
Signed-off-by: NOleg Nesterov <oleg@tv-sign.ru>
Cc: Balbir Singh <balbir@in.ibm.com>
Acked-by: NShailabh Nagar <nagar@watson.ibm.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 38da288b
...@@ -416,7 +416,6 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info) ...@@ -416,7 +416,6 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu) void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu)
{ {
struct listener_list *listeners; struct listener_list *listeners;
struct taskstats *tmp;
/* /*
* This is the cpu on which the task is exiting currently and will * This is the cpu on which the task is exiting currently and will
* be the one for which the exit event is sent, even if the cpu * be the one for which the exit event is sent, even if the cpu
...@@ -424,19 +423,11 @@ void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu) ...@@ -424,19 +423,11 @@ void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu)
*/ */
*mycpu = raw_smp_processor_id(); *mycpu = raw_smp_processor_id();
*ptidstats = NULL;
tmp = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
if (!tmp)
return;
listeners = &per_cpu(listener_array, *mycpu); listeners = &per_cpu(listener_array, *mycpu);
down_read(&listeners->sem);
if (!list_empty(&listeners->list)) { *ptidstats = NULL;
*ptidstats = tmp; if (!list_empty(&listeners->list))
tmp = NULL; *ptidstats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
}
up_read(&listeners->sem);
kfree(tmp);
} }
/* Send pid data out on exit */ /* Send pid data out on exit */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册