linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/vmstat: don't do count if no needs
@ 2020-07-20  5:23 Alex Shi
  2020-07-20  5:42 ` Alex Shi
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Shi @ 2020-07-20  5:23 UTC (permalink / raw)
  Cc: Alex Shi, Andrew Morton, linux-mm, linux-kernel

For couple of vmstat account funcs, the caller usually doesn't check the
delta value, if delta == 0, irq or atomic operator is a waste. That's
better to be skipped.

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Andrew Morton <akpm@linux-foundation.org> 
Cc: linux-mm@kvack.org 
Cc: linux-kernel@vger.kernel.org 
---
 mm/vmstat.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/mm/vmstat.c b/mm/vmstat.c
index 3fb23a21f6dd..91f28146daa7 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -321,6 +321,9 @@ void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
 	long x;
 	long t;
 
+	if (!delta)
+		return;
+
 	x = delta + __this_cpu_read(*p);
 
 	t = __this_cpu_read(pcp->stat_threshold);
@@ -341,6 +344,9 @@ void __mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item,
 	long x;
 	long t;
 
+	if (!delta)
+		return;
+
 	x = delta + __this_cpu_read(*p);
 
 	t = __this_cpu_read(pcp->stat_threshold);
@@ -484,6 +490,9 @@ static inline void mod_zone_state(struct zone *zone,
 	s8 __percpu *p = pcp->vm_stat_diff + item;
 	long o, n, t, z;
 
+	if (!delta)
+		return;
+
 	do {
 		z = 0;  /* overflow to zone counters */
 
@@ -518,6 +527,9 @@ static inline void mod_zone_state(struct zone *zone,
 void mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
 			 long delta)
 {
+	if (!delta)
+		return;
+
 	mod_zone_state(zone, item, delta, 0);
 }
 EXPORT_SYMBOL(mod_zone_page_state);
@@ -541,6 +553,9 @@ static inline void mod_node_state(struct pglist_data *pgdat,
 	s8 __percpu *p = pcp->vm_node_stat_diff + item;
 	long o, n, t, z;
 
+	if (!delta)
+		return;
+
 	do {
 		z = 0;  /* overflow to node counters */
 
@@ -581,6 +596,9 @@ EXPORT_SYMBOL(mod_node_page_state);
 
 void inc_node_state(struct pglist_data *pgdat, enum node_stat_item item)
 {
+	if (!delta)
+		return;
+
 	mod_node_state(pgdat, item, 1, 1);
 }
 
@@ -604,6 +622,9 @@ void mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
 {
 	unsigned long flags;
 
+	if (!delta)
+		return;
+
 	local_irq_save(flags);
 	__mod_zone_page_state(zone, item, delta);
 	local_irq_restore(flags);
@@ -647,6 +668,9 @@ void mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item,
 {
 	unsigned long flags;
 
+	if (!delta)
+		return;
+
 	local_irq_save(flags);
 	__mod_node_page_state(pgdat, item, delta);
 	local_irq_restore(flags);
-- 
2.18.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/vmstat: don't do count if no needs
  2020-07-20  5:23 [PATCH] mm/vmstat: don't do count if no needs Alex Shi
@ 2020-07-20  5:42 ` Alex Shi
  2020-07-20 23:14   ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Shi @ 2020-07-20  5:42 UTC (permalink / raw)
  Cc: Andrew Morton, linux-mm, linux-kernel


From 4cb977d34227e4bafa95b8da5e47dbd8b6141d26 Mon Sep 17 00:00:00 2001
From: Alex Shi <alex.shi@linux.alibaba.com>
Date: Mon, 20 Jul 2020 11:50:12 +0800
Subject: [PATCH v2] mm/vmstat: don't do count if no needs

For couple of vmstat account funcs, the caller usually doesn't check the
delta value, if delta == 0, irq or atomic operator is a waste. That's
better to be skipped, also add unlikey() since !delta is less happened.

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
---
 mm/vmstat.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/mm/vmstat.c b/mm/vmstat.c
