From patchwork Fri Sep 6 22:57:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13794838 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BA35E6FE49 for ; Fri, 6 Sep 2024 22:57:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F1696B009B; Fri, 6 Sep 2024 18:57:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A41A6B009C; Fri, 6 Sep 2024 18:57:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BA1A6B009E; Fri, 6 Sep 2024 18:57:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 18EC46B009B for ; Fri, 6 Sep 2024 18:57:13 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CD5DCC05B8 for ; Fri, 6 Sep 2024 22:57:12 +0000 (UTC) X-FDA: 82535825904.09.E12BF6B Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by imf16.hostedemail.com (Postfix) with ESMTP id E996F18000C for ; Fri, 6 Sep 2024 22:57:10 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QytKF2Kw; spf=pass (imf16.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.167.52 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725663405; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=llWa+KY1CsE699NO6/Qz9OdhajA1Gh72FplwVQHN8Os=; b=6fPflszuRPhcTeFOcA3lccJXUbIIsOaE4vln3gCTemn+UBdDXh3tt9w9Yswbti736EV6hy Z9EAF/KYuBneseiiIqIQ7xYANTB/gdrHrAZJbhlt1UuWDhjJQS6B48Il+HZlW5p8XyhuPL X93uLNz17SHnnbSUkmGkYlWCMPAArI0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QytKF2Kw; spf=pass (imf16.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.167.52 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725663405; a=rsa-sha256; cv=none; b=BbSxk1YpCKQclbwEvJgrcUzRlJw6Q0/RQnD7c/Aqe7g8uVP+mEAU3QVovKpCMSLkidlGUi ePsXyXAWjeLygB9Ffh6OfvUmCdSv1+pWNVdgDLPTaHK1H7meQaC5mZUBTnogGw78Nx0xSZ K7LtFqk9sKPEZutL5/5X+xNZc8OTNj0= Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-535be093a43so3180053e87.3 for ; Fri, 06 Sep 2024 15:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725663429; x=1726268229; darn=kvack.org; 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=llWa+KY1CsE699NO6/Qz9OdhajA1Gh72FplwVQHN8Os=; b=QytKF2KwklOJq6NOhHtImwB54K+K9k+jatEGP9Fwrykjh9OwK5Zo5GE0Hpye3BzK3C Fa5Md9zyD7r/Ly1JCOg6iRpQRkOv21lVOg12LWNKiJ/9CizUv5neANjr9yAk8Gu0mje5 XPhy+6X5pwrTh/4eHwk5HJZcg++twUTvobxyRRNaWACnlFfd6X3kmPYfVdECb6YdMLV9 R1Ax9xgbQL4BdzVf/Ebti1/udBNJiBhsfNEVhpeflx6+W/ciVEjDy8qMKdPhzcGiBknR MorTRlbpI6srbp2A818PR7I9UDbQxl96mLzAU92LoaSH9W8B9d6U3sNPcg157CFUI1UC yldQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725663429; x=1726268229; 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=llWa+KY1CsE699NO6/Qz9OdhajA1Gh72FplwVQHN8Os=; b=CBjMmq5lK5sRYvqWpIYHl9wQ7fDd6J1rAG9CUqCIDqkHBL3CaxDfENmvG6RU6BeUO1 ZlI2Ili3sXpXtGekTuX+ygc5U+ns4CfHfcRiUXe+5bkez4U9428LmQdd9PeIZ16sEvUa oRNTlJyaBx33vJ2H+uo8KUVAs9iu5tgLaA+PIWyJUqpbsZQxHj2mP3kuCTm4qmCrkvLD 4TCfDoyPu2F6L8CRubxcivgzLQpPBFQ/h9QzqNw+ksyaM6T/0iSUU6+0lnpuN3ALnAWf vl5ElOYz/KeW8bGrYhG72YT3viVDuESBcjF9M4AZ6PCqN19/o7Dhfu3bnEwm27zIaY8/ lMeA== X-Forwarded-Encrypted: i=1; AJvYcCWZ3NDgcrxcUPev/PPbqIJZzUGIeke1k8fOMzt48MGfEYZIyqjYUQwnl7HBPTsbzusB2/UcfdRfZg==@kvack.org X-Gm-Message-State: AOJu0YwQxrU3VKgXS+lbZpdkaYsQ6J6NI5EOSAGoKDP4n04/0Bq3F5xb V6wQi1LLR3QrtOh2pyc9y6yaK3uhSpUr9UTwGvkElP+LmVa1zwhb X-Google-Smtp-Source: AGHT+IF7dy6Fwnb2jmgqk1DE1zvsMyOI+fNBEs5xezgv4QpyDJkwby70G9EHhdLSnvBeBbSkACl5HA== X-Received: by 2002:a05:6512:10d0:b0:52c:d904:d26e with SMTP id 2adb3069b0e04-536587abee5mr2790225e87.21.1725663429138; Fri, 06 Sep 2024 15:57:09 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.146.236]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25d54978sm2679566b.199.2024.09.06.15.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 15:57:08 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Conrad Meyer , linux-block@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig Subject: [PATCH v4 8/8] block: implement async write zero pages command Date: Fri, 6 Sep 2024 23:57:25 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: pgdwqx49uq8toiwi8w41tera9u8uinga X-Rspamd-Queue-Id: E996F18000C X-Rspamd-Server: rspam11 X-HE-Tag: 1725663430-726855 X-HE-Meta: U2FsdGVkX19owr+FigYWLGSm/KFjNvhKQ31r/v1ubWpZVErwGc9pLWFwSzjs0whLheClpKJcdxC83oxd8JIkGqDEvnhSV3xKW/wclDVDtpwhmnb5PEvSZkvkp6z0x76WcuiqAxdMKexkJ7qND6Xx39NCkG8wfP36HugpT1HRj9chPlla8KF66s2Ra8M+wtXrE+sK/Inm4/3awYt5Ybm60jCNfxgyXcxu1PKiFe3k15TDtz+F2Djfek3WqvDV3WvRCW/uEMFZSu6HxABCs7W3zIz+TkKOWFr4Z/z4HnEi507jPO3xRRyq+Y+OV1fYMlZttzAHB/x6F4jGAssoqfROOGxb+yjlCv+73a+x/zW+Qt/byy68OSJCorGvziShYurYZ8LywgBCFvBs/pBd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bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a command that writes the zero page to the drive. Apart from passing the zero page instead of actual data it uses the normal write path and doesn't do any further acceleration, nor it requires any special hardware support. The indended use is to have a fallback when BLOCK_URING_CMD_WRITE_ZEROES is not supported. Signed-off-by: Pavel Begunkov --- block/ioctl.c | 24 +++++++++++++++++++++--- include/uapi/linux/fs.h | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index ef4b2a90ad79..3cb479192023 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -774,7 +774,8 @@ static void bio_cmd_bio_end_io(struct bio *bio) static int blkdev_cmd_write_zeroes(struct io_uring_cmd *cmd, struct block_device *bdev, - uint64_t start, uint64_t len, bool nowait) + uint64_t start, uint64_t len, + bool nowait, bool zero_pages) { sector_t bs_mask = (bdev_logical_block_size(bdev) >> SECTOR_SHIFT) - 1; @@ -793,6 +794,20 @@ static int blkdev_cmd_write_zeroes(struct io_uring_cmd *cmd, if (err) return err; + if (zero_pages) { + struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, + struct blk_iou_cmd); + + err = blkdev_issue_zero_pages_bio(bdev, sector, nr_sects, + gfp, &prev, + BLKDEV_ZERO_PAGES_NOWAIT); + if (!prev) + return -EAGAIN; + if (err) + bic->res = err; + goto out_submit; + } + if (!limit) return -EOPNOTSUPP; /* @@ -826,7 +841,7 @@ static int blkdev_cmd_write_zeroes(struct io_uring_cmd *cmd, } if (!prev) return -EAGAIN; - +out_submit: prev->bi_private = cmd; prev->bi_end_io = bio_cmd_bio_end_io; submit_bio(prev); @@ -904,7 +919,10 @@ int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) return blkdev_cmd_discard(cmd, bdev, start, len, bic->nowait); case BLOCK_URING_CMD_WRITE_ZEROES: return blkdev_cmd_write_zeroes(cmd, bdev, start, len, - bic->nowait); + bic->nowait, false); + case BLOCK_URING_CMD_WRITE_ZERO_PAGE: + return blkdev_cmd_write_zeroes(cmd, bdev, start, len, + bic->nowait, true); } return -EINVAL; } diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 68b0fccebf92..f4337b87d846 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -210,6 +210,7 @@ struct fsxattr { #define BLOCK_URING_CMD_DISCARD _IO(0x12,137) #define BLOCK_URING_CMD_WRITE_ZEROES _IO(0x12,138) +#define BLOCK_URING_CMD_WRITE_ZERO_PAGE _IO(0x12,139) #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1) /* bmap access */