linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Christoph Lameter (Ampere)" <cl@linux.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Chen Jun <chenjun102@huawei.com>,
	linux-kernel@vger.kernel.org,  linux-mm@kvack.org,
	penberg@kernel.org, rientjes@google.com,  iamjoonsoo.kim@lge.com,
	akpm@linux-foundation.org,  roman.gushchin@linux.dev,
	42.hyeyoo@gmail.com, xuqiang36@huawei.com,
	 wangkefeng.wang@huawei.com
Subject: Re: [PATCH v2] mm/slub: Reduce memory consumption in extreme scenarios
Date: Mon, 8 Apr 2024 11:17:02 -0700 (PDT)	[thread overview]
Message-ID: <e3cb4e2d-c80c-71d4-8d86-8391c2780511@linux.com> (raw)
In-Reply-To: <a8b554c8-b71a-4f0f-a291-996c31674966@suse.cz>

On Mon, 8 Apr 2024, Vlastimil Babka wrote:

> On 4/5/24 6:50 PM, Christoph Lameter (Ampere) wrote:
>> On Sat, 30 Mar 2024, 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.
>>
>> Hmmm... This would mean that we do not consult the partial lists of the
>> other nodes. That is something to be fixed in the allocator.
>
> Which allocator? If you mean SLUB, this patch fixes it. If you mean page
> allocator, I don't see how.


The SLUB allocator of course. And the patch does not fix it. It tries to 
convince the page allocator to give us a folio from the right node.

That kind of activity can be controlled within the page allocator via the 
node reclaim setting. No point in doing multiple calls into the page 
allocator.


>>> 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.
>>
>> That should only occur if a request for an object for node X follows a
>> request for an object from node Y.
>
> Are you sure? I think it's a stream of requests for node X happening on a
> cpu of node Y, AFAICS the first attempt will allocate the slab page from
> node different than X (possibly node Y because it's local and has pages
> available unlike node X which is full). It does get installed as the cpu
> slab, but then the next request is also for node X, so the node matching
> checks make the slab deactivate and allocate a new one.

Then there is something broken in the cpuslab logic.

The first request of CPU C for memory from node X should lead to:

1. deactivation of current cpu slab if it is not from node X
2. retrieval of a slab from node X and activation of that slab as cpuslab
3. Return of an object from that slab and therefore from node X.

Further allocation should be caught by the hotpatch where we realize that 
there is a request from node X and the current cpuslab is from node X and 
therefore fastpath logic can be used to retrieve the next object.


>> get_any_partial() should do that. Maybe it is not called in the
>> kmalloc_node case.
>
> Yes, get_any_partial() is currently skipped for requests of numa node
> different from NUMA_NO_NODE.

Maybe we can use that function after checking that the page allocator is 
over the watermark on the node that we were wanting to allocate from. That 
check should be fast.

>> I think it's a useful tradeof to first try satisfy the node preference with
> a GFP_NOWAIT allocation. If it succeeds, the target node is not overloaded,
> we get the page from the desired node and further allocations will of the
> same node will not deactivate it. If it doesn't succeed then we indeed
> fallback to slabs on partial list from other nodes before wastefully
> allocating new pages from the other nodes, which addresses the scenario that
> motivated this patch.

There are also the memory policies etc to consider. F.e. for the 
interleave policy the pages must come from different nodes in sequence to 
properly balance the allocations over multiple NUMA nodes. There are cases 
in which the allocations are forced to specific sets of nodes or where a 
node is preferred but fallback to local should occur.

If you now do multiple page allocator calls then the NUMA interleave 
policy etc etc may no longer work. I have not looked to deep into those.



  reply	other threads:[~2024-04-08 18:17 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
2024-04-05 16:50 ` Christoph Lameter (Ampere)
2024-04-08 13:17   ` Vlastimil Babka
2024-04-08 18:17     ` Christoph Lameter (Ampere) [this message]
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=e3cb4e2d-c80c-71d4-8d86-8391c2780511@linux.com \
    --to=cl@linux.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chenjun102@huawei.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=vbabka@suse.cz \
    --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