Re: [PATCH v1 05/10] mm/huge_memory: remove READ_ONLY_THP_FOR_FS from file_thp_enabled()

Zi Yan
2026-04-10T15:18:38Z

On 10 Apr 2026, at 11:06, Andres Freund wrote:

> Hi,
>
> On 2026-03-26 21:42:50 -0400, Zi Yan wrote:
>> Replace it with a check on the max folio order of the file's address space
>> mapping, making sure PMD_ORDER is supported.
>
> Question from a user space developer (who learned of this via LWN [1]):
>
> Right now MADV_COlLAPSE on file mappings appears to only only work with
> CONFIG_READ_ONLY_THP_FOR_FS.
>
> That's pretty sad, because I see quite consistent gains (~15%) from doing
> madvise(MADV_COLLAPSE) on e.g. postgres' .text - but because
> CONFIG_READ_ONLY_THP_FOR_FS is not enabled default (or at least not commonly,
> I think?) in distro kernels, it never quite seemed worth the fiddliness.
>
>
> Do I understand correctly that by replacing the check here (and the
> predecessor commits), madvise(MADV_COLLAPSE) on file mappings might actually
> start working in more situations on typical distro kernels?

Yes, assuming your file system supports PMD THPs.

Based on[1], ext4 and xfs have the support, btrfs supports large folio but
not up to PMD order. I have not checked other FSes supporting large folio[2].

[1] https://lore.kernel.org/all/20260330160942.173324-1-r@hev.cc/
[2] https://lore.kernel.org/all/aTJg9vOijOGVTnVt@casper.infradead.org/

Best Regards,
Yan, Zi