2022-01-11 14:55:11

by Mike Rapoport

[permalink] [raw]
Subject: [PATCH] mm/pgtable: define pte_index so that preprocessor could recognize it

From: Mike Rapoport <[email protected]>

Since commit 974b9b2c68f3 ("mm: consolidate pte_index() and pte_offset_*()
definitions") pte_index is a static inline and there is no define for it
that can be recognized by the preprocessor. As the result,
vm_insert_pages() uses slower loop over vm_insert_page() instead of
insert_pages() that amortizes the cost of spinlock operations when
inserting multiple pages.

Fixes: 974b9b2c68f3 ("mm: consolidate pte_index() and pte_offset_*() definitions")
Reported-by: Christian Dietrich <[email protected]>
Signed-off-by: Mike Rapoport <[email protected]>
Cc: [email protected]
---
include/linux/pgtable.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index e24d2c992b11..d468efcf48f4 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -62,6 +62,7 @@ static inline unsigned long pte_index(unsigned long address)
{
return (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
}
+#define pte_index pte_index

#ifndef pmd_index
static inline unsigned long pmd_index(unsigned long address)

base-commit: 2585cf9dfaaddf00b069673f27bb3f8530e2039c
--
2.28.0



2022-01-11 15:30:11

by Christian Dietrich

[permalink] [raw]
Subject: Re: [PATCH] mm/pgtable: define pte_index so that preprocessor could recognize it

Hello Mike!

Mike Rapoport <[email protected]> [11. Januar 2022]:

> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index e24d2c992b11..d468efcf48f4 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -62,6 +62,7 @@ static inline unsigned long pte_index(unsigned long address)
> {
> return (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
> }
> +#define pte_index pte_index

Wouldn't it make sense to remove the dead CPP blocks (#ifdef pte_index)
from mm/memory.c? Or is there a case were pte_index is not defined for
an architecture?

chris
--
Prof. Dr.-Ing. Christian Dietrich
Operating System Group (E-EXK4)
Technische Universität Hamburg
Am Schwarzenberg-Campus 3 (E), 4.092
21073 Hamburg

eMail: [email protected]
Tel: +49 40 42878 2188
WWW: https://osg.tuhh.de/

2022-01-11 17:11:09

by Mike Rapoport

[permalink] [raw]
Subject: Re: [PATCH] mm/pgtable: define pte_index so that preprocessor could recognize it

Hi Christian,

On Tue, Jan 11, 2022 at 04:20:34PM +0100, Christian Dietrich wrote:
> Hello Mike!
>
> Mike Rapoport <[email protected]> [11. Januar 2022]:
>
> > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> > index e24d2c992b11..d468efcf48f4 100644
> > --- a/include/linux/pgtable.h
> > +++ b/include/linux/pgtable.h
> > @@ -62,6 +62,7 @@ static inline unsigned long pte_index(unsigned long address)
> > {
> > return (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
> > }
> > +#define pte_index pte_index
>
> Wouldn't it make sense to remove the dead CPP blocks (#ifdef pte_index)
> from mm/memory.c?

It does make sense to remove the dead code, but this cleanup does not need
stable backporting so it'll be a separate patch.

Care to send a patch? ;-)

> Or is there a case were pte_index is not defined for an architecture?

Nope, the fix in include/linux/pgtable.h covers MMU architectures and NOMMU
do not compile mm/memory.c anyway.

> chris
> --

--
Sincerely yours,
Mike.

2022-01-11 18:44:29

by Khalid Aziz

[permalink] [raw]
Subject: Re: [PATCH] mm/pgtable: define pte_index so that preprocessor could recognize it

On Tue, 2022-01-11 at 16:54 +0200, Mike Rapoport wrote:
> From: Mike Rapoport <[email protected]>
>
> Since commit 974b9b2c68f3 ("mm: consolidate pte_index() and
> pte_offset_*()
> definitions") pte_index is a static inline and there is no define for
> it
> that can be recognized by the preprocessor. As the result,
> vm_insert_pages() uses slower loop over vm_insert_page() instead of
> insert_pages() that amortizes the cost of spinlock operations when
> inserting multiple pages.
>
> Fixes: 974b9b2c68f3 ("mm: consolidate pte_index() and pte_offset_*()
> definitions")
> Reported-by: Christian Dietrich <[email protected]>
> Signed-off-by: Mike Rapoport <[email protected]>
> Cc: [email protected]
> ---
>  include/linux/pgtable.h | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index e24d2c992b11..d468efcf48f4 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -62,6 +62,7 @@ static inline unsigned long pte_index(unsigned long
> address)
>  {
>         return (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
>  }
> +#define pte_index pte_index
>  
>  #ifndef pmd_index
>  static inline unsigned long pmd_index(unsigned long address)
>
> base-commit: 2585cf9dfaaddf00b069673f27bb3f8530e2039c

This is a good fix with positive performance impact.

Reviewed-by: Khalid Aziz <[email protected]>