From patchwork Wed Nov 29 09:53:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13472570 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72756C07CB1 for ; Wed, 29 Nov 2023 09:53:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A39216B03BD; Wed, 29 Nov 2023 04:53:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 32A1D6B03C0; Wed, 29 Nov 2023 04:53:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E26106B03C5; Wed, 29 Nov 2023 04:53:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3D9D46B03BD for ; Wed, 29 Nov 2023 04:53:42 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1ABF5160237 for ; Wed, 29 Nov 2023 09:53:42 +0000 (UTC) X-FDA: 81510529884.17.42C5E19 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf15.hostedemail.com (Postfix) with ESMTP id E19BEA0012 for ; Wed, 29 Nov 2023 09:53:39 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=inSOz4yT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Fx7hfg5V; dmarc=none; spf=pass (imf15.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701251620; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OzJx1XLcKpfOVPPxGeC45HXa1Ww2Cw/dmnDirEUeMrA=; b=OyaCTykdSFvlzrn2BiPtZlkwBzTN6gX2YxaVuBINh0sX3aEuXmGJdF/kNNJNHPTqhi1V9G SjhopG1y8lONKlEFxkWkM3pcIDok90zSbm7rxJnPBOQ2hprqiI7d1Hkl6lwx+8m+BEDvRH Pra6nSHj0rwcBzIb13vJwM7SnNh852w= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=inSOz4yT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Fx7hfg5V; dmarc=none; spf=pass (imf15.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701251620; a=rsa-sha256; cv=none; b=APd2z0heL9t2hbrCyVdkgz5EwidlTTkqKClBZWFoBMnJIEZIPufu+37RHS/TKwgDz3rDaU YXy1+jZ041R6Sj5uvfuy8qLXOj9/9GHFItjlO8JJ1cv7zcmR/ZoBGzhrH3n0fCyDUgHB4v T+FL/TbXdNCLaUElvcQ0/jFW7p0Bmic= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [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-out2.suse.de (Postfix) with ESMTPS id F1F931F8BE; Wed, 29 Nov 2023 09:53:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1701251618; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OzJx1XLcKpfOVPPxGeC45HXa1Ww2Cw/dmnDirEUeMrA=; b=inSOz4yT8TFgPaEVNqR0q6mY6UH6gJHUbkvbIB60MQaG+WfZTTe8fyxGmqgFcEPzn+zbkH X4wFuffCvNZPe31CV8gw6BNVz2L7dpmQFwcoVuq+TvUiUMdeAYgBVI4N/mYaqnMfUmr0nc /CknMU6FEMRIquT7ifcgQ/wnwv5HELU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1701251618; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OzJx1XLcKpfOVPPxGeC45HXa1Ww2Cw/dmnDirEUeMrA=; b=Fx7hfg5Vv0T5+dLFQWNf1/uBwvIhSApKaJpzlzazw7YdiXTEwqcjlUJKSONFGFXMIuuIIj UDa9Bi0THVElqdBA== 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 AC77013AA1; Wed, 29 Nov 2023 09:53:37 +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 aFDSKSEKZ2UrfQAAD6G6ig (envelope-from ); Wed, 29 Nov 2023 09:53:37 +0000 From: Vlastimil Babka Date: Wed, 29 Nov 2023 10:53:34 +0100 Subject: [PATCH RFC v3 9/9] maple_tree: replace preallocation with slub percpu array prefill MIME-Version: 1.0 Message-Id: <20231129-slub-percpu-caches-v3-9-6bcf536772bc@suse.cz> References: <20231129-slub-percpu-caches-v3-0-6bcf536772bc@suse.cz> In-Reply-To: <20231129-slub-percpu-caches-v3-0-6bcf536772bc@suse.cz> To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Matthew Wilcox , "Liam R. Howlett" Cc: Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Alexander Potapenko , Marco Elver , Dmitry Vyukov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, kasan-dev@googlegroups.com X-Mailer: b4 0.12.4 X-Rspamd-Queue-Id: E19BEA0012 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 13fxjt8uowhnbdgir1uod8osqztnzedb X-HE-Tag: 1701251619-871978 X-HE-Meta: U2FsdGVkX19BvpYvS/64SFFIzj6I7rs9LVae8WcMAYZ7oJHSiEh3Us8Sjwjblh+GwTExK/TlpwK177uvNsQVWEA3XJl59H9xvq2OxTqvqZx8FH1tQHg92hRfQG8sW0x6gnD9346fuo5yZlKaXHuROoEt4Sn6/58rtGpTrVp1Cenu7i2B/UVBIantTCTOwxuWXz9MlIzN+os2Lcy6VPEO702QN0uPVwXpoJ1XPiCBZcSLM9kGJyej7YZBQVJy/7lTNZeMxrIH2WSpEQQ5RQsMsp7zfXtivA8AWYP8B0qmOtB97hUWkosGX1XrP3eXiZJjCbQrqrGKDqoM/bbbyRgUYCqxj8qyIzdmcp9w82skGmvRbTFK8vDT7XmNi6sKvc1Mk6XDwnr34IQ1TkwTr+/MYGg1y5L2j2VR5tJpV36g9nOFeL+7ypPS9MXeshUL8wue5Pe29tuMIjdZDJIUtA57qXbQ9AJShxXI+xyDLmjS2dddv9gdJM4qT659s3zdkyRJE12b/anvNRVIvA346h0KqJijjNInBeSx0aA9bPpjcqjKaq+Y/YB9qmN5tnNOGu0HqjJhaxdPiZ9nRxreffBJrnGHyXSpLPkFrksO6dYsp1JlBVXmH7wjc+oAm3dTm1QGEu3X1gSFgtzdB/1Hqx/FiNa25OhenNtVPi4ipLLoy5dLGXcArktkbdG+gbN0tTrXw5TODZdejVSG3gavapxB0J5ElcxJfPGOv6ntmA98Xf+53IR5F554NE9egiGgRP619vwOAPHy7mvLUTdCGyGhAtqIxk0WU0Izt7H89gG9ENdJCqqaXkc/klu3scOAZynA6bkAVBo/+SNMk+Y38hOK+ATfRu8KuRHsPN2WKD7CMOqYOIFLeeE9wOSSZJUFMT8Y8SkdJ4B9NUsbAtqyr0RIQsR0ldvXCHOSgPUfGQd0S6+CuZ6mVs/PmnZp6+1cLTrmWfj+oWo+rdTfmzsPjZW A4YCwQDn fVvn+Zabtmm9+DO7hS5saVaUI3EylPI9r/96eXCuklnAtv4EpZgNmpWHn7KQNtdfDKtEapMkMWK2klGz5SR85Elx29ttn395yB2GPS1zjHU5zjxxRqeLCN4/gkOvBd0q9LdpHBahtu97UbdiD6XmTWKXYv+JEGHL8FlKBKadGgQZEOGepY2WSZUgMPOkuxd1OqveZXbmRbe/z4di4Q0SJ0JKgTmxsl2bzO2r0Q6DWJBrwAmm+8Dq4ogR2q40arlzYiig2Lk5N087M34t4htfIsoLJ0d/ujSZzKwsjuk8WGnwMJCOxZGI0WOVn/HOjltXI83lE9hwh+VCzvhhaNvXhZQ8QtA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With the percpu array we can try not doing the preallocations in maple tree, and instead make sure the percpu array is prefilled, and using GFP_ATOMIC in places that relied on the preallocation (in case we miss or fail trylock on the array), i.e. mas_store_prealloc(). For now simply add __GFP_NOFAIL there as well. --- lib/maple_tree.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index f5c0bca2c5d7..d84a0c0fe83b 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5452,7 +5452,12 @@ void mas_store_prealloc(struct ma_state *mas, void *entry) mas_wr_store_setup(&wr_mas); trace_ma_write(__func__, mas, 0, entry); + +retry: mas_wr_store_entry(&wr_mas); + if (unlikely(mas_nomem(mas, GFP_ATOMIC | __GFP_NOFAIL))) + goto retry; + MAS_WR_BUG_ON(&wr_mas, mas_is_err(mas)); mas_destroy(mas); } @@ -5471,8 +5476,6 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp) MA_WR_STATE(wr_mas, mas, entry); unsigned char node_size; int request = 1; - int ret; - if (unlikely(!mas->index && mas->last == ULONG_MAX)) goto ask_now; @@ -5512,16 +5515,8 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp) /* node store, slot store needs one node */ ask_now: - mas_node_count_gfp(mas, request, gfp); - if (likely(!mas_is_err(mas))) - return 0; + return kmem_cache_prefill_percpu_array(maple_node_cache, request, gfp); - mas_set_alloc_req(mas, 0); - ret = xa_err(mas->node); - mas_reset(mas); - mas_destroy(mas); - mas_reset(mas); - return ret; } EXPORT_SYMBOL_GPL(mas_preallocate);