mm/mmap: allow MAP_DROPPABLE | MAP_PRIVATE in mmap()
Subsystems (2)
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.
--- mm/mmap.c | 1 + 1 file changed, 1 insertion(+)
mm/mmap.c +1 -0
@@ -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 ;/*
Signature · 1 line
2.45.2
Quoted 11 lines · Lance Yang
Currently,
mmap()fails with-EINVALwhen bothMAP_DROPPABLEandMAP_PRIVATEare specified. This behavior might be inconsistent, as the implementation ofMAP_DROPPABLEunder the hood already includes the semantics ofMAP_PRIVATE. So, IMO, whetherMAP_PRIVATEis explicitly specified or not, it should work as expected.For example, when
mmap()is called withMAP_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 thedp(MAP_DROPPABLE) flag, and thePrivate_*fields confirm private memory semantics. The output for a 2MiB mapping with these flags might look like:
Note that "Private_" in the stats has *nothing* to do with MAP_PRIVATE.
Quoted 19 lines
``` 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 ```
Quoted 6 lines
This patch changes
mmap()to allow the combination ofMAP_DROPPABLE | MAP_PRIVATE. Formmap(), at least one ofMAP_PRIVATEorMAP_SHAREDcould be explicitly specified, regardless of the combination with otherMAP_*flags.Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")
"How about we just say that VM_DROPPABLE really is something separate from MAP_PRIVATE or MAP_SHARED..
And then we make the rule be that VM_DROPPABLE is never dumped and always dropped on fork, just to make things simpler." [1]
[1] https://lore.kernel.org/linux-mm/CAHk-=wi=XvCZ9r897LjEb4ZarLzLtKN1p+Fyig+F2fmQDF8GSA@mail.gmail.com/
So, nack from my side.
Signature · 3 lines
Cheers, David / dhildenb
Agree with David, NACK.
Quoted 39 lines · David Hildenbrand
Quoted 11 lines · Lance Yang
Currently,
mmap()fails with-EINVALwhen bothMAP_DROPPABLEandMAP_PRIVATEare specified. This behavior might be inconsistent, as the implementation ofMAP_DROPPABLEunder the hood already includes the semantics ofMAP_PRIVATE. So, IMO, whetherMAP_PRIVATEis explicitly specified or not, it should work as expected.For example, when
mmap()is called withMAP_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 thedp(MAP_DROPPABLE) flag, and thePrivate_*fields confirm private memory semantics. The output for a 2MiB mapping with these flags might look like:Note that "
Private_" in the stats has *nothing* to do withMAP_PRIVATE.Quoted 24 lines
``` 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 ofMAP_DROPPABLE | MAP_PRIVATE. Formmap(), at least one ofMAP_PRIVATEorMAP_SHAREDcould be explicitly specified, regardless of the combination with otherMAP_*flags.
Quoted 4 lines
Quoted 1 line
Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")"How about we just say that
VM_DROPPABLEreally is something separate fromMAP_PRIVATEorMAP_SHARED..
Which is also how I view it. I -really- do not want to add a weird situation too where people wonder whether _not_ setting MAP_PRIVATE infers some different semantics.
This mode is aggregate in behaviour by design and intended to be _specifically_ asked for, not in conjection with other map flags.
Quoted 3 lines
And then we make the rule be that
VM_DROPPABLEis never dumped and always dropped on fork, just to make things simpler." [1]
Yup.
Quoted 4 lines
[1] https://lore.kernel.org/linux-mm/CAHk-=wi=XvCZ9r897LjEb4ZarLzLtKN1p+Fyig+F2fmQDF8GSA@mail.gmail.com/
So, nack from my side.
Also, mine.
Quoted 6 lines
--
Cheers,David / dhildenb
Hi David and Lorenzo,
Quoted 18 lines · Lorenzo Stoakes
Agree with David, NACK.
Quoted 14 lines · David Hildenbrand
Quoted 11 lines · Lance Yang
Currently,
mmap()fails with-EINVALwhen bothMAP_DROPPABLEandMAP_PRIVATEare specified. This behavior might be inconsistent, as the implementation ofMAP_DROPPABLEunder the hood already includes the semantics ofMAP_PRIVATE. So, IMO, whetherMAP_PRIVATEis explicitly specified or not, it should work as expected.For example, when
mmap()is called withMAP_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 thedp(MAP_DROPPABLE) flag, and thePrivate_*fields confirm private memory semantics. The output for a 2MiB mapping with these flags might look like:Note that "
Private_" in the stats has *nothing* to do withMAP_PRIVATE.
Oh, I see. Thanks for pointing this out!
Quoted 30 lines
Quoted 25 lines
Quoted 25 lines
``` 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 ofMAP_DROPPABLE | MAP_PRIVATE. Formmap(), at least one ofMAP_PRIVATEorMAP_SHAREDcould be explicitly specified, regardless of the combination with otherMAP_*flags.Quoted 4 lines
Quoted 1 line
Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")"How about we just say that
VM_DROPPABLEreally is something separate fromMAP_PRIVATEorMAP_SHARED..
Quoted 6 lines
Which is also how I view it. I -really- do not want to add a weird situation too where people wonder whether _not_ setting
MAP_PRIVATEinfers some different semantics.This mode is aggregate in behaviour by design and intended to be _specifically_ asked for, not in conjection with other map flags.
Thanks for the lesson! I missed this important info before :(
Quoted 5 lines
Quoted 4 lines
And then we make the rule be that
VM_DROPPABLEis never dumped and always dropped on fork, just to make things simpler." [1]
Quoted 8 lines
Yup.
Quoted 4 lines
[1] https://lore.kernel.org/linux-mm/CAHk-=wi=XvCZ9r897LjEb4ZarLzLtKN1p+Fyig+F2fmQDF8GSA@mail.gmail.com/
So, nack from my side.
Also, mine.
Thanks again for your time!
Lance
Quoted 7 lines
Quoted 7 lines
--
Cheers,David / dhildenb