From patchwork Fri Oct 21 10:34:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 6631 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp622455wrr; Fri, 21 Oct 2022 03:43:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5EmqxOjhjm5ukwRHvNWFa9LPlAbc82BV9KfZbBlFiEkICF/+fgzIhxXaN7nsuLKiQQI+BX X-Received: by 2002:a17:907:270f:b0:78d:728b:ff4 with SMTP id w15-20020a170907270f00b0078d728b0ff4mr15211208ejk.501.1666349002308; Fri, 21 Oct 2022 03:43:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666349002; cv=none; d=google.com; s=arc-20160816; b=H6UxZtnrgsxD5X5f5L1DNou3LCrYfZhv8sn1cYW3T1eR2LDj77iNCInZ4/kVvrnCTO TDxSGmwu6irQqGlI5r0TSw3BjR/IBIG1QuWwec3EKsR8ykZGHFb6/RHIOqX7htzVZSR/ wEmJ5hLLTHPIoplRJ88wp5fIM6RRTvyMSIKYUhf5DAb2PEcppKa0MZNQogIIbTL2vGkr R+CQa4n/Z4C2QX6hyFDcTI0wWQhvAcMZy0HYwKhVYNvswpU1wDwalOK5MhN9H1ZjnqVq kISJ+mjNzf3keg+OYvm+Cr6I88z2+3XLDMocqMwYqzLV7tph117AekFhZozQlE07Llq0 1L+Q== 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; bh=erLTlmyi83dM0fdrryvYn9BtXwohwFqw9KpHLk/mAwk=; b=HFoE0tceNLXy1+vtDMMRyo4t8FNN1hFlS/XERBgWCyfmBR8teCqyXs7/qevHHnQipJ W6UDUEVbfnewQD9OJg06BaWKvQLp1Yh56/kLRYB1KU5DzcD+SzAdpdIQQam5tiKPuYXj GAw6KUS72rSgNL7YF3ag04gBOXIf8LdX/2Y6HI8jhxI6fWb40+9s+A/21EwK9qWM2o4t Nd+q/J93WG4ipM62dFSRh7paWAh0mMIhwVk3zKzODjD88rwKltp72LwD7Ab5RHdGCJi0 iH+Ew1rhNwGAQCnji77ig/5Jrepnh3TMXB67AACUlWGlFfQXn6WJ7R2jJWGuyTvWuLXO 7V1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="GV/LMIDH"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a0564021e8800b0045a1559b97bsi23455523edf.356.2022.10.21.03.42.56; Fri, 21 Oct 2022 03:43:22 -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=@gmail.com header.s=20210112 header.b="GV/LMIDH"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbiJUKgf (ORCPT + 99 others); Fri, 21 Oct 2022 06:36:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbiJUKgY (ORCPT ); Fri, 21 Oct 2022 06:36:24 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F71245E9F; Fri, 21 Oct 2022 03:36:17 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id a14so1331458wru.5; Fri, 21 Oct 2022 03:36:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=erLTlmyi83dM0fdrryvYn9BtXwohwFqw9KpHLk/mAwk=; b=GV/LMIDHpWiYWvuunCnNMCfMciupdhaB5W5535rM/tXU0gpxVIvM+yzcu3C9SR1/Fx D8VmDEZeN9TzxytOkxU8Kco6zYiEbxeUK+jFfP8jBaXEKdNSJG596vY6ufysfC76/C6d 1BtLT5SC70uCaSMgXnra6nsp43gD6HXiIeaek2Xig9VTryLdFsZGRV5LhRBjILmtt03H 0yRmvaYyyxagUklmTYxuIByuAympM67kQ8x9bMkcgi3OCzGqVv+mEh79UYyQCIj25jtM Di6Oiz5wr0IlNj0B9/L23ruHDVRX///hOp1G6Xyj26gUMP7z2Z7q4eZ+1f6yA2U4dt1H QD1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=erLTlmyi83dM0fdrryvYn9BtXwohwFqw9KpHLk/mAwk=; b=FPsJdRAP41XhIigGFN5D4RNaLeBQLSUG4znMl2QYtQ+s1lZspH/mYqvmVESmcnh2gW n5p0c9/BvqobdjPETBSEAChRdOmyAz99qk0GrgrOE/TtTTPAIfrD8bwfoouFQzCF+JJ6 oGLmrZmj/jZJyKiG1KwESV0w8qSLYaPtxjVYrAj4Z33CtD8SYwWudpzdu7O3dFD692OP rgtGTAUuQnbwJRC4KTE9yz5o9FbcdtdTcq0euc1JdRtF6/UxFoEBsGYxWh7RWX24Qf6Y 9M31ED4k0NQOArZHma9tSNTrSpVRdcnzfd7VpvQrAi8iBOFOs8cwQ5Mcyf/begSaSZd8 utyA== X-Gm-Message-State: ACrzQf2pZSFNgoTFbwMw+cohudUv3FeLyQBXoo9iFdE2X0YI/yfP1N9a wfw3IaeOSKqQWJEKVlgXD7c= X-Received: by 2002:a05:6000:184e:b0:22e:4649:b3c9 with SMTP id c14-20020a056000184e00b0022e4649b3c9mr12323125wri.671.1666348575442; Fri, 21 Oct 2022 03:36:15 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:f27e]) by smtp.gmail.com with ESMTPSA id e14-20020a5d65ce000000b0022abcc1e3cesm18544759wrw.116.2022.10.21.03.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 03:36:14 -0700 (PDT) From: Pavel Begunkov To: Jens Axboe , linux-block@vger.kernel.org Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Pavel Begunkov Subject: [PATCH for-next v3 1/3] bio: split pcpu cache part of bio_put into a helper Date: Fri, 21 Oct 2022 11:34:05 +0100 Message-Id: <5cbfcc454cd9ecda250332b393f282d5742ba987.1666347703.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747293571541435799?= X-GMAIL-MSGID: =?utf-8?q?1747293571541435799?= Extract a helper out of bio_put for recycling into percpu caches. It's a preparation patch without functional changes. Signed-off-by: Pavel Begunkov --- block/bio.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/block/bio.c b/block/bio.c index 0a14af923738..7a573e0f5f52 100644 --- a/block/bio.c +++ b/block/bio.c @@ -725,6 +725,28 @@ static void bio_alloc_cache_destroy(struct bio_set *bs) bs->cache = NULL; } +static inline void bio_put_percpu_cache(struct bio *bio) +{ + struct bio_alloc_cache *cache; + + cache = per_cpu_ptr(bio->bi_pool->cache, get_cpu()); + bio_uninit(bio); + + if ((bio->bi_opf & REQ_POLLED) && !WARN_ON_ONCE(in_interrupt())) { + bio->bi_next = cache->free_list; + cache->free_list = bio; + cache->nr++; + } else { + put_cpu(); + bio_free(bio); + return; + } + + if (cache->nr > ALLOC_CACHE_MAX + ALLOC_CACHE_SLACK) + bio_alloc_cache_prune(cache, ALLOC_CACHE_SLACK); + put_cpu(); +} + /** * bio_put - release a reference to a bio * @bio: bio to release reference to @@ -740,20 +762,10 @@ void bio_put(struct bio *bio) if (!atomic_dec_and_test(&bio->__bi_cnt)) return; } - - if ((bio->bi_opf & REQ_ALLOC_CACHE) && !WARN_ON_ONCE(in_interrupt())) { - struct bio_alloc_cache *cache; - - bio_uninit(bio); - cache = per_cpu_ptr(bio->bi_pool->cache, get_cpu()); - bio->bi_next = cache->free_list; - cache->free_list = bio; - if (++cache->nr > ALLOC_CACHE_MAX + ALLOC_CACHE_SLACK) - bio_alloc_cache_prune(cache, ALLOC_CACHE_SLACK); - put_cpu(); - } else { + if (bio->bi_opf & REQ_ALLOC_CACHE) + bio_put_percpu_cache(bio); + else bio_free(bio); - } } EXPORT_SYMBOL(bio_put);