mm, compaction: make testing mapping_unmovable() safe
Subsystems (10)
PATCH v2 1/1 mm, compaction: make testing mapping_unmovable() safe
As Kirill pointed out, mapping can be removed under us due to truncation. Test it under folio lock as already done for the async compaction / dirty folio case. To prevent locking every folio with mapping to do the test, do it only for unevictable folios, as we can expect the unmovable mapping folios are also unevictable. To enforce that expecation, make mapping_set_unmovable() also set AS_UNEVICTABLE.
Also incorporate comment update suggested by Matthew.
---
v2: mapping_set_unmovable() sets also AS_UNEVICTABLE, as Sean suggested.
include/linux/pagemap.h | 6 +++++ mm/compaction.c | 49 +++++++++++++++++++++++++++-------------- virt/kvm/guest_mem.c | 2 +- 3 files changed, 39 insertions(+), 18 deletions(-)
include/linux/pagemap.h +6 -0
@@ -276,6 +276,12 @@ static inline int mapping_use_writeback_tags(struct address_space *mapping)static inline void mapping_set_unmovable (struct address_space *mapping) { +/* +* It's expected unmovable mappings are also unevictable. Compaction +* migrate scanner (isolate_migratepages_block()) relies on this to +* reduce page locking. +*/ +set_bit (AS_UNEVICTABLE , &mapping->flags);set_bit (AS_UNMOVABLE , &mapping->flags); }
mm/compaction.c +32 -17
82 lines not on this page · raw message
virt/kvm/guest_mem.c +1 -1
@@ -390,7 +390,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags, inode->i_size = size;mapping_set_gfp_mask (inode->i_mapping,GFP_HIGHUSER );mapping_set_large_folios (inode->i_mapping); -mapping_set_unevictable (inode->i_mapping); +/* this also sets the mapping as unevictable */ mapping_set_unmovable (inode->i_mapping); fd =get_unused_fd_flags (0 );
Signature · 1 line
2.42.0
Quoted 8 lines · Vlastimil Babka
As Kirill pointed out, mapping can be removed under us due to truncation. Test it under folio lock as already done for the async compaction / dirty folio case. To prevent locking every folio with mapping to do the test, do it only for unevictable folios, as we can expect the unmovable mapping folios are also unevictable. To enforce that expecation, make
mapping_set_unmovable()also setAS_UNEVICTABLE.[...]
Applied to kvm-x86 guest_memfd, thanks!
[1/1] mm, compaction: make testing mapping_unmovable() safe
https://github.com/kvm-x86/linux/commit/4876a35647b9
--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes