[PATCH v2 0/3] mm: kmemleak: default min_unref_scans to 2 for verbose kernels

From: Breno Leitao

Date: Fri Jul 31 2026 - 06:21:44 EST


When CONFIG_DEBUG_KMEMLEAK_VERBOSE is set, which means the host is in
auto scan mode, set min_unref_scans to 2, avoiding false positives.

CONFIG_DEBUG_KMEMLEAK_VERBOSE depends on CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN,
so a kernel built with it already runs the scan thread periodically and
the user has asked for detailed leak reports.

The confirming second scan comes for free there, so default
min_unref_scans to 2 in that case and keep it at 1 everywhere else.
CONFIG_DEBUG_KMEMLEAK_VERBOSE defaults to n, so nothing changes for
kernels that do not opt in.

The other two patches bring the documentation and the selftest comments
in line with the new conditional default.

PS: A similar patch (v1 of this patchset) is applied to Meta's kernel,
in real production hosts.

Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
---
Changes in v2:
- Test only CONFIG_DEBUG_KMEMLEAK_VERBOSE, which already depends on
CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN; the #if block becomes a plain
IS_ENABLED() initializer
- Note in the changelog that CONFIG_DEBUG_KMEMLEAK_VERBOSE defaults to n
- New patch: update Documentation/dev-tools/kmemleak.rst, which still
documented the default as unconditionally 1
- New patch: drop the stale "default" wording from the
ksft_kmemleak_confirm.sh comments
- Link to v1: https://patch.msgid.link/20260730-kmemleak_hardened-v1-1-b0b20033b4bb@xxxxxxxxxx

To: Catalin Marinas <catalin.marinas@xxxxxxx>
To: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
To: Jonathan Corbet <corbet@xxxxxxx>
To: Shuah Khan <skhan@xxxxxxxxxxxxxxxxxxx>
To: David Hildenbrand <david@xxxxxxxxxx>
To: Lorenzo Stoakes <ljs@xxxxxxxxxx>
To: "Liam R. Howlett" <liam@xxxxxxxxxxxxx>
To: Vlastimil Babka <vbabka@xxxxxxxxxx>
To: Mike Rapoport <rppt@xxxxxxxxxx>
To: Suren Baghdasaryan <surenb@xxxxxxxxxx>
To: Michal Hocko <mhocko@xxxxxxxx>
To: Shuah Khan <shuah@xxxxxxxxxx>
Cc: linux-mm@xxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: workflows@xxxxxxxxxxxxxxx
Cc: linux-doc@xxxxxxxxxxxxxxx
Cc: linux-kselftest@xxxxxxxxxxxxxxx

---
Breno Leitao (3):
mm: kmemleak: default min_unref_scans to 2 for verbose auto-scan
Documentation: kmemleak: document the conditional min_unref_scans default
selftests/mm: kmemleak: drop stale min_unref_scans default from comments

Documentation/dev-tools/kmemleak.rst | 12 +++++++-----
mm/kmemleak.c | 3 ++-
tools/testing/selftests/mm/ksft_kmemleak_confirm.sh | 10 ++++------
3 files changed, 13 insertions(+), 12 deletions(-)
---
base-commit: 78bc8af4affb9a732504eb22eeac7d1e50883853
change-id: 20260730-kmemleak_hardened-e80542d1152f

Best regards,
--
Breno Leitao <leitao@xxxxxxxxxx>