Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] mm/damon: five misc fixups
@ 2026-06-29 14:55 SJ Park
  2026-06-29 14:55 ` [PATCH 1/5] mm/damon/core: use kvmalloc for target regions array SJ Park
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: SJ Park @ 2026-06-29 14:55 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SJ Park, Liam R. Howlett, Brendan Higgins, David Gow,
	David Hildenbrand, Jonathan Corbet, Lorenzo Stoakes, Michal Hocko,
	Mike Rapoport, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
	damon, kunit-dev, linux-doc, linux-kernel, linux-kselftest,
	linux-mm

Five patches for miscellaneous DAMON fixups.  Use better fit kernel
functions, cleanup/fixup documents, and add unit tests.

Below is a note that is better to drop from the final commit message.
The five patches were initially sent and revisioned by different
individuals.  Each patch contains changelog on their commentary area.
The patches are curated into this series by SJ, for the convenience in
reposting.

Akinobu Mita (1):
  mm/damon/core: use kvmalloc for target regions array

Asier Gutierrez (1):
  samples/damon: Fix typos in Kconfig help text

Doehyun Baek (1):
  Docs/{admin-guide,mm}/damon: fix DAMON documentation details

Philippe Laferriere (1):
  mm/damon/stat: use secs_to_jiffies() instead of msecs_to_jiffies()

Sailesh Nandanavanam (1):
  mm/damon/tests/core-kunit: add KUnit test for walk_control_obsolete
    behavior

 Documentation/admin-guide/mm/damon/usage.rst |  8 +++---
 Documentation/mm/damon/design.rst            | 12 ++++-----
 mm/damon/core.c                              |  4 +--
 mm/damon/stat.c                              |  2 +-
 mm/damon/tests/core-kunit.h                  | 28 ++++++++++++++++++++
 samples/damon/Kconfig                        |  2 +-
 6 files changed, 42 insertions(+), 14 deletions(-)


base-commit: 58a53a487b7a86995fdfba07723fb8416fccf830
-- 
2.47.3


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

* [PATCH 1/5] mm/damon/core: use kvmalloc for target regions array
  2026-06-29 14:55 [PATCH 0/5] mm/damon: five misc fixups SJ Park
@ 2026-06-29 14:55 ` SJ Park
  2026-06-30  5:57   ` SJ Park
  2026-06-29 14:55 ` [PATCH 2/5] mm/damon/stat: use secs_to_jiffies() instead of msecs_to_jiffies() SJ Park
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: SJ Park @ 2026-06-29 14:55 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Akinobu Mita, SJ Park, damon, linux-kernel, linux-mm, SJ Park

From: Akinobu Mita <akinobu.mita@gmail.com>

damon_commit_target_regions() temporarily allocates a single contiguous
memory region using kmalloc to store copies of all damon_regions of the
damon_target.
However, if the damon_target has a large number of damon_regions, the
total size may exceed KMALLOC_MAX_SIZE.

This problem can be avoided by using kvmalloc instead of kmalloc.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Reviewed-by: SJ Park <sj@kkernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20260603112306.58490-1-akinobu.mita@gmail.com
- Collect R-b: from SJ.
- Rebase to latest mm-new.

 mm/damon/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 3dd2750c2ef20..ded76719e8a14 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1362,14 +1362,14 @@ static int damon_commit_target_regions(struct damon_target *dst,
 	if (!i)
 		return 0;
 
-	ranges = kmalloc_objs(*ranges, i, GFP_KERNEL | __GFP_NOWARN);
+	ranges = kvmalloc_objs(*ranges, i, GFP_KERNEL | __GFP_NOWARN);
 	if (!ranges)
 		return -ENOMEM;
 	i = 0;
 	damon_for_each_region(src_region, src)
 		ranges[i++] = src_region->ar;
 	err = damon_set_regions(dst, ranges, i, src_min_region_sz);
-	kfree(ranges);
+	kvfree(ranges);
 	return err;
 }
 
-- 
2.47.3


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

