[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9dc33d5f-fc04-4780-80ae-3c5f80a8b891@suse.cz>
Date: Mon, 18 Nov 2024 15:26:31 +0100
From: Vlastimil Babka <vbabka@...e.cz>
To: Hyeonggon Yoo <42.hyeyoo@...il.com>
Cc: Suren Baghdasaryan <surenb@...gle.com>,
"Liam R. Howlett" <Liam.Howlett@...cle.com>, Christoph Lameter
<cl@...ux.com>, David Rientjes <rientjes@...gle.com>,
Pekka Enberg <penberg@...nel.org>, Joonsoo Kim <iamjoonsoo.kim@....com>,
Roman Gushchin <roman.gushchin@...ux.dev>,
"Paul E. McKenney" <paulmck@...nel.org>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
Matthew Wilcox <willy@...radead.org>, Boqun Feng <boqun.feng@...il.com>,
Uladzislau Rezki <urezki@...il.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, rcu@...r.kernel.org,
maple-tree@...ts.infradead.org
Subject: Re: [PATCH RFC 6/6] mm, slub: sheaf prefilling for guaranteed
allocations
On 11/18/24 14:13, Hyeonggon Yoo wrote:
> On Wed, Nov 13, 2024 at 1:39 AM Vlastimil Babka <vbabka@...e.cz> wrote:
>> +
>> +/*
>> + * Allocate from a sheaf obtained by kmem_cache_prefill_sheaf()
>> + *
>> + * Guaranteed not to fail as many allocations as was the requested count.
>> + * After the sheaf is emptied, it fails - no fallback to the slab cache itself.
>> + *
>> + * The gfp parameter is meant only to specify __GFP_ZERO or __GFP_ACCOUNT
>> + * memcg charging is forced over limit if necessary, to avoid failure.
>> + */
>> +void *
>> +kmem_cache_alloc_from_sheaf_noprof(struct kmem_cache *s, gfp_t gfp,
>> + struct slab_sheaf *sheaf)
>> +{
>> + void *ret = NULL;
>> + bool init;
>> +
>> + if (sheaf->size == 0)
>> + goto out;
>> +
>> + ret = sheaf->objects[--sheaf->size];
>> +
>> + init = slab_want_init_on_alloc(gfp, s);
>> +
>> + /* add __GFP_NOFAIL to force successful memcg charging */
>> + slab_post_alloc_hook(s, NULL, gfp | __GFP_NOFAIL, 1, &ret, init, s->object_size);
>
> Maybe I'm missing something, but how can this be used for non-sleepable contexts
> if __GFP_NOFAIL is used? I think we have to charge them when the sheaf
AFAIK it forces memcg to simply charge even if allocated memory goes over
the memcg limit. So there's no issue with a non-sleepable context, there
shouldn't be memcg reclaim happening in that case.
> is returned
> via kmem_cache_prefill_sheaf(), just like users of bulk alloc/free?
That would be very costly to charge/uncharge if most of the objects are not
actually used - it's what we want to avoid here.
Going over the memcgs limit a bit in a very rare case isn't considered such
an issue, for example Linus advocated such approach too in another context.
> Best,
> Hyeonggon
>
>> +out:
>> + trace_kmem_cache_alloc(_RET_IP_, ret, s, gfp, NUMA_NO_NODE);
>> +
>> + return ret;
>> +}
>> +
>> /*
>> * To avoid unnecessary overhead, we pass through large allocation requests
>> * directly to the page allocator. We use __GFP_COMP, because we will need to
>>
>> --
>> 2.47.0
>>
Powered by blists - more mailing lists