* Re: [PATCH] mm: Remove the redundant updating of stats_flush_threshold
2022-07-22 16:49 ` Jiebin Sun
(?)
@ 2022-07-22 16:22 ` Shakeel Butt
-1 siblings, 0 replies; 9+ messages in thread
From: Shakeel Butt @ 2022-07-22 16:22 UTC (permalink / raw)
To: Jiebin Sun
Cc: linux-kernel, linux-mm, cgroups, hannes, mhocko, roman.gushchin,
songmuchun, akpm, tim.c.chen, ying.huang, amadeuszx.slawinski,
tianyou.li, wangyang.guo
On Sat, Jul 23, 2022 at 12:49:49AM +0800, Jiebin Sun wrote:
> From: jiebin sun <jiebin.sun@intel.com>
>
> Remove the redundant updating of stats_flush_threshold. If the
> global var stats_flush_threshold has exceeded the trigger value
> for __mem_cgroup_flush_stats, further increment is unnecessary.
>
> Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads).
>
> Score gain: 1.95x
> Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%)
>
> CPU: ICX 8380 x 2 sockets
> Core number: 40 x 2 physical cores
> Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads)
>
> Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
Yes, this makes sense. No need to dirty a cacheline if we are already
over the threshold.
Acked-by: Shakeel Butt <shakeelb@google.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] mm: Remove the redundant updating of stats_flush_threshold
@ 2022-07-22 16:49 ` Jiebin Sun
0 siblings, 0 replies; 9+ messages in thread
From: Jiebin Sun @ 2022-07-22 16:49 UTC (permalink / raw)
To: linux-kernel, linux-mm, cgroups
Cc: hannes, mhocko, roman.gushchin, shakeelb, songmuchun, akpm,
tim.c.chen, ying.huang, amadeuszx.slawinski, tianyou.li,
wangyang.guo, jiebin sun
From: jiebin sun <jiebin.sun@intel.com>
Remove the redundant updating of stats_flush_threshold. If the
global var stats_flush_threshold has exceeded the trigger value
for __mem_cgroup_flush_stats, further increment is unnecessary.
Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads).
Score gain: 1.95x
Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%)
CPU: ICX 8380 x 2 sockets
Core number: 40 x 2 physical cores
Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads)
Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
---
mm/memcontrol.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index abec50f31fe6..9e8c6f24c694 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -626,7 +626,14 @@ static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val)
x = __this_cpu_add_return(stats_updates, abs(val));
if (x > MEMCG_CHARGE_BATCH) {
- atomic_add(x / MEMCG_CHARGE_BATCH, &stats_flush_threshold);
+ /*
+ * If stats_flush_threshold exceeds the threshold
+ * (>num_online_cpus()), cgroup stats update will be triggered
+ * in __mem_cgroup_flush_stats(). Increasing this var further
+ * is redundant and simply adds overhead in atomic update.
+ */
+ if (atomic_read(&stats_flush_threshold) <= num_online_cpus())
+ atomic_add(x / MEMCG_CHARGE_BATCH, &stats_flush_threshold);
__this_cpu_write(stats_updates, 0);
}
}
--
2.31.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] mm: Remove the redundant updating of stats_flush_threshold
@ 2022-07-22 16:49 ` Jiebin Sun
0 siblings, 0 replies; 9+ messages in thread
From: Jiebin Sun @ 2022-07-22 16:49 UTC (permalink / raw)
To: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-mm-Bw31MaZKKs3YtjvyW6yDsg, cgroups-u79uwXL29TY76Z2rM5mHXA
Cc: hannes-druUgvl0LCNAfugRpC6u6w, mhocko-DgEjT+Ai2ygdnm+yROfE0A,
roman.gushchin-fxUVXftIFDnyG1zEObXtfA,
shakeelb-hpIqsD4AKlfQT0dZR+AlfA,
songmuchun-EC8Uxl6Npydl57MIdRCFDg,
akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
tim.c.chen-ral2JQCrhuEAvxtiuMwx3w,
ying.huang-ral2JQCrhuEAvxtiuMwx3w,
amadeuszx.slawinski-VuQAYsv1563Yd54FQh9/CA,
tianyou.li-ral2JQCrhuEAvxtiuMwx3w,
wangyang.guo-ral2JQCrhuEAvxtiuMwx3w, jiebin sun
From: jiebin sun <jiebin.sun-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Remove the redundant updating of stats_flush_threshold. If the
global var stats_flush_threshold has exceeded the trigger value
for __mem_cgroup_flush_stats, further increment is unnecessary.
Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads).
Score gain: 1.95x
Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%)
CPU: ICX 8380 x 2 sockets
Core number: 40 x 2 physical cores
Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads)
Signed-off-by: Jiebin Sun <jiebin.sun-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
mm/memcontrol.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index abec50f31fe6..9e8c6f24c694 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -626,7 +626,14 @@ static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val)
x = __this_cpu_add_return(stats_updates, abs(val));
if (x > MEMCG_CHARGE_BATCH) {
- atomic_add(x / MEMCG_CHARGE_BATCH, &stats_flush_threshold);
+ /*
+ * If stats_flush_threshold exceeds the threshold
+ * (>num_online_cpus()), cgroup stats update will be triggered
+ * in __mem_cgroup_flush_stats(). Increasing this var further
+ * is redundant and simply adds overhead in atomic update.
+ */
+ if (atomic_read(&stats_flush_threshold) <= num_online_cpus())
+ atomic_add(x / MEMCG_CHARGE_BATCH, &stats_flush_threshold);
__this_cpu_write(stats_updates, 0);
}
}
--
2.31.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] mm: Remove the redundant updating of stats_flush_threshold
@ 2022-07-22 17:05 ` Roman Gushchin
0 siblings, 0 replies; 9+ messages in thread
From: Roman Gushchin @ 2022-07-22 17:05 UTC (permalink / raw)
To: Jiebin Sun
Cc: linux-kernel, linux-mm, cgroups, hannes, mhocko, shakeelb,
songmuchun, akpm, tim.c.chen, ying.huang, amadeuszx.slawinski,
tianyou.li, wangyang.guo
On Sat, Jul 23, 2022 at 12:49:49AM +0800, Jiebin Sun wrote:
> From: jiebin sun <jiebin.sun@intel.com>
>
> Remove the redundant updating of stats_flush_threshold. If the
> global var stats_flush_threshold has exceeded the trigger value
> for __mem_cgroup_flush_stats, further increment is unnecessary.
>
> Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads).
>
> Score gain: 1.95x
> Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%)
>
> CPU: ICX 8380 x 2 sockets
> Core number: 40 x 2 physical cores
> Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads)
>
> Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Good optimization, thanks!
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mm: Remove the redundant updating of stats_flush_threshold
@ 2022-07-22 17:05 ` Roman Gushchin
0 siblings, 0 replies; 9+ messages in thread
From: Roman Gushchin @ 2022-07-22 17:05 UTC (permalink / raw)
To: Jiebin Sun
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-mm-Bw31MaZKKs3YtjvyW6yDsg, cgroups-u79uwXL29TY76Z2rM5mHXA,
hannes-druUgvl0LCNAfugRpC6u6w, mhocko-DgEjT+Ai2ygdnm+yROfE0A,
shakeelb-hpIqsD4AKlfQT0dZR+AlfA,
songmuchun-EC8Uxl6Npydl57MIdRCFDg,
akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
tim.c.chen-ral2JQCrhuEAvxtiuMwx3w,
ying.huang-ral2JQCrhuEAvxtiuMwx3w,
amadeuszx.slawinski-VuQAYsv1563Yd54FQh9/CA,
tianyou.li-ral2JQCrhuEAvxtiuMwx3w,
wangyang.guo-ral2JQCrhuEAvxtiuMwx3w
On Sat, Jul 23, 2022 at 12:49:49AM +0800, Jiebin Sun wrote:
> From: jiebin sun <jiebin.sun-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>
> Remove the redundant updating of stats_flush_threshold. If the
> global var stats_flush_threshold has exceeded the trigger value
> for __mem_cgroup_flush_stats, further increment is unnecessary.
>
> Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads).
>
> Score gain: 1.95x
> Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%)
>
> CPU: ICX 8380 x 2 sockets
> Core number: 40 x 2 physical cores
> Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads)
>
> Signed-off-by: Jiebin Sun <jiebin.sun-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Reviewed-by: Roman Gushchin <roman.gushchin-fxUVXftIFDnyG1zEObXtfA@public.gmane.org>
Good optimization, thanks!
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] mm: Remove the redundant updating of stats_flush_threshold
2022-07-22 17:05 ` Roman Gushchin
@ 2022-07-22 17:57 ` Chen, Tim C
-1 siblings, 0 replies; 9+ messages in thread
From: Chen, Tim C @ 2022-07-22 17:57 UTC (permalink / raw)
To: Roman Gushchin, Sun, Jiebin
Cc: linux-kernel, linux-mm, cgroups, hannes, mhocko, shakeelb,
songmuchun, akpm, Huang, Ying, amadeuszx.slawinski, Li, Tianyou,
Guo, Wangyang
>
>On Sat, Jul 23, 2022 at 12:49:49AM +0800, Jiebin Sun wrote:
>> From: jiebin sun <jiebin.sun@intel.com>
>>
>> Remove the redundant updating of stats_flush_threshold. If the global
>> var stats_flush_threshold has exceeded the trigger value for
>> __mem_cgroup_flush_stats, further increment is unnecessary.
>>
>> Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads).
>>
>> Score gain: 1.95x
>> Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%)
>>
>> CPU: ICX 8380 x 2 sockets
>> Core number: 40 x 2 physical cores
>> Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads)
>>
>> Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
>
>Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
>
>Good optimization, thanks!
Looks good. Nice performance improvement.
Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] mm: Remove the redundant updating of stats_flush_threshold
@ 2022-07-22 17:57 ` Chen, Tim C
0 siblings, 0 replies; 9+ messages in thread
From: Chen, Tim C @ 2022-07-22 17:57 UTC (permalink / raw)
To: Roman Gushchin, Sun, Jiebin
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-mm-Bw31MaZKKs3YtjvyW6yDsg, cgroups-u79uwXL29TY76Z2rM5mHXA,
hannes-druUgvl0LCNAfugRpC6u6w, mhocko-DgEjT+Ai2ygdnm+yROfE0A,
shakeelb-hpIqsD4AKlfQT0dZR+AlfA,
songmuchun-EC8Uxl6Npydl57MIdRCFDg,
akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, Huang, Ying,
amadeuszx.slawinski-VuQAYsv1563Yd54FQh9/CA, Li, Tianyou, Guo,
Wangyang
>
>On Sat, Jul 23, 2022 at 12:49:49AM +0800, Jiebin Sun wrote:
>> From: jiebin sun <jiebin.sun-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>>
>> Remove the redundant updating of stats_flush_threshold. If the global
>> var stats_flush_threshold has exceeded the trigger value for
>> __mem_cgroup_flush_stats, further increment is unnecessary.
>>
>> Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads).
>>
>> Score gain: 1.95x
>> Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%)
>>
>> CPU: ICX 8380 x 2 sockets
>> Core number: 40 x 2 physical cores
>> Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads)
>>
>> Signed-off-by: Jiebin Sun <jiebin.sun-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>
>Reviewed-by: Roman Gushchin <roman.gushchin-fxUVXftIFDnyG1zEObXtfA@public.gmane.org>
>
>Good optimization, thanks!
Looks good. Nice performance improvement.
Reviewed-by: Tim Chen <tim.c.chen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mm: Remove the redundant updating of stats_flush_threshold
@ 2022-07-23 13:43 ` Muchun Song
0 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2022-07-23 13:43 UTC (permalink / raw)
To: Jiebin Sun
Cc: linux-kernel, linux-mm, cgroups, hannes, mhocko, roman.gushchin,
shakeelb, akpm, tim.c.chen, ying.huang, amadeuszx.slawinski,
tianyou.li, wangyang.guo
On Sat, Jul 23, 2022 at 12:49:49AM +0800, Jiebin Sun wrote:
> From: jiebin sun <jiebin.sun@intel.com>
>
> Remove the redundant updating of stats_flush_threshold. If the
> global var stats_flush_threshold has exceeded the trigger value
> for __mem_cgroup_flush_stats, further increment is unnecessary.
>
> Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads).
>
> Score gain: 1.95x
> Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%)
>
> CPU: ICX 8380 x 2 sockets
> Core number: 40 x 2 physical cores
> Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads)
>
> Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
Acked-by: Muchun Song <songmuchun@bytedance.com>
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mm: Remove the redundant updating of stats_flush_threshold
@ 2022-07-23 13:43 ` Muchun Song
0 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2022-07-23 13:43 UTC (permalink / raw)
To: Jiebin Sun
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-mm-Bw31MaZKKs3YtjvyW6yDsg, cgroups-u79uwXL29TY76Z2rM5mHXA,
hannes-druUgvl0LCNAfugRpC6u6w, mhocko-DgEjT+Ai2ygdnm+yROfE0A,
roman.gushchin-fxUVXftIFDnyG1zEObXtfA,
shakeelb-hpIqsD4AKlfQT0dZR+AlfA,
akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
tim.c.chen-ral2JQCrhuEAvxtiuMwx3w,
ying.huang-ral2JQCrhuEAvxtiuMwx3w,
amadeuszx.slawinski-VuQAYsv1563Yd54FQh9/CA,
tianyou.li-ral2JQCrhuEAvxtiuMwx3w,
wangyang.guo-ral2JQCrhuEAvxtiuMwx3w
On Sat, Jul 23, 2022 at 12:49:49AM +0800, Jiebin Sun wrote:
> From: jiebin sun <jiebin.sun-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>
> Remove the redundant updating of stats_flush_threshold. If the
> global var stats_flush_threshold has exceeded the trigger value
> for __mem_cgroup_flush_stats, further increment is unnecessary.
>
> Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads).
>
> Score gain: 1.95x
> Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%)
>
> CPU: ICX 8380 x 2 sockets
> Core number: 40 x 2 physical cores
> Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads)
>
> Signed-off-by: Jiebin Sun <jiebin.sun-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Acked-by: Muchun Song <songmuchun-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org>
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-07-23 13:43 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22 16:49 [PATCH] mm: Remove the redundant updating of stats_flush_threshold Jiebin Sun
2022-07-22 16:49 ` Jiebin Sun
2022-07-22 16:22 ` Shakeel Butt
2022-07-22 17:05 ` Roman Gushchin
2022-07-22 17:05 ` Roman Gushchin
2022-07-22 17:57 ` Chen, Tim C
2022-07-22 17:57 ` Chen, Tim C
2022-07-23 13:43 ` Muchun Song
2022-07-23 13:43 ` Muchun Song
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.