Skip to contentSkip to conversation

mm/page_alloc: cache the result of node_dirty_ok()

PATCH Applied Wonhyuk Yang 4 participants 4 messages Apr 30, 2022 – May 3, 2022

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

PATCH 1/1 mm/page_alloc: cache the result of node_dirty_ok()

To spread dirty page, nodes are checked whether it reached the dirty limit using the expensive node_dirty_ok(). To reduce the number of calling node_dirty_ok(), last node that hit the dirty limit is cached.

Instead of caching the node, caching both node and it's result of node_dirty_ok() can reduce the number of calling node_dirty_ok() more than before.

---
 mm/page_alloc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
mm/page_alloc.c +7 -6
index 0e42038382c1..aba62cf31a0e 100644
@@ -4068,7 +4068,8 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,
 {
 	struct zoneref *z;
 	struct zone *zone;
-	struct pglist_data *last_pgdat_dirty_limit = NULL;
+	struct pglist_data *last_pgdat = NULL;
+	bool last_pgdat_dirty_limit = false;
 	bool no_fallback;
 
 retry:
@@ -4107,13 +4108,13 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,
 		 * dirty-throttling and the flusher threads.
 		 */
 		if (ac->spread_dirty_pages) {
-			if (last_pgdat_dirty_limit == zone->zone_pgdat)
-				continue;
+			if (last_pgdat != zone->zone_pgdat) {
+				last_pgdat = zone->zone_pgdat;
+				last_pgdat_dirty_limit = node_dirty_ok(zone->zone_pgdat);
+			}
 
-			if (!node_dirty_ok(zone->zone_pgdat)) {
-				last_pgdat_dirty_limit = zone->zone_pgdat;
+			if (!last_pgdat_dirty_limit)
 				continue;
-			}
 		}
 
 		if (no_fallback && nr_online_nodes > 1 &&
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 34 lines · On Sat, 30 Apr 2022 10:10:32 +0900 Wonhyuk Yang <[email protected]> wrote:

To spread dirty page, nodes are checked whether it reached the dirty limit using the expensive node_dirty_ok(). To reduce the number of calling node_dirty_ok(), last node that hit the dirty limit is cached.

Instead of caching the node, caching both node and it's result of node_dirty_ok() can reduce the number of calling node_dirty_ok() more than before.

...

mm/page_alloc.c +5 -3
@@ -4068,7 +4068,8 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,
 {
 	struct zoneref *z;
 	struct zone *zone;
-	struct pglist_data *last_pgdat_dirty_limit = NULL;
+	struct pglist_data *last_pgdat = NULL;
+	bool last_pgdat_dirty_limit = false;
 	bool no_fallback;
 
 retry:
@@ -4107,13 +4108,13 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,
 		 * dirty-throttling and the flusher threads.
 		 */
 		if (ac->spread_dirty_pages) {
-			if (last_pgdat_dirty_limit == zone->zone_pgdat)
-				continue;
+			if (last_pgdat != zone->zone_pgdat) {
+				last_pgdat = zone->zone_pgdat;
+				last_pgdat_dirty_limit = node_dirty_ok(zone->zone_pgdat);

mm/page_alloc.c get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, · line 4120

Quoted 10 lines
mm/page_alloc.c +2 -3
+			}
 
-			if (!node_dirty_ok(zone->zone_pgdat)) {
-				last_pgdat_dirty_limit = zone->zone_pgdat;
+			if (!last_pgdat_dirty_limit)
 				continue;
-			}
 		}
 
 		if (no_fallback && nr_online_nodes > 1 &&

Looks reasonable to me. Hopefully Mel and Johannes can review.

I think last_pgdat_dirty_limit isn't a great name. It records the dirty_ok state of last_pgdat. So why not call it last_pgdat_dirty_ok?

mm/page_alloc.c renamed from mm/page_alloc.c~mm-page_alloc-cache-the-result-of-node_dirty_ok-fix +3 -3
@@ -4022,7 +4022,7 @@ get_page_from_freelist(gfp_t gfp_mask, u
 	struct zoneref *z;
 	struct zone *zone;
 	struct pglist_data *last_pgdat = NULL;
-	bool last_pgdat_dirty_limit = false;
+	bool last_pgdat_dirty_ok = false;
 	bool no_fallback;
 
 retry:
@@ -4063,10 +4063,10 @@ retry:
 		if (ac->spread_dirty_pages) {
 			if (last_pgdat != zone->zone_pgdat) {
 				last_pgdat = zone->zone_pgdat;
-				last_pgdat_dirty_limit = node_dirty_ok(zone->zone_pgdat);
+				last_pgdat_dirty_ok = node_dirty_ok(zone->zone_pgdat);
 			}
 
-			if (!last_pgdat_dirty_limit)
+			if (!last_pgdat_dirty_ok)
 				continue;
 		}
 

_

Acked-by on v1 1/1
#2 lore raw
In reply to Wonhyuk Yang
Quoted 6 lines · Wonhyuk Yang

To spread dirty page, nodes are checked whether it reached the dirty limit using the expensive node_dirty_ok(). To reduce the number of calling node_dirty_ok(), last node that hit the dirty limit is cached.

Quoted 6 lines

Instead of caching the node, caching both node and it's result of node_dirty_ok() can reduce the number of calling node_dirty_ok() more than before.

I agree with Andrew that last_pgdat_dirty_ok is a better name. The old name was also bad but seeing as the area is being changed, fixing the name is harmless.

Signature · 2 lines
Mel Gorman
SUSE Labs
reviewer Acked-by on v1 1/1
#3 lore raw
In reply to Wonhyuk Yang
Quoted 6 lines · Wonhyuk Yang

To spread dirty page, nodes are checked whether it reached the dirty limit using the expensive node_dirty_ok(). To reduce the number of calling node_dirty_ok(), last node that hit the dirty limit is cached.

Quoted 6 lines

Instead of caching the node, caching both node and it's result of node_dirty_ok() can reduce the number of calling node_dirty_ok() more than before.

Looks good to me. I like Andrew's naming fixlet as well.