Re: [PATCH v4 0/2] fix MADV_COLLAPSE issue if THP settings are disabled

From: David Hildenbrand
Date: Wed Jun 25 2025 - 06:29:27 EST


On 25.06.25 12:15, Lorenzo Stoakes wrote:
On Wed, Jun 25, 2025 at 12:07:12PM +0200, David Hildenbrand wrote:
Yes, I don't mean it will prevent madvise_collapse(), just as you said
that it could be problematic (it's horrible to try to collapse 512MB).

Well, assume you have a VM at that is 2 GiB and could use 4 THPs. It's
stupid, but there might be some selected use cases where it's not completely
stupid.

I guess we limit the stupidity by MADV_COLLAPSE working on a PMD-aligned range
so it'll be a no-op for an attempt to collapse 2 MiB (unless I'm misreading the
code).

At least the doc says: "MADV_COLLAPSE will automatically clamp the provided range to be hugepage-aligned.", and skimming over the code that seems to be the case.

Which makes sense to me: never collapse outside the provided range.

So if someone would ever specify something smaller (e.g., 2MiB aligned range with 512MiB PMD size) we could decide to collapse a 2MiB THP there instead. Right now, it would be ignored.

Guess the rule is simply to not collapse outside of the requested range. Maybe that rule can be used to support collapsing of smaller THPs in the future as well. Maybe (can of worms) :)

--
Cheers,

David / dhildenb