* [PATCH 2/5] mm/damon/stat: use secs_to_jiffies() instead of msecs_to_jiffies()
  2026-06-29 14:55 [PATCH 0/5] mm/damon: five misc fixups SJ Park
  2026-06-29 14:55 ` [PATCH 1/5] mm/damon/core: use kvmalloc for target regions array SJ Park
@ 2026-06-29 14:55 ` SJ Park
  2026-06-29 14:55 ` [PATCH 3/5] Docs/{admin-guide,mm}/damon: fix DAMON documentation details SJ Park
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-06-29 14:55 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Philippe Laferriere, SJ Park, damon, linux-kernel, linux-mm

From: Philippe Laferriere <plafer@proton.me>

The conversion of a duration expressed in seconds reads as
msecs_to_jiffies(5 * MSEC_PER_SEC), which obscures the intent and
needlessly goes through milliseconds. Use the dedicated
secs_to_jiffies() helper, which expresses the 5-second refresh
interval directly. No functional change.

Found using Coccinelle (scripts/coccinelle/misc/secs_to_jiffies.cocci).

Signed-off-by: Philippe Laferriere <plafer@proton.me>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20260615214113.122923-1-plafer@proton.me
- Collect R-b: from SJ.
- Rebase to latest mm-new.

 mm/damon/stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/damon/stat.c b/mm/damon/stat.c
index 0e14f5bb8f75d..b05b68f73e10d 100644
--- a/mm/damon/stat.c
+++ b/mm/damon/stat.c
@@ -138,7 +138,7 @@ static int damon_stat_damon_call_fn(void *data)
 
 	/* avoid unnecessarily frequent stat update */
 	if (time_before_eq(jiffies, damon_stat_last_refresh_jiffies +
-				msecs_to_jiffies(5 * MSEC_PER_SEC)))
+				secs_to_jiffies(5)))
 		return 0;
 	damon_stat_last_refresh_jiffies = jiffies;
 
-- 
2.47.3


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

* [PATCH 3/5] Docs/{admin-guide,mm}/damon: fix DAMON documentation details
  2026-06-29 14:55 [PATCH 0/5] mm/damon: five misc fixups SJ Park
  2026-06-29 14:55 ` [PATCH 1/5] mm/damon/core: use kvmalloc for target regions array SJ Park
  2026-06-29 14:55 ` [PATCH 2/5] mm/damon/stat: use secs_to_jiffies() instead of msecs_to_jiffies() SJ Park
@ 2026-06-29 14:55 ` SJ Park
  2026-06-29 14:55 ` [PATCH 4/5] samples/damon: Fix typos in Kconfig help text SJ Park
  2026-06-29 14:55 ` [PATCH 5/5] mm/damon/tests/core-kunit: add KUnit test for walk_control_obsolete behavior SJ Park
  4 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-06-29 14:55 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Doehyun Baek, Liam R. Howlett, David Hildenbrand, Jonathan Corbet,
	Lorenzo Stoakes, Michal Hocko, Mike Rapoport, SJ Park, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, damon, linux-doc,
	linux-kernel, linux-mm

From: Doehyun Baek <doehyunbaek@gmail.com>

Fix minor DAMON documentation issues.  Correct the sysfs scheme file name
apply_interval_us, the DAMON_STAT module count, a malformed reference, a
misplaced label indentation, and a few typos.

Signed-off-by: Doehyun Baek <doehyunbaek@gmail.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: "Liam R. Howlett" <liam@infradead.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v5
- v5: https://lore.kernel.org/20260610053951.553739-1-doehyunbaek@gmail.com
- Collect R-b: from SJ.
- Rebase to latest mm-new.

 Documentation/admin-guide/mm/damon/usage.rst |  8 ++++----
 Documentation/mm/damon/design.rst            | 12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index 011296f1e7c21..b2649ea011f93 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -246,7 +246,7 @@ writing to and reading from the files.
 Under ``nr_regions`` directory, two files for the lower-bound and upper-bound
 of DAMON's monitoring regions (``min`` and ``max``, respectively), which
 controls the monitoring overhead, exist.  You can set and get the values by
