Re: [PATCH v2 1/2] mm,page_owner: Fix refcount imbalance

From: Andrew Morton
Date: Tue Mar 19 2024 - 19:24:38 EST


On Tue, 19 Mar 2024 19:32:11 +0100 Oscar Salvador <osalvador@xxxxxxx> wrote:

> Current code does not contemplate scenarios were an allocation and
> free operation on the same pages do not handle it in the same amount
> at once.
> To give an example, page_alloc_exact(), where we will allocate a page
> of enough order to stafisfy the size request, but we will free the
> remainings right away.
>
> In the above example, we will increment the stack_record refcount
> only once, but we will decrease it the same number of times as number
> of unused pages we have to free.
> This will lead to a warning because of refcount imbalance.
>
> Fix this by recording the number of base pages in the refcount field.
>
> ...
>
> -static void dec_stack_record_count(depot_stack_handle_t handle)
> +static void dec_stack_record_count(depot_stack_handle_t handle,
> + int nr_base_pages)
> {
> struct stack_record *stack_record = __stack_depot_get_stack_record(handle);
>
> if (stack_record)
> - refcount_dec(&stack_record->count);
> + refcount_sub_and_test(nr_base_pages, &stack_record->count);
> }

mm/page_owner.c: In function 'dec_stack_record_count':
mm/page_owner.c:226:17: error: ignoring return value of 'refcount_sub_and_test' declared with attribute 'warn_unused_result' [-Werror=unused-result]
226 | refcount_sub_and_test(nr_base_pages, &stack_record->count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors