[PATCH] taskstats: cleanup ->signal->stats allocation
authorOleg Nesterov <oleg@tv-sign.ru>
Thu, 7 Dec 2006 04:36:52 +0000 (20:36 -0800)
committerLinus Torvalds <torvalds@woody.osdl.org>
Thu, 7 Dec 2006 16:39:34 +0000 (08:39 -0800)
Allocate ->signal->stats on demand in taskstats_exit(), this allows us to
remove taskstats_tgid_alloc() (the last non-trivial inline) from taskstat's
public interface.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Shailabh Nagar <nagar@watson.ibm.com>
Cc: Jay Lan <jlan@engr.sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/linux/taskstats_kern.h
kernel/fork.c
kernel/taskstats.c

index f1261a5..7e9680f 100644 (file)
@@ -20,28 +20,6 @@ static inline void taskstats_tgid_init(struct signal_struct *sig)
        sig->stats = NULL;
 }
 
-static inline void taskstats_tgid_alloc(struct task_struct *tsk)
-{
-       struct signal_struct *sig = tsk->signal;
-       struct taskstats *stats;
-
-       if (sig->stats != NULL)
-               return;
-
-       /* No problem if kmem_cache_zalloc() fails */
-       stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
-
-       spin_lock_irq(&tsk->sighand->siglock);
-       if (!sig->stats) {
-               sig->stats = stats;
-               stats = NULL;
-       }
-       spin_unlock_irq(&tsk->sighand->siglock);
-
-       if (stats)
-               kmem_cache_free(taskstats_cache, stats);
-}
-
 static inline void taskstats_tgid_free(struct signal_struct *sig)
 {
        if (sig->stats)
@@ -55,8 +33,6 @@ static inline void taskstats_exit(struct task_struct *tsk, int group_dead)
 {}
 static inline void taskstats_tgid_init(struct signal_struct *sig)
 {}
-static inline void taskstats_tgid_alloc(struct task_struct *tsk)
-{}
 static inline void taskstats_tgid_free(struct signal_struct *sig)
 {}
 static inline void taskstats_init_early(void)
index f37980d..6588381 100644 (file)
@@ -847,7 +847,6 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts
        if (clone_flags & CLONE_THREAD) {
                atomic_inc(&current->signal->count);
                atomic_inc(&current->signal->live);
-               taskstats_tgid_alloc(current);
                return 0;
        }
        sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
index 2654886..7d793d6 100644 (file)
@@ -412,6 +412,30 @@ err:
        return rc;
 }
 
+static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk)
+{
+       struct signal_struct *sig = tsk->signal;
+       struct taskstats *stats;
+
+       if (sig->stats || thread_group_empty(tsk))
+               goto ret;
+
+       /* No problem if kmem_cache_zalloc() fails */
+       stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
+
+       spin_lock_irq(&tsk->sighand->siglock);
+       if (!sig->stats) {
+               sig->stats = stats;
+               stats = NULL;
+       }
+       spin_unlock_irq(&tsk->sighand->siglock);
+
+       if (stats)
+               kmem_cache_free(taskstats_cache, stats);
+ret:
+       return sig->stats;
+}
+
 /* Send pid data out on exit */
 void taskstats_exit(struct task_struct *tsk, int group_dead)
 {
@@ -433,7 +457,7 @@ void taskstats_exit(struct task_struct *tsk, int group_dead)
        size = nla_total_size(sizeof(u32)) +
                nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
 
-       is_thread_group = (tsk->signal->stats != NULL);
+       is_thread_group = !!taskstats_tgid_alloc(tsk);
        if (is_thread_group) {
                /* PID + STATS + TGID + STATS */
                size = 2 * size;