-writing to and rading from the files.
+writing to and reading from the files.
 
 For more details about the intervals and monitoring regions range, please refer
 to the Design document (:doc:`/mm/damon/design`).
@@ -264,7 +264,7 @@ Please refer to  the :ref:`design document of the feature
 <damon_design_monitoring_intervals_autotuning>` for the internal of the tuning
 mechanism.  Reading and writing the four files under ``intervals_goal``
 directory shows and updates the tuning parameters that described in the
-:ref:design doc <damon_design_monitoring_intervals_autotuning>` with the same
+:ref:`design doc <damon_design_monitoring_intervals_autotuning>` with the same
 names.  The tuning starts with the user-set ``sample_us`` and ``aggr_us``.  The
 tuning-applied current values of the two intervals can be read from the
 ``sample_us`` and ``aggr_us`` files after writing ``update_tuned_intervals`` to
@@ -377,7 +377,7 @@ schemes/<N>/
 In each scheme directory, nine directories (``access_pattern``, ``quotas``,
 ``watermarks``, ``core_filters``, ``ops_filters``, ``filters``, ``dests``,
 ``stats``, and ``tried_regions``) and three files (``action``, ``target_nid``
-and ``apply_interval``) exist.
+and ``apply_interval_us``) exist.
 
 The ``action`` file is for setting and getting the scheme's :ref:`action
 <damon_design_damos_action>`.  The keywords that can be written to and read
@@ -743,7 +743,7 @@ counter).  Finally the tenth field (``X``) shows the ``age`` of the region
 (refer to :ref:`design <damon_design_age_tracking>` for more details of the
 counter).
 
-If the event was ``damon:damos_beofre_apply``, the ``perf script`` output would
+If the event was ``damon:damos_before_apply``, the ``perf script`` output would
 be somewhat like below::
 
     kdamond.0 47293 [000] 80801.060214: damon:damos_before_apply: ctx_idx=0 scheme_idx=0 target_idx=0 nr_regions=11 121932607488-135128711168: 0 136
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index 2da7ca0d3d17a..c16a3bb288d07 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -86,7 +86,7 @@ To know how user-space can do the configuration via :ref:`DAMON sysfs interface
 documentation.
 
 
- .. _damon_design_vaddr_target_regions_construction:
+.. _damon_design_vaddr_target_regions_construction:
 
 VMA-based Target Address Range Construction
 -------------------------------------------
@@ -930,11 +930,11 @@ control parameters for the usage would also need to be optimized for the
 purpose.
 
 To support such cases, yet more DAMON API user kernel modules that provide more
-simple and optimized user space interfaces are available.  Currently, two
-modules for proactive reclamation and LRU lists manipulation are provided.  For
-more detail, please read the usage documents for those
-(:doc:`/admin-guide/mm/damon/stat`, :doc:`/admin-guide/mm/damon/reclaim` and
-:doc:`/admin-guide/mm/damon/lru_sort`).
+simple and optimized user space interfaces are available.  Currently, three
+modules for access monitoring statistics, proactive reclamation, and LRU lists
+manipulation are provided.  For more detail, please read the usage documents for
+those (:doc:`/admin-guide/mm/damon/stat`, :doc:`/admin-guide/mm/damon/reclaim`
+and :doc:`/admin-guide/mm/damon/lru_sort`).
 
 .. _damon_design_special_purpose_modules_exclusivity:
 
-- 
2.47.3


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

* [PATCH 4/5] samples/damon: Fix typos in Kconfig help text
  2026-06-29 14:55 [PATCH 0/5] mm/damon: five misc fixups SJ Park
                   ` (2 preceding siblings ...)
  2026-06-29 14:55 ` [PATCH 3/5] Docs/{admin-guide,mm}/damon: fix DAMON documentation details SJ Park
