mm/damon: five misc fixups
Subsystems (5)
SJ Park
maintainercover mm/damon: five misc fixups
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
Signature · 1 line
2.47.3
SJ Park
maintainerPATCH 1/5 mm/damon/core: use kvmalloc for target regions array
From: Akinobu Mita <[email protected]>
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.
---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.
mm/damon/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/damon/core.c +2 -2
@@ -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; }
Signature · 1 line
2.47.3
SJ Park
maintainerPATCH 2/5 mm/damon/stat: use secs_to_jiffies() instead of msecs_to_jiffies()
In reply to SJ ParkFrom: Philippe Laferriere <[email protected]>
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).
---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.
mm/damon/stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/stat.c +1 -1
@@ -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;
Signature · 1 line
2.47.3
SJ Park
maintainerPATCH 3/5 Docs/{admin-guide,mm}/damon: fix DAMON documentation details
In reply to SJ ParkFrom: Doehyun Baek <[email protected]>
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.
---
Changes from v5
- v5: https://lore.kernel.org/[email protected]
- 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(-)
Documentation/admin-guide/mm/damon/usage.rst +4 -4
@@ -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
Documentation/mm/damon/design.rst +6 -6
@@ -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:
Signature · 1 line
2.47.3
SJ Park
maintainerPATCH 4/5 samples/damon: Fix typos in Kconfig help text
In reply to SJ ParkFrom: Asier Gutierrez <[email protected]>
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/[email protected]
- Fix one more type: s/tierign/tiering/
- Add R-b: from SJ.
- Rebase to latest mm-new.
--- samples/damon/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
samples/damon/Kconfig +1 -1
@@ -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,
Signature · 1 line
2.47.3
SJ Park
maintainerPATCH 5/5 mm/damon/tests/core-kunit: add KUnit test for walk_control_obsolete behavior
In reply to SJ ParkFrom: Sailesh Nandanavanam <[email protected]>
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.
---
Changes from v3
- v3: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.
Changes since v2
- v2: https://lore.kernel.org/[email protected]
- 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/[email protected]
- 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(+)
mm/damon/tests/core-kunit.h +28 -0
@@ -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), {}, };
Signature · 1 line
2.47.3
SJ Park
maintainerRe: [PATCH 1/5] mm/damon/core: use kvmalloc for target regions array
In reply to SJ ParkQuoted 8 lines · On Mon, 29 Jun 2026 07:55:32 -0700 SJ Park <[email protected]> wrote:
From: Akinobu Mita <[email protected]>
damon_commit_target_regions()temporarily allocates a single contiguous memory region using kmalloc to store copies of alldamon_regionsof thedamon_target.
However, if thedamon_targethas a large number ofdamon_regions, the total size may exceedKMALLOC_MAX_SIZE.
Quoted 4 lines
This problem can be avoided by using kvmalloc instead of kmalloc.
Signed-off-by Akinobu Mita <[email protected]>Reviewed-by SJ Park <[email protected]>
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
[...]