From: Adrian Huang <adrianhuang0701@gmail.com>
To: raghavendra.kt@amd.com
Cc: adrianhuang0701@gmail.com, ahuang12@lenovo.com,
akpm@linux-foundation.org, bsegall@google.com,
dietmar.eggemann@arm.com, juri.lelli@redhat.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
mgorman@suse.de, mingo@redhat.com, peterz@infradead.org,
rostedt@goodmis.org, sunjw10@lenovo.com,
vincent.guittot@linaro.org, vschneid@redhat.com
Subject: Re: [PATCH 1/1] sched/numa: Fix memory leak due to the overwritten vma->numab_state
Date: Mon, 11 Nov 2024 18:08:09 +0800 [thread overview]
Message-ID: <20241111100809.20527-1-ahuang12@lenovo.com> (raw)
In-Reply-To: <1794be3c-358c-4cdc-a43d-a1f841d91ef7@amd.com>
<snip>
>However since there are 800 threads, I see there might be an opportunity
>for another thread to enter in the next 'numa_scan_period' while
>we have not gotten till numab_state allocation.
>
>There should be simpler ways to overcome like Vlastimil already pointed
>in the other thread, and having lock is an overkill.
>
>for e.g.,
>numab_state = kzalloc(..)
>
>if we see that some other thread able to successfully assign
>vma->numab_state with their allocation (with cmpxchg), simply
>free your allocation.
>
>Can you please check if my understanding is correct?
Thanks for Vlastimil's and Raghu's reviews and comments.
Yes, your understanding is correct. Before submitting this patch,
I had two internal proposals: lock and cmpxchg. Here is the my cmpxchg
version (Test passed). If you're ok with this cmpxchg version, may I have
your reviewed-by? I'll send a v2 then.
---
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 3356315d7e64..7f99df294583 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3399,10 +3399,16 @@ static void task_numa_work(struct callback_head *work)
/* Initialise new per-VMA NUMAB state. */
if (!vma->numab_state) {
- vma->numab_state = kzalloc(sizeof(struct vma_numab_state),
- GFP_KERNEL);
- if (!vma->numab_state)
+ struct vma_numab_state *ptr;
+
+ ptr = kzalloc(sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ continue;
+
+ if (cmpxchg(&vma->numab_state, NULL, ptr)) {
+ kfree(ptr);
continue;
+ }
vma->numab_state->start_scan_seq = mm->numa_scan_seq;
next prev parent reply other threads:[~2024-11-11 10:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-08 13:31 Adrian Huang
2024-11-08 16:00 ` Vlastimil Babka
2024-11-08 20:50 ` kernel test robot
2024-11-08 22:12 ` kernel test robot
2024-11-09 4:03 ` Raghavendra K T
2024-11-11 10:08 ` Adrian Huang [this message]
2024-11-11 10:31 ` Raghavendra K T
2024-11-13 18:41 ` Vlastimil Babka
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=20241111100809.20527-1-ahuang12@lenovo.com \
--to=adrianhuang0701@gmail.com \
--cc=ahuang12@lenovo.com \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=raghavendra.kt@amd.com \
--cc=rostedt@goodmis.org \
--cc=sunjw10@lenovo.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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