mm: move mask update out of the atomic context
Subsystems (2)
PATCH 1/1 mm: move mask update out of the atomic context
There is not need to modify page table synchronization mask while apply_to_pte_range() holds user page tables spinlock.
--- mm/memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/memory.c +2 -1
@@ -3035,12 +3035,13 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd, } }while (pte++, addr +=PAGE_SIZE , addr != end); } - *mask |=PGTBL_PTE_MODIFIED ;arch_leave_lazy_mmu_mode ();if (mm != &init_mm)pte_unmap_unlock (mapped_pte, ptl); + *mask |=PGTBL_PTE_MODIFIED ; +return err; }
Signature · 1 line
2.48.1
Quoted 2 lines · Alexander Gordeev
There is not need to modify page table synchronization mask while
apply_to_pte_range()holds user page tables spinlock.
I don't get you, what is the problem with the current code? Are you just concerned about the duration of holding the lock?
Quoted 25 lines
Signed-off-by Alexander Gordeev <[email protected]>--- mm/memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/memory.c +2
-1@@ -3035,12 +3035,13 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd, } }while (pte++, addr +=PAGE_SIZE , addr != end); } - *mask |=PGTBL_PTE_MODIFIED ;arch_leave_lazy_mmu_mode ();if (mm != &init_mm)pte_unmap_unlock (mapped_pte, ptl); + *mask |=PGTBL_PTE_MODIFIED ; +return err; }
Quoted 8 lines · Dev Jain
Quoted 2 lines · Alexander Gordeev
There is not need to modify page table synchronization mask while
apply_to_pte_range()holds user page tables spinlock.I don't get you, what is the problem with the current code? Are you just concerned about the duration of holding the lock?
Yes.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Alexander Gordeev <[email protected]>--- mm/memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/memory.c +2
-1@@ -3035,12 +3035,13 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd, } }while (pte++, addr +=PAGE_SIZE , addr != end); } - *mask |=PGTBL_PTE_MODIFIED ;arch_leave_lazy_mmu_mode ();if (mm != &init_mm)pte_unmap_unlock (mapped_pte, ptl); + *mask |=PGTBL_PTE_MODIFIED ; +return err; }
Dev Jain
Reviewed-byQuoted 8 lines · Alexander Gordeev
Quoted 6 lines · Dev Jain
Quoted 2 lines · Alexander Gordeev
There is not need to modify page table synchronization mask while
apply_to_pte_range()holds user page tables spinlock.I don't get you, what is the problem with the current code? Are you just concerned about the duration of holding the lock?
Yes.
Doesn't really matter but still a correct change:
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Signed-off-by Alexander Gordeev <[email protected]>--- mm/memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/memory.c +2
-1@@ -3035,12 +3035,13 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd, } }while (pte++, addr +=PAGE_SIZE , addr != end); } - *mask |=PGTBL_PTE_MODIFIED ;arch_leave_lazy_mmu_mode ();if (mm != &init_mm)pte_unmap_unlock (mapped_pte, ptl); + *mask |=PGTBL_PTE_MODIFIED ; +return err; }
Quoted 4 lines · Dev Jain
Quoted 2 lines · Alexander Gordeev
Quoted 1 line · Dev Jain
On 23/06/25 1:34 pm, Alexander Gordeev wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
There is not need to modify page table synchronization mask while
apply_to_pte_range()holds user page tables spinlock.I don't get you, what is the problem with the current code? Are you just concerned about the duration of holding the lock?
Yes.
Doesn't really matter but still a correct change:
Let's ask the real questions: who checks PGTBL_PTE_MODIFIED?
I see
if (mask & ARCH_PAGE_TABLE_SYNC_MASK)
arch_sync_kernel_mappings(start, start + size);
And then
arch/arm/include/asm/page.h:#define ARCH_PAGE_TABLE_SYNC_MASK PGTBL_PMD_MODIFIED
arch/x86/include/asm/pgtable-2level_types.h:#define ARCH_PAGE_TABLE_SYNC_MASK PGTBL_PMD_MODIFIED
arch/x86/include/asm/pgtable-3level_types.h:#define ARCH_PAGE_TABLE_SYNC_MASK PGTBL_PMD_MODIFIED
Which makes me wonder why we need PGTBL_PTE_MODIFIED at all? Is there some other check I am missing?
(same question regarding everything excepy PGTBL_PMD_MODIFIED, because that actually seems to be used)
Signature · 3 lines
Cheers, David / dhildenb
On Mon, Jun 23, 2025 at 09:45:34PM +0200, David Hildenbrand wrote:
...
Quoted 9 lines
Let's ask the real questions: who checks
PGTBL_PTE_MODIFIED?I see
if (mask &
ARCH_PAGE_TABLE_SYNC_MASK)arch_sync_kernel_mappings(start, start + size);And then
Quoted 8 lines
arch/arm/include/asm/page.h:#define
ARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIED
arch/x86/include/asm/pgtable-2level_types.h:#defineARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIED
arch/x86/include/asm/pgtable-3level_types.h:#defineARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIEDWhich makes me wonder why we need
PGTBL_PTE_MODIFIEDat all? Is there some other check I am missing?(same question regarding everything excepy
PGTBL_PMD_MODIFIED, because that actually seems to be used)
AFAICT it was thought as architecture-specific:
/*
* Architectures can set this mask to a combination of PGTBL_P?D_MODIFIED values
* and let generic vmalloc and ioremap code know when arch_sync_kernel_mappings()
* needs to be called.
*/
#ifndef ARCH_PAGE_TABLE_SYNC_MASK
#define ARCH_PAGE_TABLE_SYNC_MASK 0
#endif
Not sure if that needs to be addressed at all.
Quoted 4 lines
Signature · 3 lines
Cheers, David / dhildenb
Thanks!
Quoted 31 lines · Alexander Gordeev
On Mon, Jun 23, 2025 at 09:45:34PM +0200, David Hildenbrand wrote:
...Quoted 9 lines
Let's ask the real questions: who checks
PGTBL_PTE_MODIFIED?I see
if (mask &
ARCH_PAGE_TABLE_SYNC_MASK)arch_sync_kernel_mappings(start, start + size);And then
Quoted 8 lines
arch/arm/include/asm/page.h:#define
ARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIED
arch/x86/include/asm/pgtable-2level_types.h:#defineARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIED
arch/x86/include/asm/pgtable-3level_types.h:#defineARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIEDWhich makes me wonder why we need
PGTBL_PTE_MODIFIEDat all? Is there some other check I am missing?(same question regarding everything excepy
PGTBL_PMD_MODIFIED, because that actually seems to be used)AFAICT it was thought as architecture-specific:
/*
* Architectures can set this mask to a combination of PGTBL_P?D_MODIFIED values
* and let generic vmalloc and ioremap code know whenarch_sync_kernel_mappings()
* needs to be called.
*/
#ifndefARCH_PAGE_TABLE_SYNC_MASK
#defineARCH_PAGE_TABLE_SYNC_MASK0
#endif
Quoted 1 line
Not sure if that needs to be addressed at all.
Okay, if there are no users of PGTBL_PTE_MODIFIED we could just ... remove it. Dead code.
Signature · 3 lines
Cheers, David / dhildenb
Quoted 32 lines · David Hildenbrand
Quoted 31 lines · Alexander Gordeev
On Mon, Jun 23, 2025 at 09:45:34PM +0200, David Hildenbrand wrote:
...Quoted 9 lines
Let's ask the real questions: who checks
PGTBL_PTE_MODIFIED?I see
if (mask &
ARCH_PAGE_TABLE_SYNC_MASK)arch_sync_kernel_mappings(start, start + size);And then
Quoted 8 lines
arch/arm/include/asm/page.h:#define
ARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIED
arch/x86/include/asm/pgtable-2level_types.h:#defineARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIED
arch/x86/include/asm/pgtable-3level_types.h:#defineARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIEDWhich makes me wonder why we need
PGTBL_PTE_MODIFIEDat all? Is there some other check I am missing?(same question regarding everything excepy
PGTBL_PMD_MODIFIED, because that actually seems to be used)AFAICT it was thought as architecture-specific:
/*
* Architectures can set this mask to a combination of PGTBL_P?D_MODIFIED values
* and let generic vmalloc and ioremap code know whenarch_sync_kernel_mappings()
* needs to be called.
*/
#ifndefARCH_PAGE_TABLE_SYNC_MASK
#defineARCH_PAGE_TABLE_SYNC_MASK0
#endif
Quoted 4 lines
Quoted 1 line
Not sure if that needs to be addressed at all.
Okay, if there are no users of
PGTBL_PTE_MODIFIEDwe could just ... remove it. Dead code.
As you noticed, PGTBL_PMD_MODIFIED bit is used only. Thus, all other bits would have to be removed as well, not just PGTBL_PTE_MODIFIED?
That is more or less revert of at least the below commits and rewriting it in a PMD-focused manner:
2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified") d8626138009b ("mm: add functions to track page directory modifications")
That would be a completely different effort, which I am not aming at ;)
Quoted 4 lines
Signature · 3 lines
Cheers, David / dhildenb
Thanks!
Quoted 33 lines · Alexander Gordeev
Quoted 32 lines · David Hildenbrand
Quoted 31 lines · Alexander Gordeev
On Mon, Jun 23, 2025 at 09:45:34PM +0200, David Hildenbrand wrote:
...Quoted 9 lines
Let's ask the real questions: who checks
PGTBL_PTE_MODIFIED?I see
if (mask &
ARCH_PAGE_TABLE_SYNC_MASK)arch_sync_kernel_mappings(start, start + size);And then
Quoted 8 lines
arch/arm/include/asm/page.h:#define
ARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIED
arch/x86/include/asm/pgtable-2level_types.h:#defineARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIED
arch/x86/include/asm/pgtable-3level_types.h:#defineARCH_PAGE_TABLE_SYNC_MASKPGTBL_PMD_MODIFIEDWhich makes me wonder why we need
PGTBL_PTE_MODIFIEDat all? Is there some other check I am missing?(same question regarding everything excepy
PGTBL_PMD_MODIFIED, because that actually seems to be used)AFAICT it was thought as architecture-specific:
/*
* Architectures can set this mask to a combination of PGTBL_P?D_MODIFIED values
* and let generic vmalloc and ioremap code know whenarch_sync_kernel_mappings()
* needs to be called.
*/
#ifndefARCH_PAGE_TABLE_SYNC_MASK
#defineARCH_PAGE_TABLE_SYNC_MASK0
#endif
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Not sure if that needs to be addressed at all.
Okay, if there are no users of
PGTBL_PTE_MODIFIEDwe could just ... remove it. Dead code.As you noticed,
PGTBL_PMD_MODIFIEDbit is used only. Thus, all other bits would have to be removed as well, not justPGTBL_PTE_MODIFIED?
Likely, yes.
Quoted 8 lines
That is more or less revert of at least the below commits and rewriting it in a PMD-focused manner:
2ba3e6947aed("mm/vmalloc: track which page-table levels were modified")d8626138009b("mm: add functions to track page directory modifications")That would be a completely different effort, which I am not aming at ;)
Well, I don't think we should be taking this micro-optimization patch here TBH. The real optimization is getting rid of dead code, not optimizing dead code.
Signature · 3 lines
Cheers, David / dhildenb