From: Vlastimil Babka <vbabka@suse.cz>
To: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Suren Baghdasaryan <surenb@google.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Christoph Lameter <cl@linux.com>,
David Rientjes <rientjes@google.com>,
Pekka Enberg <penberg@kernel.org>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
"Paul E. McKenney" <paulmck@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Matthew Wilcox <willy@infradead.org>,
Boqun Feng <boqun.feng@gmail.com>,
Uladzislau Rezki <urezki@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
rcu@vger.kernel.org, maple-tree@lists.infradead.org
Subject: Re: [PATCH RFC 6/6] mm, slub: sheaf prefilling for guaranteed allocations
Date: Tue, 19 Nov 2024 09:27:00 +0100 [thread overview]
Message-ID: <dac2e02c-9a71-4ced-8ac1-7b15dea120c3@suse.cz> (raw)
In-Reply-To: <CAB=+i9RZra587ik+A-hZtVwzppAt9CsA7oiuVg9QhgEHT=-daQ@mail.gmail.com>
On 11/19/24 03:29, Hyeonggon Yoo wrote:
> On Mon, Nov 18, 2024 at 11:26 PM Vlastimil Babka <vbabka@suse.cz> wrote:
>>
>> On 11/18/24 14:13, Hyeonggon Yoo wrote:
>> > On Wed, Nov 13, 2024 at 1:39 AM Vlastimil Babka <vbabka@suse.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.
>
> Ok, but I am still worried about mem alloc profiling/memcg trying to
> allocate some memory
> with __GFP_NOFAIL flag and eventually passing it to the buddy allocator,
> which does not want __GFP_NOFAIL without __GFP_DIRECT_RECLAIM?
> e.g.) memcg hook calls
> alloc_slab_obj_exts()->kcalloc_node()->....->alloc_pages()
alloc_slab_obj_exts() removes __GFP_NOFAIL via OBJCGS_CLEAR_MASK so that's fine.
I think kmemleak_alloc_recursive() is also fine as it ends up in
mem_pool_alloc() and will clear __GFP_NOFAIL it via gfp_nested_mask()
Hope I'm not missing something else.
>> > 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.
>
> Thanks for the explanation! That was a point I was missing.
>
>> > 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
>> >>
>>
prev parent reply other threads:[~2024-11-19 8:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-12 16:38 [PATCH RFC 0/6] SLUB percpu sheaves Vlastimil Babka
2024-11-12 16:38 ` [PATCH RFC 1/6] mm/slub: add opt-in caching layer of " Vlastimil Babka
2024-11-12 16:38 ` [PATCH RFC 2/6] mm/slub: add sheaf support for batching kfree_rcu() operations Vlastimil Babka
2024-11-14 16:57 ` Uladzislau Rezki
2024-11-17 11:01 ` Vlastimil Babka
2024-11-20 12:37 ` Uladzislau Rezki
2024-11-25 11:02 ` Vlastimil Babka
2024-11-25 11:18 ` Uladzislau Rezki
2024-11-28 16:24 ` Uladzislau Rezki
2024-11-29 13:54 ` Vlastimil Babka
2024-11-29 14:20 ` Uladzislau Rezki
2024-11-12 16:38 ` [PATCH RFC 3/6] maple_tree: use percpu sheaves for maple_node_cache Vlastimil Babka
2024-11-12 16:38 ` [PATCH RFC 4/6] mm, vma: use sheaves for vm_area_struct cache Vlastimil Babka
2024-11-12 16:38 ` [PATCH RFC 5/6] mm, slub: cheaper locking for percpu sheaves Vlastimil Babka
2024-11-12 16:38 ` [PATCH RFC 6/6] mm, slub: sheaf prefilling for guaranteed allocations Vlastimil Babka
2024-11-18 13:13 ` Hyeonggon Yoo
2024-11-18 14:26 ` Vlastimil Babka
2024-11-19 2:29 ` Hyeonggon Yoo
2024-11-19 8:27 ` Vlastimil Babka [this message]
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=dac2e02c-9a71-4ced-8ac1-7b15dea120c3@suse.cz \
--to=vbabka@suse.cz \
--cc=42.hyeyoo@gmail.com \
--cc=Liam.Howlett@oracle.com \
--cc=boqun.feng@gmail.com \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=maple-tree@lists.infradead.org \
--cc=paulmck@kernel.org \
--cc=penberg@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=surenb@google.com \
--cc=urezki@gmail.com \
--cc=willy@infradead.org \
/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
all inboxes | Powered by JetHome®