From: Raghavendra K T <raghavendra.kt@amd.com>
To: Adrian Huang <adrianhuang0701@gmail.com>
Cc: 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 16:01:49 +0530 [thread overview]
Message-ID: <dff2a860-c92a-4371-8bf4-010a2b127bff@amd.com> (raw)
In-Reply-To: <20241111100809.20527-1-ahuang12@lenovo.com>
On 11/11/2024 3:38 PM, Adrian Huang wrote:
> <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;
>
LGTM. Sure feel free to add
Reviewed-by: Raghavendra K T <raghavendra.kt@amd.com>
Since allocation for numab_state happen only once.. I hope there is not
much impact on the performance also.
Thanks and Regards
- Raghu
next prev parent reply other threads:[~2024-11-11 10:32 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
2024-11-11 10:31 ` Raghavendra K T [this message]
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=dff2a860-c92a-4371-8bf4-010a2b127bff@amd.com \
--to=raghavendra.kt@amd.com \
--cc=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=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