mm/madvise: fail MADV_PAGEOUT on VM_DROPPABLE VMA
Subsystems (2)
RFC 1/1 mm/madvise: fail MADV_PAGEOUT on VM_DROPPABLE VMA
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.
--- mm/madvise.c | 2 ++ 1 file changed, 2 insertions(+)
mm/madvise.c +2 -0
@@ -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 :
Signature · 1 line
2.45.2
Quoted 9 lines · Lance Yang
MADV_PAGEOUTshould fail on VMAs with theVM_DROPPABLEflag. WhileMADV_PAGEOUTis intended to move anonymous pages to swap,VM_DROPPABLEshould not be swapped out.There is an issue where using
MADV_PAGEOUTon a VMA with theVM_DROPPABLEflag behaves likeMADV_DONTNEED, causing the pages to be dropped. This could break the semantics ofMADV_PAGEOUT, IMO.
Quoted 6 lines
So, let's add a check to detect the
VM_DROPPABLEflag before doingMADV_PAGEOUTand returns-EINVAL.Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Signed-off-by Mingzhe Yang <[email protected]>Signed-off-by Lance Yang <[email protected]>
I am not convinced this is a correct patch. try_to_unmap_one() will drop the folio.madvise_pageout(vma, prev, start, end) will still go to shrink_folio_list() and try_to_unmap_one().
Quoted 18 lines
--- mm/madvise.c | 2 ++ 1 file changed, 2 insertions(+)mm/madvise.c +2
-1@@ -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 : --
Quoted 2 lines
2.45.2
Thanks
Barry
Quoted 7 lines · Lance Yang
MADV_PAGEOUTshould fail on VMAs with theVM_DROPPABLEflag. WhileMADV_PAGEOUTis intended to move anonymous pages to swap,VM_DROPPABLEshould not be swapped out.There is an issue where using
MADV_PAGEOUTon a VMA with theVM_DROPPABLEflag behaves likeMADV_DONTNEED, causing the pages to be dropped. This could break the semantics ofMADV_PAGEOUT, IMO.
It behaves exactly correct I think. They can be dropped any time, which includes on misplaced MADV_PAGEOUT.
Signature · 3 lines
Cheers, David / dhildenb
Sorry but NACK again on this :(
Quoted 10 lines · Lance Yang
MADV_PAGEOUTshould fail on VMAs with theVM_DROPPABLEflag. WhileMADV_PAGEOUTis intended to move anonymous pages to swap,VM_DROPPABLEshould not be swapped out.There is an issue where using
MADV_PAGEOUTon a VMA with theVM_DROPPABLEflag behaves likeMADV_DONTNEED, causing the pages to be dropped. This could break the semantics ofMADV_PAGEOUT, IMO.So, let's add a check to detect the
VM_DROPPABLEflag before doingMADV_PAGEOUTand returns-EINVAL.
No, let's not.
Firstly this behaviour, whether you feel it is right or not, is now _established userland behaviour_. A pedantic interpretation of how MADV_PAGEOUT ought to interact with MAP_DROPPABLE doesn't trump what is already in released kernel versions, unless it is wrong in a -broken- fashion.
Also I'd say you'd 100% expect an anon page to be dropped in the case of MAP_DROPPABLE, the semantics of which are 'if there is a request to drop this, drop it'. Here, the user is saying 'hey drop this'. So we drop it :)
I think the more correct patch would be to extend the man page to explicitly mention MAP_DROPPABLE.
Quoted 24 lines
Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Signed-off-by Mingzhe Yang <[email protected]>Signed-off-by Lance Yang <[email protected]>--- mm/madvise.c | 2 ++ 1 file changed, 2 insertions(+)mm/madvise.c +2
-1@@ -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
Hi Barry, David and Lorenzo,
Thanks a lot for taking time to review!
Quoted 8 lines · Lorenzo Stoakes
Sorry but NACK again on this :(
Quoted 4 lines · Lance Yang
MADV_PAGEOUTshould fail on VMAs with theVM_DROPPABLEflag. WhileMADV_PAGEOUTis intended to move anonymous pages to swap,VM_DROPPABLEshould not be swapped out.
Quoted 8 lines
Quoted 6 lines
There is an issue where using
MADV_PAGEOUTon a VMA with theVM_DROPPABLEflag behaves likeMADV_DONTNEED, causing the pages to be dropped. This could break the semantics ofMADV_PAGEOUT, IMO.So, let's add a check to detect the
VM_DROPPABLEflag before doingMADV_PAGEOUTand returns-EINVAL.No, let's not.
I think I completely got it wrong. Learning so much from your patient responses!
Quoted 6 lines
Firstly this behaviour, whether you feel it is right or not, is now
_establisheduserlandbehaviour_. A pedantic interpretation of howMADV_PAGEOUTought to interact withMAP_DROPPABLEdoesn't trump what is already in released kernel versions, unless it is wrong in a -broken- fashion.
Yeah, this patch would break the established userland behaviour as well.
Quoted 4 lines
Also I'd say you'd 100% expect an anon page to be dropped in the case of
MAP_DROPPABLE, the semantics of which are 'if there is a request to drop this, drop it'. Here, the user is saying 'hey drop this'. So we drop it :)
Yep, you're right.
Quoted 3 lines
I think the more correct patch would be to extend the man page to explicitly mention
MAP_DROPPABLE.
Thanks again for your time!
Lance
Quoted 25 lines
Quoted 25 lines
Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Signed-off-by Mingzhe Yang <[email protected]>Signed-off-by Lance Yang <[email protected]>--- mm/madvise.c | 2 ++ 1 file changed, 2 insertions(+)mm/madvise.c +2
-1@@ -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
Quoted 18 lines · Lance Yang
Hi Barry, David and Lorenzo,
Thanks a lot for taking time to review!
Quoted 12 lines · Lorenzo Stoakes
Sorry but NACK again on this :(
Quoted 8 lines · Lance Yang
MADV_PAGEOUTshould fail on VMAs with theVM_DROPPABLEflag. WhileMADV_PAGEOUTis intended to move anonymous pages to swap,VM_DROPPABLEshould not be swapped out.There is an issue where using
MADV_PAGEOUTon a VMA with theVM_DROPPABLEflag behaves likeMADV_DONTNEED, causing the pages to be dropped. This could break the semantics ofMADV_PAGEOUT, IMO.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
So, let's add a check to detect the
VM_DROPPABLEflag before doingMADV_PAGEOUTand returns-EINVAL.No, let's not.
I think I completely got it wrong. Learning so much from your patient responses!
Maybe you can make the documentation (man pages?) clearer in that regard? Thanks!
Signature · 3 lines
Cheers, David / dhildenb
Quoted 23 lines · David Hildenbrand
Quoted 21 lines · Lance Yang
Hi Barry, David and Lorenzo,
Thanks a lot for taking time to review!
Quoted 15 lines · Lorenzo Stoakes
Sorry but NACK again on this :(
Quoted 10 lines · Lance Yang
MADV_PAGEOUTshould fail on VMAs with theVM_DROPPABLEflag. WhileMADV_PAGEOUTis intended to move anonymous pages to swap,VM_DROPPABLEshould not be swapped out.There is an issue where using
MADV_PAGEOUTon a VMA with theVM_DROPPABLEflag behaves likeMADV_DONTNEED, causing the pages to be dropped. This could break the semantics ofMADV_PAGEOUT, IMO.So, let's add a check to detect the
VM_DROPPABLEflag before doingMADV_PAGEOUTand returns-EINVAL.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
No, let's not.
I think I completely got it wrong. Learning so much from your patient responses!
Maybe you can make the documentation (man pages?) clearer in that regard? Thanks!
Of course, I will give it a try ASAP ;)
Thanks for your suggestion!
Lance
Quoted 6 lines
--
Cheers,David / dhildenb