From patchwork Thu Aug 10 16:36: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: 134136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp603186vqi; Thu, 10 Aug 2023 11:24:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMQ+yKlJ63fyvOOvwCOAq0yUmBvCKrsJD2SXnWsjSO/uvEiRnptx3DhMrJaDaxemf171AL X-Received: by 2002:a17:902:e995:b0:1b8:9b90:e2bc with SMTP id f21-20020a170902e99500b001b89b90e2bcmr3095391plb.52.1691691847907; Thu, 10 Aug 2023 11:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691691847; cv=none; d=google.com; s=arc-20160816; b=WGg1X5HmwUFG1Q4XKgBfp0HQYHideLaPkn5I4lIVi0gdrht5O4DBWT/m7Yp+dmsffO G5yJQyac46yYAdonCOmvCXXQfMeXoomAPVzIzMP+TS6aoxpq+SnFmkHBJnsmfIk6ERWo t06zQXTk1aDgFLsWkkaMqyVLhtaHHMoEghgqKgANHzJPF3Iijk0+HCImbV86pXrGYCHY tDGA9sO0iLpxW+OFFQimOzJ5VNaW6NPQsz4y22pTyecTXOaTV0KrpjIbARe8vPfUkmwS QRKx5513N0poZwzOoClTOiKZU0W11QMOL7v7pIhixqWnVoqIAE9RCc/NjWI0cBdSaJlj QB0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=0YgBKGsaXsGLSxrzXPhBkvZQSAlAP3ciKJFIHzEnvRY=; fh=2pBnSfjX50e7Wv5klf1T27fGwt6nBz7bVyyBTq15zE4=; b=Pd+F4T9QaF0iM8kUxWLBKKzkc1p/IrksVNIDy8iORn8nVywUuIT113HSe8RY6TGCw4 oTWPy7M3pMs9iM6OsRb1LPmF30gERWYMdNAY/v2Z2vpJMf4mfqSgMwnYzwaxQnaYvZXp OtKLlWNJTD6cwSC2vueghtuE+N7KyrQ3K9SZRHVUI4RSjZJifi7peLc/mpkaV5AxtZIJ 9N3uro6Y4Gv8UdUWzQ0zL5VpLFoV8cqpgnV1KhbBacaBHyVJSFToKF1yWYFMgedKcRkI nSJf3j18AGZ8QEYl+ehVgK2pS2Xy9RJLV9ha+3hfO5TttdJVxJnDw+HoH0oYf+dAjt4u Tf3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=ahOAhspP; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=Cj3pdlbc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h23-20020a170902ac9700b001b8bab3d5dasi1819521plr.108.2023.08.10.11.23.53; Thu, 10 Aug 2023 11:24:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=ahOAhspP; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=Cj3pdlbc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235767AbjHJQgu (ORCPT + 99 others); Thu, 10 Aug 2023 12:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235078AbjHJQgf (ORCPT ); Thu, 10 Aug 2023 12:36:35 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1496690 for ; Thu, 10 Aug 2023 09:36:35 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8DD541F855; Thu, 10 Aug 2023 16:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1691685393; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0YgBKGsaXsGLSxrzXPhBkvZQSAlAP3ciKJFIHzEnvRY=; b=ahOAhspPOh9gWRokiULaPvSVlO7+FXuxKO4tvOHBGWkFdq68YuUC556iHKh4f3O7IPBUEb 9+o7trNIK7n0OsSei8wrjxwksDOg4QP9utkyO1S6+9mIqAA9POXLcynrS+eRBvJDWA5e2u SJ68T9v+Br03Qj02Wz/h3oGxsa+KMn0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1691685393; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0YgBKGsaXsGLSxrzXPhBkvZQSAlAP3ciKJFIHzEnvRY=; b=Cj3pdlbc0C8qo51lQJTDCKqNdKlP6jg3SiLPuDNcG94XPwf5LjRYss+oyxhSePhcqfnwz9 44KQ/fhVgwG1ijAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 63EF5138E0; Thu, 10 Aug 2023 16:36:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SEF4FxES1WSEPQAAMHmgww (envelope-from ); Thu, 10 Aug 2023 16:36:33 +0000 From: Vlastimil Babka To: "Liam R. Howlett" , Matthew Wilcox , Suren Baghdasaryan , Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Vlastimil Babka Subject: [RFC v2 6/7] maple_tree: replace preallocation with slub percpu array prefill Date: Thu, 10 Aug 2023 18:36:34 +0200 Message-ID: <20230810163627.6206-15-vbabka@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230810163627.6206-9-vbabka@suse.cz> References: <20230810163627.6206-9-vbabka@suse.cz> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773867471328246607 X-GMAIL-MSGID: 1773867471328246607 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 | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 8bd4a79537d8..304f2453fac9 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5530,7 +5530,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); } @@ -5545,19 +5550,12 @@ EXPORT_SYMBOL_GPL(mas_store_prealloc); */ int mas_preallocate(struct ma_state *mas, gfp_t gfp) { - int ret; + int count = 1 + mas_mt_height(mas) * 3; - mas_node_count_gfp(mas, 1 + mas_mt_height(mas) * 3, gfp); - mas->mas_flags |= MA_STATE_PREALLOC; - if (likely(!mas_is_err(mas))) - return 0; + // TODO: should probably indicate if it failed the prefill? + kmem_cache_prefill_percpu_array(maple_node_cache, count, gfp); - mas_set_alloc_req(mas, 0); - ret = xa_err(mas->node); - mas_reset(mas); - mas_destroy(mas); - mas_reset(mas); - return ret; + return 0; } EXPORT_SYMBOL_GPL(mas_preallocate);