From: Yang Shi <shy828301@gmail.com>
To: Avi Kivity <avi@scylladb.com>
Cc: linux-mm <linux-mm@kvack.org>,
Baolin Wang <baolin.wang@linux.alibaba.com>
Subject: Re: Possible regression with file madvise(MADV_COLLAPSE)
Date: Sat, 12 Oct 2024 16:50:32 -0700 [thread overview]
Message-ID: <CAHbLzkoGhUrVKFm1BQLTdNTgFfNVihVOx9_1gmLkujF1RDYfYA@mail.gmail.com> (raw)
In-Reply-To: <04a11431e9edffb85470da3611c287cb7caf3281.camel@scylladb.com>
On Sat, Oct 12, 2024 at 1:24 PM Avi Kivity <avi@scylladb.com> wrote:
>
> On Sat, 2024-10-12 at 13:05 -0700, Yang Shi wrote:
> > On Sat, Oct 12, 2024 at 8:38 AM Avi Kivity <avi@scylladb.com> wrote:
> > >
> > > On Fri, 2024-10-11 at 15:29 -0700, Yang Shi wrote:
> > > > On Wed, Oct 9, 2024 at 9:04 AM Avi Kivity <avi@scylladb.com>
> > > > wrote:
> > > > >
> > > > > On Linux 6.10.10 with CONFIG_READ_ONLY_THP_FOR_FS=y,
> > > > > madvise(MADV_COLLAPSE) on program text fails with EINVAL.
> > > > >
> > > > > To reproduce, compile the reproducer with
> > > > >
> > > > > clang -g -o text-hugepage text-hugepage.c \
> > > > > -fuse-ld=lld \
> > > > > -Wl,-zcommon-page-size=2097152 -Wl,-zmax-page-
> > > > > size=2097152
> > > > > \
> > > > > -Wl,-z,separate-loadable-segments
> > > > >
> > > > > and run:
> > > >
> > > > Didn't clang make the page cache dirty?
> > > >
> > > > Having sync between clang and the execution made the problem go
> > > > away
> > > > for me.
> > > >
> > >
> > > I see it even with sync (and msync just before the madvise calls).
> >
> > Did you stop khugepaged? It may race with MADV_COLLAPSE. If it failed
> > due to race with khugepaged, you should see -EAGAIN instead of
> > -EINVAL.
>
>
> I did not, but I don't imagine I hit the race in all my attempts.
>
> >
> > I did the below commands in a loop for 1000 times, it never failed (I
> > modified the test program a little bit to print out failure if
> > MADV_COLLAPSE returns failure). I had khugepaged stopped and ran the
> > test on v6.12-rc1 kernel on my AmpereOne machine.
> >
> > rm text-hugepage
> > clang -g -o text-hugepage text-hugepage.c -fuse-ld=lld
> > -Wl,-zcommon-page-size=2097152 -Wl,-zmax-page-size=2097152
> > -Wl,-z,separate-loadable-segments
> > sync
> > ./text-hugepage
> >
> > >
> > >
> > > Tracing shows this (last lines before syscall exit):
> > >
> > > > hpage_collapse_scan_file() {
> > > > __rcu_read_lock();
> > > > __rcu_read_unlock();
> > > > }
> >
> > It meant collapse_file() was not called at all.
> > hpage_collapse_scan_file() failed. A couple of reasons may fail it,
> > for example, refcount is not expected, not on lru, etc. You can trace
> > huge_memory:mm_khugepaged_scan_file to get more information about the
> > failure.
>
>
> text-hugepage-689146 [023] 200457.073794: mm_khugepaged_scan_file:
> mm=0xffff92fc512aac00, scan_pfn=0x5a4310, filename=text-hugepage,
> present=0, swap=0, result=page_compound
Aha, it is because v6.10 doesn't support collapse non-PMD order large
folios. It has been fixed in v6.12-rc1. The patch series is:
https://lore.kernel.org/all/cover.1724140601.git.baolin.wang@linux.alibaba.com/
The subject says "shmem", but it actually works for regular files too.
>
>
next prev parent reply other threads:[~2024-10-12 23:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 15:54 Avi Kivity
2024-10-11 6:32 ` Gavin Shan
2024-10-11 22:29 ` Yang Shi
2024-10-12 15:38 ` Avi Kivity
2024-10-12 20:05 ` Yang Shi
2024-10-12 20:24 ` Avi Kivity
2024-10-12 23:50 ` Yang Shi [this message]
2024-10-13 11:04 ` Avi Kivity
2024-10-13 13:25 ` Avi Kivity
2024-10-14 22:06 ` Yang Shi
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=CAHbLzkoGhUrVKFm1BQLTdNTgFfNVihVOx9_1gmLkujF1RDYfYA@mail.gmail.com \
--to=shy828301@gmail.com \
--cc=avi@scylladb.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=linux-mm@kvack.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