linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lance Yang <ioworker0@gmail.com>
To: akpm@linux-foundation.org
Cc: 21cnbao@gmail.com, ryan.roberts@arm.com, dev.jain@arm.com,
	david@redhat.com, shy828301@gmail.com, ziy@nvidia.com,
	libang.li@antgroup.com, baolin.wang@linux.alibaba.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com,
	vbabka@suse.cz, jannh@google.com, Jason@zx2c4.com,
	Lance Yang <ioworker0@gmail.com>,
	Mingzhe Yang <mingzhe.yang@ly.com>
Subject: [RFC 1/1] mm/madvise: fail MADV_PAGEOUT on VM_DROPPABLE VMA
Date: Mon, 20 Jan 2025 09:30:38 +0800	[thread overview]
Message-ID: <20250120013038.6657-1-ioworker0@gmail.com> (raw)

MADV_PAGEOUT should fail on VMAs with the VM_DROPPABLE flag. While
MADV_PAGEOUT is intended to move anonymous pages to swap, VM_DROPPABLE
should not be swapped out.

There is an issue where using MADV_PAGEOUT on a VMA with the VM_DROPPABLE
flag behaves like MADV_DONTNEED, causing the pages to be dropped. This
could break the semantics of MADV_PAGEOUT, IMO.

So, let's add a check to detect the VM_DROPPABLE flag before doing
MADV_PAGEOUT and returns -EINVAL.

Fixes: 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")
Signed-off-by: Mingzhe Yang <mingzhe.yang@ly.com>
Signed-off-by: Lance Yang <ioworker0@gmail.com>
---
 mm/madvise.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/madvise.c b/mm/madvise.c
index 49f3a75046f6..29d0234da8a1 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1263,6 +1263,8 @@ static int madvise_vma_behavior(struct vm_area_struct *vma,
 	case MADV_COLD:
 		return madvise_cold(vma, prev, start, end);
 	case MADV_PAGEOUT:
+		if (vma->vm_flags & VM_DROPPABLE)
+			return -EINVAL;
 		return madvise_pageout(vma, prev, start, end);
 	case MADV_FREE:
 	case MADV_DONTNEED:
-- 
2.45.2



             reply	other threads:[~2025-01-20  1:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20  1:30 Lance Yang [this message]
2025-01-20  2:02 ` Barry Song
2025-01-20  8:03 ` David Hildenbrand
2025-01-20 10:45 ` Lorenzo Stoakes
2025-01-20 13:47   ` Lance Yang
2025-01-20 13:56     ` David Hildenbrand
2025-01-21  2:28       ` Lance Yang

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=20250120013038.6657-1-ioworker0@gmail.com \
    --to=ioworker0@gmail.com \
    --cc=21cnbao@gmail.com \
    --cc=Jason@zx2c4.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=dev.jain@arm.com \
    --cc=jannh@google.com \
    --cc=libang.li@antgroup.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mingzhe.yang@ly.com \
    --cc=ryan.roberts@arm.com \
    --cc=shy828301@gmail.com \
    --cc=vbabka@suse.cz \
    --cc=ziy@nvidia.com \
    /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