index 3fb23a21f6dd..b02d99dff443 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -321,6 +321,9 @@ void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
 	long x;
 	long t;
 
+	if (unlikely(!delta))
+		return;
+
 	x = delta + __this_cpu_read(*p);
 
 	t = __this_cpu_read(pcp->stat_threshold);
@@ -341,6 +344,9 @@ void __mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item,
 	long x;
 	long t;
 
+	if (unlikely(!delta))
+		return;
+
 	x = delta + __this_cpu_read(*p);
 
 	t = __this_cpu_read(pcp->stat_threshold);
@@ -484,6 +490,9 @@ static inline void mod_zone_state(struct zone *zone,
 	s8 __percpu *p = pcp->vm_stat_diff + item;
 	long o, n, t, z;
 
+	if (unlikely(!delta))
+		return;
+
 	do {
 		z = 0;  /* overflow to zone counters */
 
@@ -518,6 +527,9 @@ static inline void mod_zone_state(struct zone *zone,
 void mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
 			 long delta)
 {
+	if (unlikely(!delta))
+		return;
+
 	mod_zone_state(zone, item, delta, 0);
 }
 EXPORT_SYMBOL(mod_zone_page_state);
@@ -541,6 +553,9 @@ static inline void mod_node_state(struct pglist_data *pgdat,
 	s8 __percpu *p = pcp->vm_node_stat_diff + item;
 	long o, n, t, z;
 
+	if (unlikely(!delta))
+		return;
+
 	do {
 		z = 0;  /* overflow to node counters */
 
@@ -604,6 +619,9 @@ void mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
 {
 	unsigned long flags;
 
+	if (unlikely(!delta))
+		return;
+
 	local_irq_save(flags);
 	__mod_zone_page_state(zone, item, delta);
 	local_irq_restore(flags);
@@ -647,6 +665,9 @@ void mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item,
 {
 	unsigned long flags;
 
+	if (unlikely(!delta))
+		return;
+
 	local_irq_save(flags);
 	__mod_node_page_state(pgdat, item, delta);
 	local_irq_restore(flags);
-- 
2.18.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/vmstat: don't do count if no needs
  2020-07-20  5:42 ` Alex Shi
@ 2020-07-20 23:14   ` Andrew Morton
  2020-07-21  3:07     ` Alex Shi
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2020-07-20 23:14 UTC (permalink / raw)
  To: Alex Shi; +Cc: linux-mm, linux-kernel

On Mon, 20 Jul 2020 13:42:45 +0800 Alex Shi <alex.shi@linux.alibaba.com> wrote:

> 
> For couple of vmstat account funcs, the caller usually doesn't check the
> delta value, if delta == 0, irq or atomic operator is a waste. That's
> better to be skipped, also add unlikey() since !delta is less happened.
> 
> ...
>
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -321,6 +321,9 @@ void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
>  	long x;
>  	long t;
>  
> +	if (unlikely(!delta))
> +		return;
> +

Do we know that delta==0 is frequent enough to make the change a net
benefit?



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/vmstat: don't do count if no needs
  2020-07-20 23:14   ` Andrew Morton
@ 2020-07-21  3:07     ` Alex Shi
  0 siblings, 0 replies; 4+ messages in thread
From: Alex Shi @ 2020-07-21  3:07 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel



在 2020/7/21 上午7:14, Andrew Morton 写道:
>> --- a/mm/vmstat.c
>> +++ b/mm/vmstat.c
>> @@ -321,6 +321,9 @@ void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
>>  	long x;
>>  	long t;
>>  
>> +	if (unlikely(!delta))
>> +		return;
>> +
> Do we know that delta==0 is frequent enough to make the change a net
> benefit?

Uh,I check again. it seems no much place delta==0, forget this patch.

Thanks
Alex


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-21  3:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20  5:23 [PATCH] mm/vmstat: don't do count if no needs Alex Shi
2020-07-20  5:42 ` Alex Shi
2020-07-20 23:14   ` Andrew Morton
2020-07-21  3:07     ` Alex Shi

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).