Skip to content

Commit 1df4bd8

Browse files
oleg-nesterovakpm00
authored andcommitted
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/[email protected] Signed-off-by: Oleg Nesterov <[email protected]> Cc: "Eric W. Biederman" <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 2320222 commit 1df4bd8

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
@@ -2973,7 +2973,6 @@ static const struct file_operations proc_coredump_filter_operations = {
29732973
static int do_io_accounting(struct task_struct *task, struct seq_file *m, int whole)
29742974
{
29752975
struct task_io_accounting acct;
2976-
unsigned long flags;
29772976
int result;
29782977

29792978
result = down_read_killable(&task->signal->exec_update_lock);
@@ -2985,15 +2984,24 @@ static int do_io_accounting(struct task_struct *task, struct seq_file *m, int wh
29852984
goto out_unlock;
29862985
}
29872986

2988-
if (whole && lock_task_sighand(task, &flags)) {
2987+
if (whole) {
29892988
struct signal_struct *sig = task->signal;
29902989
struct task_struct *t;
2990+
unsigned int seq = 1;
2991+
unsigned long flags;
2992+
2993+
rcu_read_lock();
2994+
do {
2995+
seq++; /* 2 on the 1st/lockless path, otherwise odd */
2996+
flags = read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq);
29912997

2992-
acct = sig->ioac;
2993-
__for_each_thread(sig, t)
2994-
task_io_accounting_add(&acct, &t->ioac);
2998+
acct = sig->ioac;
2999+
__for_each_thread(sig, t)
3000+
task_io_accounting_add(&acct, &t->ioac);
29953001

2996-
unlock_task_sighand(task, &flags);
3002+
} while (need_seqretry(&sig->stats_lock, seq));
3003+
done_seqretry_irqrestore(&sig->stats_lock, seq, flags);
3004+
rcu_read_unlock();
29973005
} else {
29983006
acct = task->ioac;
29993007
}

0 commit comments

Comments
 (0)