From: Raghavendra K T <raghavendra.kt@amd.com>
To: Adrian Huang <adrianhuang0701@gmail.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Adrian Huang <ahuang12@lenovo.com>,
Jiwei Sun <sunjw10@lenovo.com>
Subject: Re: [PATCH 1/1] sched/numa: Fix memory leak due to the overwritten vma->numab_state
Date: Sat, 9 Nov 2024 09:33:57 +0530 [thread overview]
Message-ID: <1794be3c-358c-4cdc-a43d-a1f841d91ef7@amd.com> (raw)
In-Reply-To: <20241108133139.25326-1-ahuang12@lenovo.com>
On 11/8/2024 7:01 PM, Adrian Huang wrote:
> From: Adrian Huang <ahuang12@lenovo.com>
>
> [Problem Description]
> When running the hackbench program of LTP, the following memory leak is
> reported by kmemleak.
>
> # /opt/ltp/testcases/bin/hackbench 20 thread 1000
> Running with 20*40 (== 800) tasks.
>
> # dmesg | grep kmemleak
> ...
> kmemleak: 480 new suspected memory leaks (see /sys/kernel/debug/kmemleak)
> kmemleak: 665 new suspected memory leaks (see /sys/kernel/debug/kmemleak)
>
> # cat /sys/kernel/debug/kmemleak
> unreferenced object 0xffff888cd8ca2c40 (size 64):
> comm "hackbench", pid 17142, jiffies 4299780315
> hex dump (first 32 bytes):
> ac 74 49 00 01 00 00 00 4c 84 49 00 01 00 00 00 .tI.....L.I.....
> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
> backtrace (crc bff18fd4):
> [<ffffffff81419a89>] __kmalloc_cache_noprof+0x2f9/0x3f0
> [<ffffffff8113f715>] task_numa_work+0x725/0xa00
> [<ffffffff8110f878>] task_work_run+0x58/0x90
> [<ffffffff81ddd9f8>] syscall_exit_to_user_mode+0x1c8/0x1e0
> [<ffffffff81dd78d5>] do_syscall_64+0x85/0x150
> [<ffffffff81e0012b>] entry_SYSCALL_64_after_hwframe+0x76/0x7e
> ...
>
> This issue can be consistently reproduced on three different servers:
> * a 448-core server
> * a 256-core server
> * a 192-core server
>
> [Root Cause]
> Since multiple threads are created by the hackbench program (along with
> the command argument 'thread'), a shared vma might be accessed by two or
> more cores simultaneously. When two or more cores observe that
> vma->numab_state is NULL at the same time, vma->numab_state will be
> overwritten.
>
Thanks for reporting.
IIRC, This is not the entire scenario. Chunk above the vma->numab code
ideally ensures, only one thread descend down to scan the VMA's in a
single 'numa_scan_period'
migrate = mm->numa_next_scan;
if (time_before(now, migrate))
return;
next_scan = now + msecs_to_jiffies(p->numa_scan_period);
if (!try_cmpxchg(&mm->numa_next_scan, &migrate, next_scan))
return;
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
- Raghu
[...]
next prev parent reply other threads:[~2024-11-09 4:04 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 [this message]
2024-11-11 10:08 ` Adrian Huang
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=1794be3c-358c-4cdc-a43d-a1f841d91ef7@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