From patchwork Wed Sep 20 19:14:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 725129 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 70BFDC04FFE for ; Wed, 20 Sep 2023 19:15:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230133AbjITTPd (ORCPT ); Wed, 20 Sep 2023 15:15:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230062AbjITTP1 (ORCPT ); Wed, 20 Sep 2023 15:15:27 -0400 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0448FF1; Wed, 20 Sep 2023 12:14:57 -0700 (PDT) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-690fa0eea3cso126309b3a.0; Wed, 20 Sep 2023 12:14:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695237297; x=1695842097; 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=h0JT6YyO9iHowYYbRVgNrx63Uw1Cg4HkMWvKRurcKVE=; b=IEBkxmZvdFrmF8FRDS3X0gRbLQ5SYHLXmuLEj8GOHDbKNtZOf5/m7pON2NJ/r3VLKc H/dLRZhuH5VYUiJ94KijEJry/PCDNFfFCsW+Vg0j6nlw7nD93tbwrL7FJJy590rrZ7/s 47oGddxK1CfbKtWdMjq6qxkld+I9T3PdAW8IoYdOGF5ONdNJZVEeZlbmUdc7fRuAQ5sN 0zEuxi70n5yIbf2H996SgepkX62RZm+lcILFO6m8skuiJliAgVt4PsJp5NXIs0GMDQJx HghGSvARirLHzGRCfJzmcc/C0/AKb2R/Vx4tECKSV1cXWAJ40tSqxVNc4xxXynogw3Qo /8Xg== X-Gm-Message-State: AOJu0Yz3IkfzwA52i14CnITJn/CpMhlEjuLM32USVsmocl/Xoo7wFxhG bjNlVzRTB19mhhLw80G5bYOzL+Kg1oc= X-Google-Smtp-Source: AGHT+IEcDNBYiZdgQSVNHajqIkMGPmqVHwUJnJ/QGvA+CzmJvXTvQTBel5DOmZieTsv6ZiK/Aluc5w== X-Received: by 2002:a05:6a20:4408:b0:14c:f16a:2b78 with SMTP id ce8-20020a056a20440800b0014cf16a2b78mr4162363pzb.45.1695237297146; Wed, 20 Sep 2023 12:14:57 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:b0c6:e5b6:49ef:e0bd]) by smtp.gmail.com with ESMTPSA id a13-20020a17090a8c0d00b002633fa95ac2sm1656318pjo.13.2023.09.20.12.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:14:56 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Alexander Viro , Christian Brauner , Jaegeuk Kim , Chao Yu , "Darrick J. Wong" Subject: [PATCH 04/13] block: Restore write hint support Date: Wed, 20 Sep 2023 12:14:29 -0700 Message-ID: <20230920191442.3701673-5-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog In-Reply-To: <20230920191442.3701673-1-bvanassche@acm.org> References: <20230920191442.3701673-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch partially reverts commit c75e707fe1aa ("block: remove the per-bio/request write hint"). The following aspects of that commit have been reverted: - Pass the struct kiocb write hint information to struct bio. - Pass the struct bio write hint information to struct request. - Do not merge requests with different write hints. - Passing write hint information from the VFS layer to the block layer. - In F2FS, initialization of bio.bi_write_hint. The following aspects of that commit have been dropped: - Debugfs support for retrieving and modifying write hints. - md-raid, BTRFS, ext4, gfs2 and zonefs write hint support. - The write_hints[] array in struct request_queue. Cc: Christoph Hellwig Signed-off-by: Bart Van Assche Reviewed-by: Avri Altman Reviewed-by: Bean Huo Reviewed-by: Daejun Park --- block/bio.c | 2 ++ block/blk-crypto-fallback.c | 1 + block/blk-merge.c | 14 ++++++++++++++ block/blk-mq.c | 2 ++ block/bounce.c | 1 + block/fops.c | 3 +++ fs/buffer.c | 13 ++++++++----- fs/direct-io.c | 1 + fs/f2fs/data.c | 2 ++ fs/iomap/buffered-io.c | 2 ++ fs/iomap/direct-io.c | 1 + fs/mpage.c | 1 + include/linux/blk-mq.h | 1 + include/linux/blk_types.h | 1 + 14 files changed, 40 insertions(+), 5 deletions(-) diff --git a/block/bio.c b/block/bio.c index 816d412c06e9..755fcde5cb66 100644 --- a/block/bio.c +++ b/block/bio.c @@ -251,6 +251,7 @@ void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table, bio->bi_opf = opf; bio->bi_flags = 0; bio->bi_ioprio = 0; + bio->bi_write_hint = 0; bio->bi_status = 0; bio->bi_iter.bi_sector = 0; bio->bi_iter.bi_size = 0; @@ -813,6 +814,7 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp) { bio_set_flag(bio, BIO_CLONED); bio->bi_ioprio = bio_src->bi_ioprio; + bio->bi_write_hint = bio_src->bi_write_hint; bio->bi_iter = bio_src->bi_iter; if (bio->bi_bdev) { diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c index e6468eab2681..b1e7415f8439 100644 --- a/block/blk-crypto-fallback.c +++ b/block/blk-crypto-fallback.c @@ -172,6 +172,7 @@ static struct bio *blk_crypto_fallback_clone_bio(struct bio *bio_src) if (bio_flagged(bio_src, BIO_REMAPPED)) bio_set_flag(bio, BIO_REMAPPED); bio->bi_ioprio = bio_src->bi_ioprio; + bio->bi_write_hint = bio_src->bi_write_hint; bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; diff --git a/block/blk-merge.c b/block/blk-merge.c index 65e75efa9bd3..b1854d6bd081 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -817,6 +817,13 @@ static struct request *attempt_merge(struct request_queue *q, if (req->ioprio != next->ioprio) return NULL; + /* + * Don't allow merge of different write hints, or for a hint with + * non-hint IO. + */ + if (req->write_hint != next->write_hint) + return NULL; + /* * If we are allowed to merge, then append bio list * from next to rq and release next. merge_requests_fn @@ -944,6 +951,13 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) if (rq->ioprio != bio_prio(bio)) return false; + /* + * Don't allow merge of different write hints, or for a hint with + * non-hint IO. + */ + if (rq->write_hint != bio->bi_write_hint) + return false; + return true; } diff --git a/block/blk-mq.c b/block/blk-mq.c index ec922c6bccbe..1326d1661f0e 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2563,6 +2563,7 @@ static void blk_mq_bio_to_request(struct request *rq, struct bio *bio, rq->cmd_flags |= REQ_FAILFAST_MASK; rq->__sector = bio->bi_iter.bi_sector; + rq->write_hint = bio->bi_write_hint; blk_rq_bio_prep(rq, bio, nr_segs); /* This can't fail, since GFP_NOIO includes __GFP_DIRECT_RECLAIM. */ @@ -3160,6 +3161,7 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src, } rq->nr_phys_segments = rq_src->nr_phys_segments; rq->ioprio = rq_src->ioprio; + rq->write_hint = rq_src->write_hint; if (rq->bio && blk_crypto_rq_bio_prep(rq, rq->bio, gfp_mask) < 0) goto free_and_out; diff --git a/block/bounce.c b/block/bounce.c index 7cfcb242f9a1..d6a5219f29dd 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -169,6 +169,7 @@ static struct bio *bounce_clone_bio(struct bio *bio_src) if (bio_flagged(bio_src, BIO_REMAPPED)) bio_set_flag(bio, BIO_REMAPPED); bio->bi_ioprio = bio_src->bi_ioprio; + bio->bi_write_hint = bio_src->bi_write_hint; bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; diff --git a/block/fops.c b/block/fops.c index acff3d5d22d4..6923de13665f 100644 --- a/block/fops.c +++ b/block/fops.c @@ -74,6 +74,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, } bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio.bi_ioprio = iocb->ki_ioprio; + bio.bi_write_hint = iocb->ki_hint; ret = bio_iov_iter_get_pages(&bio, iter); if (unlikely(ret)) @@ -206,6 +207,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, bio->bi_private = dio; bio->bi_end_io = blkdev_bio_end_io; bio->bi_ioprio = iocb->ki_ioprio; + bio->bi_write_hint = iocb->ki_hint; ret = bio_iov_iter_get_pages(bio, iter); if (unlikely(ret)) { @@ -323,6 +325,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, bio->bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio->bi_end_io = blkdev_bio_end_io_async; bio->bi_ioprio = iocb->ki_ioprio; + bio->bi_write_hint = iocb->ki_hint; if (iov_iter_is_bvec(iter)) { /* diff --git a/fs/buffer.c b/fs/buffer.c index 2379564e5aea..bf1d94f7a96a 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -55,7 +55,7 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list); static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, - struct writeback_control *wbc); + enum rw_hint hint, struct writeback_control *wbc); #define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_buffers) @@ -1904,7 +1904,8 @@ int __block_write_full_folio(struct inode *inode, struct folio *folio, do { struct buffer_head *next = bh->b_this_page; if (buffer_async_write(bh)) { - submit_bh_wbc(REQ_OP_WRITE | write_flags, bh, wbc); + submit_bh_wbc(REQ_OP_WRITE | write_flags, bh, + inode->i_write_hint, wbc); nr_underway++; } bh = next; @@ -1958,7 +1959,8 @@ int __block_write_full_folio(struct inode *inode, struct folio *folio, struct buffer_head *next = bh->b_this_page; if (buffer_async_write(bh)) { clear_buffer_dirty(bh); - submit_bh_wbc(REQ_OP_WRITE | write_flags, bh, wbc); + submit_bh_wbc(REQ_OP_WRITE | write_flags, bh, + inode->i_write_hint, wbc); nr_underway++; } bh = next; @@ -2770,7 +2772,7 @@ static void end_bio_bh_io_sync(struct bio *bio) } static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, - struct writeback_control *wbc) + enum rw_hint write_hint, struct writeback_control *wbc) { const enum req_op op = opf & REQ_OP_MASK; struct bio *bio; @@ -2797,6 +2799,7 @@ static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO); bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9); + bio->bi_write_hint = write_hint; __bio_add_page(bio, bh->b_page, bh->b_size, bh_offset(bh)); @@ -2816,7 +2819,7 @@ static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, void submit_bh(blk_opf_t opf, struct buffer_head *bh) { - submit_bh_wbc(opf, bh, NULL); + submit_bh_wbc(opf, bh, 0, NULL); } EXPORT_SYMBOL(submit_bh); diff --git a/fs/direct-io.c b/fs/direct-io.c index 7bc494ee56b9..bfa32c6ed3dd 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -404,6 +404,7 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, */ bio = bio_alloc(bdev, nr_vecs, dio->opf, GFP_KERNEL); bio->bi_iter.bi_sector = first_sector; + bio->bi_write_hint = dio->iocb->ki_hint; if (dio->is_async) bio->bi_end_io = dio_bio_end_aio; else diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 916e317ac925..d759a7b8478f 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -478,6 +478,8 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages) } else { bio->bi_end_io = f2fs_write_end_io; bio->bi_private = sbi; + bio->bi_write_hint = + f2fs_io_type_to_rw_hint(sbi, fio->type, fio->temp); } iostat_alloc_and_bind_ctx(sbi, bio, NULL); diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index ae8673ce08b1..a344418a82ad 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1654,6 +1654,7 @@ iomap_alloc_ioend(struct inode *inode, struct iomap_writepage_ctx *wpc, REQ_OP_WRITE | wbc_to_write_flags(wbc), GFP_NOFS, &iomap_ioend_bioset); bio->bi_iter.bi_sector = sector; + bio->bi_write_hint = inode->i_write_hint; wbc_init_bio(wbc, bio); ioend = container_of(bio, struct iomap_ioend, io_inline_bio); @@ -1684,6 +1685,7 @@ iomap_chain_bio(struct bio *prev) new = bio_alloc(prev->bi_bdev, BIO_MAX_VECS, prev->bi_opf, GFP_NOFS); bio_clone_blkg_association(new, prev); new->bi_iter.bi_sector = bio_end_sector(prev); + new->bi_write_hint = prev->bi_write_hint; bio_chain(prev, new); bio_get(prev); /* for iomap_finish_ioend */ diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index bcd3f8cf5ea4..afb704f98a97 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -380,6 +380,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits, GFP_KERNEL); bio->bi_iter.bi_sector = iomap_sector(iomap, pos); + bio->bi_write_hint = dio->iocb->ki_hint; bio->bi_ioprio = dio->iocb->ki_ioprio; bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; diff --git a/fs/mpage.c b/fs/mpage.c index 242e213ee064..5d444d2c39f1 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -612,6 +612,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, GFP_NOFS); bio->bi_iter.bi_sector = blocks[0] << (blkbits - 9); wbc_init_bio(wbc, bio); + bio->bi_write_hint = inode->i_write_hint; } /* diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 958ed7e89b30..d2605fb5ee63 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -137,6 +137,7 @@ struct request { struct blk_crypto_keyslot *crypt_keyslot; #endif + unsigned short write_hint; unsigned short ioprio; enum mq_rq_state state; diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index d5c5e59ddbd2..6d1617f2123b 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -269,6 +269,7 @@ struct bio { */ unsigned short bi_flags; /* BIO_* below */ unsigned short bi_ioprio; + unsigned short bi_write_hint; blk_status_t bi_status; atomic_t __bi_remaining;