From: Andrew Morton <akpm@linux-foundation.org>
To: Ryan Roberts <ryan.roberts@arm.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
David Hildenbrand <david@redhat.com>,
Barry Song <baohua@kernel.org>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Lance Yang <ioworker0@gmail.com>, Yang Shi <shy828301@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] mm: Fix khugepaged activation policy
Date: Thu, 4 Jul 2024 11:33:25 -0700 [thread overview]
Message-ID: <20240704113325.fb9f1b04f99abaac315b5c88@linux-foundation.org> (raw)
In-Reply-To: <20240704091051.2411934-1-ryan.roberts@arm.com>
On Thu, 4 Jul 2024 10:10:50 +0100 Ryan Roberts <ryan.roberts@arm.com> wrote:
> Since the introduction of mTHP, the docuementation has stated that
> khugepaged would be enabled when any mTHP size is enabled, and disabled
> when all mTHP sizes are disabled. There are 2 problems with this; 1.
> this is not what was implemented by the code and 2. this is not the
> desirable behavior.
>
> Desirable behavior is for khugepaged to be enabled when any PMD-sized
> THP is enabled, anon or file. (Note that file THP is still controlled by
> the top-level control so we must always consider that, as well as the
> PMD-size mTHP control for anon). khugepaged only supports collapsing to
> PMD-sized THP so there is no value in enabling it when PMD-sized THP is
> disabled. So let's change the code and documentation to reflect this
> policy.
>
> Further, per-size enabled control modification events were not
> previously forwarded to khugepaged to give it an opportunity to start or
> stop. Consequently the following was resulting in khugepaged eroneously
> not being activated:
>
> echo never > /sys/kernel/mm/transparent_hugepage/enabled
> echo always > /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled
>
> ...
>
> -static inline bool hugepage_flags_enabled(void)
> +static inline bool hugepage_pmd_enabled(void)
> {
> /*
> - * We cover both the anon and the file-backed case here; we must return
> - * true if globally enabled, even when all anon sizes are set to never.
> - * So we don't need to look at huge_anon_orders_inherit.
> + * We cover both the anon and the file-backed case here; file-backed
> + * hugepages, when configured in, are determined by the global control.
> + * Anon pmd-sized hugepages are determined by the pmd-size control.
> */
> - return hugepage_global_enabled() ||
> - READ_ONCE(huge_anon_orders_always) ||
> - READ_ONCE(huge_anon_orders_madvise);
> + return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && hugepage_global_enabled()) ||
> + test_bit(PMD_ORDER, &huge_anon_orders_always) ||
> + test_bit(PMD_ORDER, &huge_anon_orders_madvise) ||
> + (test_bit(PMD_ORDER, &huge_anon_orders_inherit) && hugepage_global_enabled());
> }
That's rather a mouthful. Is this nicer?
static inline bool hugepage_pmd_enabled(void)
{
/*
* We cover both the anon and the file-backed case here; file-backed
* hugepages, when configured in, are determined by the global control.
* Anon pmd-sized hugepages are determined by the pmd-size control.
*/
if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
hugepage_global_enabled())
return true;
if (test_bit(PMD_ORDER, &huge_anon_orders_always))
return true;
if (test_bit(PMD_ORDER, &huge_anon_orders_madvise))
return true;
if (test_bit(PMD_ORDER, &huge_anon_orders_inherit) &&
hugepage_global_enabled())
return true;
return false;
}
Also, that's a pretty large function to be inlined. It could be a
non-inline function static to khugepaged.c. But I suppose that's a
separate patch.
next prev parent reply other threads:[~2024-07-04 18:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-04 9:10 Ryan Roberts
2024-07-04 18:33 ` Andrew Morton [this message]
2024-07-05 9:34 ` Ryan Roberts
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=20240704113325.fb9f1b04f99abaac315b5c88@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=ioworker0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--cc=shy828301@gmail.com \
--cc=stable@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox