[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250120012607.4808-1-ioworker0@gmail.com>
Date: Mon, 20 Jan 2025 09:26:07 +0800
From: Lance Yang <ioworker0@...il.com>
To: akpm@...ux-foundation.org
Cc: 21cnbao@...il.com,
ryan.roberts@....com,
dev.jain@....com,
david@...hat.com,
shy828301@...il.com,
ziy@...dia.com,
libang.li@...group.com,
baolin.wang@...ux.alibaba.com,
linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
Liam.Howlett@...cle.com,
lorenzo.stoakes@...cle.com,
vbabka@...e.cz,
jannh@...gle.com,
Jason@...c4.com,
Lance Yang <ioworker0@...il.com>,
Mingzhe Yang <mingzhe.yang@...com>
Subject: [PATCH 1/1] mm/mmap: allow MAP_DROPPABLE | MAP_PRIVATE in mmap()
Currently, mmap() fails with `-EINVAL` when both MAP_DROPPABLE and
MAP_PRIVATE are specified. This behavior might be inconsistent, as the
implementation of MAP_DROPPABLE under the hood already includes the
semantics of MAP_PRIVATE. So, IMO, whether MAP_PRIVATE is explicitly
specified or not, it should work as expected.
For example, when mmap() is called with `MAP_DROPPABLE | MAP_ANONYMOUS`,
it creates a private anonymous mapping. Users can verify this behavior
via `/proc/self/smaps`, where the resulting VMA is marked with the `dp`
(MAP_DROPPABLE) flag, and the `Private_*` fields confirm private memory
semantics. The output for a 2MiB mapping with these flags might look like:
```
f433ace00000-f433ad000000 rw-p 00000000 00:00 0
Size: 2048 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Rss: 2048 kB
Pss: 2048 kB
Pss_Dirty: 2048 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 2048 kB
Referenced: 2048 kB
Anonymous: 2048 kB
...
VmFlags: rd wr mr mw me nr wf dd dp
```
This patch changes mmap() to allow the combination of `MAP_DROPPABLE |
MAP_PRIVATE`. For mmap(), at least one of MAP_PRIVATE or MAP_SHARED could
be explicitly specified, regardless of the combination with other `MAP_*`
flags.
Fixes: 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")
Signed-off-by: Mingzhe Yang <mingzhe.yang@...com>
Signed-off-by: Lance Yang <ioworker0@...il.com>
---
mm/mmap.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/mmap.c b/mm/mmap.c
index cda01071c7b1..840889b5bfb2 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -504,6 +504,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
vm_flags |= VM_SHARED | VM_MAYSHARE;
break;
case MAP_DROPPABLE:
+ case MAP_DROPPABLE | MAP_PRIVATE:
if (VM_DROPPABLE == VM_NONE)
return -ENOTSUPP;
/*
--
2.45.2
Powered by blists - more mailing lists