+ mm-khugepaged-replace-mutex_lock-mutex_unlock-usage-with-guard-macro.patch added to mm-new branch
Andrew Morton <[email protected]> Tue, 28 Jul 2026 16:56:19 -0700
| Newsgroups | org.kernel.vger.mm-commits |
|---|---|
| Message-ID | <[email protected]> |
The patch titled
Subject: mm/khugepaged: replace mutex_lock/mutex_unlock usage with guard macro
has been added to the -mm mm-new branch. Its filename is
mm-khugepaged-replace-mutex_lock-mutex_unlock-usage-with-guard-macro.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-khugepaged-replace-mutex_lock-mutex_unlock-usage-with-guard-macro.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: Jakov Novak <[email protected]>
Subject: mm/khugepaged: replace mutex_lock/mutex_unlock usage with guard macro
Date: Tue, 28 Jul 2026 22:46:37 +0200
Currently, khugepaged locks the khugepaged_mutex in two functions:
start_stop_khugepaged and khugepaged_min_free_kbytes_update. Remove
mutex_lock/mutex_unlock usage in these functions and replace it with the
guard macro. This makes the code more readable (removing a goto
statement) and makes it harder to introduce bugs in the future. No
functional changes introduced.
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Jakov Novak <[email protected]>
Reviewed-by: Dev Jain <[email protected]>
Reviewed-by: Lorenzo Stoakes (ARM) <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: Barry Song <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Lance Yang <[email protected]>
Cc: Liam R. Howlett <[email protected]>
Cc: Nico Pache <[email protected]>
Cc: Ryan Roberts <[email protected]>
Cc: Zi Yan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
---
mm/khugepaged.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
--- a/mm/khugepaged.c~mm-khugepaged-replace-mutex_lock-mutex_unlock-usage-with-guard-macro
+++ a/mm/khugepaged.c
@@ -23,6 +23,7 @@
#include <linux/ksm.h>
#include <linux/pgalloc.h>
#include <linux/backing-dev.h>
+#include <linux/cleanup.h>
#include <asm/tlb.h>
#include "internal.h"
@@ -3115,18 +3116,17 @@ update_wmarks:
int start_stop_khugepaged(void)
{
- int err = 0;
-
- mutex_lock(&khugepaged_mutex);
+ guard(mutex)(&khugepaged_mutex);
if (hugepage_enabled()) {
if (!khugepaged_thread)
khugepaged_thread = kthread_run(khugepaged, NULL,
"khugepaged");
if (IS_ERR(khugepaged_thread)) {
+ int err;
pr_err("khugepaged: kthread_run(khugepaged) failed\n");
err = PTR_ERR(khugepaged_thread);
khugepaged_thread = NULL;
- goto fail;
+ return err;
}
if (!list_empty(&khugepaged_scan.mm_head))
@@ -3136,17 +3136,14 @@ int start_stop_khugepaged(void)
khugepaged_thread = NULL;
}
set_recommended_min_free_kbytes();
-fail:
- mutex_unlock(&khugepaged_mutex);
- return err;
+ return 0;
}
void khugepaged_min_free_kbytes_update(void)
{
- mutex_lock(&khugepaged_mutex);
+ guard(mutex)(&khugepaged_mutex);
if (hugepage_enabled() && khugepaged_thread)
set_recommended_min_free_kbytes();
- mutex_unlock(&khugepaged_mutex);
}
bool current_is_khugepaged(void)
_
Patches currently in -mm which might be from [email protected] are
mm-khugepaged-replace-mutex_lock-mutex_unlock-usage-with-guard-macro.patch