linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Ryan Roberts <ryan.roberts@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>, Barry Song <baohua@kernel.org>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Lance Yang <ioworker0@gmail.com>, Yang Shi <shy828301@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v1] mm: Fix khugepaged activation policy
Date: Tue, 2 Jul 2024 16:57:44 +0200	[thread overview]
Message-ID: <c877a136-4294-4f00-b0ac-7194fe170452@redhat.com> (raw)
In-Reply-To: <20240702144617.2291480-1-ryan.roberts@arm.com>

On 02.07.24 16:46, Ryan Roberts 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
> 
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> Fixes: 3485b88390b0 ("mm: thp: introduce multi-size THP sysfs interface")
> Closes: https://lore.kernel.org/linux-mm/7a0bbe69-1e3d-4263-b206-da007791a5c4@redhat.com/
> Cc: stable@vger.kernel.org
> ---
> 
> Hi All,
> 
> Applies on top of today's mm-unstable (9bb8753acdd8). No regressions observed in
> mm selftests.
> 
> When fixing this I also noticed that khugepaged doesn't get (and never has been)
> activated/deactivated by `shmem_enabled=`. I'm not sure if khugepaged knows how
> to collapse shmem - perhaps it should be activated in this case?
> 

Call me confused.

khugepaged_scan_mm_slot() and madvise_collapse() only all 
hpage_collapse_scan_file() with ... IS_ENABLED(CONFIG_SHMEM) ?

collapse_file() is only called by hpage_collapse_scan_file() ... and 
there we check "shmem_file(file)".

So why is the IS_ENABLED(CONFIG_SHMEM) check in there if collapse_file() 
seems to "collapse filemap/tmpfs/shmem pages into huge one".

Anyhow, we certainly can collapse shmem (that's how it all started IIUC).

Besides that, khugepaged only seems to collapse !shmem with
   VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem);

The thp_vma_allowable_order() check tests if we are allowed to collapse 
a PMD_ORDER in that VMA.

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2024-07-02 14:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-02 14:46 Ryan Roberts
2024-07-02 14:57 ` David Hildenbrand [this message]
2024-07-02 15:29   ` Ryan Roberts
2024-07-02 15:38     ` David Hildenbrand
2024-07-02 16:33       ` Ryan Roberts
2024-07-02 21:29         ` David Hildenbrand

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=c877a136-4294-4f00-b0ac-7194fe170452@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=corbet@lwn.net \
    --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