From patchwork Wed Sep 4 14:18:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13790938 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 31FD7CA0ED3 for ; Wed, 4 Sep 2024 14:18:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 141856B00D2; Wed, 4 Sep 2024 10:17:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F1646B00D6; Wed, 4 Sep 2024 10:17:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC2F56B00DC; Wed, 4 Sep 2024 10:17:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C921A6B00D2 for ; Wed, 4 Sep 2024 10:17:57 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5CA0E1A15F3 for ; Wed, 4 Sep 2024 14:17:57 +0000 (UTC) X-FDA: 82527259794.12.60E993A Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by imf23.hostedemail.com (Postfix) with ESMTP id 5EAE9140018 for ; Wed, 4 Sep 2024 14:17:55 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TaN2CGMQ; spf=pass (imf23.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.208.49 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=1725459380; 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=0KHOfpOSvFEK7x+noNeVMJOoM4Kq6yXoCuMi/qta8ZiMSXU+tPzG9QGqukmgtFwyhYFHOi bLQNHEBfOs7HuJKhXlue2ryAU6XQcCx6s8dvAUwFccHLo3f7p+yKWslIflMJl6uRT93eLv GmajNTKoRavcYnUuDOs5C30Mzydggog= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725459380; a=rsa-sha256; cv=none; b=ScUV/TJi7w8NohaHJ1cBaA1+3jRxcSBDxzp178nAcG68vnNB3KbVfIqMvVw7ldD5yZt29s wzhmN0bBt+0SjC5XL/kQiOKk85HObg+dWEKqSjXmwJgH+spjmpJZEEzkTNJEXvc3Cgrw4j v2tme5LXaOAunEgI46yyeqZ+NfzzN7I= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TaN2CGMQ; spf=pass (imf23.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.208.49 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c24ebaa427so1253755a12.1 for ; Wed, 04 Sep 2024 07:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725459474; x=1726064274; 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=TaN2CGMQqLQcUmcyZyIEW/nuy5z1SjHhj7fQlCaGrgSOGcvycT/7rvuBCzYjFTRPQu 8H5gFO+TMJdWv6wl98GNrP+pApQpXh4fn8L6FpB5F4wfv1YpsnC8Dz55SxEjceWSiLQy 588fz/plplDXfUSIH2WBtMCYPZ//pRT3zwpcY52KSEcl66wh6YjpptcUKPojqEpM4MdO qYyGbXaZUjjEiJqTEv8lfLmNqTUxJ6rbd3iP0KhvKvIKasmWXSqJlDk+gf9XhB9FKVe/ i8RkqhlLfbuYNdE1hJ1NMt7BzEwYHpVKOvOFrY9o/Zk2rIuXpLEQ3oFyNJFlTavx4GAA s+sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725459474; x=1726064274; 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=Ccms4wYZXx7tJPls16pCYtfpZZyQGmt8Bc4xp6hxB3Ti7iCGok+qGES0EB3U670Pdf qqKiAx1aS7Ze4LFiWv5srH+2bWob1upJuqq14HEdWNo+pWqW2KxffVa2PMqXAmmAuUQM /38QvLypbbz15KMjTbkCUQSoZiYMMSS7vgGOMNZXgI8p2flwZ9JOFsUXn51NkMh/PyZL toD1uJZSK++Yq8uYCXlMSJ72qLeL1D68HN5ZjeCLDaryhpdhwQSCjNcBEYIRMyN0rg0/ 8vnA3GpA5TmmqWGMMkWEM1SKXrkok6+ZEb7u9rrvBWmhZcSJBLu7zlgo8Ivb80gcKkjF JtUA== X-Forwarded-Encrypted: i=1; AJvYcCVUWidYz8M3ms2Dq7GbHXOB+c+/gmeCENREhm6UWBY+DssbylV6b9zg+Aqp0FDR/Mko0zHGuRO1oQ==@kvack.org X-Gm-Message-State: AOJu0Yw0fVi6cFzIPTN6dK4xPGyO/VFmqBHX6aDMsbkJNknIN2Vd2ztJ N8l5CpvSwNdeBUoDS2pBTaHkm+nxXXTGF7rWTblk1Lxx9p0sHG4+ X-Google-Smtp-Source: AGHT+IFWD5NeSx4L5OBZcmDku0R0EHp0Mplv+v0QTrmPwvlzQ40tRMtryzZM6Z0h0n/l6uV8EPBdaQ== X-Received: by 2002:a17:907:3fa4:b0:a7a:8dcd:ffb4 with SMTP id a640c23a62f3a-a8a430913f9mr290483266b.17.1725459473656; Wed, 04 Sep 2024 07:17:53 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8989196c88sm811160766b.102.2024.09.04.07.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 07:17:52 -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 v3 8/8] block: implement async write zero pages command Date: Wed, 4 Sep 2024 15:18:07 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 5EAE9140018 X-Stat-Signature: 9g8p1nucgxazsw4q5ds7eakkkf9e4hf6 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725459475-336516 X-HE-Meta: U2FsdGVkX18dSXyTiWhzroFbI9IDLO2WlOwYWMNH25PbTO/V5JA2Ib75fDat4KsH7SDfqzTFzyYvoJbzHcVDjZTA3BdIPhnselfOiLrmTYcyPoRZGvNPdp5ctoLa7BSw1a9nIYyIUfl83ihrwRUjAN8XHS5kdJRHsx46rfCalD1VBxHV3MxeljCiLqi/+DT4ujbyoJCt3Ky9vrCS2TjF4e/cdQbiztdMyhcsjherTtZe/Af2/SCvBoZCTwY9RcZ/hlfgYkp7g65Qs+USC9khn7Lr03AbWbPHAp+kbbn0nwyOOlZowyrK1KoxvY23TiiIDzip78fbLeDMSjQs4aGt4XSKQEP3zqpZCRZJ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wQm8hp+wV7y0Q4KiJKJj4= X-Bogosity: Ham, tests=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 */