Skip to contentSkip to conversation

mm/damon/paddr: increment pa_stat damon address range by folio size

PATCH Applied Usama Arif 2 participants 2 messages Jan 13, 2025

Subsystems (2)
lore
Share & tools
lore

Usama Arif

author
#0 lore raw

PATCH v2 1/1 mm/damon/paddr: increment pa_stat damon address range by folio size

This is to avoid going through all the pages in a folio. For folio_size > PAGE_SIZE, damon_get_folio will return NULL for tail pages, so the for loop in those instances will be a nop. Have a more efficient loop by just incrementing the address by folio_size.

---
v1 -> v2 (SJ Park):
- Update commit message to change the description as an optimization instead of a fix.
- handle case when damon_get_folio returns NULL.

---
 mm/damon/paddr.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/damon/paddr.c +6 -2
index 6b4397de4199..bd8cfe10121b 100644
@@ -504,17 +504,21 @@ static unsigned long damon_pa_stat(struct damon_region *r, struct damos *s,
 	if (!damon_pa_scheme_has_filter(s))
 		return 0;
 
-	for (addr = r->ar.start; addr < r->ar.end; addr += PAGE_SIZE) {
+	addr = r->ar.start;
+	while (addr < r->ar.end) {
 		struct folio *folio = damon_get_folio(PHYS_PFN(addr));
 
-		if (!folio)
+		if (!folio) {
+			addr += PAGE_SIZE;
 			continue;
+		}
 
 		if (damos_pa_filter_out(s, folio))
 			goto put_folio;
 		else
 			*sz_filter_passed += folio_size(folio);
 put_folio:
+		addr += folio_size(folio);
 		folio_put(folio);
 	}
 	return 0;
Signature · 1 line
2.43.5
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · On Mon, 13 Jan 2025 19:07:38 +0000 Usama Arif <[email protected]> wrote:

This is to avoid going through all the pages in a folio. For folio_size > PAGE_SIZE, damon_get_folio will return NULL for tail pages, so the for loop in those instances will be a nop. Have a more efficient loop by just incrementing the address by folio_size.

Thank you for this nice patch, Usama!

Quoted 2 lines

Thanks,
SJ

[...]