Skip to contentSkip to conversation

mm/page_alloc.c: avoid statistic update with 0

PATCH In review Vasily Averin 5 participants 6 messages Oct 8, 2021 – Oct 12, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/page_alloc.c: avoid statistic update with 0

__alloc_pages_bulk can call __count_zid_vm_events and zone_statistics with nr_account = 0.

Fixes 3e23060b2d0b ("mm/page_alloc: batch the accounting updates in the bulk allocator")
---
 mm/page_alloc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/page_alloc.c +4 -3
index 602819a232e5..e67113452ee8 100644
@@ -5364,9 +5364,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 	}
 
 	local_unlock_irqrestore(&pagesets.lock, flags);
-
-	__count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account);
-	zone_statistics(ac.preferred_zoneref->zone, zone, nr_account);
+	if (nr_account) {
+		__count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account);
+		zone_statistics(ac.preferred_zoneref->zone, zone, nr_account);
+	}
 	if (objcg)
 		memcg_bulk_post_charge_hook(objcg, nr_pre_charge - nr_account);
 
Signature · 1 line
2.31.1
#1 lore raw
Quoted 2 lines · Vasily Averin

__alloc_pages_bulk can call __count_zid_vm_events and zone_statistics with nr_account = 0.

But that's not a bug, right? Just an effective no-op that's not commonly happening, so is it worth the check?

Quoted 25 lines
Fixes 3e23060b2d0b ("mm/page_alloc: batch the accounting updates in the bulk allocator")
---
 mm/page_alloc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/page_alloc.c +4 -3
index 602819a232e5..e67113452ee8 100644
@@ -5364,9 +5364,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 	}
 
 	local_unlock_irqrestore(&pagesets.lock, flags);
-
-	__count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account);
-	zone_statistics(ac.preferred_zoneref->zone, zone, nr_account);
+	if (nr_account) {
+		__count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account);
+		zone_statistics(ac.preferred_zoneref->zone, zone, nr_account);
+	}
 	if (objcg)
 		memcg_bulk_post_charge_hook(objcg, nr_pre_charge - nr_account);
 
#2 lore raw
Quoted 6 lines · Vlastimil Babka
Quoted 2 lines · Vasily Averin

__alloc_pages_bulk can call __count_zid_vm_events and zone_statistics with nr_account = 0.

But that's not a bug, right? Just an effective no-op that's not commonly happening, so is it worth the check?

Why not?

Yes, it's not a bug, it just makes the kernel a bit more efficient in a very unlikely case. However, it looks strange and makes uninformed code reviewers like me worry about possible problems inside the affected functions. No one else calls these functions from 0.

Quoted 26 lines
Quoted 25 lines
Fixes 3e23060b2d0b ("mm/page_alloc: batch the accounting updates in the bulk allocator")
---
 mm/page_alloc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/page_alloc.c +4 -3
index 602819a232e5..e67113452ee8 100644
@@ -5364,9 +5364,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 	}
 
 	local_unlock_irqrestore(&pagesets.lock, flags);
-
-	__count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account);
-	zone_statistics(ac.preferred_zoneref->zone, zone, nr_account);
+	if (nr_account) {
+		__count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account);
+		zone_statistics(ac.preferred_zoneref->zone, zone, nr_account);
+	}
 	if (objcg)
 		memcg_bulk_post_charge_hook(objcg, nr_pre_charge - nr_account);
 
#3 lore raw
Quoted 5 lines · Vasily Averin
Quoted 4 lines · Vlastimil Babka
Quoted 2 lines · Vasily Averin

__alloc_pages_bulk can call __count_zid_vm_events and zone_statistics with nr_account = 0.

Quoted 9 lines
Quoted 2 lines

But that's not a bug, right? Just an effective no-op that's not commonly happening, so is it worth the check?

Why not?

Yes, it's not a bug, it just makes the kernel a bit more efficient in a very unlikely case. However, it looks strange and makes uninformed code reviewers like me worry about possible problems inside the affected functions. No one else calls these functions from 0.

If it's not a BUG we'd better leave "Fixes:" tags away., it tends to confuse people looking for actual BUGs.

I'm also not sure if this micro-optimization is worth it. "bit more efficient in a very unlikely case" doesn't sound very compelling ... and personally I'd assume accounting functions can deal with a delta of 0.

Signature · 3 lines
Thanks,

David / dhildenb
#4 lore raw
In reply to Vasily Averin
Quoted 11 lines · Vasily Averin
Quoted 6 lines · Vlastimil Babka
Quoted 2 lines · Vasily Averin

__alloc_pages_bulk can call __count_zid_vm_events and zone_statistics with nr_account = 0.

But that's not a bug, right? Just an effective no-op that's not commonly happening, so is it worth the check?

Why not?

Yes, it's not a bug, it just makes the kernel a bit more efficient in a very unlikely case.

At the cost of an additional branch in the likely case that may be mispredicted.

Quoted 3 lines

However, it looks strange and makes uninformed code reviewers like me worry about possible problems inside the affected functions. No one else calls these functions from 0.

The accounting functions should still work with a 0 delta.

Signature · 2 lines
Mel Gorman
SUSE Labs
#5 lore raw
In reply to Vasily Averin
Quoted 3 lines · Vasily Averin

Yes, it's not a bug, it just makes the kernel a bit more efficient in a very unlikely case. However, it looks strange and makes uninformed code reviewers like me worry about possible problems inside the affected functions. No one else calls these functions from 0.

This statement is meaningless without data. If you have proof that it makes the kernel more efficient, then please provide the profiles.

As it is I'd be surprised if this improved things. Either the code is hot enough that the additional branch is cumbersome, or it's cold enough that it doesn't even matter.