[RFC PATCH 01/16] mm/madvise: use is_memory_failure() from madvise_do_behavior()

SeongJae Park posted 16 patches 9 months, 2 weeks ago
There is a newer version of this series
[RFC PATCH 01/16] mm/madvise: use is_memory_failure() from madvise_do_behavior()
Posted by SeongJae Park 9 months, 2 weeks ago
To reduce redundant open-coded checks of CONFIG_MEMORY_FAILURE and
MADV_{HWPOISON,SOFT_OFFLINE} in madvise_[un]lock(), is_memory_failure()
has introduced.  madvise_do_behavior() is still doing the same
open-coded check, though.  Use is_memory_failure() instead.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/madvise.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 388dc289b5d1..dbc8fec05cc6 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1640,10 +1640,8 @@ static int madvise_do_behavior(struct mm_struct *mm,
 	unsigned long end;
 	int error;
 
-#ifdef CONFIG_MEMORY_FAILURE
-	if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE)
+	if (is_memory_failure(behavior))
 		return madvise_inject_error(behavior, start, start + len_in);
-#endif
 	start = untagged_addr_remote(mm, start);
 	end = start + len;
 
-- 
2.39.5
Re: [RFC PATCH 01/16] mm/madvise: use is_memory_failure() from madvise_do_behavior()
Posted by Shakeel Butt 9 months, 2 weeks ago
On Wed, Mar 05, 2025 at 10:15:56AM -0800, SeongJae Park wrote:
> To reduce redundant open-coded checks of CONFIG_MEMORY_FAILURE and
> MADV_{HWPOISON,SOFT_OFFLINE} in madvise_[un]lock(), is_memory_failure()
> has introduced.  madvise_do_behavior() is still doing the same
> open-coded check, though.  Use is_memory_failure() instead.
> 
> Signed-off-by: SeongJae Park <sj@kernel.org>
> ---
>  mm/madvise.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 388dc289b5d1..dbc8fec05cc6 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -1640,10 +1640,8 @@ static int madvise_do_behavior(struct mm_struct *mm,
>  	unsigned long end;
>  	int error;
>  
> -#ifdef CONFIG_MEMORY_FAILURE
> -	if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE)
> +	if (is_memory_failure(behavior))
>  		return madvise_inject_error(behavior, start, start + len_in);

You might want to either define empty madvise_inject_error() for
!CONFIG_MEMORY_FAILURE or keep CONFIG_MEMORY_FAILURE here.

> -#endif
>  	start = untagged_addr_remote(mm, start);
>  	end = start + len;
>  
> -- 
> 2.39.5
Re: [RFC PATCH 01/16] mm/madvise: use is_memory_failure() from madvise_do_behavior()
Posted by SeongJae Park 9 months, 2 weeks ago
On Wed, 5 Mar 2025 12:25:51 -0800 Shakeel Butt <shakeel.butt@linux.dev> wrote:

> On Wed, Mar 05, 2025 at 10:15:56AM -0800, SeongJae Park wrote:
> > To reduce redundant open-coded checks of CONFIG_MEMORY_FAILURE and
> > MADV_{HWPOISON,SOFT_OFFLINE} in madvise_[un]lock(), is_memory_failure()
> > has introduced.  madvise_do_behavior() is still doing the same
> > open-coded check, though.  Use is_memory_failure() instead.
> > 
> > Signed-off-by: SeongJae Park <sj@kernel.org>
> > ---
> >  mm/madvise.c | 4 +---
> >  1 file changed, 1 insertion(+), 3 deletions(-)
> > 
> > diff --git a/mm/madvise.c b/mm/madvise.c
> > index 388dc289b5d1..dbc8fec05cc6 100644
> > --- a/mm/madvise.c
> > +++ b/mm/madvise.c
> > @@ -1640,10 +1640,8 @@ static int madvise_do_behavior(struct mm_struct *mm,
> >  	unsigned long end;
> >  	int error;
> >  
> > -#ifdef CONFIG_MEMORY_FAILURE
> > -	if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE)
> > +	if (is_memory_failure(behavior))
> >  		return madvise_inject_error(behavior, start, start + len_in);
> 
> You might want to either define empty madvise_inject_error() for
> !CONFIG_MEMORY_FAILURE or keep CONFIG_MEMORY_FAILURE here.

Good catch.  I confirmed build fails when !CONFIG_MEMORY_FAILURE.  I will
define empty madvise_inject_error().

> 
> > -#endif
> >  	start = untagged_addr_remote(mm, start);
> >  	end = start + len;
> >  
> > -- 
> > 2.39.5