2020-01-19 03:08:27

by Wei Yang

[permalink] [raw]
Subject: [PATCH 1/8] mm/migrate.c: skip node check if done in last round

Before move page to target node, we would check if the node id is valid.
In case we would try to move pages to the same target node, it is not
necessary to do the check each time.

This patch tries to skip the check if the node has been checked.

Signed-off-by: Wei Yang <[email protected]>
---
mm/migrate.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index 430fdccc733e..ba7cf4fa43a0 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1612,15 +1612,18 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
goto out_flush;
addr = (unsigned long)untagged_addr(p);

- err = -ENODEV;
- if (node < 0 || node >= MAX_NUMNODES)
- goto out_flush;
- if (!node_state(node, N_MEMORY))
- goto out_flush;
+ /* Check node if it is not checked. */
+ if (current_node == NUMA_NO_NODE || node != current_node) {
+ err = -ENODEV;
+ if (node < 0 || node >= MAX_NUMNODES)
+ goto out_flush;
+ if (!node_state(node, N_MEMORY))
+ goto out_flush;

- err = -EACCES;
- if (!node_isset(node, task_nodes))
- goto out_flush;
+ err = -EACCES;
+ if (!node_isset(node, task_nodes))
+ goto out_flush;
+ }

if (current_node == NUMA_NO_NODE) {
current_node = node;
--
2.17.1


2020-01-20 09:38:01

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH 1/8] mm/migrate.c: skip node check if done in last round

On Sun 19-01-20 11:06:29, Wei Yang wrote:
> Before move page to target node, we would check if the node id is valid.
> In case we would try to move pages to the same target node, it is not
> necessary to do the check each time.
>
> This patch tries to skip the check if the node has been checked.
>
> Signed-off-by: Wei Yang <[email protected]>
> ---
> mm/migrate.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/mm/migrate.c b/mm/migrate.c
> index 430fdccc733e..ba7cf4fa43a0 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -1612,15 +1612,18 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
> goto out_flush;
> addr = (unsigned long)untagged_addr(p);
>
> - err = -ENODEV;
> - if (node < 0 || node >= MAX_NUMNODES)
> - goto out_flush;
> - if (!node_state(node, N_MEMORY))
> - goto out_flush;
> + /* Check node if it is not checked. */
> + if (current_node == NUMA_NO_NODE || node != current_node) {
> + err = -ENODEV;
> + if (node < 0 || node >= MAX_NUMNODES)
> + goto out_flush;
> + if (!node_state(node, N_MEMORY))
> + goto out_flush;

This makes the code harder to read IMHO. The original code checks the
valid node first and it doesn't conflate that with the node caching
logic which your change does.

>
> - err = -EACCES;
> - if (!node_isset(node, task_nodes))
> - goto out_flush;
> + err = -EACCES;
> + if (!node_isset(node, task_nodes))
> + goto out_flush;
> + }
>
> if (current_node == NUMA_NO_NODE) {
> current_node = node;
> --
> 2.17.1

--
Michal Hocko
SUSE Labs

2020-01-20 22:26:34

by Wei Yang

[permalink] [raw]
Subject: Re: [PATCH 1/8] mm/migrate.c: skip node check if done in last round

On Mon, Jan 20, 2020 at 10:36:46AM +0100, Michal Hocko wrote:
>On Sun 19-01-20 11:06:29, Wei Yang wrote:
>> Before move page to target node, we would check if the node id is valid.
>> In case we would try to move pages to the same target node, it is not
>> necessary to do the check each time.
>>
>> This patch tries to skip the check if the node has been checked.
>>
>> Signed-off-by: Wei Yang <[email protected]>
>> ---
>> mm/migrate.c | 19 +++++++++++--------
>> 1 file changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/mm/migrate.c b/mm/migrate.c
>> index 430fdccc733e..ba7cf4fa43a0 100644
>> --- a/mm/migrate.c
>> +++ b/mm/migrate.c
>> @@ -1612,15 +1612,18 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
>> goto out_flush;
>> addr = (unsigned long)untagged_addr(p);
>>
>> - err = -ENODEV;
>> - if (node < 0 || node >= MAX_NUMNODES)
>> - goto out_flush;
>> - if (!node_state(node, N_MEMORY))
>> - goto out_flush;
>> + /* Check node if it is not checked. */
>> + if (current_node == NUMA_NO_NODE || node != current_node) {
>> + err = -ENODEV;
>> + if (node < 0 || node >= MAX_NUMNODES)
>> + goto out_flush;
>> + if (!node_state(node, N_MEMORY))
>> + goto out_flush;
>
>This makes the code harder to read IMHO. The original code checks the
>valid node first and it doesn't conflate that with the node caching
>logic which your change does.
>

I am sorry, would you mind showing me an example about the conflate in my
change? I don't get it.

>>
>> - err = -EACCES;
>> - if (!node_isset(node, task_nodes))
>> - goto out_flush;
>> + err = -EACCES;
>> + if (!node_isset(node, task_nodes))
>> + goto out_flush;
>> + }
>>
>> if (current_node == NUMA_NO_NODE) {
>> current_node = node;
>> --
>> 2.17.1
>
>--
>Michal Hocko
>SUSE Labs

--
Wei Yang
Help you, Help me

2020-01-21 08:44:57

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH 1/8] mm/migrate.c: skip node check if done in last round

On Tue 21-01-20 06:25:40, Wei Yang wrote:
> On Mon, Jan 20, 2020 at 10:36:46AM +0100, Michal Hocko wrote:
> >On Sun 19-01-20 11:06:29, Wei Yang wrote:
> >> Before move page to target node, we would check if the node id is valid.
> >> In case we would try to move pages to the same target node, it is not
> >> necessary to do the check each time.
> >>
> >> This patch tries to skip the check if the node has been checked.
> >>
> >> Signed-off-by: Wei Yang <[email protected]>
> >> ---
> >> mm/migrate.c | 19 +++++++++++--------
> >> 1 file changed, 11 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/mm/migrate.c b/mm/migrate.c
> >> index 430fdccc733e..ba7cf4fa43a0 100644
> >> --- a/mm/migrate.c
> >> +++ b/mm/migrate.c
> >> @@ -1612,15 +1612,18 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
> >> goto out_flush;
> >> addr = (unsigned long)untagged_addr(p);
> >>
> >> - err = -ENODEV;
> >> - if (node < 0 || node >= MAX_NUMNODES)
> >> - goto out_flush;
> >> - if (!node_state(node, N_MEMORY))
> >> - goto out_flush;
> >> + /* Check node if it is not checked. */
> >> + if (current_node == NUMA_NO_NODE || node != current_node) {
> >> + err = -ENODEV;
> >> + if (node < 0 || node >= MAX_NUMNODES)
> >> + goto out_flush;
> >> + if (!node_state(node, N_MEMORY))
> >> + goto out_flush;
> >
> >This makes the code harder to read IMHO. The original code checks the
> >valid node first and it doesn't conflate that with the node caching
> >logic which your change does.
> >
>
> I am sorry, would you mind showing me an example about the conflate in my
> change? I don't get it.

NUMA_NO_NODE is the iteration logic, right? It resets the batching node.
Node check read from the userspace is an input sanitization. Do not put
those two into the same checks. More clear now?
--
Michal Hocko
SUSE Labs

2020-01-22 00:38:59

by Wei Yang

[permalink] [raw]
Subject: Re: [PATCH 1/8] mm/migrate.c: skip node check if done in last round

On Tue, Jan 21, 2020 at 09:42:05AM +0100, Michal Hocko wrote:
>On Tue 21-01-20 06:25:40, Wei Yang wrote:
>> On Mon, Jan 20, 2020 at 10:36:46AM +0100, Michal Hocko wrote:
>> >On Sun 19-01-20 11:06:29, Wei Yang wrote:
>> >> Before move page to target node, we would check if the node id is valid.
>> >> In case we would try to move pages to the same target node, it is not
>> >> necessary to do the check each time.
>> >>
>> >> This patch tries to skip the check if the node has been checked.
>> >>
>> >> Signed-off-by: Wei Yang <[email protected]>
>> >> ---
>> >> mm/migrate.c | 19 +++++++++++--------
>> >> 1 file changed, 11 insertions(+), 8 deletions(-)
>> >>
>> >> diff --git a/mm/migrate.c b/mm/migrate.c
>> >> index 430fdccc733e..ba7cf4fa43a0 100644
>> >> --- a/mm/migrate.c
>> >> +++ b/mm/migrate.c
>> >> @@ -1612,15 +1612,18 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
>> >> goto out_flush;
>> >> addr = (unsigned long)untagged_addr(p);
>> >>
>> >> - err = -ENODEV;
>> >> - if (node < 0 || node >= MAX_NUMNODES)
>> >> - goto out_flush;
>> >> - if (!node_state(node, N_MEMORY))
>> >> - goto out_flush;
>> >> + /* Check node if it is not checked. */
>> >> + if (current_node == NUMA_NO_NODE || node != current_node) {
>> >> + err = -ENODEV;
>> >> + if (node < 0 || node >= MAX_NUMNODES)
>> >> + goto out_flush;
>> >> + if (!node_state(node, N_MEMORY))
>> >> + goto out_flush;
>> >
>> >This makes the code harder to read IMHO. The original code checks the
>> >valid node first and it doesn't conflate that with the node caching
>> >logic which your change does.
>> >
>>
>> I am sorry, would you mind showing me an example about the conflate in my
>> change? I don't get it.
>
>NUMA_NO_NODE is the iteration logic, right? It resets the batching node.
>Node check read from the userspace is an input sanitization. Do not put
>those two into the same checks. More clear now?

Yes, I see your point.

Can we think like this:

On each iteration, we do an input sanitization?

Well, this is a trivial one. If you don't like it, I would remove this.

>--
>Michal Hocko
>SUSE Labs

--
Wei Yang
Help you, Help me

2020-01-22 08:18:27

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH 1/8] mm/migrate.c: skip node check if done in last round

On Wed 22-01-20 08:36:50, Wei Yang wrote:
[...]
> Well, this is a trivial one. If you don't like it, I would remove this.

Yes, please drop it. Thanks!
--
Michal Hocko
SUSE Labs