Commit f7ec1cd
getrusage: use sig->stats_lock rather than lock_task_sighand()
lock_task_sighand() can trigger a hard lockup. If NR_CPUS threads call
getrusage() at the same time and the process has NR_THREADS, spin_lock_irq
will spin with irqs disabled O(NR_CPUS * NR_THREADS) time.
Change getrusage() to use sig->stats_lock, it was specifically designed
for this type of use. This way it runs lockless in the likely case.
TODO:
- Change do_task_stat() to use sig->stats_lock too, then we can
remove spin_lock_irq(siglock) in wait_task_zombie().
- Turn sig->stats_lock into seqcount_rwlock_t, this way the
readers in the slow mode won't exclude each other. See
https://lore.kernel.org/all/20230913154907.GA26210@redhat.com/
- stats_lock has to disable irqs because ->siglock can be taken
in irq context, it would be very nice to change __exit_signal()
to avoid the siglock->stats_lock dependency.
Link: https://lkml.kernel.org/r/20240122155053.GA26214@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reported-by: Dylan Hatch <dylanbhatch@google.com>
Tested-by: Dylan Hatch <dylanbhatch@google.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>1 parent daa694e commit f7ec1cd
1 file changed
Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1788 | 1788 | | |
1789 | 1789 | | |
1790 | 1790 | | |
| 1791 | + | |
1791 | 1792 | | |
| 1793 | + | |
1792 | 1794 | | |
1793 | 1795 | | |
1794 | 1796 | | |
| |||
1800 | 1802 | | |
1801 | 1803 | | |
1802 | 1804 | | |
1803 | | - | |
1804 | | - | |
| 1805 | + | |
1805 | 1806 | | |
1806 | 1807 | | |
1807 | 1808 | | |
| |||
1829 | 1830 | | |
1830 | 1831 | | |
1831 | 1832 | | |
| 1833 | + | |
| 1834 | + | |
1832 | 1835 | | |
1833 | 1836 | | |
| 1837 | + | |
| 1838 | + | |
1834 | 1839 | | |
1835 | 1840 | | |
1836 | 1841 | | |
1837 | 1842 | | |
1838 | 1843 | | |
1839 | | - | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
1840 | 1850 | | |
1841 | 1851 | | |
1842 | 1852 | | |
| |||
0 commit comments