From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Jakov Novak <jakovnovak30@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>, Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"\\ Liam R . Howlett \\ " <liam@infradead.org>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>,
Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
linux-kernel-mentees@lists.linux.dev,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] mm/khugepaged: replace mutex_lock/mutex_unlock usage with guard macro
Date: Tue, 28 Jul 2026 15:57:41 +0100 [thread overview]
Message-ID: <amjCQJUDNYseR6y-@lucifer> (raw)
In-Reply-To: <20260727181136.2542-1-jakovnovak30@gmail.com>
On Mon, Jul 27, 2026 at 08:11:36PM +0200, Jakov Novak wrote:
> 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.
>
> Signed-off-by: Jakov Novak <jakovnovak30@gmail.com>
Various nits below, with them addressed feel free to add:
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
To the respin.
> ---
> mm/khugepaged.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 617bca76db49..c583867f2e7a 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -3113,7 +3113,7 @@ int start_stop_khugepaged(void)
> {
Please add
#include <linux/cleanup.h>
To the #include's up top.
You might get away with not doing it locally because of recursive header
includes but be better to be explicit.
> int err = 0;
>
> - mutex_lock(&khugepaged_mutex);
> + guard(mutex)(&khugepaged_mutex);
> if (hugepage_enabled()) {
> if (!khugepaged_thread)
> khugepaged_thread = kthread_run(khugepaged, NULL,
> @@ -3122,7 +3122,7 @@ int start_stop_khugepaged(void)
if (IS_ERR(khugepaged_thread)) {
Can we move the 'int err' declaration to here then? And not initialise it as it
gets assigned below.
> 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))
> @@ -3132,17 +3132,14 @@ int start_stop_khugepaged(void)
> khugepaged_thread = NULL;
> }
> set_recommended_min_free_kbytes();
> -fail:
> - mutex_unlock(&khugepaged_mutex);
> return err;
Let's make this return 0 now.
> }
>
> 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);
Nice and simple!
> }
>
> bool current_is_khugepaged(void)
> --
> 2.55.0
>
Cheers, Lorenzo
prev parent reply other threads:[~2026-07-28 14:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 18:11 [PATCH] mm/khugepaged: replace mutex_lock/mutex_unlock usage with guard macro Jakov Novak
2026-07-28 6:12 ` Dev Jain
2026-07-28 14:57 ` Lorenzo Stoakes (ARM) [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=amjCQJUDNYseR6y-@lucifer \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=jakovnovak30@gmail.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=npache@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=skhan@linuxfoundation.org \
--cc=usama.arif@linux.dev \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.