@ 2026-06-29 14:55 ` SJ Park
  2026-06-29 14:55 ` [PATCH 5/5] mm/damon/tests/core-kunit: add KUnit test for walk_control_obsolete behavior SJ Park
  4 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-06-29 14:55 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Asier Gutierrez, SJ Park, damon, linux-kernel, linux-mm

From: Asier Gutierrez <gutierrez.asier@huawei-partners.com>

Fix a couple  of typos in samples/damon/Kconfig help text. Change "Thps"
to "This", and "tierign" to "tiering".

Changes from v1
- v1: https://lore.kernel.org/20260617065716.750179-1-gutierrez.asier@huawei-partners.com
- Fix one more type: s/tierign/tiering/
- Add R-b: from SJ.
- Rebase to latest mm-new.

Signed-off-by: Asier Gutierrez <gutierrez.asier@huawei-partners.com>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
 samples/damon/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/samples/damon/Kconfig b/samples/damon/Kconfig
index cbf96fd8a8bf9..00be3e6bdd659 100644
--- a/samples/damon/Kconfig
+++ b/samples/damon/Kconfig
@@ -31,7 +31,7 @@ config SAMPLE_DAMON_MTIER
 	bool "DAMON sample module for memory tiering"
 	depends on DAMON && DAMON_PADDR
 	help
-	  Thps builds DAMON sample module for memory tierign.
+	  This builds DAMON sample module for memory tiering.
 
 	  The module assumes the system is constructed with two NUMA nodes,
 	  which seems as local and remote nodes to all CPUs.  For example,
-- 
2.47.3


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

* [PATCH 5/5] mm/damon/tests/core-kunit: add KUnit test for walk_control_obsolete behavior
  2026-06-29 14:55 [PATCH 0/5] mm/damon: five misc fixups SJ Park
                   ` (3 preceding siblings ...)
  2026-06-29 14:55 ` [PATCH 4/5] samples/damon: Fix typos in Kconfig help text SJ Park
@ 2026-06-29 14:55 ` SJ Park
  4 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-06-29 14:55 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Sailesh Nandanavanam, Brendan Higgins, David Gow, SJ Park, damon,
	kunit-dev, linux-kernel, linux-kselftest, linux-mm

From: Sailesh Nandanavanam <saileshnandanavanam@gmail.com>

Add a KUnit test to verify that damos_walk() rejects
new requests when walk_control_obsolete is set.

Commit 33c3f6c2b48c ("mm/damon/core: fix damos_walk() vs
kdamond_fn() exit race") introduced walk_control_obsolete
to prevent a race condition where new requests could be
registered during kdamond shutdown and never handled.

This test simulates the shutdown condition by setting
walk_control_obsolete and verifies that damos_walk()
returns -ECANCELED immediately.

This validates the invariant introduced by the fix and
helps prevent regressions.

Link: https://patch.msgid.link/20260612062337.2459-1-saileshnandanavanam@gmail.com
Suggested-by: SJ Park <sj@kernel.org>
Signed-off-by: Sailesh Nandanavanam <saileshnandanavanam@gmail.com>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v3
- v3: https://lore.kernel.org/20260612062337.2459-1-saileshnandanavanam@gmail.com
- Collect R-b: from SJ.
- Rebase to latest mm-new.
Changes since v2
- v2: https://lore.kernel.org/20260524100258.36819-1-saileshnandanavanam@gmail.com
- Dropped the userspace selftest approach entirely. SJ tested
  v2 100 times on a kernel with the fix reverted and it always
  passed, confirming the microsecond-wide race window cannot be
  reliably hit from userspace due to syscall overhead.
- Added a KUnit test for damos_walk() + walk_control_obsolete
  instead, as suggested by SJ. This directly sets the
  obsolete flag and verifies damos_walk() returns -ECANCELED
  immediately, without timing dependency.
Changes since v1
- v1: https://lore.kernel.org/20260524091812.35283-1-saileshnandanavanam@gmail.com
- Addressed sashiko bot review comments (execute bit, threading,
  dynamic sysfs path, OSError handling) - superseded by the v3
  approach above.

 mm/damon/tests/core-kunit.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index fcf7c7fadb5fe..c5f5124c3d1f4 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -1456,6 +1456,33 @@ static void damon_test_is_last_region(struct kunit *test)
 	damon_free_target(t);
 }
 
+/*
+ * Verify that damos_walk() rejects new requests when
+ * walk_control_obsolete is set.
+ *
+ * This tests the invariant introduced by:
+ * commit 33c3f6c2b48c ("mm/damon/core: fix damos_walk() vs kdamond_fn() exit race")
+ */
+static void damon_test_walk_control_obsolete(struct kunit *test)
+{
+	struct damon_ctx *ctx;
+	struct damos_walk_control control = {};
+	int ret;
+
+	ctx = damon_new_ctx();
+	if (!ctx)
+		kunit_skip(test, "ctx alloc fail");
+
+	/* Simulate shutdown phase */
+	ctx->walk_control_obsolete = true;
+
+	ret = damos_walk(ctx, &control);
+
+	KUNIT_EXPECT_EQ(test, ret, -ECANCELED);
+
+	damon_destroy_ctx(ctx);
+}
+
 static struct kunit_case damon_test_cases[] = {
 	KUNIT_CASE(damon_test_target),
 	KUNIT_CASE(damon_test_regions),
@@ -1485,6 +1512,7 @@ static struct kunit_case damon_test_cases[] = {
 	KUNIT_CASE(damon_test_set_filters_default_reject),
 	KUNIT_CASE(damon_test_apply_min_nr_regions),
 	KUNIT_CASE(damon_test_is_last_region),
+	KUNIT_CASE(damon_test_walk_control_obsolete),
 	{},
 };
 
-- 
2.47.3


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

* Re: [PATCH 1/5] mm/damon/core: use kvmalloc for target regions array
  2026-06-29 14:55 ` [PATCH 1/5] mm/damon/core: use kvmalloc for target regions array SJ Park
