include/linux/sched.h | 1 + kernel/exit.c | 4 ++++ kernel/fork.c | 2 ++ kernel/signal.c | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index ffb6eb55cd13..ac44ed5bb0ab 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1103,6 +1103,7 @@ struct task_struct { /* Signal handlers: */ struct signal_struct *signal; struct sighand_struct __rcu *sighand; + struct sigqueue *sigqueue_cache; sigset_t blocked; sigset_t real_blocked; /* Restored if set_restore_sigmask() was used: */ diff --git a/kernel/exit.c b/kernel/exit.c index 35e0a31a0315..8d287c8481b4 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -157,6 +157,10 @@ static void __exit_signal(struct task_struct *tsk) */ flush_sigqueue(&tsk->pending); tsk->sighand = NULL; + if (tsk->sigqueue_cache) { + kmem_cache_free(sigqueue_cachep, tsk->sigqueue_cache); + tsk->sigqueue_cache = NULL; + } spin_unlock(&sighand->siglock); __cleanup_sighand(sighand); diff --git a/kernel/fork.c b/kernel/fork.c index 08969f5aa38d..96ffbce88aa3 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -535,6 +535,8 @@ void put_task_stack(struct task_struct *tsk) void free_task(struct task_struct *tsk) { + if (tsk->sigqueue_cache) + kmem_cache_free(sigqueue_cachep, tsk->sigqueue_cache); release_user_cpus_ptr(tsk); scs_release(tsk); diff --git a/kernel/signal.c b/kernel/signal.c index d140672185a4..ccc0c7aa84e6 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1107,6 +1107,12 @@ static int __send_signal_locked(int sig, struct kernel_siginfo *info, if ((sig == SIGKILL) || (t->flags & PF_KTHREAD)) goto out_set; + if (t->sigqueue_cache) { + q = t->sigqueue_cache; + t->sigqueue_cache = NULL; + goto add_sigqueue; + } + /* * Real-time signals must be queued if sent by sigqueue, or * some other real-time mechanism. It is implementation @@ -1124,6 +1130,7 @@ static int __send_signal_locked(int sig, struct kernel_siginfo *info, q = __sigqueue_alloc(sig, t, GFP_ATOMIC, override_rlimit, 0); if (q) { +add_sigqueue: list_add_tail(&q->list, &pending->list); switch ((unsigned long) info) { case (unsigned long) SEND_SIG_NOINFO: @@ -1933,6 +1940,13 @@ struct sigqueue *sigqueue_alloc(void) return __sigqueue_alloc(-1, current, GFP_KERNEL, 0, SIGQUEUE_PREALLOC); } +/* + * We only add sigqueues with SIGQUEUE_PREALLOC set + * and list_empty(&q->list) to the sigqueue_cache. + * + * That automatically means that we don't count them + * towards any limits. + */ void sigqueue_free(struct sigqueue *q) { unsigned long flags; @@ -1945,6 +1959,12 @@ void sigqueue_free(struct sigqueue *q) * __exit_signal()->flush_sigqueue(). */ spin_lock_irqsave(lock, flags); + if (!current->sigqueue_cache && list_empty(&q->list)) { + current->sigqueue_cache = q; + spin_unlock_irqrestore(lock, flags); + return; + } + q->flags &= ~SIGQUEUE_PREALLOC; /* * If it is queued it will be freed when dequeued,