Skip to content

Commit 9c1fe3b

Browse files
committed
do_io_accounting: use sig->stats_lock
JIRA: https://issues.redhat.com/browse/RHEL-105165 commit 1df4bd8 Author: Oleg Nesterov <oleg@redhat.com> Date: Mon, 23 Oct 2023 17:34:05 +0200 do_io_accounting: use sig->stats_lock Rather than lock_task_sighand(), sig->stats_lock was specifically designed for this type of use. This way the "if (whole)" branch runs lockless in the likely case. Link: https://lkml.kernel.org/r/20231023153405.GA4639@redhat.com Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Waiman Long <longman@redhat.com>
1 parent 6eb7560 commit 9c1fe3b

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

fs/proc/base.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,7 +2949,6 @@ static const struct file_operations proc_coredump_filter_operations = {
29492949
static int do_io_accounting(struct task_struct *task, struct seq_file *m, int whole)
29502950
{
29512951
struct task_io_accounting acct;
2952-
unsigned long flags;
29532952
int result;
29542953

29552954
result = down_read_killable(&task->signal->exec_update_lock);
@@ -2961,15 +2960,24 @@ static int do_io_accounting(struct task_struct *task, struct seq_file *m, int wh
29612960
goto out_unlock;
29622961
}
29632962

2964-
if (whole && lock_task_sighand(task, &flags)) {
2963+
if (whole) {
29652964
struct signal_struct *sig = task->signal;
29662965
struct task_struct *t;
2966+
unsigned int seq = 1;
2967+
unsigned long flags;
2968+
2969+
rcu_read_lock();
2970+
do {
2971+
seq++; /* 2 on the 1st/lockless path, otherwise odd */
2972+
flags = read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq);
29672973

2968-
acct = sig->ioac;
2969-
__for_each_thread(sig, t)
2970-
task_io_accounting_add(&acct, &t->ioac);
2974+
acct = sig->ioac;
2975+
__for_each_thread(sig, t)
2976+
task_io_accounting_add(&acct, &t->ioac);
29712977

2972-
unlock_task_sighand(task, &flags);
2978+
} while (need_seqretry(&sig->stats_lock, seq));
2979+
done_seqretry_irqrestore(&sig->stats_lock, seq, flags);
2980+
rcu_read_unlock();
29732981
} else {
29742982
acct = task->ioac;
29752983
}

0 commit comments

Comments
 (0)