@ 2026-06-30  5:57   ` SJ Park
  0 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-06-30  5:57 UTC (permalink / raw)
  To: SJ Park; +Cc: Andrew Morton, Akinobu Mita, damon, linux-kernel, linux-mm,
	SJ Park

On Mon, 29 Jun 2026 07:55:32 -0700 SJ Park <sj@kernel.org> wrote:

> From: Akinobu Mita <akinobu.mita@gmail.com>
> 
> damon_commit_target_regions() temporarily allocates a single contiguous
> memory region using kmalloc to store copies of all damon_regions of the
> damon_target.
> However, if the damon_target has a large number of damon_regions, the
> total size may exceed KMALLOC_MAX_SIZE.
> 
> This problem can be avoided by using kvmalloc instead of kmalloc.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Reviewed-by: SJ Park <sj@kkernel.org>

Oops, another typo...  Should do s/kkernel/kernel/

Andrew, I saw this is already picked up to mm-new.  Could you please fix this
up in place?  Let me know if you'd prefer sending a new revision with the fix.


Thanks,
SJ

[...]


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

end of thread, other threads:[~2026-06-30  5:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29 14:55 [PATCH 0/5] mm/damon: five misc fixups SJ Park
2026-06-29 14:55 ` [PATCH 1/5] mm/damon/core: use kvmalloc for target regions array SJ Park
2026-06-30  5:57   ` SJ Park
2026-06-29 14:55 ` [PATCH 2/5] mm/damon/stat: use secs_to_jiffies() instead of msecs_to_jiffies() SJ Park
2026-06-29 14:55 ` [PATCH 3/5] Docs/{admin-guide,mm}/damon: fix DAMON documentation details SJ Park
2026-06-29 14:55 ` [PATCH 4/5] samples/damon: Fix typos in Kconfig help text SJ Park
2026-06-29 14:55 ` [PATCH 5/5] mm/damon/tests/core-kunit: add KUnit test for walk_control_obsolete behavior SJ Park

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