From patchwork Tue Oct 18 19:50:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 4305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2133825wrs; Tue, 18 Oct 2022 12:54:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6HGfGXIsthMtxm3Te0qaiQijCXju4imywekP7qzadwTAh8ApBjTd/qlF1EX6WfOHB/QKnF X-Received: by 2002:a63:6b44:0:b0:46a:fa55:b6a0 with SMTP id g65-20020a636b44000000b0046afa55b6a0mr4033606pgc.614.1666122894307; Tue, 18 Oct 2022 12:54:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666122894; cv=none; d=google.com; s=arc-20160816; b=U7IahsgdVSBjN8ykQSetD2yQWHviNdYr+wZ0w0H0xa7AF/hi1bf2/whYEUVLbpn8Lw +912yNlgzdTAL1W7JwJOBNKa0QGmZ1t5NHzPjHqvTZmgGRhzD+NSE2X1uYxdg0FjDIkm Dcwc/bli/DMYQUxSp4hb2FM5vcxSaa56OLnTzfhm2get9D1zDXpyzp8hDViGesBIBfvp iUso77jwj2BxFcpZNMBlNbocTLiklgPjc2oTOhJ5hRa6j4PCY/S0c8l17Sms1RBtPMvj qjcD6D2ACZabNzOVJXuOr23j0Z0wo4ecVSNA+6RuBE36f9o2QJZ9D1xFjD2CVYJiHAc+ zn5w== 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=u5GqQPQo1EN7QTPOq98P7aatI+dm61orL9Tt4wQrx+M=; b=Ec+j4bRi5It/hs47jw6jSKVGLcRL1+g+PtWcpFoBSjTXajArg9MMKiGF3dAs/n31Ib VmL3I+ZJJQwRT8xlbKYHBt++c/vcsvFJJRk42IOGu9gSIkwEihPyijvgJabIC/M2L7O4 whQ9ev2ZCVpR7ASf1dIAgsUimS1NX0Y9EmqPE+oLznrhHBFB53vpWFFxWMvHNqb99+6V PKgSjaxO89a8/uRf3jQHNCTQmkkxNeP62zYp8Em4bUOYAps2GgHMCOikE2SCFfd5rqAf frmWkrspECk9ARNHwFfpYqe43OjG+fkzgPzcsW5LHllNOUPmnom7gjTXu/sQK1lwhrW4 jOHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DxrIRWF3; 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 n2-20020a170903404200b00172f759f9c2si13383654pla.280.2022.10.18.12.54.28; Tue, 18 Oct 2022 12:54:54 -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=DxrIRWF3; 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 S229909AbiJRTwp (ORCPT + 99 others); Tue, 18 Oct 2022 15:52:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbiJRTwj (ORCPT ); Tue, 18 Oct 2022 15:52:39 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B38B18768D; Tue, 18 Oct 2022 12:52:29 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a26so34605046ejc.4; Tue, 18 Oct 2022 12:52:29 -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=u5GqQPQo1EN7QTPOq98P7aatI+dm61orL9Tt4wQrx+M=; b=DxrIRWF3IlLy7RscwISMjCOi24P2yJVMt2Xc0TV752F4rLMsC93h2W5TYQdYGCt1MR jyRwSmKys8FRe2BXkY4D59joFsHthbLLe3FDyZQJZVDmwj+4W94mZQK1U5BNwQSTdfD1 T7QvSss0PnHop/E92i5X+3vitwOD+/dhuz3LihI7I7SrO0yU32x5JKCDAqLAOPDpsJxt /DFqOVPve/MX8cq5RftjsGcfxNArnWahhuxRbxc16R4CMgF4jEOBAn81HVQKTW8rveeq x/maZeaY21ZPPxj+fw2xBewgJBEtwCF5TT3xLCSPbu+xL0heQuU40uzlWt2TJUKUHLK6 NrNg== 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=u5GqQPQo1EN7QTPOq98P7aatI+dm61orL9Tt4wQrx+M=; b=1ez2zHwpPx4yyMSrHFENL7zkBDqYN3NG/TIA9Few8ZyEcprPYdBm1JRGMVkqxr0vyz NXpf/LX4CHJj4BWnC984Tjx9pk8MDuQeKpxQR9Wc86eHOMTv/HPKgJRudW85wBf3NG0s lHGh9gQ6owpBqBPklnuAldh1IKFVhyr8CneVOk15PTGgZ3g508ubaiJPLFF5bsVQDZ9Z N3UHicVAA1WO7URpF0CdmnpGFZgD/tpa3H/Rh7QFaafBJryFrGBnOWRBS2FiEO00kO39 YEFWJ8Lb3V2Cuf6h12Wpy7mAY5BBOfsV5YUX7fabCMke0F2lV9h7Ua7Pu3YSdkbm6zjV 1g7A== X-Gm-Message-State: ACrzQf2gwCilgAEeSWDZim++TCYu2G1HaLWj2cUWbakk4MUc8JCjyknI fP7YZFxX+g+0wigUi2/8LKc+Eoe4Gwk= X-Received: by 2002:a17:907:6e9e:b0:78e:214b:e3c2 with SMTP id sh30-20020a1709076e9e00b0078e214be3c2mr3709856ejc.15.1666122726606; Tue, 18 Oct 2022 12:52:06 -0700 (PDT) Received: from 127.0.0.1localhost (94.197.72.2.threembb.co.uk. [94.197.72.2]) by smtp.gmail.com with ESMTPSA id r1-20020a1709061ba100b0072a881b21d8sm7945858ejg.119.2022.10.18.12.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 12:52:05 -0700 (PDT) From: Pavel Begunkov To: Jens Axboe , linux-block@vger.kernel.org Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Pavel Begunkov Subject: [RFC for-next v2 2/4] bio: split pcpu cache part of bio_put into a helper Date: Tue, 18 Oct 2022 20:50:56 +0100 Message-Id: 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?1747056479897633936?= X-GMAIL-MSGID: =?utf-8?q?1747056479897633936?= 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 5b4594daa259..ac16cc154476 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);