diff mbox series

[v13,9/9] lib/nodemask: Optimize node_random for nodemask with single NUMA node

Message ID 20220808062601.836025-10-aneesh.kumar@linux.ibm.com (mailing list archive)
State New
Headers show
Series mm/demotion: Memory tiers and demotion | expand

Commit Message

Aneesh Kumar K.V Aug. 8, 2022, 6:26 a.m. UTC
The most common case for certain node_random usage (demotion nodemask) is with
nodemask weight 1. We can avoid calling get_random_init() in that case and
always return the only node set in the nodemask.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 lib/nodemask.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Huang, Ying Aug. 9, 2022, 3:13 a.m. UTC | #1
"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com> writes:

> The most common case for certain node_random usage (demotion nodemask) is with
> nodemask weight 1. We can avoid calling get_random_init() in that case and
> always return the only node set in the nodemask.

I think that this patch can sit between [5/9] and [6/9], just after it
is used.

> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> ---
>  lib/nodemask.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/lib/nodemask.c b/lib/nodemask.c
> index e22647f5181b..c91a6b0404a5 100644
> --- a/lib/nodemask.c
> +++ b/lib/nodemask.c
> @@ -20,12 +20,21 @@ EXPORT_SYMBOL(__next_node_in);
>   */
>  int node_random(const nodemask_t *maskp)
>  {
> -	int w, bit = NUMA_NO_NODE;
> +	int w, bit;
>  
>  	w = nodes_weight(*maskp);
> -	if (w)
> +	switch (w) {
> +	case 0:
> +		bit = NUMA_NO_NODE;
> +		break;
> +	case 1:
> +		bit = __first_node(maskp);

Per my understanding, first_node() is the formal API and we should use
that?  Just like we use nodes_weight() instead of __nodes_weight().

Best Regards,
Huang, Ying

> +		break;
> +	default:
>  		bit = bitmap_ord_to_pos(maskp->bits,
> -			get_random_int() % w, MAX_NUMNODES);
> +					get_random_int() % w, MAX_NUMNODES);
> +		break;
> +	}
>  	return bit;
>  }
>  #endif
Aneesh Kumar K.V Aug. 9, 2022, 5:43 a.m. UTC | #2
On 8/9/22 8:43 AM, Huang, Ying wrote:
> "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com> writes:
> 
>> The most common case for certain node_random usage (demotion nodemask) is with
>> nodemask weight 1. We can avoid calling get_random_init() in that case and
>> always return the only node set in the nodemask.
> 
> I think that this patch can sit between [5/9] and [6/9], just after it
> is used.
> 
>> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
>> ---
>>  lib/nodemask.c | 15 ++++++++++++---
>>  1 file changed, 12 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/nodemask.c b/lib/nodemask.c
>> index e22647f5181b..c91a6b0404a5 100644
>> --- a/lib/nodemask.c
>> +++ b/lib/nodemask.c
>> @@ -20,12 +20,21 @@ EXPORT_SYMBOL(__next_node_in);
>>   */
>>  int node_random(const nodemask_t *maskp)
>>  {
>> -	int w, bit = NUMA_NO_NODE;
>> +	int w, bit;
>>  
>>  	w = nodes_weight(*maskp);
>> -	if (w)
>> +	switch (w) {
>> +	case 0:
>> +		bit = NUMA_NO_NODE;
>> +		break;
>> +	case 1:
>> +		bit = __first_node(maskp);
> 
> Per my understanding, first_node() is the formal API and we should use
> that?  Just like we use nodes_weight() instead of __nodes_weight().
> 

updated.

-aneesh
diff mbox series

Patch

diff --git a/lib/nodemask.c b/lib/nodemask.c
index e22647f5181b..c91a6b0404a5 100644
--- a/lib/nodemask.c
+++ b/lib/nodemask.c
@@ -20,12 +20,21 @@  EXPORT_SYMBOL(__next_node_in);
  */
 int node_random(const nodemask_t *maskp)
 {
-	int w, bit = NUMA_NO_NODE;
+	int w, bit;
 
 	w = nodes_weight(*maskp);
-	if (w)
+	switch (w) {
+	case 0:
+		bit = NUMA_NO_NODE;
+		break;
+	case 1:
+		bit = __first_node(maskp);
+		break;
+	default:
 		bit = bitmap_ord_to_pos(maskp->bits,
-			get_random_int() % w, MAX_NUMNODES);
+					get_random_int() % w, MAX_NUMNODES);
+		break;
+	}
 	return bit;
 }
 #endif