diff mbox series

[1/3] mm/page_alloc: A minor fix to the calculation of pcp->free_count

Message ID 20240707094956.94654-2-laoar.shao@gmail.com (mailing list archive)
State New
Headers show
Series mm/page_alloc: Introduce a new sysctl knob vm.pcp_batch_scale_max | expand

Commit Message

Yafang Shao July 7, 2024, 9:49 a.m. UTC
Currently, At worst, the pcp->free_count can be
(batch - 1 + (1 << MAX_ORDER)), which may exceed the expected max value of
(batch << CONFIG_PCP_BATCH_SCALE_MAX).

This issue was identified through code review, and no real problems have
been observed.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
---
 mm/page_alloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Huang, Ying July 10, 2024, 1:52 a.m. UTC | #1
Yafang Shao <laoar.shao@gmail.com> writes:

> Currently, At worst, the pcp->free_count can be
> (batch - 1 + (1 << MAX_ORDER)), which may exceed the expected max value of
> (batch << CONFIG_PCP_BATCH_SCALE_MAX).
>
> This issue was identified through code review, and no real problems have
> been observed.
>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> Cc: "Huang, Ying" <ying.huang@intel.com>

LGTM, Thanks!

Reviewed-by: "Huang, Ying" <ying.huang@intel.com>

> ---
>  mm/page_alloc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 2e22ce5675ca..8e2f4e1ab4f2 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -2534,7 +2534,8 @@ static void free_unref_page_commit(struct zone *zone, struct per_cpu_pages *pcp,
>  		pcp->flags &= ~PCPF_PREV_FREE_HIGH_ORDER;
>  	}
>  	if (pcp->free_count < (batch << CONFIG_PCP_BATCH_SCALE_MAX))
> -		pcp->free_count += (1 << order);
> +		pcp->free_count = min(pcp->free_count + (1 << order),
> +				      batch << CONFIG_PCP_BATCH_SCALE_MAX);
>  	high = nr_pcp_high(pcp, zone, batch, free_high);
>  	if (pcp->count >= high) {
>  		free_pcppages_bulk(zone, nr_pcp_free(pcp, batch, high, free_high),
diff mbox series

Patch

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 2e22ce5675ca..8e2f4e1ab4f2 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2534,7 +2534,8 @@  static void free_unref_page_commit(struct zone *zone, struct per_cpu_pages *pcp,
 		pcp->flags &= ~PCPF_PREV_FREE_HIGH_ORDER;
 	}
 	if (pcp->free_count < (batch << CONFIG_PCP_BATCH_SCALE_MAX))
-		pcp->free_count += (1 << order);
+		pcp->free_count = min(pcp->free_count + (1 << order),
+				      batch << CONFIG_PCP_BATCH_SCALE_MAX);
 	high = nr_pcp_high(pcp, zone, batch, free_high);
 	if (pcp->count >= high) {
 		free_pcppages_bulk(zone, nr_pcp_free(pcp, batch, high, free_high),