Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4573456rdh; Wed, 29 Nov 2023 05:26:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqS8+mhtA4+P3pFyd+l7IOdxu6QVilKiXXPYwg4NL7t2Qca+W9fUYpWFg+NqaP/TH+DazI X-Received: by 2002:a17:90b:224f:b0:27e:1ea0:c6fc with SMTP id hk15-20020a17090b224f00b0027e1ea0c6fcmr16449262pjb.6.1701264363539; Wed, 29 Nov 2023 05:26:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701264363; cv=none; d=google.com; s=arc-20160816; b=BDE/iRNFJoXxULqN3MoSnH7sv+9CQLSR3+wQ6KveqFiGY/08oa3saal4rfSnW/a95G jgTB63PdEMW3TQqprWjv44yC9QWRKhY5ao7P59LvwdEMqBOaE0FFhDO0Fvl9IcUvsIJK LbywH+O8rzOOy+n8zEYp8rmWjUZ9w/crf2Pu9Ljy8I1GHtVymYc2qA3a0VZDyMbLhA1A b8Yi97LdjJsOP57bhbtEeoxvAIva80flagNtMl9JsXYdiyuFtb0P1zhchbAlkWD7hq6I PvujzWNF4AMjlA4TJsR3CuddcMJotoLxROxU8OPUbCq2zAPvHwdndf9J9dWy/0NfMkoO BMTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=vgDzde4pY4k1GqnqACoj4vz/jHMaBo876Ngk3IPD1kM=; fh=06Rq2vjelAbZenP4uEGrLX438t8MeOm30SbbsqQ9Zm8=; b=GX34C0RwysdouohC40AMUqw0mpeLEFUNM4HiVABzNBeRk49wIacvE8mjVCbjIJBmO5 VVa+yom9Z14GUetkScffqcPRrR8MXoA1/trbpRubLSoB3LI/Bf7JI+E6OMI6P24JyKCb PgW6i9QvfiIByVzKFTIuJcekYhIoMa/tzWP8/MDedwdZqn7uu3d5KXp4UUIdRi8EEUvk JlKewvd6hzf4W8S4OEMjpDPK06PfsxtlLPBLyy4kq6Z+Z+Bf7okf8WXhhOJuh6V7H5Zj s/nD78qoMCpL9zkKC5UWl2HrrrKHLrtOTWTQBVFQdXf4+m9vrKRUsR59XMfpWWRirLGf 6DtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id cp24-20020a17090afb9800b0028586287407si1246434pjb.69.2023.11.29.05.26.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 05:26:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 108E8804C667; Wed, 29 Nov 2023 05:25:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233970AbjK2NZ3 (ORCPT + 99 others); Wed, 29 Nov 2023 08:25:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233621AbjK2NZ2 (ORCPT ); Wed, 29 Nov 2023 08:25:28 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64FA983 for ; Wed, 29 Nov 2023 05:25:34 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A3BCF210DF; Wed, 29 Nov 2023 13:25:32 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 861A113637; Wed, 29 Nov 2023 13:25:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 47hXIMw7Z2XlRAAAD6G6ig (envelope-from ); Wed, 29 Nov 2023 13:25:32 +0000 Message-ID: Date: Wed, 29 Nov 2023 14:25:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [RFC v2 2/7] mm, slub: add opt-in slub_percpu_array Content-Language: en-US To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: "Liam R. Howlett" , Matthew Wilcox , Suren Baghdasaryan , Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev References: <20230810163627.6206-9-vbabka@suse.cz> <20230810163627.6206-11-vbabka@suse.cz> <077e8e97-e88f-0b8e-2788-4031458be090@suse.cz> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spamd-Bar: +++++++++++ X-Spam-Score: 11.63 X-Rspamd-Server: rspamd1 Authentication-Results: smtp-out1.suse.de; dkim=none; spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of vbabka@suse.cz) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Queue-Id: A3BCF210DF X-Spamd-Result: default: False [11.63 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(1.20)[suse.cz]; R_SPF_SOFTFAIL(4.60)[~all]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.05)[-0.257]; RCPT_COUNT_TWELVE(0.00)[12]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email]; NEURAL_SPAM_LONG(2.29)[0.655]; FREEMAIL_TO(0.00)[gmail.com]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Spam-Status: No, score=-2.9 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 29 Nov 2023 05:25:59 -0800 (PST) On 11/29/23 01:46, Hyeonggon Yoo wrote: > On Wed, Nov 29, 2023 at 2:37 AM Vlastimil Babka wrote: > >> >> @@ -4060,6 +4201,45 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, >> >> } >> >> EXPORT_SYMBOL(kmem_cache_alloc_bulk); >> >> >> >> +int kmem_cache_prefill_percpu_array(struct kmem_cache *s, unsigned int count, >> >> + gfp_t gfp) >> >> +{ >> >> + struct slub_percpu_array *pca; >> >> + void *objects[32]; >> >> + unsigned int used; >> >> + unsigned int allocated; >> >> + >> >> + if (!s->cpu_array) >> >> + return -EINVAL; >> >> + >> >> + /* racy but we don't care */ >> >> + pca = raw_cpu_ptr(s->cpu_array); >> >> + >> >> + used = READ_ONCE(pca->used); >> > >> > Hmm for the prefill to be meaningful, >> > remote allocation should be possible, right? >> >> Remote in what sense? > > TL;DR) What I wanted to ask was: > "How pre-filling a number of objects works when the pre-filled objects > are not shared between CPUs" > > IIUC the prefill is opportunistically filling the array so (hopefully) > expecting there are > some objects filled in it. Yes. > Let's say CPU X calls kmem_cache_prefill_percpu_array(32) and all 32 > objects are filled into CPU X's array. > But if CPU Y can't allocate from CPU X's array (which I referred to as > "remote allocation"), the semantics differ from > the maple tree's perspective because preallocated objects were shared > between CPUs before, but now it's not? The assumption is that the operation will prefill on CPU X and then consume it also on X, because shortly after prefill it will enter some restricted context (i.e. spin_lock_irqsave or whatnot) that prevents it from migrating. That's not guaranteed of course, but migration in a bad moment and subsequent depleted array should be rare enough that we'll just handle it in the slow paths, and if it results in dipping into reserves, it won't be too disruptive. > Thanks! > > -- > Hyeonggon