kernel/fork: put some fork variables into read-mostly section
Subsystems (3)
PATCH 1/1 kernel/fork: put some fork variables into read-mostly section
From: chenqiwu <[email protected]>
Since total_forks/nr_threads/max_threads global variables are frequently used for process fork, putting these variables into read_mostly section can avoid unnecessary cache line bouncing.
--- kernel/fork.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/fork.c +3 -3
@@ -120,10 +120,10 @@/* * Protected counters by write_lock_irq(&tasklist_lock) */ -unsigned long total_forks;/* Handle normal Linux uptimes. */ -int nr_threads;/* The idle threads do not count.. */ +unsigned long total_forks__read_mostly ;/* Handle normal Linux uptimes. */ +int nr_threads__read_mostly ;/* The idle threads do not count.. */ -static int max_threads;/* tunable limit on nr_threads */ +static int max_threads__read_mostly ;/* tunable limit on nr_threads */ #define NAMED_ARRAY_INDEX (x) [x] = __stringify(x)
Signature · 1 line
1.9.1
Quoted 16 lines · On Mon, Jan 13, 2020 at 11:23:13AM +0800, [email protected] wrote:
From: chenqiwu <[email protected]>
Since total_forks/nr_threads/max_threads global variables are frequently used for process fork, putting these variables into
read_mostlysection can avoid unnecessary cache line bouncing.Signed-off-by chenqiwu <[email protected]>--- kernel/fork.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)kernel/fork.c +0
-0
kernel/fork.c line 124
Quoted 7 lines
kernel/fork.c +2
-2@@ -120,10 +120,10 @@/* * Protected counters by write_lock_irq(&tasklist_lock) */ -unsigned long total_forks;/* Handle normal Linux uptimes. */ -int nr_threads;/* The idle threads do not count.. */ +unsigned long total_forks__read_mostly ;/* Handle normal Linux uptimes. */ +int nr_threads__read_mostly ;/* The idle threads do not count.. */
total_forks is incremented at every ~CLONE_THREAD and nr_threads at CLONE_THREAD I wouldn't exactly say that this qualifies as mostly reading.
kernel/fork.c line 126
Quoted 3 lines
kernel/fork.c +1
-1-static int max_threads;/* tunable limit on nr_threads */ +static int max_threads__read_mostly ;/* tunable limit on nr_threads */
That make sense.
Christian
Quoted 12 lines · Christian Brauner
Quoted 11 lines · On Mon, Jan 13, 2020 at 11:23:13AM +0800, [email protected] wrote:
From: chenqiwu <[email protected]>
Since total_forks/nr_threads/max_threads global variables are frequently used for process fork, putting these variables into
read_mostlysection can avoid unnecessary cache line bouncing.Signed-off-by chenqiwu <[email protected]>--- kernel/fork.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 17 lines
kernel/fork.c line 124
Quoted 12 lines
kernel/fork.c +2
-2@@ -120,10 +120,10 @@/* * Protected counters by write_lock_irq(&tasklist_lock) */ -unsigned long total_forks;/* Handle normal Linux uptimes. */ -int nr_threads;/* The idle threads do not count.. */ +unsigned long total_forks__read_mostly ;/* Handle normal Linux uptimes. */ +int nr_threads__read_mostly ;/* The idle threads do not count.. */
total_forksis incremented at every ~CLONE_THREAD andnr_threadsatCLONE_THREADI wouldn't exactly say that this qualifies as mostly reading.
Hi Christian,
I'm holding different views on this matter.
1) total_forks is incremented when any process does sys_fork() reasonablely, it counts for every process fork.
2) nr_threads counts for any parent process (except for idle thread) does fork successfully, it never exceeds than max_threads.
For an example of arm64 kdump, the system has been running at 119057s, we can see total_forks is very large, so total_forks is very qualified as mostly reading because it is referenced frequntly.
crash> p max_threadsmax_threads = $2 = 39150
crash> p nr_threadsnr_threads = $1 = 2676
crash> p total_forkstotal_forks = $3 = 2413880
nr_threads and max_threads is also qualified as mostly reading because they are frequntly referenced in the following code of copy_process():
if (nr_threads >= max_threads) goto bad_fork_cleanup_count;
Quoted 7 lines
kernel/fork.c line 126
Quoted 3 lines
kernel/fork.c +1
-1-static int max_threads;/* tunable limit on nr_threads */ +static int max_threads__read_mostly ;/* tunable limit on nr_threads */ That make sense.
Christian
Thanks for your review!
Qiwu