mm/vma: some more minor changes
Subsystems (7)
v2 cover mm/vma: some more minor changes
The motivation here is to consolidate VMA flags and helpers in generic memory header and reduce code duplication when ever applicable. If there are other possible similar instances which might be missing here, please do let me me know. I will be happy to incorporate them.
This series is based on v5.6-rc3. This series has been build tested on multiple platforms but boot tested only on arm64 and x86.
Changes in V2:
- Moved VM_NO_KHUGEPAGED after VM_SPECIAL with a comment per Vlastimil
- Renamed is_vma_temporary_stack() as vma_is_temporary_stack() per Vlastimil
Changes in V1: (https://patchwork.kernel.org/cover/11405177/)
Anshuman Khandual (3):
mm/vma: Move VM_NO_KHUGEPAGED into generic header mm/vma: Make vma_is_foreign() available for general use mm/vma: Make is_vma_temporary_stack() available for general use
arch/powerpc/mm/book3s64/pkeys.c | 12 ------------ arch/x86/include/asm/mmu_context.h | 15 --------------- include/linux/huge_mm.h | 4 +--- include/linux/mm.h | 29 ++++++++++++++++++++++++++++- mm/khugepaged.c | 4 +--- mm/mremap.c | 2 +- mm/rmap.c | 16 +--------------- 7 files changed, 32 insertions(+), 50 deletions(-)
Signature · 1 line
2.20.1
PATCH v2 1/3 mm/vma: Move VM_NO_KHUGEPAGED into generic header
Move VM_NO_KHUGEPAGED into generic header (include/linux/mm.h). This just makes sure that no VMA flag is scattered in individual function files any longer. While at this, fix an old comment which is no longer valid. This should not cause any functional change.
--- include/linux/mm.h | 4 +++- mm/khugepaged.c | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/mm.h +3 -1
@@ -356,10 +356,12 @@ extern unsigned int kobjsize(const void *objp);/* * Special vmas that are non-mergable, non-mlock()able. -* Note: mm/huge_memory.c VM_NO_THP depends on this definition. */ #define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP) +/* This mask prevents VMA from being scanned with khugepaged */ +#define VM_NO_KHUGEPAGED (VM_SPECIAL | VM_HUGETLB) +/* This mask defines which mm->def_flags a process can inherit its parent */ #define VM_INIT_DEF_MASK VM_NOHUGEPAGE
mm/khugepaged.c +0 -2
@@ -308,8 +308,6 @@ struct attribute_group khugepaged_attr_group = { };#endif /* CONFIG_SYSFS */ -#define VM_NO_KHUGEPAGED (VM_SPECIAL | VM_HUGETLB) -int hugepage_madvise (struct vm_area_struct *vma,unsigned long *vm_flags,int advice) {
Signature · 1 line
2.20.1
Re: [PATCH V2 1/3] mm/vma: Move VM_NO_KHUGEPAGED into generic header
Quoted 9 lines · Anshuman Khandual
Move
VM_NO_KHUGEPAGEDinto generic header (include/linux/mm.h). This just makes sure that no VMA flag is scattered in individual function files any longer. While at this, fix an old comment which is no longer valid. This should not cause any functional change.Cc Andrew Morton <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>
Thanks.
PATCH v2 2/3 mm/vma: Make vma_is_foreign() available for general use
In reply to Anshuman KhandualIdea of a foreign VMA with respect to the present context is very generic. But currently there are two identical definitions for this in powerpc and x86 platforms. Lets consolidate those redundant definitions while making vma_is_foreign() available for general use later. This should not cause any functional change.
--- arch/powerpc/mm/book3s64/pkeys.c | 12 ------------ arch/x86/include/asm/mmu_context.h | 15 --------------- include/linux/mm.h | 11 +++++++++++ 3 files changed, 11 insertions(+), 27 deletions(-)
arch/powerpc/mm/book3s64/pkeys.c +0 -12
@@ -381,18 +381,6 @@ bool arch_pte_access_permitted(u64 pte, bool write, bool execute)* So do not enforce things if the VMA is not from the current mm, or if we are * in a kernel thread. */ -static inline bool vma_is_foreign (struct vm_area_struct *vma) -{ -if (!current->mm) -return true; - -/* if it is not our ->mm, it has to be foreign */ -if (current->mm != vma->vm_mm) -return true; - -return false; -} -bool arch_vma_access_permitted (struct vm_area_struct *vma,bool write,bool execute,bool foreign) {
arch/x86/include/asm/mmu_context.h +0 -15
@@ -213,21 +213,6 @@ static inline void arch_unmap(struct mm_struct *mm, unsigned long start,* So do not enforce things if the VMA is not from the current * mm, or if we are in a kernel thread. */ -static inline bool vma_is_foreign (struct vm_area_struct *vma) -{ -if (!current->mm) -return true; -/* -* Should PKRU be enforced on the access to this VMA? If -* the VMA is from another process, then PKRU has no -* relevance and should not be enforced. -*/ -if (current->mm != vma->vm_mm) -return true; - -return false; -} -static inline bool arch_vma_access_permitted (struct vm_area_struct *vma,bool write,bool execute,bool foreign) {
include/linux/mm.h +11 -0
@@ -27,6 +27,7 @@#include <linux/memremap.h> #include <linux/overflow.h> #include <linux/sizes.h> +#include <linux/sched.h> struct mempolicy ;struct anon_vma ;
@@ -543,6 +544,16 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma)return !vma->vm_ops; } +static inline bool vma_is_foreign (struct vm_area_struct *vma) +{ +if (!current->mm) +return true; + +if (current->mm != vma->vm_mm) +return true; + +return false; +}#ifdef CONFIG_SHMEM /* * The vma_is_shmem is not inline because it is used only by slow
Signature · 1 line
2.20.1
PATCH v2 3/3 mm/vma: Make is_vma_temporary_stack() available for general use
In reply to Anshuman KhandualCurrently the declaration and definition for is_vma_temporary_stack() are scattered. Lets make is_vma_temporary_stack() helper available for general use and also drop the declaration from (include/linux/huge_mm.h) which is no longer required. While at this, rename this as vma_is_temporary_stack() in line with existing helpers. This should not cause any functional change.
--- include/linux/huge_mm.h | 4 +--- include/linux/mm.h | 14 ++++++++++++++ mm/khugepaged.c | 2 +- mm/mremap.c | 2 +- mm/rmap.c | 16 +--------------- 5 files changed, 18 insertions(+), 20 deletions(-)
include/linux/huge_mm.h +1 -3
@@ -87,8 +87,6 @@ extern struct kobj_attribute shmem_enabled_attr;#define HPAGE_PUD_SIZE ((1UL) << HPAGE_PUD_SHIFT)#define HPAGE_PUD_MASK (~(HPAGE_PUD_SIZE - 1)) -extern bool is_vma_temporary_stack (struct vm_area_struct *vma); -extern unsigned long transparent_hugepage_flags;/*
@@ -100,7 +98,7 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma)if (vma->vm_flags &VM_NOHUGEPAGE )return false; -if (is_vma_temporary_stack (vma)) +if (vma_is_temporary_stack (vma))return false;if (test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags))
include/linux/mm.h +14 -0
@@ -544,6 +544,20 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma)return !vma->vm_ops; } +static inline bool vma_is_temporary_stack (struct vm_area_struct *vma) +{ +int maybe_stack = vma->vm_flags & (VM_GROWSDOWN |VM_GROWSUP ); + +if (!maybe_stack) +return false; + +if ((vma->vm_flags &VM_STACK_INCOMPLETE_SETUP ) == +VM_STACK_INCOMPLETE_SETUP ) +return true; + +return false; +} +static inline bool vma_is_foreign (struct vm_area_struct *vma) {if (!current->mm)
mm/khugepaged.c +1 -1
@@ -421,7 +421,7 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, }if (!vma->anon_vma || vma->vm_ops)return false; -if (is_vma_temporary_stack (vma)) +if (vma_is_temporary_stack (vma))return false;return !(vm_flags &VM_NO_KHUGEPAGED ); }
mm/mremap.c +1 -1
@@ -133,7 +133,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,* such races: * * - During exec() shift_arg_pages(), we use a specially tagged vma -* which rmap call sites look for using is_vma_temporary_stack(). +* which rmap call sites look for using vma_is_temporary_stack(). * * - During mremap(), new_vma is often known to be placed after vma * in rmap traversal order. This ensures rmap will always observe
mm/rmap.c +1 -15
@@ -1696,23 +1696,9 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,return ret; } -bool is_vma_temporary_stack (struct vm_area_struct *vma) -{ -int maybe_stack = vma->vm_flags & (VM_GROWSDOWN |VM_GROWSUP ); - -if (!maybe_stack) -return false; - -if ((vma->vm_flags &VM_STACK_INCOMPLETE_SETUP ) == -VM_STACK_INCOMPLETE_SETUP ) -return true; - -return false; -} -static bool invalid_migration_vma (struct vm_area_struct *vma,void *arg) { -return is_vma_temporary_stack (vma); +return vma_is_temporary_stack (vma); }static int page_mapcount_is_zero (struct page *page)
Signature · 1 line
2.20.1
Re: [PATCH V2 3/3] mm/vma: Make is_vma_temporary_stack() available for general use
Quoted 10 lines · Anshuman Khandual
Currently the declaration and definition for
is_vma_temporary_stack()are scattered. Lets makeis_vma_temporary_stack()helper available for general use and also drop the declaration from (include/linux/huge_mm.h) which is no longer required. While at this, rename this asvma_is_temporary_stack()in line with existing helpers. This should not cause any functional change.Cc Andrew Morton <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>
Thanks.