From patchwork Thu Feb 16 15:19:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13143357 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81515C64ED6 for ; Thu, 16 Feb 2023 15:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbjBPPT0 (ORCPT ); Thu, 16 Feb 2023 10:19:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbjBPPTZ (ORCPT ); Thu, 16 Feb 2023 10:19:25 -0500 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AEDE93FA for ; Thu, 16 Feb 2023 07:19:24 -0800 (PST) Received: by mail-io1-xd29.google.com with SMTP id f8so241099ioo.0 for ; Thu, 16 Feb 2023 07:19:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.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=/F3fWfMedxCdmHWDLO4jWxLDIXa+8W9/VD2h3x3YdLE=; b=n7NMQgUwwQ2lV3+N2KcdRGMX7e7mSpP5B+MqazTTWnq/qyDn7uAr5jVX1N91P2oV1a aIzr56pwYXFNBbz3xNrroizN63sx+BAovpMsQf2E8+VbgTNcIY9O3h0qQsIgg+qTL/kq CM/3S/ePYMOUBfdfZy0CVo+WlZZAlE6MilxcE3dYVQfDvgOtSo59LbSvh439ztwBfwMc mIN1Z+UB5S314OynuIlbE710Ym89tznIOp3M+3YuTcOPWkjagv2KZcB1np7Ez6WXS6KV dr2cJkRbe0mu+zi54KEp6kVkoRMDVzCzW3PmZiEIBvl+YouT9JiF7/lQahoBiXyfIUt6 0PtA== 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=/F3fWfMedxCdmHWDLO4jWxLDIXa+8W9/VD2h3x3YdLE=; b=GwLmbyf2RE2D6b++TaAZ8QFql0FLQaEDVDrtUYDSCLIA14kt1WkRbLdAgbeavVjWTe meGzpVESHtd6i3fFdCmwDtS0d0330bGQ6w+O70pPvNVb1ND4fQMi4JFxmK63AcNEvdKO wAR7GbX0CW2YrE1kWcR+qdqLRU0B8DGiguzPI2NtdCv4HFde7XL0Sp/aW5P66WJ1cj6P b/p/k4vw43eLLAYus1e3/bBzQIEODxdJGCulXcqnPaFIT3SL/qcU7ARzHjBskPbBiva8 NTG4BKU+Vyj/3/V57NF6mMOXxheH4W99prsR4MuGAan7MHXnpDZ+VbSr6FoZG83eg9BU V5Cg== X-Gm-Message-State: AO0yUKV604kybvKUy6XGusVOYWNaMzPtgj3GCycwn6oqbHS1jrDqYtFN 4HBU+jjqTj4z/gpyK9yFhaG2B2yroJSaBuLH X-Google-Smtp-Source: AK7set9LWTTzjD5GXy/p4+RQKI/uf/IChRvuK1DjWxxfbFY+Fi743xVLaKmgmrmeLMb5DAgnWuzd7A== X-Received: by 2002:a05:6602:2ac8:b0:740:7d21:d96f with SMTP id m8-20020a0566022ac800b007407d21d96fmr4855169iov.1.1676560763243; Thu, 16 Feb 2023 07:19:23 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p10-20020a0566022b0a00b006e2f2369d3csm561600iov.50.2023.02.16.07.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 07:19:21 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: hch@infradead.org, Jens Axboe , stable@vger.kernel.org Subject: [PATCH 1/4] brd: return 0/-error from brd_insert_page() Date: Thu, 16 Feb 2023 08:19:15 -0700 Message-Id: <20230216151918.319585-2-axboe@kernel.dk> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216151918.319585-1-axboe@kernel.dk> References: <20230216151918.319585-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org It currently returns a page, but callers just check for NULL/page to gauge success. Clean this up and return the appropriate error directly instead. Cc: stable@vger.kernel.org # 5.10+ Signed-off-by: Jens Axboe Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- drivers/block/brd.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 20acc4a1fd6d..15a148d5aad9 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -78,11 +78,9 @@ static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector) } /* - * Look up and return a brd's page for a given sector. - * If one does not exist, allocate an empty page, and insert that. Then - * return it. + * Insert a new page for a given sector, if one does not already exist. */ -static struct page *brd_insert_page(struct brd_device *brd, sector_t sector) +static int brd_insert_page(struct brd_device *brd, sector_t sector) { pgoff_t idx; struct page *page; @@ -90,7 +88,7 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector) page = brd_lookup_page(brd, sector); if (page) - return page; + return 0; /* * Must use NOIO because we don't want to recurse back into the @@ -99,11 +97,11 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector) gfp_flags = GFP_NOIO | __GFP_ZERO | __GFP_HIGHMEM; page = alloc_page(gfp_flags); if (!page) - return NULL; + return -ENOMEM; if (radix_tree_preload(GFP_NOIO)) { __free_page(page); - return NULL; + return -ENOMEM; } spin_lock(&brd->brd_lock); @@ -120,8 +118,7 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector) spin_unlock(&brd->brd_lock); radix_tree_preload_end(); - - return page; + return 0; } /* @@ -174,16 +171,17 @@ static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n) { unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT; size_t copy; + int ret; copy = min_t(size_t, n, PAGE_SIZE - offset); - if (!brd_insert_page(brd, sector)) - return -ENOSPC; + ret = brd_insert_page(brd, sector); + if (ret) + return ret; if (copy < n) { sector += copy >> SECTOR_SHIFT; - if (!brd_insert_page(brd, sector)) - return -ENOSPC; + ret = brd_insert_page(brd, sector); } - return 0; + return ret; } /* From patchwork Thu Feb 16 15:19:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13143358 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FC5FC636CC for ; Thu, 16 Feb 2023 15:19:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229983AbjBPPT2 (ORCPT ); Thu, 16 Feb 2023 10:19:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230044AbjBPPT0 (ORCPT ); Thu, 16 Feb 2023 10:19:26 -0500 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98BD54C3C0 for ; Thu, 16 Feb 2023 07:19:25 -0800 (PST) Received: by mail-io1-xd36.google.com with SMTP id w24so749632iow.13 for ; Thu, 16 Feb 2023 07:19:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.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=yjez0L/LxXn3HnvptBOuF6EryK2CIHbWYpMFu4wG7eM=; b=N5uYZFPyPxmNEk32kZ/oC5b31XMpTEOipncdIs4QhjqlmHXWGnZVMiQ4HCxY8tPwdX ax2rexF/04te8O5vaGAdNXflw3oUSYJAy0QkFgQpxim1JwAba6rbmDkr8mM+SfsQRL5I xGpiEsbxG/eZOEu8hxUQPdLXcbMb6ujkYKS72vVO9gwiFCAwHkHFFVDKnKspE9irqhVE pKex2uBDJgwf6fUKoRvSpcKG1XzWXEoryXDqk3LjVlXp5ESMAm7wU9lDuNFWVm3hoJ2z PJOdFIXcUOr0AsYOoHbfrJj+Ws3OEu/ZOG34Fh6tr9CxvqbnjkxAQbga8OOU5m9c02mU 1kiQ== 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=yjez0L/LxXn3HnvptBOuF6EryK2CIHbWYpMFu4wG7eM=; b=guoirNpW+c9O4WhZvfW57XvkGTxOmeoGHHM602BnA41Lu7a+Sbtk2Y22I8DgCLgqU1 HdlccN4X08ypo9Yoak1x5857T8HY9zIbOywq+9S7k863pLoCHthfR8X7hlT6FgpaAHAj XHXozEcWB9GojtPYap4DKBsIiyb2jbgCM/XJyDLluQDx0ThWQnkHeMV6T5He3AgD7R0E LAiO82NXHtSLgzzY/m49qkHKxxaMc1HOWz0PNVHFnb1k6NLKy8dZpOqXylAzwuse/bS4 ngzm1NZSyjaMo8UIcpjMeGzoPbwO7DasggITrvvj6vXUtEuUaB41Tpx8xa2fAnnsUuD0 bmxQ== X-Gm-Message-State: AO0yUKUnfecsXxWk6/yxSV4jYQq6yNQrm9exEw+mEVNdYHe8gbUVhccj c3R7BtUV0k24vx3/L2z9ZypTojBx4rMgtLlT X-Google-Smtp-Source: AK7set8ogXJq2FZihrnyVHUVJVLr/QSbrgdSCf+Lvbix/Imrf3Q8zkt/0s4ShIsSgyj1F1GULrCWqQ== X-Received: by 2002:a6b:b2d1:0:b0:744:5aff:2ea9 with SMTP id b200-20020a6bb2d1000000b007445aff2ea9mr1461325iof.2.1676560764606; Thu, 16 Feb 2023 07:19:24 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p10-20020a0566022b0a00b006e2f2369d3csm561600iov.50.2023.02.16.07.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 07:19:24 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: hch@infradead.org, Jens Axboe , stable@vger.kernel.org Subject: [PATCH 2/4] brd: check for REQ_NOWAIT and set correct page allocation mask Date: Thu, 16 Feb 2023 08:19:16 -0700 Message-Id: <20230216151918.319585-3-axboe@kernel.dk> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216151918.319585-1-axboe@kernel.dk> References: <20230216151918.319585-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org If REQ_NOWAIT is set, then do a non-blocking allocation if the operation is a write and we need to insert a new page. Currently REQ_NOWAIT cannot be set as the queue isn't marked as supporting nowait, this change is in preparation for allowing that. Cc: stable@vger.kernel.org # 5.10+ Signed-off-by: Jens Axboe Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- drivers/block/brd.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 15a148d5aad9..1ddada0cdaca 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -80,26 +80,20 @@ static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector) /* * Insert a new page for a given sector, if one does not already exist. */ -static int brd_insert_page(struct brd_device *brd, sector_t sector) +static int brd_insert_page(struct brd_device *brd, sector_t sector, gfp_t gfp) { pgoff_t idx; struct page *page; - gfp_t gfp_flags; page = brd_lookup_page(brd, sector); if (page) return 0; - /* - * Must use NOIO because we don't want to recurse back into the - * block or filesystem layers from page reclaim. - */ - gfp_flags = GFP_NOIO | __GFP_ZERO | __GFP_HIGHMEM; - page = alloc_page(gfp_flags); + page = alloc_page(gfp | __GFP_ZERO | __GFP_HIGHMEM); if (!page) return -ENOMEM; - if (radix_tree_preload(GFP_NOIO)) { + if (radix_tree_preload(gfp)) { __free_page(page); return -ENOMEM; } @@ -167,19 +161,20 @@ static void brd_free_pages(struct brd_device *brd) /* * copy_to_brd_setup must be called before copy_to_brd. It may sleep. */ -static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n) +static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n, + gfp_t gfp) { unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT; size_t copy; int ret; copy = min_t(size_t, n, PAGE_SIZE - offset); - ret = brd_insert_page(brd, sector); + ret = brd_insert_page(brd, sector, gfp); if (ret) return ret; if (copy < n) { sector += copy >> SECTOR_SHIFT; - ret = brd_insert_page(brd, sector); + ret = brd_insert_page(brd, sector, gfp); } return ret; } @@ -254,20 +249,26 @@ static void copy_from_brd(void *dst, struct brd_device *brd, * Process a single bvec of a bio. */ static int brd_do_bvec(struct brd_device *brd, struct page *page, - unsigned int len, unsigned int off, enum req_op op, + unsigned int len, unsigned int off, blk_opf_t opf, sector_t sector) { void *mem; int err = 0; - if (op_is_write(op)) { - err = copy_to_brd_setup(brd, sector, len); + if (op_is_write(opf)) { + /* + * Must use NOIO because we don't want to recurse back into the + * block or filesystem layers from page reclaim. + */ + gfp_t gfp = opf & REQ_NOWAIT ? GFP_NOWAIT : GFP_NOIO; + + err = copy_to_brd_setup(brd, sector, len, gfp); if (err) goto out; } mem = kmap_atomic(page); - if (!op_is_write(op)) { + if (!op_is_write(opf)) { copy_from_brd(mem + off, brd, sector, len); flush_dcache_page(page); } else { @@ -296,8 +297,12 @@ static void brd_submit_bio(struct bio *bio) (len & (SECTOR_SIZE - 1))); err = brd_do_bvec(brd, bvec.bv_page, len, bvec.bv_offset, - bio_op(bio), sector); + bio->bi_opf, sector); if (err) { + if (err == -ENOMEM && bio->bi_opf & REQ_NOWAIT) { + bio_wouldblock_error(bio); + return; + } bio_io_error(bio); return; } From patchwork Thu Feb 16 15:19:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13143359 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23441C636D7 for ; Thu, 16 Feb 2023 15:19:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229960AbjBPPTe (ORCPT ); Thu, 16 Feb 2023 10:19:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229883AbjBPPTc (ORCPT ); Thu, 16 Feb 2023 10:19:32 -0500 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96FC53B20D for ; Thu, 16 Feb 2023 07:19:26 -0800 (PST) Received: by mail-io1-xd31.google.com with SMTP id d10so319769ioc.3 for ; Thu, 16 Feb 2023 07:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1676560765; 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=CulG6zK2nW/HgGbhd9JkZzAHs0nEf73drPFn60pMvSQ=; b=JZiE+1WytL5c1cjaZbScE5/h8NtfsKgMUNvCJP/lTXNoLt4FGC189+3uPudVOIAlHy 33qmKz8ODkFLVf0KsQ1yjGqN0SjzmS8bI088jlZRr4mL4HAja0oWz+Ap58ZxYbnjHSri 5+f+UxVgu8ShJtlSoEkoWktBL1JKDqlYRaUumK0Wpf1IFTial0CwFn9W2ik3m+PVfBKO RcNykP57vmNQbd++6Je+KCeWFwWOOxf15xmudmCEwuRt4pFTCvBGOMKng6Q9pwWe+IAM tRTG2lrI3A+QDr0Ag37IhkXiV7oqLHLUvRSXF1B14j1RS1MpwjUHcL7HRAq7NADZXlfY GjWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1676560765; 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=CulG6zK2nW/HgGbhd9JkZzAHs0nEf73drPFn60pMvSQ=; b=jvLMNE2PViYQXez9tX2X6QoDP/rSXBs1EfKOBmY7DsLfFzcZPJAYVel8N/HcyNHkOx J8myPYX5ifkJZV8NaqOhN9aM2Df5JAdscUVUd/AmcQlU23Zbobi8x9OUfw/KE6Qyp5Zf ctT+w0OXTgOgwJcy/YOpWl2gKKEVFSCmxzCdCidmAcBseekQf6ib/egttVd+m4SwoIBI egg2rWGaIl2XZwGS/jfEb4zsmlBfkIF66jh4RcqHHmeQvAQX2hHGN7cEChUC81fmX8i5 C+n/o5Gzv2r+uYu4jm92KS9OhlK8Rdgq7Pzle3eIwyam1glAO16GDQ+XQ2CLrChHJPWz C+eQ== X-Gm-Message-State: AO0yUKXnxIrn8SyS6JloUHffxwzdCXAKs/11UwsbsOMVB27fFgtbFFhB 9Nh77CIxU5IErFgc4nN1m2UF8DfB6+XwkjwU X-Google-Smtp-Source: AK7set9ajQ9uDKbPcAl17QNiFke5xKDK+BOgSt8RK+k4lTC+8vd0IFOxq2KqydCY9etadKicXQYSMA== X-Received: by 2002:a05:6602:154b:b0:715:f031:a7f5 with SMTP id h11-20020a056602154b00b00715f031a7f5mr4894275iow.1.1676560765660; Thu, 16 Feb 2023 07:19:25 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p10-20020a0566022b0a00b006e2f2369d3csm561600iov.50.2023.02.16.07.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 07:19:25 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: hch@infradead.org, Jens Axboe , stable@vger.kernel.org Subject: [PATCH 3/4] brd: only preload radix tree if we're using a blocking gfp mask Date: Thu, 16 Feb 2023 08:19:17 -0700 Message-Id: <20230216151918.319585-4-axboe@kernel.dk> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216151918.319585-1-axboe@kernel.dk> References: <20230216151918.319585-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org radix_tree_preload() warns on attempting to call it with an allocation mask that doesn't allow blocking. While that warning could arguably be removed, we need to handle radix insertion failures anyway as they are more likely if we cannot block to get memory. Remove legacy BUG_ON()'s and turn them into proper errors instead, one for the allocation failure and one for finding a page that doesn't match the correct index. Cc: stable@vger.kernel.org # 5.10+ Signed-off-by: Jens Axboe --- drivers/block/brd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 1ddada0cdaca..6019ef23344f 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -84,6 +84,7 @@ static int brd_insert_page(struct brd_device *brd, sector_t sector, gfp_t gfp) { pgoff_t idx; struct page *page; + int ret = 0; page = brd_lookup_page(brd, sector); if (page) @@ -93,7 +94,7 @@ static int brd_insert_page(struct brd_device *brd, sector_t sector, gfp_t gfp) if (!page) return -ENOMEM; - if (radix_tree_preload(gfp)) { + if (gfpflags_allow_blocking(gfp) && radix_tree_preload(gfp)) { __free_page(page); return -ENOMEM; } @@ -104,8 +105,10 @@ static int brd_insert_page(struct brd_device *brd, sector_t sector, gfp_t gfp) if (radix_tree_insert(&brd->brd_pages, idx, page)) { __free_page(page); page = radix_tree_lookup(&brd->brd_pages, idx); - BUG_ON(!page); - BUG_ON(page->index != idx); + if (!page) + ret = -ENOMEM; + else if (page->index != idx) + ret = -EIO; } else { brd->brd_nr_pages++; } From patchwork Thu Feb 16 15:19:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13143360 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 687A7C64ED6 for ; Thu, 16 Feb 2023 15:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230091AbjBPPTf (ORCPT ); Thu, 16 Feb 2023 10:19:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230097AbjBPPTc (ORCPT ); Thu, 16 Feb 2023 10:19:32 -0500 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9BE12A150 for ; Thu, 16 Feb 2023 07:19:27 -0800 (PST) Received: by mail-io1-xd36.google.com with SMTP id w24so749682iow.13 for ; Thu, 16 Feb 2023 07:19:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.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=Nr9P+q3lnc60G0QD7ZQ8r9aN9DUVZpnJXngdvhp1uOE=; b=hmtSj3LLxpeouHeeJ3nCPBuwu55gk23lkWi/SoikASdagk5d1DXV7w0YevnChGwkP4 I+Nw/5hz+vFwaETiqCXEr2PqGSOr/MIiw4db3IrvOxelwVKw1NvUx98ODIPmsOSz8fiy 5t6j+LcGMagpyQfAL6E3/6uh1qFW9xP1xq0FKDrJAut33v2pJcdHr34uA0uJHlR4SjuX 2/sWKkVjlQm4U1V8p3waKECBNf+Tm9zsP82HGZXGYMY8+hIJTB2ijfsAVMGatV4nJm57 zq5+XZUyaXAGHoIImmLHpcLfHvWlkpqOPD2hWd2qSfskTVfBpN0YrUAZ7MvpLag3Rtbe sHsQ== 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=Nr9P+q3lnc60G0QD7ZQ8r9aN9DUVZpnJXngdvhp1uOE=; b=vjqrYdRre/FCg7xDilWg+gd6JAliq/X6JacqEiUULEDBBqxIFyfdsBrjKGt6C/OuoE dR+E2OO8DeqCAT2r3onjZUucMa0wuIloTAtMFwAp2EqZgW8k7DVFlIrXBkNS3pbRt7sy eidNRhLFpRzX9dGCIPdMr4Bb40QBq7bZn6BKxKrTix3jZy/z6A7rdKTayQjr8yEc7QZa SYBlkyRFtQQabaVBLvI6xdI+yXbyYPtda58LAaVD0vCJk/GQDDltGbAyvfkU64AjC0VY sxzY7J+X9MsG2SyQ41KgNS5KkGg8d19ByGqggF38MfSY6BrdUY81kqtewmLCgqAqJpO6 T+pA== X-Gm-Message-State: AO0yUKW/kFzP+hgaPBfQTYkRf/+MZ0N5tDzdERvZBQgG1+NZ+KWLgo2O eaRii5JpwxBqfO4F9tXrlAJ5pRQQWKCVFPBb X-Google-Smtp-Source: AK7set+aGnXeawkhgrUQxhA1aznl3o0LZ42cyIBR/Mu9EDLgtiiI8a+o5RnpeyLcIUCUl0r5DC4s9Q== X-Received: by 2002:a05:6602:5cd:b0:73a:6c75:5a85 with SMTP id w13-20020a05660205cd00b0073a6c755a85mr3699921iox.0.1676560767271; Thu, 16 Feb 2023 07:19:27 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p10-20020a0566022b0a00b006e2f2369d3csm561600iov.50.2023.02.16.07.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 07:19:26 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: hch@infradead.org, Jens Axboe , stable@vger.kernel.org Subject: [PATCH 4/4] brd: mark as nowait compatible Date: Thu, 16 Feb 2023 08:19:18 -0700 Message-Id: <20230216151918.319585-5-axboe@kernel.dk> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216151918.319585-1-axboe@kernel.dk> References: <20230216151918.319585-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org By default, non-mq drivers do not support nowait. This causes io_uring to use a slower path as the driver cannot be trust not to block. brd can safely set the nowait flag, as worst case all it does is a NOIO allocation. For io_uring, this makes a substantial difference. Before: submitter=0, tid=453, file=/dev/ram0, node=-1 polled=0, fixedbufs=1/0, register_files=1, buffered=0, QD=128 Engine=io_uring, sq_ring=128, cq_ring=128 IOPS=440.03K, BW=1718MiB/s, IOS/call=32/31 IOPS=428.96K, BW=1675MiB/s, IOS/call=32/32 IOPS=442.59K, BW=1728MiB/s, IOS/call=32/31 IOPS=419.65K, BW=1639MiB/s, IOS/call=32/32 IOPS=426.82K, BW=1667MiB/s, IOS/call=32/31 and after: submitter=0, tid=354, file=/dev/ram0, node=-1 polled=0, fixedbufs=1/0, register_files=1, buffered=0, QD=128 Engine=io_uring, sq_ring=128, cq_ring=128 IOPS=3.37M, BW=13.15GiB/s, IOS/call=32/31 IOPS=3.45M, BW=13.46GiB/s, IOS/call=32/31 IOPS=3.43M, BW=13.42GiB/s, IOS/call=32/32 IOPS=3.43M, BW=13.39GiB/s, IOS/call=32/31 IOPS=3.43M, BW=13.38GiB/s, IOS/call=32/31 or about an 8x in difference. Now that brd is prepared to deal with REQ_NOWAIT reads/writes, mark it as supporting that. Cc: stable@vger.kernel.org # 5.10+ Link: https://lore.kernel.org/linux-block/20230203103005.31290-1-p.raghav@samsung.com/ Signed-off-by: Jens Axboe --- drivers/block/brd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 6019ef23344f..522530a6ebca 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -418,6 +418,7 @@ static int brd_alloc(int i) /* Tell the block layer that this is not a rotational device */ blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue); blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, disk->queue); + blk_queue_flag_set(QUEUE_FLAG_NOWAIT, disk->queue); err = add_disk(disk); if (err) goto out_cleanup_disk;