Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4250789rdh; Tue, 28 Nov 2023 16:47:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUPDCVQkYfAzYvPPoL2t7buox9QkvNnObxZLkbMV1V+pI5jlcP5BTkGXZ8oNyNFYxDqTez X-Received: by 2002:a05:6a20:12c6:b0:18a:59fa:7da4 with SMTP id v6-20020a056a2012c600b0018a59fa7da4mr17506442pzg.29.1701218840847; Tue, 28 Nov 2023 16:47:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701218840; cv=none; d=google.com; s=arc-20160816; b=c3l36YGPkad1jD24Ceb6UoVDDWhiZuCtRas/BWvLf60UhE3y/jA3DurbeskCItOsEH D7Nnt1/EyvC2SNf+emu7jEvhSvsowEuLBjcEfiqY6x2D5ig3pViS0Am+FaxRmx2/GaEe JrWPpZITi0UojYXMtGcpmeLcZp3PKmHbRD6EsuBqLJLKq1JpPIAAM5NzLoQIlmA4iLl0 W5uzFpNlqW+14ntezo6YB5tlI3HGAnV1VuE/m4FjZwGGdKlJTL4tM9gUP9vB77e6veRW 4CVgKKrjXuzBNo/yGF62sxYVq/FGZfv7dfPObgi04HDD6iaZ1rFa8UMIjzqM99Cl3t0e OpwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+oDh1aIguEdHpwRt07bECjWeSQzO3Fxi6hNx6EgBsZw=; fh=mRjp7OlODyTnz1IK8S+QdWvSVtiEjBMSKGJBOsuDc0E=; b=UGIip516X3e3e48xO/HtLxcWMmzK8X9ZDb5BUleQiLfQtcFoyy3wZ/RmaV5trjiyH4 c3JBKJ4ZtEHzDUggm94YTQZPxFTlJtSCdlVFo41/MGiaeON5RVZDTW5Bnu6U89++Efy5 T0Rp0rk+461nqmDJrCFzaSbXBybC5Mrc4bDlC5O1RyVufQTiVizbGOXBaG27p6e1cEKw 1M/4ra2XPzEGXeALnszq7XoECAXOWDd7Dhx+l2w9yChgEWODYsyLPHa6fh7qW6M+8qN2 83YHV/dnek8Gjaen367WrAxOD7y8Pv+3xgUzz4auFkOQh8yjzdtBDWdJZyQ5RtNlSMeY DUPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JdlTmnzA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id c1-20020a170902d48100b001cc467f87f8si13250895plg.381.2023.11.28.16.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 16:47:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JdlTmnzA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 461C382072C7; Tue, 28 Nov 2023 16:47:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230000AbjK2Aqq (ORCPT + 99 others); Tue, 28 Nov 2023 19:46:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbjK2Aqp (ORCPT ); Tue, 28 Nov 2023 19:46:45 -0500 Received: from mail-vk1-xa32.google.com (mail-vk1-xa32.google.com [IPv6:2607:f8b0:4864:20::a32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D951B10C1 for ; Tue, 28 Nov 2023 16:46:51 -0800 (PST) Received: by mail-vk1-xa32.google.com with SMTP id 71dfb90a1353d-4ac0d137835so1956925e0c.2 for ; Tue, 28 Nov 2023 16:46:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701218811; x=1701823611; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+oDh1aIguEdHpwRt07bECjWeSQzO3Fxi6hNx6EgBsZw=; b=JdlTmnzA7eCJONVLzPygFC9sGQ7/D3ZuLjhPPfenDInfKeJg50o8Yza+WM9X10Hxb9 p8EhBuv9DdGJRscOf1zewWiRWPQb/d5vTWEvCTi3gDeJhzomoZXTWll9JunGUpkBPvup z7ZHdjMVzw39Uf1uACiCOXJAMggL1Q0yQOyDl+IqvaQ6yTr3oRDJQXSVignvI0sWxxDe 8LuKRoMQd8KEvGZh1wt4e2mDVFNK87UfD4hDRvxrqixpSo3rbQ1L/2LwZsGlgtDSedXb eSaTVIfQ+YCF2LyXzsus47ZJM7uvu7y66kHXQXZ4i68/UGAimlBpSUyAxXcwpzHD07hv atRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701218811; x=1701823611; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+oDh1aIguEdHpwRt07bECjWeSQzO3Fxi6hNx6EgBsZw=; b=uRKZH1XcK0l7L5EOgPKG3WS82D8yR3SK+stLgCHD1uX4pOLN84vLivdrjwstS8yjwq CTfHjeI07paOd4WfAU+FZlW1ws3ghAMLXyMCTrHwjw+tJf6BIkDtx/Mcc1WW9xhb6GyZ dpaovzo41IcSR6yy+6f8qUuUjkwyq4YTj7FcfPPIK3ypfMdtvAHYKtTR7WItnfYU3i0X PcW7zm/gB9ktboGyheddLwYWoCpfKvAzOxF0b5W6OicE1F0c7byj1DP4xhDTfAqjOhoF k9qMLIkZIxrhqKNhshhIKbozzXEKE+QFsbTW0gOjLVssvkpCH2aDos36VZXAzpYqF6ng R4Fw== X-Gm-Message-State: AOJu0Yw15NkippzeiHAtuLdqLv38k7ygw45LXJJnxZVxrDY6DXZjc6n+ O39UCMMrn9RN4CMpRRObsWqhtNNJ4DHurVXsBvM= X-Received: by 2002:a1f:f8cf:0:b0:4b2:777a:a860 with SMTP id w198-20020a1ff8cf000000b004b2777aa860mr3478556vkh.13.1701218810686; Tue, 28 Nov 2023 16:46:50 -0800 (PST) MIME-Version: 1.0 References: <20230810163627.6206-9-vbabka@suse.cz> <20230810163627.6206-11-vbabka@suse.cz> <077e8e97-e88f-0b8e-2788-4031458be090@suse.cz> In-Reply-To: <077e8e97-e88f-0b8e-2788-4031458be090@suse.cz> From: Hyeonggon Yoo <42.hyeyoo@gmail.com> Date: Wed, 29 Nov 2023 09:46:38 +0900 Message-ID: Subject: Re: [RFC v2 2/7] mm, slub: add opt-in slub_percpu_array To: Vlastimil Babka 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Tue, 28 Nov 2023 16:47:18 -0800 (PST) On Wed, Nov 29, 2023 at 2:37=E2=80=AFAM Vlastimil Babka wr= ote: > > On 8/21/23 16:57, Hyeonggon Yoo wrote: > > Hi, > > > > On Fri, Aug 11, 2023 at 1:36=E2=80=AFAM Vlastimil Babka wrote: > > Oops, looks like I forgot reply, sorry (preparing v3 now). It's fine, you were busy removing SLAB :) thanks for replying. > > > >> /* > >> * Inlined fastpath so that allocation functions (kmalloc, kmem_cache= _alloc) > >> * have the fastpath folded into their functions. So no function call > >> @@ -3465,7 +3564,11 @@ static __fastpath_inline void *slab_alloc_node(= struct kmem_cache *s, struct list > >> if (unlikely(object)) > >> goto out; > >> > >> - object =3D __slab_alloc_node(s, gfpflags, node, addr, orig_siz= e); > >> + if (s->cpu_array) > >> + object =3D alloc_from_pca(s); > >> + > >> + if (!object) > >> + object =3D __slab_alloc_node(s, gfpflags, node, addr, = orig_size); > >> > >> maybe_wipe_obj_freeptr(s, object); > >> init =3D slab_want_init_on_alloc(gfpflags, s); > >> @@ -3715,6 +3818,34 @@ static void __slab_free(struct kmem_cache *s, s= truct slab *slab, > >> discard_slab(s, slab); > >> } > > > >> #ifndef CONFIG_SLUB_TINY > >> /* > >> * Fastpath with forced inlining to produce a kfree and kmem_cache_fr= ee that > >> @@ -3740,6 +3871,11 @@ static __always_inline void do_slab_free(struct= kmem_cache *s, > >> unsigned long tid; > >> void **freelist; > >> > >> + if (s->cpu_array && cnt =3D=3D 1) { > >> + if (free_to_pca(s, head)) > >> + return; > >> + } > >> + > >> redo: > >> /* > >> * Determine the currently cpus per cpu slab. > >> @@ -3793,6 +3929,11 @@ static void do_slab_free(struct kmem_cache *s, > >> { > >> void *tail_obj =3D tail ? : head; > >> > >> + if (s->cpu_array && cnt =3D=3D 1) { > >> + if (free_to_pca(s, head)) > >> + return; > >> + } > >> + > >> __slab_free(s, slab, head, tail_obj, cnt, addr); > >> } > >> #endif /* CONFIG_SLUB_TINY */ > > > > Is this functionality needed for SLUB_TINY? > > Due to the prefill semantics, I think it has to be be even in TINY, or we > risk running out of memory reserves. Also later I want to investigate > extending this approach for supporting allocations in very constrained > contexts (NMI) so e.g. bpf doesn't have to reimplement the slab allocator= , > and that would also not be good to limit to !SLUB_TINY. I've got the point, thanks for the explanation! > >> @@ -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 in= t 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 =3D raw_cpu_ptr(s->cpu_array); > >> + > >> + used =3D 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. 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? Thanks! -- Hyeonggon