linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [v2] mm/damon/paddr: increment pa_stat damon address range by folio size
@ 2025-01-13 19:07 Usama Arif
  2025-01-13 19:27 ` SeongJae Park
  0 siblings, 1 reply; 2+ messages in thread
From: Usama Arif @ 2025-01-13 19:07 UTC (permalink / raw)
  To: sj, akpm; +Cc: damon, linux-mm, Usama Arif

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.

Signed-off-by: Usama Arif <usamaarif642@gmail.com>
---
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(-)

diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 6b4397de4199..bd8cfe10121b 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -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;
-- 
2.43.5



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

* Re: [v2] mm/damon/paddr: increment pa_stat damon address range by folio size
  2025-01-13 19:07 [v2] mm/damon/paddr: increment pa_stat damon address range by folio size Usama Arif
@ 2025-01-13 19:27 ` SeongJae Park
  0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2025-01-13 19:27 UTC (permalink / raw)
  To: Usama Arif; +Cc: SeongJae Park, akpm, damon, linux-mm

On Mon, 13 Jan 2025 19:07:38 +0000 Usama Arif <usamaarif642@gmail.com> 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!

> 
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]


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

end of thread, other threads:[~2025-01-13 19:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-13 19:07 [v2] mm/damon/paddr: increment pa_stat damon address range by folio size Usama Arif
2025-01-13 19:27 ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox