diff mbox series

[2/3] mm/vmstat: simplify the array size calculation

Message ID 20210715122911.15700-3-linmiaohe@huawei.com (mailing list archive)
State New
Headers show
Series Cleanup for vmstat | expand

Commit Message

Miaohe Lin July 15, 2021, 12:29 p.m. UTC
We can replace the array_num * sizeof(array[0]) with sizeof(array) to
simplify the code.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/vmstat.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

David Hildenbrand July 16, 2021, 12:58 p.m. UTC | #1
On 15.07.21 14:29, Miaohe Lin wrote:
> We can replace the array_num * sizeof(array[0]) with sizeof(array) to
> simplify the code.

Could have mentioned taht your fixing indentation of one "return true;"

LGTM

Reviewed-by: David Hildenbrand <david@redhat.com>

> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>   mm/vmstat.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> index 57e8e7fda7aa..76aef9510f6d 100644
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -1889,17 +1889,15 @@ static bool need_update(int cpu)
>   		/*
>   		 * The fast way of checking if there are any vmstat diffs.
>   		 */
> -		if (memchr_inv(pzstats->vm_stat_diff, 0, NR_VM_ZONE_STAT_ITEMS *
> -			       sizeof(pzstats->vm_stat_diff[0])))
> +		if (memchr_inv(pzstats->vm_stat_diff, 0, sizeof(pzstats->vm_stat_diff)))
>   			return true;
>   
>   		if (last_pgdat == zone->zone_pgdat)
>   			continue;
>   		last_pgdat = zone->zone_pgdat;
>   		n = per_cpu_ptr(zone->zone_pgdat->per_cpu_nodestats, cpu);
> -		if (memchr_inv(n->vm_node_stat_diff, 0, NR_VM_NODE_STAT_ITEMS *
> -			       sizeof(n->vm_node_stat_diff[0])))
> -		    return true;
> +		if (memchr_inv(n->vm_node_stat_diff, 0, sizeof(n->vm_node_stat_diff)))
> +			return true;
>   	}
>   	return false;
>   }
>
Miaohe Lin July 17, 2021, 1:54 a.m. UTC | #2
On 2021/7/16 20:58, David Hildenbrand wrote:
> On 15.07.21 14:29, Miaohe Lin wrote:
>> We can replace the array_num * sizeof(array[0]) with sizeof(array) to
>> simplify the code.
> 
> Could have mentioned taht your fixing indentation of one "return true;"
> 

Yes, but I thought that's too trivial to mention... I would pay attention to it later.

> LGTM
> 
> Reviewed-by: David Hildenbrand <david@redhat.com>

Many thanks for your review and reply!

> 
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
>>   mm/vmstat.c | 8 +++-----
>>   1 file changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/mm/vmstat.c b/mm/vmstat.c
>> index 57e8e7fda7aa..76aef9510f6d 100644
>> --- a/mm/vmstat.c
>> +++ b/mm/vmstat.c
>> @@ -1889,17 +1889,15 @@ static bool need_update(int cpu)
>>           /*
>>            * The fast way of checking if there are any vmstat diffs.
>>            */
>> -        if (memchr_inv(pzstats->vm_stat_diff, 0, NR_VM_ZONE_STAT_ITEMS *
>> -                   sizeof(pzstats->vm_stat_diff[0])))
>> +        if (memchr_inv(pzstats->vm_stat_diff, 0, sizeof(pzstats->vm_stat_diff)))
>>               return true;
>>             if (last_pgdat == zone->zone_pgdat)
>>               continue;
>>           last_pgdat = zone->zone_pgdat;
>>           n = per_cpu_ptr(zone->zone_pgdat->per_cpu_nodestats, cpu);
>> -        if (memchr_inv(n->vm_node_stat_diff, 0, NR_VM_NODE_STAT_ITEMS *
>> -                   sizeof(n->vm_node_stat_diff[0])))
>> -            return true;
>> +        if (memchr_inv(n->vm_node_stat_diff, 0, sizeof(n->vm_node_stat_diff)))
>> +            return true;
>>       }
>>       return false;
>>   }
>>
> 
>
diff mbox series

Patch

diff --git a/mm/vmstat.c b/mm/vmstat.c
index 57e8e7fda7aa..76aef9510f6d 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1889,17 +1889,15 @@  static bool need_update(int cpu)
 		/*
 		 * The fast way of checking if there are any vmstat diffs.
 		 */
-		if (memchr_inv(pzstats->vm_stat_diff, 0, NR_VM_ZONE_STAT_ITEMS *
-			       sizeof(pzstats->vm_stat_diff[0])))
+		if (memchr_inv(pzstats->vm_stat_diff, 0, sizeof(pzstats->vm_stat_diff)))
 			return true;
 
 		if (last_pgdat == zone->zone_pgdat)
 			continue;
 		last_pgdat = zone->zone_pgdat;
 		n = per_cpu_ptr(zone->zone_pgdat->per_cpu_nodestats, cpu);
-		if (memchr_inv(n->vm_node_stat_diff, 0, NR_VM_NODE_STAT_ITEMS *
-			       sizeof(n->vm_node_stat_diff[0])))
-		    return true;
+		if (memchr_inv(n->vm_node_stat_diff, 0, sizeof(n->vm_node_stat_diff)))
+			return true;
 	}
 	return false;
 }