On Fri, 2024-10-11 at 15:29 -0700, Yang Shi wrote: > On Wed, Oct 9, 2024 at 9:04 AM Avi Kivity <avi@xxxxxxxxxxxx> 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). Tracing shows this (last lines before syscall exit): | hpage_collapse_scan_file() { | __rcu_read_lock(); | __rcu_read_unlock(); | } so, it's not clear what the root cause is.