Re: [PATCH stable] mm/khugepaged: write all dirty file folios when collapsing

From: Matthew Wilcox

Date: Fri Jul 03 2026 - 20:50:34 EST


On Thu, Jul 02, 2026 at 05:54:09PM +0100, Pedro Falcato wrote:
> +++ b/mm/khugepaged.c
> @@ -2094,32 +2094,43 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
> goto xa_unlocked;
> }
>
> - if (!is_shmem) {
> +xa_locked:
> + xas_unlock_irq(&xas);
> +xa_unlocked:

Hmm. Before this patch, we increment nr_thps while holding the i_pages
lock. Now we aren't holding it, but we are holding the invalidate lock.
Can you put something in the commit message that notes this change and
argues that it's totally fine actually?

You were good enough to not point out that my suggestion of calling
write_and_wait in the existing !is_shmem condition would result in
sleeping with a spinlock held. Silly me ;-)