From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D48EE56A; Wed, 15 Jul 2026 04:45:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784090727; cv=none; b=OWdK3vycctopjXjzwFf3mlKCnKCBHnj8EVILPw7olr2vzeZFOKKpz+hEVh0vvIF7BLlS7MGm/tp+TVWOAoN/Ud8ovmPKnF6q7EoyHhUjerf55PvO/rk5Tu7LySSQJ7m0NhvuBhJ+MQ2QNrGepxP9IUL+m9iJUw6L4eBxBUuwSbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784090727; c=relaxed/simple; bh=OH1+0eHjuiB3yX5B7S+mkdLETjrxQuuO9xbyYlQfezc=; h=Date:To:From:Subject:Message-Id; b=Szqg5VrZXHBi5AqbVLfEzQIQseLHPKwFDDABvUx25/1mAYyE1R2CX0yIq92NLcgOWWBfJEyerAzkxz8MxLD7cB9qAsdDHNyAkmTgj1YYHUaKC1zsJK1NN+LFaDnC4FrJ3Sy1MNtmTX7MxoX/l8UmDohOlVMce7PxHiJNiiXQyxc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=qLjgL1uK; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="qLjgL1uK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2ED2F1F00A3A; Wed, 15 Jul 2026 04:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1784090725; bh=xRnHFavFxNiLXAt6CIpCdyVkqL6x1wN96KB/4sWIEEw=; h=Date:To:From:Subject; b=qLjgL1uKULLDxBL1eKAcy0igOpk3Ug9T9/sd0YWcXM1EfVyP/6DZ+vFCKAJexY+Ox SLpoO8slTRY3nlR5G1qf5zQXhjOZ/S/qsfuEjcX4So9e2nMGKkUaOMXUpo66QF2FZV gwKuWLGBV49oqm02cXDAdyJYpxCCUySJZBDl5xZU= Date: Tue, 14 Jul 2026 21:45:24 -0700 To: mm-commits@vger.kernel.org,stable@vger.kernel.org,sj@kernel.org,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-damon-vaddr-drop-last-same-folio-access-check-optimization.patch added to mm-new branch Message-Id: <20260715044525.2ED2F1F00A3A@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: mm/damon/vaddr: drop last same folio access check optimization has been added to the -mm mm-new branch. Its filename is mm-damon-vaddr-drop-last-same-folio-access-check-optimization.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-damon-vaddr-drop-last-same-folio-access-check-optimization.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: SJ Park Subject: mm/damon/vaddr: drop last same folio access check optimization Date: Tue, 14 Jul 2026 20:09:58 -0700 The optimization can race when multiple kdamonds are running. Meanwhile, the impact of the optimization is quite doubtful. Just remove it. The user impact of the issue should be quite trivial. After all, the race can happen only when the user intentionally setup DAMON in the way. Even if it happens, it would be rare and only degrade the best-effort monitoring results. No critical consequences like kernel panic or memory corruption happen. The race possibility was discovered [1] by Sashiko. Link: https://lore.kernel.org/20260715031002.108504-4-sj@kernel.org Link: https://lore.kernel.org/20260621204050.10993-1-sj@kernel.org [1] Fixes: 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces") Signed-off-by: SJ Park Cc: # 5.15.x Signed-off-by: Andrew Morton --- mm/damon/vaddr.c | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) --- a/mm/damon/vaddr.c~mm-damon-vaddr-drop-last-same-folio-access-check-optimization +++ a/mm/damon/vaddr.c @@ -383,8 +383,6 @@ static void damon_va_prepare_access_chec } struct damon_young_walk_private { - /* size of the folio for the access checked virtual memory address */ - unsigned long *folio_sz; bool young; }; @@ -411,7 +409,6 @@ static int damon_young_pmd_entry(pmd_t * mmu_notifier_test_young(walk->mm, addr)) priv->young = true; - *priv->folio_sz = HPAGE_PMD_SIZE; huge_out: spin_unlock(ptl); return 0; @@ -430,7 +427,6 @@ huge_out: if (pte_young(ptent) || !folio_test_idle(folio) || mmu_notifier_test_young(walk->mm, addr)) priv->young = true; - *priv->folio_sz = folio_size(folio); out: pte_unmap_unlock(pte, ptl); return 0; @@ -458,7 +454,6 @@ static int damon_young_hugetlb_entry(pte if (pte_young(entry) || !folio_test_idle(folio) || mmu_notifier_test_young(walk->mm, addr)) priv->young = true; - *priv->folio_sz = huge_page_size(h); folio_put(folio); @@ -470,11 +465,9 @@ out: #define damon_young_hugetlb_entry NULL #endif /* CONFIG_HUGETLB_PAGE */ -static bool damon_va_young(struct mm_struct *mm, unsigned long addr, - unsigned long *folio_sz) +static bool damon_va_young(struct mm_struct *mm, unsigned long addr) { struct damon_young_walk_private arg = { - .folio_sz = folio_sz, .young = false, }; @@ -494,28 +487,17 @@ static bool damon_va_young(struct mm_str * r the region to be checked */ static void __damon_va_check_access(struct mm_struct *mm, - struct damon_region *r, bool same_target) + struct damon_region *r) { - static unsigned long last_addr; - static unsigned long last_folio_sz = PAGE_SIZE; - static bool last_accessed; + bool accessed; if (!mm) { damon_update_region_access_rate(r, false); return; } - /* If the region is in the last checked page, reuse the result */ - if (same_target && (ALIGN_DOWN(last_addr, last_folio_sz) == - ALIGN_DOWN(r->sampling_addr, last_folio_sz))) { - damon_update_region_access_rate(r, last_accessed); - return; - } - - last_accessed = damon_va_young(mm, r->sampling_addr, &last_folio_sz); - damon_update_region_access_rate(r, last_accessed); - - last_addr = r->sampling_addr; + accessed = damon_va_young(mm, r->sampling_addr); + damon_update_region_access_rate(r, accessed); } static unsigned int damon_va_check_accesses(struct damon_ctx *ctx) @@ -524,15 +506,12 @@ static unsigned int damon_va_check_acces struct mm_struct *mm; struct damon_region *r; unsigned int max_nr_accesses = 0; - bool same_target; damon_for_each_target(t, ctx) { mm = damon_get_mm(t); - same_target = false; damon_for_each_region(r, t) { - __damon_va_check_access(mm, r, same_target); + __damon_va_check_access(mm, r); max_nr_accesses = max(r->nr_accesses, max_nr_accesses); - same_target = true; } if (mm) mmput(mm); _ Patches currently in -mm which might be from sj@kernel.org are samples-damon-wsse-handle-damon_start-failure.patch samples-damon-prcl-handle-damon_start-failure.patch samples-damon-mtier-handle-damon_start-failure.patch samples-damon-mtier-handle-damon_stop-failure.patch samples-damon-wsse-stop-and-free-damon-ctx-when-damon_call-fails.patch samples-damon-prcl-stop-and-free-damon-ctx-when-damon_call-fails.patch mm-damon-sysfs-kobject_del-target-normal-context-and-kdamond-dirs.patch mm-damon-sysfs-kobject_del-region-and-target-error-dirs.patch mm-damon-sysfs-schemes-kobject_del-scheme-dirs.patch mm-damon-sysfs-schemes-kobject_del-scheme-region-dirs.patch mm-damon-sysfs-schemes-kobject_del-scheme-filter-dirs.patch mm-damon-sysfs-schemes-kobject_del-scheme-quota-goal-dirs.patch mm-damon-sysfs-schemes-kobject_del-scheme-action-destination-dirs.patch mm-damon-sysfs-kobject_del-probe-dirs.patch mm-damon-sysfs-kobject_del-probe-filter-dirs.patch mm-damon-sysfs-kobject_del-probe-dirs-in-probes_addd_dir-error-path.patch mm-damon-sysfs-schemes-kobject_del-region-for-populate_region-error.patch docs-mm-damon-design-update-for-damos_quota_node_eligible_mem_bp.patch docs-abi-damon-document-probe-files.patch mm-damon-tests-core-kunit-test-damon_rand.patch selftests-damon-sysfssh-test-multiple-probe-dirs-creation.patch selftests-damon-sysfssh-test-coreops_filters-directories.patch selftests-damon-sysfssh-test-dests-dir.patch selftests-damon-sysfssh-test-all-files-in-quota-goal-dir.patch mm-damon-core-reduce-range-setup-in-damon_commit_target_regions.patch mm-damon-sysfs-split-probe-setup-function-out.patch mm-damon-sysfs-split-out-filters-setup-function.patch mm-damon-sysfs-fix-typos-in-probe_addrm_dirs-s-attr-probe.patch mm-damon-core-introduce-damon_nr_accesses_mvsum.patch mm-damon-tests-core-kunit-test-damon_mvsum.patch mm-damon-core-always-update-last_nr_accesses-for-intervals-change.patch mm-damon-core-handle-unreset-nr_accesses-in-damon_nr_accesses_mvsum.patch mm-damon-core-use-damon_nr_accesses_mvsum-in-__damos_valid_target.patch mm-damon-core-use-damon_nr_accesses_mvsum-for-damos-region-tracing.patch mm-damon-sysfs-schemes-use-damon_nr_accesses_mvsum-for-damo-regions.patch mm-damon-core-remove-damon_warn_fix_nr_accesses_corruption.patch mm-damon-core-remove-damon_verify_reset_aggregated.patch mm-damon-core-remove-damon_verify_merge_regions_of.patch mm-damon-tests-core-kunit-remove-nr_accesses_bp-setup-and-tests.patch selftests-damon-drgn_dump_damon_status-do-not-dump-nr_accesses_bp.patch mm-damon-core-remove-nr_accesses_bp-setups-and-updates.patch mm-damon-core-remove-attrs-param-from-damon_update_region_access_rate.patch mm-damon-paddr-remove-attrs-param-from-__damon_pa_check_access.patch mm-damon-vaddr-remove-attrs-param-from-__damon_va_check_access.patch mm-damon-core-remove-damon_moving_sum-and-its-unit-test.patch mm-damon-core-remove-damon_region-nr_accesses_bp.patch mm-damon-add-damon_region-last_probe_hits.patch mm-damon-core-introduce-damon_probe_hits_mvsum.patch mm-damon-sysfs-schemes-set-probe-hits-as-pseudo-moving-sums.patch mm-damon-core-safely-validate-src-on-damon_commit_ctx.patch mm-damon-core-do-parameter-testing-commit-on-damon_start.patch mm-damon-sysfs-remove-duplicated-commit-input-validity-check.patch mm-damon-reclaim-remove-duplicated-min_region_sz-power-of-2-check.patch mm-damon-lru_sort-remove-duplicated-min_region_sz-power_of_2-check.patch mm-damon-document-region-size-validation-in-damon_set_regions.patch mm-damon-core-remove-start-end-check-in-damon_set_region_system_rams.patch mm-damon-sysfs-remove-region-size-validation.patch mm-damon-core-stop-ctxs-in-damon_start-before-returning-an-error.patch samples-damon-mtier-do-not-stop-first-context-for-damon_start-failure.patch mm-damon-core-make-damon_stop-never-fails.patch mm-damon-sysfs-ignore-damon_stop-return-value.patch mm-damon-reclaaim-ignore-damon_stop-return-value.patch mm-damon-lru_sort-ignore-damon_stop-return-value.patch mm-damon-core-change-damon_stop-return-type-to-void.patch samples-damon-mtier-stop-all-contexts-with-single-damon_stop-call.patch mm-damon-core-wait-ctx-stop-in-damon_call-before-reruning-an-error.patch samples-damon-wsse-do-not-stop-ctx-for-damon_call-failure.patch samples-damon-prcl-do-not-stop-damon-for-damon_call-failure.patch mm-damon-core-remove-comment-and-test-for-nr_to_bp-divide-by-zero.patch mm-damon-core-s-damon_max_nr_accesses-damon_nr_samples_per_aggr.patch mm-damon-core-s-accesses_bp_to_nr_accesses-sample_bp_to_count.patch mm-damon-core-s-nr_accesses_to_accesses_bp-sample_count_to_bp.patch mm-damon-core-s-nr_accesses_for_new_attrs-nr_samples_for_new_attrs.patch mm-damon-core-update-probe-hits-for-new-parameter-commit.patch mm-damon-core-handle-unreset-probe_hits-in-probe_hits_mvsum.patch mm-damon-core-introduce-damon_probe-weight.patch mm-damon-core-ask-apply_probes-ops-callback-to-set-sampling-address.patch mm-damon-paddr-set-samples-in-apply_probes-if-requested.patch mm-damon-core-ask-apply_probe-to-return-max-probe-hits-weighted-sum.patch mm-damon-core-implement-damon_probe_hits_wsum.patch mm-damon-paddr-respect-return_max_wsum.patch mm-damon-core-use-abs_diff-instead-of-abs.patch mm-damon-core-extend-merge-function-to-work-with-probe-hits.patch mm-damon-core-disallow-probe_hits-overflow-on-attrs-only-monitoring.patch mm-damon-core-validate-params-for-probe-hits-weighted-sum-overflow.patch mm-damon-core-disable-access-monitoring-when-probe-weights-are-set.patch mm-damon-core-set-samples-in-apply_probes-if-probe-weights-are-set.patch mm-damon-core-s-max_nr_accesses-max_merge_score-in-kdamond_fn.patch mm-damon-core-get-merge-threshold-from-probe-hits-when-weights-are-set.patch mm-damon-core-implement-damon_has_probe_weight.patch mm-damon-sysfs-implement-probe-weight-file.patch docs-mm-damon-design-document-attrs-only-monitoring.patch docs-admin-guide-mm-damon-usage-document-weight-sysfs-file.patch docs-abi-damon-document-probe-weight-file.patch mm-damon-core-skip-aging-from-repeated-aggressive-merging.patch mm-damon-core-hide-private-damon_region-fields.patch mm-damon-core-hide-private-damon_target-fields.patch mm-damon-core-hide-private-damos_quota_goal-fields.patch mm-damon-core-hide-private-damos_quota-fields.patch mm-damon-core-hide-private-damos_filter-fields.patch mm-damon-core-hide-private-damos-fields.patch mm-damon-core-hide-private-damon_filter-fields.patch mm-damon-core-hide-private-damon_probe-fields.patch mm-damon-sysfs-do-not-directly-access-damon_ctx-ops.patch mm-damon-core-hide-core-private-damon_ctx-fields.patch mm-damon-core-avoid-infinite-kdamond_merge_regions-internal-loop.patch mm-damon-tests-core-kunit-catch-test-failure-in-test_merge_regions_of.patch mm-damon-vaddr-drop-last-same-folio-access-check-optimization.patch mm-damon-paddr-drop-last-same-folio-access-check-reuse-optimization.patch mm-damon-sysfs-read-addr_unit-only-once-in-damon_sysfs_apply_inputs.patch mm-damon-sysfs-read-ops_id-only-once-in-damon_sysfs_apply_inputs.patch