mm: Define pte_index as macro for x86
Subsystems (3)
PATCH v3 1/2 mm: Define pte_index as macro for x86
From: Arjun Roy <[email protected]>
pte_index() is either defined as a macro (e.g. sparc64) or as an inlined function (e.g. x86). vm_insert_pages() depends on pte_index but it is not defined on all platforms (e.g. m68k).
To fix compilation of vm_insert_pages() on architectures not providing pte_index(), we perform the following fix:
0. For platforms where it is meaningful, and defined as a macro, no change is needed.
1. For platforms where it is meaningful and defined as an inlined function, and we want to use it with vm_insert_pages(), we define a degenerate macro of the form: #define pte_index pte_index
2. vm_insert_pages() checks for the existence of a pte_index macro definition. If found, it implements a batched insert. If not found, it devolves to calling vm_insert_page() in a loop.
This patch implements step 1 for x86.
v3 of this patch fixes a compilation warning for an unused method. v2 of this patch moved a macro definition to a more readable location.
--- arch/x86/include/asm/pgtable.h | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/include/asm/pgtable.h +3 -0
@@ -828,7 +828,10 @@ static inline unsigned long pmd_index(unsigned long address)* * this function returns the index of the entry in the pte page which would * control the given virtual address +* +* Also define macro so we can test if pte_index is defined for arch. */ +#define pte_index pte_indexstatic inline unsigned long pte_index (unsigned long address) {return (address >>PAGE_SHIFT ) & (PTRS_PER_PTE -1 );
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v3 2/2 mm: vm_insert_pages() checks if pte_index defined.
From: Arjun Roy <[email protected]>
pte_index() is either defined as a macro (e.g. sparc64) or as an inlined function (e.g. x86). vm_insert_pages() depends on pte_index but it is not defined on all platforms (e.g. m68k).
To fix compilation of vm_insert_pages() on architectures not providing pte_index(), we perform the following fix:
0. For platforms where it is meaningful, and defined as a macro, no change is needed.
1. For platforms where it is meaningful and defined as an inlined function, and we want to use it with vm_insert_pages(), we define a degenerate macro of the form: #define pte_index pte_index
2. vm_insert_pages() checks for the existence of a pte_index macro definition. If found, it implements a batched insert. If not found, it devolves to calling vm_insert_page() in a loop.
This patch implements step 2.
v3 of this patch fixes a compilation warning for an unused method. v2 of this patch moved a macro definition to a more readable location.
--- mm/memory.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-)
mm/memory.c +28 -13
@@ -1460,18 +1460,6 @@ static int insert_page_into_pte_locked(struct mm_struct *mm, pte_t *pte,return 0 ; } -static int insert_page_in_batch_locked (struct mm_struct *mm,pmd_t *pmd, -unsigned long addr,struct page *page,pgprot_t prot) -{ -int err; - -if (!page_count (page)) -return -EINVAL ; - err =validate_page_before_insert (page); -return err ? err :insert_page_into_pte_locked ( - mm,pte_offset_map (pmd, addr), addr, page, prot); -} -/* * This is the old fallback for page remapping. *
@@ -1500,8 +1488,21 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,return retval; } +#ifdef pte_index +static int insert_page_in_batch_locked (struct mm_struct *mm,pmd_t *pmd, +unsigned long addr,struct page *page,pgprot_t prot) +{ +int err; + +if (!page_count (page)) +return -EINVAL ; + err =validate_page_before_insert (page); +return err ? err :insert_page_into_pte_locked ( + mm,pte_offset_map (pmd, addr), addr, page, prot); +} +/* insert_pages() amortizes the cost of spinlock operations -* when inserting pages in a loop. +* when inserting pages in a loop. Arch *must* define pte_index. */ static int insert_pages (struct vm_area_struct *vma,unsigned long addr,struct page **pages,unsigned long *num,pgprot_t prot)
@@ -1556,6 +1557,7 @@ static int insert_pages(struct vm_area_struct *vma, unsigned long addr, *num = remaining_pages_total; return ret; } +#endif /* ifdef pte_index */ /** * vm_insert_pages - insert multiple pages into user vma, batching the pmd lock.
@@ -1575,6 +1577,7 @@ static int insert_pages(struct vm_area_struct *vma, unsigned long addr,int vm_insert_pages (struct vm_area_struct *vma,unsigned long addr,struct page **pages,unsigned long *num) { +#ifdef pte_indexconst unsigned long end_addr = addr + (*num *PAGE_SIZE ) -1 ;if (addr < vma->vm_start || end_addr >= vma->vm_end)
@@ -1586,6 +1589,18 @@ int vm_insert_pages(struct vm_area_struct *vma, unsigned long addr, }/* Defer page refcount checking till we're about to map that page. */ return insert_pages (vma, addr, pages, num, vma->vm_page_prot); +#else +unsigned long idx =0 , pgcount = *num; +int err; + +for (; idx < pgcount; ++idx) { + err =vm_insert_page (vma, addr + (PAGE_SIZE * idx), pages[idx]); +if (err) +break ; + } + *num = pgcount - idx; +return err; +#endif /* ifdef pte_index */ }EXPORT_SYMBOL (vm_insert_pages);
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Re: [PATCH v3 mm 2/2] mm: vm_insert_pages() checks if pte_index defined.
Quoted 23 lines · Arjun Roy
mm/memory.c +1
-12+++ b/mm/memory.c@@ -1460,18 +1460,6 @@ static int insert_page_into_pte_locked(struct mm_struct *mm, pte_t *pte,return 0 ; } -static int insert_page_in_batch_locked (struct mm_struct *mm,pmd_t *pmd, -unsigned long addr,struct page *page,pgprot_t prot) -{ -int err; - -if (!page_count (page)) -return -EINVAL ; - err =validate_page_before_insert (page); -return err ? err :insert_page_into_pte_locked ( - mm,pte_offset_map (pmd, addr), addr, page, prot); -} -/* * This is the old fallback for page remapping. *
mm/memory.c static int insert_page(struct vm_area_struct *vma, unsigned long addr, · line 1491
Quoted 4 lines
mm/memory.c +1
-0@@ -1500,8 +1488,21 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,return retval; } +#ifdef pte_index
It seems a bit weird like this, don't we usually do this kind of stuff with some CONFIG_ARCH_HAS_XX thing?
IMHO all arches should implement pte_index as the static inline, that has been the general direction lately.
Jason
Re: [PATCH v3 mm 2/2] mm: vm_insert_pages() checks if pte_index defined.
Quoted 28 lines · Jason Gunthorpe
Quoted 26 lines · Arjun Roy
mm/memory.c +1
-12+++ b/mm/memory.c@@ -1460,18 +1460,6 @@ static int insert_page_into_pte_locked(struct mm_struct *mm, pte_t *pte,return 0 ; } -static int insert_page_in_batch_locked (struct mm_struct *mm,pmd_t *pmd, -unsigned long addr,struct page *page,pgprot_t prot) -{ -int err; - -if (!page_count (page)) -return -EINVAL ; - err =validate_page_before_insert (page); -return err ? err :insert_page_into_pte_locked ( - mm,pte_offset_map (pmd, addr), addr, page, prot); -} -/* * This is the old fallback for page remapping. * @@ -1500,8 +1488,21 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,return retval; }
Quoted 7 lines
mm/memory.c static int insert_page(struct vm_area_struct *vma, unsigned long addr, · line 1491
Quoted 1 line
mm/memory.c +1
-0+#ifdef pte_indexIt seems a bit weird like this, don't we usually do this kind of stuff with some
CONFIG_ARCH_HAS_XXthing?IMHO all arches should implement
pte_indexas the static inline, that has been the general direction lately.
Based on a comment from Stephen Rothwell, we found out that "static inline" functions are only used in tile and x86. That's why Arjun opted for this method to create a smaller patch-series to fix the build breakage.
Thanks,
Soheil
Quoted 1 line
Jason