Skip to content

Commit

Permalink
[PATCH] taskstats: cleanup ->signal->stats allocation
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Balbir Singh <[email protected]>
Cc: Shailabh Nagar <[email protected]>
Cc: Jay Lan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Dec 7, 2006
1 parent 115085e commit 34ec123
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
24 changes: 0 additions & 24 deletions include/linux/taskstats_kern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 25 additions & 1 deletion kernel/taskstats.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,30 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
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)
{
Expand All @@ -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;
Expand Down

0 comments on commit 34ec123

Please sign in to comment.