Skip to content

Commit 34ec123

Browse files
Oleg NesterovLinus Torvalds
authored andcommitted
[PATCH] taskstats: cleanup ->signal->stats allocation
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>
1 parent 115085e commit 34ec123

3 files changed

Lines changed: 25 additions & 26 deletions

File tree

‎include/linux/taskstats_kern.h‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,6 @@ static inline void taskstats_tgid_init(struct signal_struct *sig)
2020
sig->stats = NULL;
2121
}
2222

23-
static inline void taskstats_tgid_alloc(struct task_struct *tsk)
24-
{
25-
struct signal_struct *sig = tsk->signal;
26-
struct taskstats *stats;
27-
28-
if (sig->stats != NULL)
29-
return;
30-
31-
/* No problem if kmem_cache_zalloc() fails */
32-
stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
33-
34-
spin_lock_irq(&tsk->sighand->siglock);
35-
if (!sig->stats) {
36-
sig->stats = stats;
37-
stats = NULL;
38-
}
39-
spin_unlock_irq(&tsk->sighand->siglock);
40-
41-
if (stats)
42-
kmem_cache_free(taskstats_cache, stats);
43-
}
44-
4523
static inline void taskstats_tgid_free(struct signal_struct *sig)
4624
{
4725
if (sig->stats)
@@ -55,8 +33,6 @@ static inline void taskstats_exit(struct task_struct *tsk, int group_dead)
5533
{}
5634
static inline void taskstats_tgid_init(struct signal_struct *sig)
5735
{}
58-
static inline void taskstats_tgid_alloc(struct task_struct *tsk)
59-
{}
6036
static inline void taskstats_tgid_free(struct signal_struct *sig)
6137
{}
6238
static inline void taskstats_init_early(void)

‎kernel/fork.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,6 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts
847847
if (clone_flags & CLONE_THREAD) {
848848
atomic_inc(&current->signal->count);
849849
atomic_inc(&current->signal->live);
850-
taskstats_tgid_alloc(current);
851850
return 0;
852851
}
853852
sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);

‎kernel/taskstats.c‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,30 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
412412
return rc;
413413
}
414414

415+
static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk)
416+
{
417+
struct signal_struct *sig = tsk->signal;
418+
struct taskstats *stats;
419+
420+
if (sig->stats || thread_group_empty(tsk))
421+
goto ret;
422+
423+
/* No problem if kmem_cache_zalloc() fails */
424+
stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
425+
426+
spin_lock_irq(&tsk->sighand->siglock);
427+
if (!sig->stats) {
428+
sig->stats = stats;
429+
stats = NULL;
430+
}
431+
spin_unlock_irq(&tsk->sighand->siglock);
432+
433+
if (stats)
434+
kmem_cache_free(taskstats_cache, stats);
435+
ret:
436+
return sig->stats;
437+
}
438+
415439
/* Send pid data out on exit */
416440
void taskstats_exit(struct task_struct *tsk, int group_dead)
417441
{
@@ -433,7 +457,7 @@ void taskstats_exit(struct task_struct *tsk, int group_dead)
433457
size = nla_total_size(sizeof(u32)) +
434458
nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
435459

436-
is_thread_group = (tsk->signal->stats != NULL);
460+
is_thread_group = !!taskstats_tgid_alloc(tsk);
437461
if (is_thread_group) {
438462
/* PID + STATS + TGID + STATS */
439463
size = 2 * size;

0 commit comments

Comments
 (0)