On Mon, Dec 09, 2024 at 02:43:08PM +0800, Jinjiang Tu wrote: > > 在 2024/12/6 21:58, Matthew Wilcox 写道: > > On Thu, Dec 05, 2024 at 10:30:38PM +0800, Jinjiang Tu wrote: > > > During our tests in containers, there is a read-only file (i.e., shared > > Show your test. > > I mmap an overlayfs file with PROT_READ, and call madvise(MADV_COLLAPSE), the code > is as follows: > > fd = open(path, O_RDONLY); > addr = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); > ret = madvise(addr, size, MADV_COLLAPSE); > > The addr isn't THP-aligned and ret is -1, errno is EINVAL. Then your test is buggy. * Check alignment for file vma and size for both file and anon vma by * filtering out the unsuitable orders. You didn't align your mmap, so it's expected to fail.