From patchwork Wed Sep 11 16:34:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13800884 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 D0B57EE57C0 for ; Wed, 11 Sep 2024 16:34:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E252694006B; Wed, 11 Sep 2024 12:34:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBBBA940066; Wed, 11 Sep 2024 12:34:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD9F994006B; Wed, 11 Sep 2024 12:34:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8E112940066 for ; Wed, 11 Sep 2024 12:34:34 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 46390C19A3 for ; Wed, 11 Sep 2024 16:34:34 +0000 (UTC) X-FDA: 82553005668.10.114475B Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf23.hostedemail.com (Postfix) with ESMTP id 0CA5C14000E for ; Wed, 11 Sep 2024 16:34:31 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DgnkOgEP; spf=pass (imf23.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.51 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=1726072444; 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=tt1Sdp5HcYzfSkBqCxePJrZcv+DNb0SwUWNG181PEJo=; b=TFOIh9wtXAXBq12qIdMYNT3O8Pwv6i+Wys6ohUNSDHgtnP5MxbWcKw9oH8sDkHyVznOEyJ JRci/p8MZwV35FipYktts0O0CKhA5GVMviH/EzH8DxpZNXiQ9uhmOPVUShTmJgjqEYPj+n +cG8lWhL6Iq4ZKuNOu5NCXBMRX8Fgn0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DgnkOgEP; spf=pass (imf23.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.51 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=1726072444; a=rsa-sha256; cv=none; b=gcPCOm4RuD6w+6rJQy+qhPRe4bkoIe3BZn0u4BPDqj2k5IhLUubhZ/OBnw4+JlizYssOIO z56dATDvxNvdWUIQskWSK2CveOV/oFScq7V7y+J8kORRwY36SSIKM3YbDqsepqQIJG3lkY oT9KzIkQcEye3eLlr6DDK70DXbIcMGs= Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a8a7929fd64so6665666b.0 for ; Wed, 11 Sep 2024 09:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726072470; x=1726677270; 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=tt1Sdp5HcYzfSkBqCxePJrZcv+DNb0SwUWNG181PEJo=; b=DgnkOgEPV3QXGTbsDOXNZ+LtJeVGgevmEvoGUYWjdiVYkRNKzKU7FldSw2At/MNPv/ V5+s/4JS1mKyhFaPioogdA4Ftimhd9OGyteoSBhu6dMYjvstqJOKyaWcm+naPlhy7CzH Y3mipIzB5zjx9n07TR9jUSypkydmf2hsrkJdOfXimY3s9pXa7ehnEXF364icCX4zPTcf GuDyWUFODJa5HtwFpfxZEWn776mKLTdVLQnDj4p7eUiOGv0ivhW9ZRw5tjUJwkO6rS+f C01uv4PVuvyZD5oq3xs4KRyBAY3ocUGspscVU072kqjTNv2NQd6lj8o9uSKaUEanN70m E92Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726072470; x=1726677270; 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=tt1Sdp5HcYzfSkBqCxePJrZcv+DNb0SwUWNG181PEJo=; b=pXM0cJrpjuZT/7VjR9r0rvYWlL7m5PVYZUWC54+BIyGSpWAa7R+WUL/Ha1/St0IKW1 fdpj62/fHxUaapE5lELuDpj9JYz/EtoorcDovFNPX3FBFIbVSgydk3AY3Yg2EOzBL95r NBFQpce85/YDUd/Wf/Qmya6y7hXshEP0S2pQKYq64zE52ZEm3tfnrdgM9wVFI81NKwuT kudjczmlXtFIJsnE350x2nf6l5qOAC6u4IxKIROjfOd5aH8kL0xrv6pP0RuNH98XczqE pGdqqeRSp6NPlc6ZH1MU/XFuAARbjJM8uwSvELmpGJlopINLI9wyaiss0z2L70tU/J4b GyFw== X-Forwarded-Encrypted: i=1; AJvYcCV1pSYsl4rwbPtZFa8UFAjS8RiN7NYhGAv92OT+WGpDGabOtRpPgztmowA6w6qtZWukR0VQUMcA/w==@kvack.org X-Gm-Message-State: AOJu0Yztwv165ShrHB6d9MZ/azlnO+09iuos+W9xO4w30ezFI0A7m+FN oRXvODqKa4nNWJTave3w0p0kxt9VW6MWEOY7J+ZiBfvVR9Yj71+G X-Google-Smtp-Source: AGHT+IGzBI9+dMWJvPlTYbOfk11QQ+FrGskd3fYscDMuABz9+Q22m/SZtfuiKraKUWCJKvHI3YqGqw== X-Received: by 2002:a17:907:d2ce:b0:a8d:3f6a:99ce with SMTP id a640c23a62f3a-a902961a769mr5471566b.49.1726072470444; Wed, 11 Sep 2024 09:34:30 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72ed3sm631820866b.135.2024.09.11.09.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 09:34:29 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, linux-block@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig Subject: [PATCH v5 8/8] block: implement write zero pages cmd Date: Wed, 11 Sep 2024 17:34:44 +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: ybo85afi353ki9atxdgzg8pggfa636pn X-Rspamd-Queue-Id: 0CA5C14000E X-Rspamd-Server: rspam11 X-HE-Tag: 1726072471-234729 X-HE-Meta: U2FsdGVkX18aT02obgRlKxOszwAc5pjKJiHMgTgjOr8nODssZ5jg/GutRoCJ9kivDI1Pc7jjKNbvE1TCm7W+FgJbxgmqXWWht267HY+BJUDJqwxurkPpLa+XKKdN1TT12jAEwOvrwIa7HTr5sCNTA3O24mgiPnqlhTGqSUzg+vL0jh/a04YD/s9V9+46vAQ+wMDE0W2d+R6TqM2JnxRNxEU0xvlC8DU3svwYmI3x9jQrI5jvxWnEGWBJs/x14OQZzH0MT9CeWek+DnPvUdYOwV/W7/dRj6ZeF7dB79kWJ71VBqlbwzRViv08Kit1VMl7/6nMm2O2fvfu4Ywfj+HH8c3d39Vezza7ilqp3QPeIbWevEEm3vTVdcl/g3TO+PCb33LFDHR1SfxpSanHl6xkqBOJGDWH2eGl5PaHaxrC/nT1GAL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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. Subsequently, it doesn't requires any special hardware support, and for example can be used as a fallback option for BLOCK_URING_CMD_WRITE_ZEROES. Signed-off-by: Pavel Begunkov --- block/ioctl.c | 21 ++++++++++++++++++--- include/uapi/linux/blkdev.h | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index f8f6d6a71ff0..08e0d2d52b06 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -780,7 +780,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) { struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd); sector_t bs_mask = (bdev_logical_block_size(bdev) >> SECTOR_SHIFT) - 1; @@ -799,6 +800,17 @@ static int blkdev_cmd_write_zeroes(struct io_uring_cmd *cmd, if (err) return err; + if (zero_pages) { + 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; /* @@ -834,7 +846,7 @@ static int blkdev_cmd_write_zeroes(struct io_uring_cmd *cmd, return -EAGAIN; if (unlikely(nr_sects)) bic->res = -EAGAIN; - +out_submit: prev->bi_private = cmd; prev->bi_end_io = bio_cmd_bio_end_io; submit_bio(prev); @@ -921,7 +933,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/blkdev.h b/include/uapi/linux/blkdev.h index b4664139a82a..880b292d2d0d 100644 --- a/include/uapi/linux/blkdev.h +++ b/include/uapi/linux/blkdev.h @@ -11,5 +11,6 @@ */ #define BLOCK_URING_CMD_DISCARD _IO(0x12, 0) #define BLOCK_URING_CMD_WRITE_ZEROES _IO(0x12, 1) +#define BLOCK_URING_CMD_WRITE_ZERO_PAGE _IO(0x12, 2) #endif