From: Vlastimil Babka <vbabka@suse.cz>
To: Oscar Salvador <osalvador@suse.de>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Michal Hocko <mhocko@suse.com>, Marco Elver <elver@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Alexander Potapenko <glider@google.com>,
Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
syzbot+41bbfdb8d41003d12c0f@syzkaller.appspotmail.com
Subject: Re: [PATCH v2 1/2] mm,page_owner: Fix refcount imbalance
Date: Thu, 21 Mar 2024 11:36:57 +0100 [thread overview]
Message-ID: <71e4b82b-8f32-41f1-afd1-5238e88bf0e7@suse.cz> (raw)
In-Reply-To: <20240319183212.17156-2-osalvador@suse.de>
On 3/19/24 19:32, Oscar Salvador 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.
>
> Reported-by: syzbot+41bbfdb8d41003d12c0f@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/linux-mm/00000000000090e8ff0613eda0e5@google.com
> Fixes: 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count")
> Signed-off-by: Oscar Salvador <osalvador@suse.de>
With the fixup,
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
But I think you'll need to resend with the missing hunk already applied, it
had broken whitespace in your email and IIUC this is was dropped from mm tree.
Also I'd suggest a change:
> +++ b/mm/page_owner.c
> @@ -196,9 +196,11 @@ static void add_stack_record_to_list(struct stack_record *stack_record,
> spin_unlock_irqrestore(&stack_list_lock, flags);
> }
>
> -static void inc_stack_record_count(depot_stack_handle_t handle, gfp_t gfp_mask)
> +static void inc_stack_record_count(depot_stack_handle_t handle, gfp_t gfp_mask,
> + int nr_base_pages)
> {
> struct stack_record *stack_record = __stack_depot_get_stack_record(handle);
> + int old = REFCOUNT_SATURATED;
>
> if (!stack_record)
> return;
> @@ -210,22 +212,18 @@ static void inc_stack_record_count(depot_stack_handle_t handle, gfp_t gfp_mask)
> * Since we do not use STACK_DEPOT_FLAG_GET API, let us
> * set a refcount of 1 ourselves.
> */
> - if (refcount_read(&stack_record->count) == REFCOUNT_SATURATED) {
> - int old = REFCOUNT_SATURATED;
I think this was useful optimization in that most cases the count is not
REFCOUNT_SATURATED so we don't have to go for the expensive cmpxchg all the
time. Or do I miss a reason why this was changed?
> -
> - if (atomic_try_cmpxchg_relaxed(&stack_record->count.refs, &old, 1))
> - /* Add the new stack_record to our list */
> - add_stack_record_to_list(stack_record, gfp_mask);
> - }
> - refcount_inc(&stack_record->count);
> + if (atomic_try_cmpxchg_relaxed(&stack_record->count.refs, &old, 1))
> + add_stack_record_to_list(stack_record, gfp_mask);
> + refcount_add(nr_base_pages, &stack_record->count);
> }
>
next prev parent reply other threads:[~2024-03-21 10:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-19 18:32 [PATCH v2 0/2] page_owner: Refcount fixups Oscar Salvador
2024-03-19 18:32 ` [PATCH v2 1/2] mm,page_owner: Fix refcount imbalance Oscar Salvador
2024-03-19 23:24 ` Andrew Morton
2024-03-20 4:40 ` Tetsuo Handa
2024-03-20 5:49 ` Oscar Salvador
2024-03-20 9:42 ` Tetsuo Handa
2024-03-20 17:35 ` kernel test robot
2024-03-20 23:37 ` kernel test robot
2024-03-21 10:36 ` Vlastimil Babka [this message]
2024-03-19 18:32 ` [PATCH v2 2/2] mm,page_owner: Fix accounting of pages when migrating Oscar Salvador
2024-03-19 18:48 ` Matthew Wilcox
2024-03-20 5:00 ` Oscar Salvador
2024-03-21 10:50 ` Vlastimil Babka
2024-03-21 11:07 ` Oscar Salvador
2024-03-21 11:20 ` Vlastimil Babka
2024-03-21 11:54 ` Oscar Salvador
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=71e4b82b-8f32-41f1-afd1-5238e88bf0e7@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=osalvador@suse.de \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=syzbot+41bbfdb8d41003d12c0f@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).