linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: SeongJae Park <sj@kernel.org>, Andrew Morton <akpm@linux-foundation.org>
Cc: damon@lists.linux.dev, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Yun Levi <ppbuk5246@gmail.com>
Subject: [PATCH 2/7] mm/damon/core: avoid holes in newly set monitoring target ranges
Date: Fri,  9 Sep 2022 20:28:56 +0000	[thread overview]
Message-ID: <20220909202901.57977-3-sj@kernel.org> (raw)
In-Reply-To: <20220909202901.57977-1-sj@kernel.org>

When there are two or more non-contiguous regions intersecting with
given new ranges, 'damon_set_regions()' does not fill the holes.  This
commit makes the function to fill the holes with newly created regions.

Fixes: 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces")
Reported-by: Yun Levi <ppbuk5246@gmail.com>
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/core.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index bae41990f422..6f6c9c9aca9d 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -168,6 +168,27 @@ static bool damon_intersect(struct damon_region *r,
 	return !(r->ar.end <= re->start || re->end <= r->ar.start);
 }
 
+/*
+ * Fill holes in regions with new regions.
+ */
+static void damon_fill_regions_holes(struct damon_region *first,
+		struct damon_region *last, struct damon_target *t)
+{
+	struct damon_region *r = first;
+
+	damon_for_each_region_from(r, t) {
+		struct damon_region *next, *newr;
+
+		if (r == last)
+			break;
+		next = damon_next_region(r);
+		if (r->ar.end != next->ar.start) {
+			newr = damon_new_region(r->ar.end, next->ar.start);
+			damon_insert_region(newr, r, next, t);
+		}
+	}
+}
+
 /*
  * damon_set_regions() - Set regions of a target for given address ranges.
  * @t:		the given target.
@@ -226,6 +247,9 @@ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges,
 			first->ar.start = ALIGN_DOWN(range->start,
 					DAMON_MIN_REGION);
 			last->ar.end = ALIGN(range->end, DAMON_MIN_REGION);
+
+			/* fill possible holes in the range */
+			damon_fill_regions_holes(first, last, t);
 		}
 	}
 	return 0;
-- 
2.25.1



  parent reply	other threads:[~2022-09-09 20:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-09 20:28 [PATCH 0/7] mm/damon: minor fixes and cleanups SeongJae Park
2022-09-09 20:28 ` [PATCH 1/7] selftest/damon: add a test for duplicate context dirs creation SeongJae Park
2022-09-09 20:28 ` SeongJae Park [this message]
2022-09-09 20:28 ` [PATCH 3/7] mm/damon/core-test: test damon_set_regions SeongJae Park
2022-09-09 20:28 ` [PATCH 4/7] Docs/admin-guide/mm/damon: rename the title of the document SeongJae Park
2022-09-09 20:28 ` [PATCH 5/7] mm/damon/Kconfig: Notify debugfs deprecation plan SeongJae Park
2022-09-09 20:29 ` [PATCH 6/7] Docs/admin-guide/mm/damon/start: mention the dependency as sysfs instead of debugfs SeongJae Park
2022-09-09 20:29 ` [PATCH 7/7] Docs/admin-guide/mm/damon/usage: note DAMON debugfs interface deprecation plan SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220909202901.57977-3-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ppbuk5246@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox