linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] mm/damon: minor fixes and cleanups
@ 2022-09-09 20:28 SeongJae Park
  2022-09-09 20:28 ` [PATCH 1/7] selftest/damon: add a test for duplicate context dirs creation SeongJae Park
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: SeongJae Park @ 2022-09-09 20:28 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, Jonathan Corbet, Shuah Khan, Brendan Higgins,
	damon, linux-mm, linux-doc, linux-kselftest, linux-kernel

This patchset contains minor fixes and cleanups for DAMON including

- selftest for a bug we found before (Patch 1), 
- fix of region holes in vaddr corner case and a kunit test for it
  (Patches 2 and 3), and
- documents/Kconfig updates for title wordsmithing (Patch 4) and more
  aggressive DAMON debugfs interface deprecation announcement
  (Patches 5-7).

SeongJae Park (7):
  selftest/damon: add a test for duplicate context dirs creation
  mm/damon/core: avoid holes in newly set monitoring target ranges
  mm/damon/core-test: test damon_set_regions
  Docs/admin-guide/mm/damon: rename the title of the document
  mm/damon/Kconfig: Notify debugfs deprecation plan
  Docs/DAMON/start: mention the dependency as sysfs instead of debugfs
  Docs/admin-guide/mm/damon/usage: note DAMON debugfs interface
    deprecation plan

 Documentation/admin-guide/mm/damon/index.rst  |  6 ++---
 Documentation/admin-guide/mm/damon/start.rst  | 13 +++------
 Documentation/admin-guide/mm/damon/usage.rst  |  5 ++++
 mm/damon/Kconfig                              |  3 +++
 mm/damon/core-test.h                          | 23 ++++++++++++++++
 mm/damon/core.c                               | 24 +++++++++++++++++
 tools/testing/selftests/damon/Makefile        |  1 +
 .../debugfs_duplicate_context_creation.sh     | 27 +++++++++++++++++++
 8 files changed, 89 insertions(+), 13 deletions(-)
 create mode 100644 tools/testing/selftests/damon/debugfs_duplicate_context_creation.sh

-- 
2.25.1


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

* [PATCH 1/7] selftest/damon: add a test for duplicate context dirs creation
  2022-09-09 20:28 [PATCH 0/7] mm/damon: minor fixes and cleanups SeongJae Park
@ 2022-09-09 20:28 ` SeongJae Park
  2022-09-09 20:28 ` [PATCH 2/7] mm/damon/core: avoid holes in newly set monitoring target ranges SeongJae Park
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: SeongJae Park @ 2022-09-09 20:28 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Shuah Khan, linux-kernel, damon, linux-mm, linux-kselftest,
	SeongJae Park

Commit d26f60703606 ("mm/damon/dbgfs: avoid duplicate context directory
creation") fixes a bug which could result in memory leak and DAMON
disablement.  This commit adds a selftest for verifying the fix and
avoid regression.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 tools/testing/selftests/damon/Makefile        |  1 +
 .../debugfs_duplicate_context_creation.sh     | 27 +++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 tools/testing/selftests/damon/debugfs_duplicate_context_creation.sh

diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile
index 0470c5f3e690..a1fa2eff8192 100644
--- a/tools/testing/selftests/damon/Makefile
+++ b/tools/testing/selftests/damon/Makefile
@@ -6,6 +6,7 @@ TEST_GEN_FILES += huge_count_read_write
 TEST_FILES = _chk_dependency.sh _debugfs_common.sh
 TEST_PROGS = debugfs_attrs.sh debugfs_schemes.sh debugfs_target_ids.sh
 TEST_PROGS += debugfs_empty_targets.sh debugfs_huge_count_read_write.sh
+TEST_PROGS += debugfs_duplicate_context_creation.sh
 TEST_PROGS += sysfs.sh
 
 include ../lib.mk
diff --git a/tools/testing/selftests/damon/debugfs_duplicate_context_creation.sh b/tools/testing/selftests/damon/debugfs_duplicate_context_creation.sh
new file mode 100644
index 000000000000..4a76e37ef16b
--- /dev/null
+++ b/tools/testing/selftests/damon/debugfs_duplicate_context_creation.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+source _debugfs_common.sh
+
+# Test duplicated context creation
+# ================================
+
+if ! echo foo > "$DBGFS/mk_contexts"
+then
+	echo "context creation failed"
+	exit 1
+fi
+
+if echo foo > "$DBGFS/mk_contexts"
+then
+	echo "duplicate context creation success"
+	exit 1
+fi
+
+if ! echo foo > "$DBGFS/rm_contexts"
+then
+	echo "context deletion failed"
+	exit 1
+fi
+
+exit 0
-- 
2.25.1


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

* [PATCH 2/7] mm/damon/core: avoid holes in newly set monitoring target ranges
  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
  2022-09-09 20:28 ` [PATCH 3/7] mm/damon/core-test: test damon_set_regions SeongJae Park
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: SeongJae Park @ 2022-09-09 20:28 UTC (permalink / raw)
  To: SeongJae Park, Andrew Morton; +Cc: damon, linux-mm, linux-kernel, Yun Levi

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


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

* [PATCH 3/7] mm/damon/core-test: test damon_set_regions
  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 ` [PATCH 2/7] mm/damon/core: avoid holes in newly set monitoring target ranges SeongJae Park
@ 2022-09-09 20:28 ` SeongJae Park
  2022-09-09 20:28 ` [PATCH 4/7] Docs/admin-guide/mm/damon: rename the title of the document SeongJae Park
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: SeongJae Park @ 2022-09-09 20:28 UTC (permalink / raw)
  To: Andrew Morton; +Cc: damon, linux-mm, linux-kernel, SeongJae Park

Preceding commit fixes a bug in 'damon_set_regions()', which allows
holes in the new monitoring target ranges.  This commit adds a kunit
test case for the problem to avoid any regression.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/core-test.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
index 45db79d28fdc..3db9b7368756 100644
--- a/mm/damon/core-test.h
+++ b/mm/damon/core-test.h
@@ -267,6 +267,28 @@ static void damon_test_ops_registration(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL);
 }
 
+static void damon_test_set_regions(struct kunit *test)
+{
+	struct damon_target *t = damon_new_target();
+	struct damon_region *r1 = damon_new_region(4, 16);
+	struct damon_region *r2 = damon_new_region(24, 32);
+	struct damon_addr_range range = {.start = 8, .end = 28};
+	unsigned long expects[] = {8, 16, 16, 24, 24, 28};
+	int expect_idx = 0;
+	struct damon_region *r;
+
+	damon_add_region(r1, t);
+	damon_add_region(r2, t);
+	damon_set_regions(t, &range, 1);
+
+	KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 3);
+	damon_for_each_region(r, t) {
+		KUNIT_EXPECT_EQ(test, r->ar.start, expects[expect_idx++]);
+		KUNIT_EXPECT_EQ(test, r->ar.end, expects[expect_idx++]);
+	}
+	damon_destroy_target(t);
+}
+
 static struct kunit_case damon_test_cases[] = {
 	KUNIT_CASE(damon_test_target),
 	KUNIT_CASE(damon_test_regions),
@@ -276,6 +298,7 @@ static struct kunit_case damon_test_cases[] = {
 	KUNIT_CASE(damon_test_merge_regions_of),
 	KUNIT_CASE(damon_test_split_regions_of),
 	KUNIT_CASE(damon_test_ops_registration),
+	KUNIT_CASE(damon_test_set_regions),
 	{},
 };
 
-- 
2.25.1


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

* [PATCH 4/7] Docs/admin-guide/mm/damon: rename the title of the document
  2022-09-09 20:28 [PATCH 0/7] mm/damon: minor fixes and cleanups SeongJae Park
                   ` (2 preceding siblings ...)
  2022-09-09 20:28 ` [PATCH 3/7] mm/damon/core-test: test damon_set_regions SeongJae Park
@ 2022-09-09 20:28 ` SeongJae Park
  2022-09-09 20:28 ` [PATCH 5/7] mm/damon/Kconfig: Notify debugfs deprecation plan SeongJae Park
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: SeongJae Park @ 2022-09-09 20:28 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Jonathan Corbet, damon, linux-mm, linux-doc, linux-kernel, SeongJae Park

The title of the DAMON document for admin-guide, 'Monitoring Data
Accesses', could confuse readers in some ways.  First of all, DAMON is
not the only single way for data access monitoring.  And the document is
for not only the data access monitoring but also data access pattern
based memory management optimizations (DAMOS).  This commit updates the
title to 'DAMON: Data Access MONitor', which more explicitly explains
what the document describes.

Fixes: c4ba6014aec3 ("Documentation: add documents for DAMON")
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 Documentation/admin-guide/mm/damon/index.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/admin-guide/mm/damon/index.rst b/Documentation/admin-guide/mm/damon/index.rst
index 05500042f777..33d37bb2fb4e 100644
--- a/Documentation/admin-guide/mm/damon/index.rst
+++ b/Documentation/admin-guide/mm/damon/index.rst
@@ -1,8 +1,8 @@
 .. SPDX-License-Identifier: GPL-2.0
 
-========================
-Monitoring Data Accesses
-========================
+==========================
+DAMON: Data Access MONitor
+==========================
 
 :doc:`DAMON </mm/damon/index>` allows light-weight data access monitoring.
 Using DAMON, users can analyze the memory access patterns of their systems and
-- 
2.25.1


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

* [PATCH 5/7] mm/damon/Kconfig: Notify debugfs deprecation plan
  2022-09-09 20:28 [PATCH 0/7] mm/damon: minor fixes and cleanups SeongJae Park
                   ` (3 preceding siblings ...)
  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 ` 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
  6 siblings, 0 replies; 8+ messages in thread
From: SeongJae Park @ 2022-09-09 20:28 UTC (permalink / raw)
  To: Andrew Morton; +Cc: damon, linux-mm, linux-kernel, SeongJae Park

Commit b18402726bd1 ("Docs/admin-guide/mm/damon/usage: document DAMON
sysfs interface") announced the DAMON debugfs interface deprecation
plan, but it is not so aggressively announced.  As the deprecation time
is coming, this commit makes the announce more easy to be found by
adding the note to the config menu of DAMON debugfs interface.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/Kconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/damon/Kconfig b/mm/damon/Kconfig
index 66265e3a9c65..7821fcb3f258 100644
--- a/mm/damon/Kconfig
+++ b/mm/damon/Kconfig
@@ -68,6 +68,9 @@ config DAMON_DBGFS
 
 	  If unsure, say N.
 
+	  This will be removed after >5.15.y LTS kernel is released, so users
+	  should move to the sysfs interface (DAMON_SYSFS).
+
 config DAMON_DBGFS_KUNIT_TEST
 	bool "Test for damon debugfs interface" if !KUNIT_ALL_TESTS
 	depends on DAMON_DBGFS && KUNIT=y
-- 
2.25.1


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

* [PATCH 6/7] Docs/admin-guide/mm/damon/start: mention the dependency as sysfs instead of debugfs
  2022-09-09 20:28 [PATCH 0/7] mm/damon: minor fixes and cleanups SeongJae Park
                   ` (4 preceding siblings ...)
  2022-09-09 20:28 ` [PATCH 5/7] mm/damon/Kconfig: Notify debugfs deprecation plan SeongJae Park
@ 2022-09-09 20:29 ` SeongJae Park
  2022-09-09 20:29 ` [PATCH 7/7] Docs/admin-guide/mm/damon/usage: note DAMON debugfs interface deprecation plan SeongJae Park
  6 siblings, 0 replies; 8+ messages in thread
From: SeongJae Park @ 2022-09-09 20:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Jonathan Corbet, damon, linux-mm, linux-doc, linux-kernel, SeongJae Park

'Getting Started' document of DAMON says DAMON user-space tool, damo[1],
is using DAMON debugfs interface, and therefore it needs to ensure
debugfs is mounted.  However, the latest version of the tool is using
DAMON sysfs interface.  Moreover, DAMON debugfs interface is going to be
deprecated as announced by commit b18402726bd1
("Docs/admin-guide/mm/damon/usage: document DAMON sysfs interface").

This commit therefore update the document to tell readers about DAMON
sysfs interface dependency instead and never mention about debugfs
interface, which will be deprecated.

[1] https://github.com/awslabs/damo

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 Documentation/admin-guide/mm/damon/start.rst | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/Documentation/admin-guide/mm/damon/start.rst b/Documentation/admin-guide/mm/damon/start.rst
index 4d5ca2c46288..9f88afc734da 100644
--- a/Documentation/admin-guide/mm/damon/start.rst
+++ b/Documentation/admin-guide/mm/damon/start.rst
@@ -29,16 +29,9 @@ called DAMON Operator (DAMO).  It is available at
 https://github.com/awslabs/damo.  The examples below assume that ``damo`` is on
 your ``$PATH``.  It's not mandatory, though.
 
-Because DAMO is using the debugfs interface (refer to :doc:`usage` for the
-detail) of DAMON, you should ensure debugfs is mounted.  Mount it manually as
-below::
-
-    # mount -t debugfs none /sys/kernel/debug/
-
-or append the following line to your ``/etc/fstab`` file so that your system
-can automatically mount debugfs upon booting::
-
-    debugfs /sys/kernel/debug debugfs defaults 0 0
+Because DAMO is using the sysfs interface (refer to :doc:`usage` for the
+detail) of DAMON, you should ensure :doc:`sysfs </filesystems/sysfs>` is
+mounted.
 
 
 Recording Data Access Patterns
-- 
2.25.1


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

* [PATCH 7/7] Docs/admin-guide/mm/damon/usage: note DAMON debugfs interface deprecation plan
  2022-09-09 20:28 [PATCH 0/7] mm/damon: minor fixes and cleanups SeongJae Park
                   ` (5 preceding siblings ...)
  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 ` SeongJae Park
  6 siblings, 0 replies; 8+ messages in thread
From: SeongJae Park @ 2022-09-09 20:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Jonathan Corbet, damon, linux-mm, linux-doc, linux-kernel, SeongJae Park

Commit b18402726bd1 ("Docs/admin-guide/mm/damon/usage: document DAMON
sysfs interface") announced the DAMON debugfs interface deprecation
plan, but it is not so aggressively announced.  As the deprecation time
is coming, this commit makes the announce more easy to be found by
adding the note at the beginning of the DAMON debugfs interface usage
document.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 Documentation/admin-guide/mm/damon/usage.rst | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index d52f572a9029..c050b882ddc1 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -393,6 +393,11 @@ the files as above.  Above is only for an example.
 debugfs Interface
 =================
 
+.. note::
+
+  DAMON debugfs interface will be removed after next LTS kernel is released, so
+  users should move to the :ref:`sysfs interface <sysfs_interface>`.
+
 DAMON exports eight files, ``attrs``, ``target_ids``, ``init_regions``,
 ``schemes``, ``monitor_on``, ``kdamond_pid``, ``mk_contexts`` and
 ``rm_contexts`` under its debugfs directory, ``<debugfs>/damon/``.
-- 
2.25.1


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

end of thread, other threads:[~2022-09-09 20:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/7] mm/damon/core: avoid holes in newly set monitoring target ranges SeongJae Park
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).