From: Vlastimil Babka <vbabka@suse.cz>
To: Chen Jun <chenjun102@huawei.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org, cl@linux.com,
penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com,
akpm@linux-foundation.org, roman.gushchin@linux.dev,
42.hyeyoo@gmail.com
Cc: xuqiang36@huawei.com, wangkefeng.wang@huawei.com
Subject: Re: [PATCH v2] mm/slub: Reduce memory consumption in extreme scenarios
Date: Tue, 2 Apr 2024 18:08:53 +0200 [thread overview]
Message-ID: <906fcdfc-f2da-428d-af3d-e1eaf64d1c61@suse.cz> (raw)
In-Reply-To: <20240330082335.29710-1-chenjun102@huawei.com>
On 3/30/24 9:23 AM, Chen Jun wrote:
> When kmalloc_node() is called without __GFP_THISNODE and the target node
> lacks sufficient memory, SLUB allocates a folio from a different node
> other than the requested node, instead of taking a partial slab from it.
>
> However, since the allocated folio does not belong to the requested
> node, it is deactivated and added to the partial slab list of the node
> it belongs to.
>
> This behavior can result in excessive memory usage when the requested
> node has insufficient memory, as SLUB will repeatedly allocate folios
> from other nodes without reusing the previously allocated ones.
>
> To prevent memory wastage,
> when (node != NUMA_NO_NODE) && !(gfpflags & __GFP_THISNODE) is,
> 1) try to get a partial slab from target node with GFP_NOWAIT |
> __GFP_THISNODE opportunistically.
> 2) if 1) failed, try to allocate a new slab from target node with
> GFP_NOWAIT | __GFP_THISNODE opportunistically too.
> 3) if 2) failed, retry 1) and 2) with orignal gfpflags.
>
> when node != NUMA_NO_NODE || (gfpflags & __GFP_THISNODE), the behavior
> remains unchanged.
>
> On qemu with 4 numa nodes and each numa has 1G memory. Write a test ko
> to call kmalloc_node(196, GFP_KERNEL, 3) for (4 * 1024 + 4) * 1024 times.
>
> cat /proc/slabinfo shows:
> kmalloc-256 4200530 13519712 256 32 2 : tunables..
>
> after this patch,
> cat /proc/slabinfo shows:
> kmalloc-256 4200558 4200768 256 32 2 : tunables..
>
> Signed-off-by: Chen Jun <chenjun102@huawei.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Slightly reworded and added an unlikely() to one of the tests, and included
in slab/for-6.10:
https://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git/commit/?h=slab/for-6.10/cleanup&id=9198ffbd2b494daae3a67cac1d59c3a2754e64cd
Thanks!
next prev parent reply other threads:[~2024-04-02 16:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-30 8:23 Chen Jun
2024-04-02 16:08 ` Vlastimil Babka [this message]
2024-04-05 16:50 ` Christoph Lameter (Ampere)
2024-04-08 13:17 ` Vlastimil Babka
2024-04-08 18:17 ` Christoph Lameter (Ampere)
2024-04-09 6:16 ` 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=906fcdfc-f2da-428d-af3d-e1eaf64d1c61@suse.cz \
--to=vbabka@suse.cz \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chenjun102@huawei.com \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=wangkefeng.wang@huawei.com \
--cc=xuqiang36@huawei.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