From patchwork Tue Oct 18 18:47:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 4296 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2111494wrs; Tue, 18 Oct 2022 11:56:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4WyMoVU2qAt6vxTs7heYoPKJHDTX+XZHzxSpUSJcO2ky3vu53PzJIOg5GvOaX5co0hReTt X-Received: by 2002:aa7:db4d:0:b0:458:908f:a372 with SMTP id n13-20020aa7db4d000000b00458908fa372mr3945067edt.248.1666119379351; Tue, 18 Oct 2022 11:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666119379; cv=none; d=google.com; s=arc-20160816; b=hHvAPdA/MdDeEyuKV831BHZehUwfYNBl/W8Ji7iaU7p3MtCNo8/iJrmrNK7FHZjeQB 7KgOZroco37w6coAMGcSDb4ynuE6uxojN5xX5MpOWjCNP1uX6oz5HEcV3SKCtRGbuFz2 2jDXjK9NoxoFcxCj2Eh3h77TdaU9gl+jhMHqL46kecv350xlO/F7ZNxeol6Z/J2D65cm sZCw1hH/JtlrgIknrU4kXuy8P7vhH28WlddNAN6aIz5LghBNLvDZx4PZ8nA/BFoFNTgV ZVxAteTNkAA8wCaBpTq6k0kFt28Y+q/ZMMrKreZreYZPtarSAHKJg2Ua2HO8FvjWOCaM S/MQ== 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=lFeaHcw3WNcJNFaRay0No0wm3D4s1Mkz5fJGwkqsY20=; b=On1qC5N8gZkoGaZ2brheKtfs7YZc8KrNovSzFyvyPFetQK4GxP4cnBYe6OQMKRtbOf v/kvSxy4+kNyQDy0pxSsupzm/8ZarvtxlaPVlFtFt3Sg6Q8Gj8MWbMM81+XuDs6w1IJl e6K9AP6IHQe7zyuakNjpZwUEA7MrmzcBLDNV10zot+/rVq/M6USKGXQLP+0KuX9jolWQ mgDYzrVwBQR0AkeMUEgTFcS8eX5yCBui0JDV9o93jBz+dHZKiLHjbpxEX0tMGncAqdHy 9ycpoFLi+BZ7dHpwy99YzgS3t/XBXkFyA1Vav7EG5r4NXRHdSMFB3QodD4hMRv2f5FUH B17Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gJClO7Er; 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 he7-20020a1709073d8700b0078e1a6fbe12si14436243ejc.16.2022.10.18.11.55.54; Tue, 18 Oct 2022 11:56:19 -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=gJClO7Er; 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 S230309AbiJRStD (ORCPT + 99 others); Tue, 18 Oct 2022 14:49:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230280AbiJRSs4 (ORCPT ); Tue, 18 Oct 2022 14:48:56 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED24DA2A8E; Tue, 18 Oct 2022 11:48:45 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id u21so21847613edi.9; Tue, 18 Oct 2022 11:48:45 -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=lFeaHcw3WNcJNFaRay0No0wm3D4s1Mkz5fJGwkqsY20=; b=gJClO7ErBlCfzKPWJy/tFBQfQ+rctfzUBl11vrUnH9Tlr8O8uu0mIEqiByfJHvpTv0 dgJpBSC8TeNV/KvUIkibb7wKldRyBTdC4LwAbxVitkVdrNAum8saXf5SC8Bh8T/ftmGH jULwwtjrC6JIKLC0qu7Nu+Zr7l2ZslMOxX8olHV9ag9HRYNKRTwbBfsAJohPVl1d7+7t gogXXmQu52TXETJAsIj1dTYakj25eas+y0+Xd7469/26WacHW26Ze9IVD0HhKFvatQ04 9pmatdw2sd+f3jYjF5ObCtj9PbWa8t6QYXcUy5L+kqwQvAlXsBv4OxD9pqwZW2dStCej w+cQ== 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=lFeaHcw3WNcJNFaRay0No0wm3D4s1Mkz5fJGwkqsY20=; b=zTVb9/G9/5g8ryDQkcqET9ETsXGmmCwE5+k0LB7qG4akj1/sWwmR9+VNXyFrvZ/Jcr neUyuybGXdgiPe8ws6gXSX95tx7I26vXws2K0sUdOdvIJBDLMrcrwGj+zSj3ChJ1VF70 ly34B2RQLn5CIytWa2u21+Uc8qGWPBAbhUkf8BXdeYGBzY4aNKvkgPeoUWLaa1CCcpbk 3WS2XQExB9kpKTeulGGv45zwAwyrbAiBD7Ha1F0mIoaCSXq71LVVSD2USe7LMLj4xVcX zz6LJsL5g2K72o/JONX62myoqQSBVpUp9ajBII1OvxbrKgw2HR0yPUzVLP9LAgN3UZQL ejkw== X-Gm-Message-State: ACrzQf3CsQ9rebTp9pKmMSRYEkZY2mbk33yu6tyw7rkVKBZjLf65ciEt BYcLt7eizj6L012U+Pfmwg8= X-Received: by 2002:a05:6402:5489:b0:43b:b935:db37 with SMTP id fg9-20020a056402548900b0043bb935db37mr4018153edb.347.1666118923767; Tue, 18 Oct 2022 11:48:43 -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 j18-20020a17090623f200b0078db18d7972sm7855355ejg.117.2022.10.18.11.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 11:48:42 -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 1/4] bio: safeguard REQ_ALLOC_CACHE bio put Date: Tue, 18 Oct 2022 19:47:13 +0100 Message-Id: <558d78313476c4e9c233902efa0092644c3d420a.1666114003.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?1747052794351179567?= X-GMAIL-MSGID: =?utf-8?q?1747052794351179567?= bio_put() with REQ_ALLOC_CACHE assumes that it's executed not from an irq context. Let's add a warning if the invariant is not respected, especially since there is a couple of places removing REQ_POLLED by hand without also clearing REQ_ALLOC_CACHE. Signed-off-by: Pavel Begunkov --- block/bio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/bio.c b/block/bio.c index 7cb7d2ff139b..5b4594daa259 100644 --- a/block/bio.c +++ b/block/bio.c @@ -741,7 +741,7 @@ void bio_put(struct bio *bio) return; } - if (bio->bi_opf & REQ_ALLOC_CACHE) { + if ((bio->bi_opf & REQ_ALLOC_CACHE) && !WARN_ON_ONCE(in_interrupt())) { struct bio_alloc_cache *cache; bio_uninit(bio); From patchwork Tue Oct 18 18:47:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 4294 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2111169wrs; Tue, 18 Oct 2022 11:55:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6agS6+xlUngTWQDRqExQB7yNW8hwl8gTrziPQFLSS2WCT6T40qfle9J1iBaTfRKWJRMs2T X-Received: by 2002:a17:906:4fd1:b0:787:434f:d755 with SMTP id i17-20020a1709064fd100b00787434fd755mr3511756ejw.356.1666119325255; Tue, 18 Oct 2022 11:55:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666119325; cv=none; d=google.com; s=arc-20160816; b=fKRgKtVa0jHrMZMTuRPxeV76ozQL6LVVs21lfzIJUqNv7GfgYewrBWuE7oYPEdz8iV 9cjunFhYiws5IT/8Lx4DcFRZHYuaFACLjPxg3exAECgKxNpNl/xJCMfAahfU3q1KqLWE 87WtugLbbXu+XGo/YwWqiGNW94Viea71s5ql/y67y6iC5+eR2/XkH5TdXJxkI337MSnD hWGZ/0LmBoD6b0/eX/7kph0ovFhIqbEJFcsU7VX9yuM6YCSi15Os/N52qIcO7ZH/D5rK hxaUQmmkhJQTPbzkhsDRulfAN2A++VyTdEmnu/JP1W0uV63mFzdNAiqW83ytx5BRKM5x q27w== 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=vdFHW+LmJbYT3s2B8vp6cxXjKOH5AiUizvgO6zZCN2K/FOqVvK3aNUnjCKzce/nw4a tB3LXlGM3c06DGuDyklSRIb4fhxK/3FHdKTT7Qg2XIjtAvgi5vZKzM+Bi2IB+dIYVq4u arq5rOso6pfQkd3qiLgcSQ76tIqRt0rfeFOh9CRpEqxEmK8oVuGlrSaJPPtlhr3e8cDb o/CpCmIfm+pwEU3K3FmG8eehUVFqn4D2W/+0UqMTgzmzt3gfTTWgnuiaPUFtS6QXeugO 9ryKHoi7z33uFqFX8BgiHA+cifHOZFAQoyWfdCqE/1KIxk9MHiT29hO3V5Uz7GdXznYE brPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pQVhTRrU; 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 ga8-20020a1709070c0800b0077a5733ac08si3128202ejc.601.2022.10.18.11.54.59; Tue, 18 Oct 2022 11:55:25 -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=pQVhTRrU; 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 S230258AbiJRSsz (ORCPT + 99 others); Tue, 18 Oct 2022 14:48:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiJRSsw (ORCPT ); Tue, 18 Oct 2022 14:48:52 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3746A2ABB; Tue, 18 Oct 2022 11:48:47 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id z97so21858617ede.8; Tue, 18 Oct 2022 11:48:47 -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=pQVhTRrUCNr5iWknH5+wZ6tovh3QucpIXrfLs3BqoUkMXX5cbjzVfBS4+FhSKAU7kq cbLGxN3Bx0WzENB/z0YXhLKrxTbiaU6y3EGLc4dz4KZPwiZY/rlP5h3oVf/AcYu6p4im Uajr6V1YveMZIlhVs7KtCulPeJ1rJBCD7wdRwIO1u1eC0xgL4XxuhTvGIfcIKELNVrEK IJNyEpEkRxTHUaQvOPxa8Ph4iwEytWtPfQ3DUXpFJY5B7HwhOCwUcv90rLkrnA2vtfvb 6Bt2TpTEic8L7crNDFmNGPR05IsBB5YGLlxgADDBPHtDyekeYL9GkQocaKXTD1DycdU2 Jqfw== 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=xumUHBiu28KJJ5JpV3gwShRxFZN9TzfE8V3czluST51kk2HpLdBMYRgwQrTvCH9rG8 frgCzljnA5ZdufWbeIQL5W6LEDehp4FEu4RK2g54Q4dPhA7wnzVkLbXVZE974A7riIhx TJeh00y8YTL3xKCneYd+Pwpw21saaNarGb9s2lDvTCSWF9Emlq/YTp5UnrLoDy77Goft kKQWRjtZOwgjGM3XWM7CSAjtGYbCuzgc9vrJiiLxX3weT0f/yKGqwEOAazcBP46+OiKz abmgtXbpYq3HpfswzX57eWnGdPCbwUhCODvTov7huApCsYOi7awhoZG024MGCH41B5vY tQYA== X-Gm-Message-State: ACrzQf2fvcrx58/X9R/fvFm8UnT3yhCuOItXY+aWTxE94ddCeO9g5Ijw XzNC+pyN3xT8q+WrgwG5XRE= X-Received: by 2002:aa7:d28c:0:b0:459:3cc5:3cb8 with SMTP id w12-20020aa7d28c000000b004593cc53cb8mr3997366edq.261.1666118925643; Tue, 18 Oct 2022 11:48:45 -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 j18-20020a17090623f200b0078db18d7972sm7855355ejg.117.2022.10.18.11.48.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 11:48:44 -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 2/4] bio: split pcpu cache part of bio_put into a helper Date: Tue, 18 Oct 2022 19:47:14 +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?1747052737716225666?= X-GMAIL-MSGID: =?utf-8?q?1747052737716225666?= 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); From patchwork Tue Oct 18 18:47:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 4295 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2111282wrs; Tue, 18 Oct 2022 11:55:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4pBe/W/hVvh+TNnlb2VJKKU2xI5ZK1rWit7HfBFST/mzkWgyp2b4UQlJMd9BaZGpWf7djq X-Received: by 2002:a17:907:7286:b0:78e:22f9:f169 with SMTP id dt6-20020a170907728600b0078e22f9f169mr3747963ejc.119.1666119346726; Tue, 18 Oct 2022 11:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666119346; cv=none; d=google.com; s=arc-20160816; b=gxMPgGBAJs0hh9aB7gBV0PA3pDM3ehmcZ3F1ydde3gN1WuPicy1YsJwtDuq0DjxZ1I lumC2X+rAR4UNZBqzL2Pt806cE+kTBLrC+un/sXcQcKOKbVxcSwkG30lQRCXpcdoczrK Qn/JVG8PvYBkCeanb5ZZNSBZCuhtVCyn5AZRDg+jbgtpB6JftFYOtnGVfAooFljQR/lw CrP2fbsjSVO4Wjo34daiPfH4FqLC5b4flZhOgeEkSe1vOlyXga7UfSzEksPsbF36K4Jr Qayw9gppP3tI8PbPcA3Z6+nntW61PKnKtbqdfGCn2jLv4a9gSTVkKMai9S8C6IRiY62+ jMXg== 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=vZenMiiiYQ0xZIz3KLnoOLLCCa6zuOP8hwCIircl7LY=; b=d1L977DVePV+t0M/ZAxh6/tIKDZWKkFtO2IhUiMiVcTl43xbFyguQYlRp36UuOBzr0 rtwZGdkvaAZtykLLUJnG2mnLgdsWWlbH9KxNFYxxexP8X7xGeQCtyGXkg6XMBOY1Q+st 4elfYFcXCNAhhuSopc6WjE6pgKjdF1a/+z6priUp3Z2BKY9Tf3fpzEBCStUsNQtKi+sZ Ki34Xu/m8MvMvQSW6ZbyVNF1iZECH8nJAw6qxiBBwyykp1HhWnuGp4hPjBCGJqk/mDZN YTyOwhEZC4W4zqeeq/5pXyd8E3H+gUyBIvxcQ6U0MQ0llKflPzlwrkP4brCrWM1i3bpc aq4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="TMW6J/GJ"; 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 s5-20020a17090699c500b0078d878d8fb7si12885564ejn.920.2022.10.18.11.55.21; Tue, 18 Oct 2022 11:55:46 -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="TMW6J/GJ"; 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 S230306AbiJRStA (ORCPT + 99 others); Tue, 18 Oct 2022 14:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230281AbiJRSs4 (ORCPT ); Tue, 18 Oct 2022 14:48:56 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EFCDA02FA; Tue, 18 Oct 2022 11:48:49 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id a67so21824063edf.12; Tue, 18 Oct 2022 11:48:48 -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=vZenMiiiYQ0xZIz3KLnoOLLCCa6zuOP8hwCIircl7LY=; b=TMW6J/GJG6ZptFWYW7eF0s8MW93rzpdA+HBUOR9t4xb7SNHvfuXDwdA9Gx/2KFwcyd 4IXLZ1thCDtzhPWTLNeKXgWQeg9VYur41LLvc6jHgXUGjM011GB4t92rLcphcS5zfx+8 v/QVqnanfeC8a+g7NPIgGocQoqVY3P/+WLi/2t05SBr9qtArj4jM6A5iYWYoqkfOqzSn 1fYly/urPxlsjKB2KFGcLwA/wwkJKzmajOHrHq6NFqYuSBa6G/S7psrbRmDRqoIdiIUQ 2IpIP2K+lKsioSW8QsmSk9lGfrX3H2b8oSV507r5CgYc/Rx0xDvp3TNmJDtR9+FwB2nX JkWA== 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=vZenMiiiYQ0xZIz3KLnoOLLCCa6zuOP8hwCIircl7LY=; b=I/FOePsvHQqNGmnoh06FMV9UcCb4QWN3jAKTbIBwCOZKQVP6ei9wJ1byxLH2KTmkxq tuTz/jkLP74BAHpPWt958iu+ttmL7ynj6z4CvzW0iPQRThblkIyuS9GcsTr8BEZs37N+ 9fN7TkFn8qp91HXr2xP1Cl113QR36i9OY+lf38bDm2shg+aU1vaA2ySQ3a3GWZ6mp3i+ 9E4hg0/TOrMcz/9V/VBvq8UzqeaE6ec5mrxryoYDGlf3Ithm4mLcv1oMqvnFJclLcPrR Uo1hOQiYd4cmHQiFtYJxrTpwaB5G/pdB2rPECwXSBuTzGiTgKlCIwYSdh8pAJMsz9NPY tnxQ== X-Gm-Message-State: ACrzQf2UyQLoiOU2NxIVKWdD6aJ4ELya9Rj/PkrSw7AcNqXzmUYWrN5Y idKpDATa0VCXH1ddyweeHUk4wi2tWnY= X-Received: by 2002:a05:6402:354d:b0:45c:b772:5ef4 with SMTP id f13-20020a056402354d00b0045cb7725ef4mr3987962edd.225.1666118926805; Tue, 18 Oct 2022 11:48:46 -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 j18-20020a17090623f200b0078db18d7972sm7855355ejg.117.2022.10.18.11.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 11:48:46 -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 3/4] block/bio: add pcpu caching for non-polling bio_put Date: Tue, 18 Oct 2022 19:47:15 +0100 Message-Id: <646001320f5543e0e23a4a64e886fa8ed768d2c1.1666114003.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?1747052760255749172?= X-GMAIL-MSGID: =?utf-8?q?1747052760255749172?= This patch extends REQ_ALLOC_CACHE to IRQ completions, whenever currently it's only limited to iopoll. Instead of guarding the list with irq toggling on alloc, which is expensive, it keeps an additional irq-safe list from which bios are spliced in batches to ammortise overhead. On the put side it toggles irqs, but in many cases they're already disabled and so cheap. Signed-off-by: Pavel Begunkov --- block/bio.c | 62 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/block/bio.c b/block/bio.c index ac16cc154476..75107dc27304 100644 --- a/block/bio.c +++ b/block/bio.c @@ -25,9 +25,15 @@ #include "blk-rq-qos.h" #include "blk-cgroup.h" +#define ALLOC_CACHE_THRESHOLD 16 +#define ALLOC_CACHE_SLACK 64 +#define ALLOC_CACHE_MAX 512 + struct bio_alloc_cache { struct bio *free_list; + struct bio *free_list_irq; unsigned int nr; + unsigned int nr_irq; }; static struct biovec_slab { @@ -408,6 +414,22 @@ static void punt_bios_to_rescuer(struct bio_set *bs) queue_work(bs->rescue_workqueue, &bs->rescue_work); } +static void bio_alloc_irq_cache_splice(struct bio_alloc_cache *cache) +{ + unsigned long flags; + + /* cache->free_list must be empty */ + if (WARN_ON_ONCE(cache->free_list)) + return; + + local_irq_save(flags); + cache->free_list = cache->free_list_irq; + cache->free_list_irq = NULL; + cache->nr += cache->nr_irq; + cache->nr_irq = 0; + local_irq_restore(flags); +} + static struct bio *bio_alloc_percpu_cache(struct block_device *bdev, unsigned short nr_vecs, blk_opf_t opf, gfp_t gfp, struct bio_set *bs) @@ -416,9 +438,13 @@ static struct bio *bio_alloc_percpu_cache(struct block_device *bdev, struct bio *bio; cache = per_cpu_ptr(bs->cache, get_cpu()); - if (!cache->free_list) { - put_cpu(); - return NULL; + if (!cache->free_list && + READ_ONCE(cache->nr_irq) >= ALLOC_CACHE_THRESHOLD) { + bio_alloc_irq_cache_splice(cache); + if (!cache->free_list) { + put_cpu(); + return NULL; + } } bio = cache->free_list; cache->free_list = bio->bi_next; @@ -676,11 +702,8 @@ void guard_bio_eod(struct bio *bio) bio_truncate(bio, maxsector << 9); } -#define ALLOC_CACHE_MAX 512 -#define ALLOC_CACHE_SLACK 64 - -static void bio_alloc_cache_prune(struct bio_alloc_cache *cache, - unsigned int nr) +static int __bio_alloc_cache_prune(struct bio_alloc_cache *cache, + unsigned int nr) { unsigned int i = 0; struct bio *bio; @@ -692,6 +715,17 @@ static void bio_alloc_cache_prune(struct bio_alloc_cache *cache, if (++i == nr) break; } + return i; +} + +static void bio_alloc_cache_prune(struct bio_alloc_cache *cache, + unsigned int nr) +{ + nr -= __bio_alloc_cache_prune(cache, nr); + if (!READ_ONCE(cache->free_list)) { + bio_alloc_irq_cache_splice(cache); + __bio_alloc_cache_prune(cache, nr); + } } static int bio_cpu_dead(unsigned int cpu, struct hlist_node *node) @@ -728,6 +762,7 @@ static void bio_alloc_cache_destroy(struct bio_set *bs) static inline void bio_put_percpu_cache(struct bio *bio) { struct bio_alloc_cache *cache; + unsigned long flags; cache = per_cpu_ptr(bio->bi_pool->cache, get_cpu()); bio_uninit(bio); @@ -737,12 +772,15 @@ static inline void bio_put_percpu_cache(struct bio *bio) cache->free_list = bio; cache->nr++; } else { - put_cpu(); - bio_free(bio); - return; + local_irq_save(flags); + bio->bi_next = cache->free_list_irq; + cache->free_list_irq = bio; + cache->nr_irq++; + local_irq_restore(flags); } - if (cache->nr > ALLOC_CACHE_MAX + ALLOC_CACHE_SLACK) + if (READ_ONCE(cache->nr_irq) + cache->nr > + ALLOC_CACHE_MAX + ALLOC_CACHE_SLACK) bio_alloc_cache_prune(cache, ALLOC_CACHE_SLACK); put_cpu(); } From patchwork Tue Oct 18 18:47:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 4293 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2110977wrs; Tue, 18 Oct 2022 11:54:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4sGKD3ccy03+S9cufq0XaMRkXf1VzH3llGnvgiSr+8R6VfOhMbG8IvqMPKhGrZ5WL+6egR X-Received: by 2002:a05:6402:428a:b0:42e:8f7e:1638 with SMTP id g10-20020a056402428a00b0042e8f7e1638mr4001606edc.228.1666119290459; Tue, 18 Oct 2022 11:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666119290; cv=none; d=google.com; s=arc-20160816; b=JJupaKz0B/atTrTK1OMfFZPNel5ECk7t0g6DQ+WQWTLyniRK+1nVOb2NKh93tKd7Ss bXzvhdEFRcp+uktP2W35mseGn+2TT9+WtYv9+g0KhYgwSKmbY0NTtVXkEF2UKWypFPP/ jXsHIeIRMSIfofqqKgcvF5KTAgHQ09XX5PfhIXMeYlij6/xiqE7uZ6OBy0ZZhst42MaU byY/+YogXJ2MAG6LuOiKZDbwWPNmrEL/GEG3idZfQpTUkHf++dNMXeuWbUbMD8TiMZGm B2Ja9cACzFshx8YZgFYURasFijUYDbRAvdaisTxQUZONz+rKMUjonTDDGZ1Z1/S6ZQiA B8fA== 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=OEXvp1IreEp3SXV31DiUhQRIjvrLdojheHeDjSM1+mQ=; b=eCQ0ZxbebRx92UJMBBqMiRF1Sd4X0pSrDnHWT24iB8HJ4hQFj5WlQyZTv1fNfVHsFR Lbrklgcv6gFvvEHWzVptp9iVf1dkG5lu0d3DaMA5dwYXUxmYgtvAuRrUB6Tzcx3spVMx uC5y07DluNNPnU6cNiVt5UAnkYr3aluutYN5HuiqqJWvXt15OdoN549NWAPFJY0Pc18/ RjPbb4PCnSV5ujaveVGf3rOAsrOUBKhHa0nmooVzVNWGueeP/Ul0f5gKhKFNRESVmExQ wLb+77fIrqyAJqLIzxahU+ufAhm3SBaAdoharOTQnQKdkJ43gA846FrmtWVgNdF+OiZ5 A8yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=StZ853wy; 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 hh21-20020a170906a95500b0073d8e4e8c77si12302353ejb.1005.2022.10.18.11.54.25; Tue, 18 Oct 2022 11:54:50 -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=StZ853wy; 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 S230299AbiJRStI (ORCPT + 99 others); Tue, 18 Oct 2022 14:49:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbiJRSs5 (ORCPT ); Tue, 18 Oct 2022 14:48:57 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4589EA0242; Tue, 18 Oct 2022 11:48:50 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id d26so34480907eje.10; Tue, 18 Oct 2022 11:48:50 -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=OEXvp1IreEp3SXV31DiUhQRIjvrLdojheHeDjSM1+mQ=; b=StZ853wy/e5RtsJT54EGTUKpdC1tUlgOYlrs3sEGGMffoVhFCAcySZ+zNVfaD1MQTp hMR7D7Kq7Xkwj7xChLcHAirblIX5aaAaqxy0G/6wY09rasb4Wyz7bPp1wQmhVBenkfs3 XaUUSrpMu+p7lybYOS2F+fq432f0WVK60coyn97CguE3CAs29HGOugjHrvxF/A8W/foA evsF12c3sbuzYKU+33M7yTxBruThoComQQJs1211x2nevgPNAk6CvOnmOw1ecu6qEER1 33dhbDf7rIyUZWUKI6TvvvWxR8b8S8I4Ekt328WSeicvjAGCOySDvgplDFdTSIHYEOGB dNUA== 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=OEXvp1IreEp3SXV31DiUhQRIjvrLdojheHeDjSM1+mQ=; b=rEd69rZm96JdZRjEzTiuJU0cq2IEvTSYB/FkH6WI4irV8c43pxo5+DKOLhwryrb9S5 0TkKESplNyIfm/U4omXALfThSThVt5EQbdhIkjHOgfHsefn9JTX7uWkjjXy/YB7q37SM g47aueFhSKrnHl4zXEk00JgqZjwNJ8Saeq21q9a16xlrd5gb2RMQt6B7RFOD5DPwRcju eTMlNCQ746UTuKhEwzC0ZET3YWlo96bhccNVfzK3ePNFGlTQtvV4EmdNshLPPKjT2/MA jY2Eyh7/HPtKp96rgZDRXMxh/0573Sl0cf+xefMld3+XSi7eAnm/eoq3gFUktb//zZPX HMVQ== X-Gm-Message-State: ACrzQf0WXswtPtC8zGQWolWrabbjJwLwiaTivXRENkJPoLC12lft6WaQ fwJpaDaQM2e3r056f3+apB0= X-Received: by 2002:a17:907:7632:b0:78d:b5ba:87db with SMTP id jy18-20020a170907763200b0078db5ba87dbmr3568466ejc.661.1666118928064; Tue, 18 Oct 2022 11:48:48 -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 j18-20020a17090623f200b0078db18d7972sm7855355ejg.117.2022.10.18.11.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 11:48:47 -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 4/4] io_uring/rw: enable bio caches for IRQ rw Date: Tue, 18 Oct 2022 19:47:16 +0100 Message-Id: <11cf38513c45083955d4ee2cedbb46df0a9f6081.1666114003.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?1747052701196954650?= X-GMAIL-MSGID: =?utf-8?q?1747052701196954650?= Now we can use IOCB_ALLOC_CACHE not only for iopoll'ed reads/write but also for normal IRQ driven I/O. Signed-off-by: Pavel Begunkov --- io_uring/rw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/io_uring/rw.c b/io_uring/rw.c index 100de2626e47..ff609b762742 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -667,6 +667,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode) ret = kiocb_set_rw_flags(kiocb, rw->flags); if (unlikely(ret)) return ret; + kiocb->ki_flags |= IOCB_ALLOC_CACHE; /* * If the file is marked O_NONBLOCK, still allow retry for it if it @@ -682,7 +683,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode) return -EOPNOTSUPP; kiocb->private = NULL; - kiocb->ki_flags |= IOCB_HIPRI | IOCB_ALLOC_CACHE; + kiocb->ki_flags |= IOCB_HIPRI; kiocb->ki_complete = io_complete_rw_iopoll; req->iopoll_completed = 0; } else {