diff mbox series

[v6,6/6] mm/mempolicy: unify the create() func for bind/interleave/prefer-many policies

Message ID 1626077374-81682-7-git-send-email-feng.tang@intel.com (mailing list archive)
State New
Headers show
Series Introduce multi-preference mempolicy | expand

Commit Message

Feng Tang July 12, 2021, 8:09 a.m. UTC
As they all do the same thing: sanity check and save nodemask info, create
one mpol_new_nodemask() to reduce redundancy.

Signed-off-by: Feng Tang <feng.tang@intel.com>
---
 mm/mempolicy.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

Comments

Michal Hocko July 28, 2021, 12:51 p.m. UTC | #1
On Mon 12-07-21 16:09:34, Feng Tang wrote:
> As they all do the same thing: sanity check and save nodemask info, create
> one mpol_new_nodemask() to reduce redundancy.

Do we really need a create() callback these days?

> Signed-off-by: Feng Tang <feng.tang@intel.com>

Other than that LGTM
Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/mempolicy.c | 24 ++++--------------------
>  1 file changed, 4 insertions(+), 20 deletions(-)
> 
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index d90247d6a71b..e5ce5a7e8d92 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -192,7 +192,7 @@ static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
>  	nodes_onto(*ret, tmp, *rel);
>  }
>  
> -static int mpol_new_interleave(struct mempolicy *pol, const nodemask_t *nodes)
> +static int mpol_new_nodemask(struct mempolicy *pol, const nodemask_t *nodes)
>  {
>  	if (nodes_empty(*nodes))
>  		return -EINVAL;
> @@ -210,22 +210,6 @@ static int mpol_new_preferred(struct mempolicy *pol, const nodemask_t *nodes)
>  	return 0;
>  }
>  
> -static int mpol_new_preferred_many(struct mempolicy *pol, const nodemask_t *nodes)
> -{
> -	if (nodes_empty(*nodes))
> -		return -EINVAL;
> -	pol->nodes = *nodes;
> -	return 0;
> -}
> -
> -static int mpol_new_bind(struct mempolicy *pol, const nodemask_t *nodes)
> -{
> -	if (nodes_empty(*nodes))
> -		return -EINVAL;
> -	pol->nodes = *nodes;
> -	return 0;
> -}
> -
>  /*
>   * mpol_set_nodemask is called after mpol_new() to set up the nodemask, if
>   * any, for the new policy.  mpol_new() has already validated the nodes
> @@ -405,7 +389,7 @@ static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {
>  		.rebind = mpol_rebind_default,
>  	},
>  	[MPOL_INTERLEAVE] = {
> -		.create = mpol_new_interleave,
> +		.create = mpol_new_nodemask,
>  		.rebind = mpol_rebind_nodemask,
>  	},
>  	[MPOL_PREFERRED] = {
> @@ -413,14 +397,14 @@ static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {
>  		.rebind = mpol_rebind_preferred,
>  	},
>  	[MPOL_BIND] = {
> -		.create = mpol_new_bind,
> +		.create = mpol_new_nodemask,
>  		.rebind = mpol_rebind_nodemask,
>  	},
>  	[MPOL_LOCAL] = {
>  		.rebind = mpol_rebind_default,
>  	},
>  	[MPOL_PREFERRED_MANY] = {
> -		.create = mpol_new_preferred_many,
> +		.create = mpol_new_nodemask,
>  		.rebind = mpol_rebind_preferred,
>  	},
>  };
> -- 
> 2.7.4
Feng Tang July 28, 2021, 1:50 p.m. UTC | #2
On Wed, Jul 28, 2021 at 02:51:42PM +0200, Michal Hocko wrote:
> On Mon 12-07-21 16:09:34, Feng Tang wrote:
> > As they all do the same thing: sanity check and save nodemask info, create
> > one mpol_new_nodemask() to reduce redundancy.
> 
> Do we really need a create() callback these days?

I think it tries to provide a per-policy sanity check (though
it's the same for all existing ones), and a per-policy
nodemask setting (current 'prefer' policy is different from
others).

> > Signed-off-by: Feng Tang <feng.tang@intel.com>
> 
> Other than that LGTM
> Acked-by: Michal Hocko <mhocko@suse.com>

Thanks!

- Feng

> > ---
> >  mm/mempolicy.c | 24 ++++--------------------
> >  1 file changed, 4 insertions(+), 20 deletions(-)
> > 
> > diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> > index d90247d6a71b..e5ce5a7e8d92 100644
> > --- a/mm/mempolicy.c
> > +++ b/mm/mempolicy.c
> > @@ -192,7 +192,7 @@ static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
> >  	nodes_onto(*ret, tmp, *rel);
> >  }
> >  
> > -static int mpol_new_interleave(struct mempolicy *pol, const nodemask_t *nodes)
> > +static int mpol_new_nodemask(struct mempolicy *pol, const nodemask_t *nodes)
> >  {
> >  	if (nodes_empty(*nodes))
> >  		return -EINVAL;
> > @@ -210,22 +210,6 @@ static int mpol_new_preferred(struct mempolicy *pol, const nodemask_t *nodes)
> >  	return 0;
> >  }
> >  
> > -static int mpol_new_preferred_many(struct mempolicy *pol, const nodemask_t *nodes)
> > -{
> > -	if (nodes_empty(*nodes))
> > -		return -EINVAL;
> > -	pol->nodes = *nodes;
> > -	return 0;
> > -}
> > -
> > -static int mpol_new_bind(struct mempolicy *pol, const nodemask_t *nodes)
> > -{
> > -	if (nodes_empty(*nodes))
> > -		return -EINVAL;
> > -	pol->nodes = *nodes;
> > -	return 0;
> > -}
> > -
> >  /*
> >   * mpol_set_nodemask is called after mpol_new() to set up the nodemask, if
> >   * any, for the new policy.  mpol_new() has already validated the nodes
> > @@ -405,7 +389,7 @@ static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {
> >  		.rebind = mpol_rebind_default,
> >  	},
> >  	[MPOL_INTERLEAVE] = {
> > -		.create = mpol_new_interleave,
> > +		.create = mpol_new_nodemask,
> >  		.rebind = mpol_rebind_nodemask,
> >  	},
> >  	[MPOL_PREFERRED] = {
> > @@ -413,14 +397,14 @@ static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {
> >  		.rebind = mpol_rebind_preferred,
> >  	},
> >  	[MPOL_BIND] = {
> > -		.create = mpol_new_bind,
> > +		.create = mpol_new_nodemask,
> >  		.rebind = mpol_rebind_nodemask,
> >  	},
> >  	[MPOL_LOCAL] = {
> >  		.rebind = mpol_rebind_default,
> >  	},
> >  	[MPOL_PREFERRED_MANY] = {
> > -		.create = mpol_new_preferred_many,
> > +		.create = mpol_new_nodemask,
> >  		.rebind = mpol_rebind_preferred,
> >  	},
> >  };
> > -- 
> > 2.7.4
> 
> -- 
> Michal Hocko
> SUSE Labs
diff mbox series

Patch

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index d90247d6a71b..e5ce5a7e8d92 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -192,7 +192,7 @@  static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
 	nodes_onto(*ret, tmp, *rel);
 }
 
-static int mpol_new_interleave(struct mempolicy *pol, const nodemask_t *nodes)
+static int mpol_new_nodemask(struct mempolicy *pol, const nodemask_t *nodes)
 {
 	if (nodes_empty(*nodes))
 		return -EINVAL;
@@ -210,22 +210,6 @@  static int mpol_new_preferred(struct mempolicy *pol, const nodemask_t *nodes)
 	return 0;
 }
 
-static int mpol_new_preferred_many(struct mempolicy *pol, const nodemask_t *nodes)
-{
-	if (nodes_empty(*nodes))
-		return -EINVAL;
-	pol->nodes = *nodes;
-	return 0;
-}
-
-static int mpol_new_bind(struct mempolicy *pol, const nodemask_t *nodes)
-{
-	if (nodes_empty(*nodes))
-		return -EINVAL;
-	pol->nodes = *nodes;
-	return 0;
-}
-
 /*
  * mpol_set_nodemask is called after mpol_new() to set up the nodemask, if
  * any, for the new policy.  mpol_new() has already validated the nodes
@@ -405,7 +389,7 @@  static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {
 		.rebind = mpol_rebind_default,
 	},
 	[MPOL_INTERLEAVE] = {
-		.create = mpol_new_interleave,
+		.create = mpol_new_nodemask,
 		.rebind = mpol_rebind_nodemask,
 	},
 	[MPOL_PREFERRED] = {
@@ -413,14 +397,14 @@  static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {
 		.rebind = mpol_rebind_preferred,
 	},
 	[MPOL_BIND] = {
-		.create = mpol_new_bind,
+		.create = mpol_new_nodemask,
 		.rebind = mpol_rebind_nodemask,
 	},
 	[MPOL_LOCAL] = {
 		.rebind = mpol_rebind_default,
 	},
 	[MPOL_PREFERRED_MANY] = {
-		.create = mpol_new_preferred_many,
+		.create = mpol_new_nodemask,
 		.rebind = mpol_rebind_preferred,
 	},
 };