* [PATCH] kernel/fork: put some fork variables into read-mostly section
@ 2020-01-13 3:23 qiwuchen55
2020-01-13 9:43 ` Christian Brauner
0 siblings, 1 reply; 3+ messages in thread
From: qiwuchen55 @ 2020-01-13 3:23 UTC (permalink / raw)
To: christian.brauner, peterz, mingo, tglx, oleg, elena.reshetova,
jgg, christian, aarcange, viro, cyphar, ldv
Cc: linux-kernel, chenqiwu
From: chenqiwu <chenqiwu@xiaomi.com>
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.
Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
---
kernel/fork.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 0808095..163e152 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -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)
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kernel/fork: put some fork variables into read-mostly section
2020-01-13 3:23 [PATCH] kernel/fork: put some fork variables into read-mostly section qiwuchen55
@ 2020-01-13 9:43 ` Christian Brauner
2020-01-14 6:16 ` chenqiwu
0 siblings, 1 reply; 3+ messages in thread
From: Christian Brauner @ 2020-01-13 9:43 UTC (permalink / raw)
To: qiwuchen55
Cc: peterz, mingo, tglx, oleg, elena.reshetova, jgg, christian,
aarcange, viro, cyphar, ldv, linux-kernel, chenqiwu
On Mon, Jan 13, 2020 at 11:23:13AM +0800, qiwuchen55@gmail.com wrote:
> From: chenqiwu <chenqiwu@xiaomi.com>
>
> 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.
>
> Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
> ---
> kernel/fork.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 0808095..163e152 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -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.
>
> -static int max_threads; /* tunable limit on nr_threads */
> +static int max_threads __read_mostly; /* tunable limit on nr_threads */
That make sense.
Christian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kernel/fork: put some fork variables into read-mostly section
2020-01-13 9:43 ` Christian Brauner
@ 2020-01-14 6:16 ` chenqiwu
0 siblings, 0 replies; 3+ messages in thread
From: chenqiwu @ 2020-01-14 6:16 UTC (permalink / raw)
To: Christian Brauner
Cc: peterz, mingo, tglx, oleg, elena.reshetova, jgg, christian,
aarcange, viro, cyphar, ldv, linux-kernel, chenqiwu
On Mon, Jan 13, 2020 at 10:43:43AM +0100, Christian Brauner wrote:
> On Mon, Jan 13, 2020 at 11:23:13AM +0800, qiwuchen55@gmail.com wrote:
> > From: chenqiwu <chenqiwu@xiaomi.com>
> >
> > 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.
> >
> > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
> > ---
> > kernel/fork.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/kernel/fork.c b/kernel/fork.c
> > index 0808095..163e152 100644
> > --- a/kernel/fork.c
> > +++ b/kernel/fork.c
> > @@ -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.
>
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_threads
max_threads = $2 = 39150
crash> p nr_threads
nr_threads = $1 = 2676
crash> p total_forks
total_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;
> >
> > -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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-14 6:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-13 3:23 [PATCH] kernel/fork: put some fork variables into read-mostly section qiwuchen55
2020-01-13 9:43 ` Christian Brauner
2020-01-14 6:16 ` chenqiwu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).