From mboxrd@z Thu Jan 1 00:00:00 1970 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 6F3B5C6FD18 for ; Tue, 18 Apr 2023 23:36:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231223AbjDRXg4 (ORCPT ); Tue, 18 Apr 2023 19:36:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbjDRXf3 (ORCPT ); Tue, 18 Apr 2023 19:35:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E213BA5C6 for ; Tue, 18 Apr 2023 16:34:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7943B63A0D for ; Tue, 18 Apr 2023 23:34:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D026BC433EF; Tue, 18 Apr 2023 23:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1681860895; bh=OaGcxLw0jadckZspuXl9dxo9JQZpw2HGKbkHbt1Sef4=; h=Date:To:From:Subject:From; b=rQX9RPWN1ofA19YTx8tFE+l3OwvgIU65CHRBl8ZI+p8K9LC7APFo8eUCq6KL67OBk XHWlLoH2nW7uwqu2UUPphYtWUwh5KmX42fanuYD7ux12xxAUqXESshAOYqYzsN95eC 2tLJKOY1MRJcC+Oud/42q15jFJBlPMMInF300tM4= Date: Tue, 18 Apr 2023 16:34:55 -0700 To: mm-commits@vger.kernel.org, senozhatsky@chromium.org, minchan@kernel.org, axboe@kernel.dk, hch@lst.de, akpm@linux-foundation.org From: Andrew Morton Subject: [merged mm-stable] zram-fix-synchronous-reads.patch removed from -mm tree Message-Id: <20230418233455.D026BC433EF@smtp.kernel.org> Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The quilt patch titled Subject: zram: fix synchronous reads has been removed from the -mm tree. Its filename was zram-fix-synchronous-reads.patch This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm ------------------------------------------------------ From: Christoph Hellwig Subject: zram: fix synchronous reads Date: Tue, 11 Apr 2023 19:14:58 +0200 Currently nothing waits for the synchronous reads before accessing the data. Switch them to an on-stack bio and submit_bio_wait to make sure the I/O has actually completed when the work item has been flushed. This also removes the call to page_endio that would unlock a page that has never been locked. Drop the partial_io/sync flag, as chaining only makes sense for the asynchronous reads of the entire page. Link: https://lkml.kernel.org/r/20230411171459.567614-17-hch@lst.de Signed-off-by: Christoph Hellwig Reviewed-by: Sergey Senozhatsky Acked-by: Minchan Kim Cc: Jens Axboe Signed-off-by: Andrew Morton --- drivers/block/zram/zram_drv.c | 60 +++++++++++--------------------- 1 file changed, 22 insertions(+), 38 deletions(-) --- a/drivers/block/zram/zram_drv.c~zram-fix-synchronous-reads +++ a/drivers/block/zram/zram_drv.c @@ -55,7 +55,7 @@ static const struct block_device_operati static void zram_free_page(struct zram *zram, size_t index); static int zram_read_page(struct zram *zram, struct page *page, u32 index, - struct bio *bio, bool partial_io); + struct bio *parent); static int zram_slot_trylock(struct zram *zram, u32 index) { @@ -576,31 +576,15 @@ static void free_block_bdev(struct zram atomic64_dec(&zram->stats.bd_count); } -static void zram_page_end_io(struct bio *bio) -{ - struct page *page = bio_first_page_all(bio); - - page_endio(page, op_is_write(bio_op(bio)), - blk_status_to_errno(bio->bi_status)); - bio_put(bio); -} - static void read_from_bdev_async(struct zram *zram, struct page *page, unsigned long entry, struct bio *parent) { struct bio *bio; - bio = bio_alloc(zram->bdev, 1, parent ? parent->bi_opf : REQ_OP_READ, - GFP_NOIO); - + bio = bio_alloc(zram->bdev, 1, parent->bi_opf, GFP_NOIO); bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9); __bio_add_page(bio, page, PAGE_SIZE, 0); - - if (!parent) - bio->bi_end_io = zram_page_end_io; - else - bio_chain(bio, parent); - + bio_chain(bio, parent); submit_bio(bio); } @@ -705,7 +689,7 @@ static ssize_t writeback_store(struct de /* Need for hugepage writeback racing */ zram_set_flag(zram, index, ZRAM_IDLE); zram_slot_unlock(zram, index); - if (zram_read_page(zram, page, index, NULL, false)) { + if (zram_read_page(zram, page, index, NULL)) { zram_slot_lock(zram, index); zram_clear_flag(zram, index, ZRAM_UNDER_WB); zram_clear_flag(zram, index, ZRAM_IDLE); @@ -785,18 +769,19 @@ struct zram_work { struct work_struct work; struct zram *zram; unsigned long entry; - struct bio *bio; struct page *page; }; static void zram_sync_read(struct work_struct *work) { struct zram_work *zw = container_of(work, struct zram_work, work); - struct zram *zram = zw->zram; - unsigned long entry = zw->entry; - struct bio *bio = zw->bio; + struct bio_vec bv; + struct bio bio; - read_from_bdev_async(zram, zw->page, entry, bio); + bio_init(&bio, zw->zram->bdev, &bv, 1, REQ_OP_READ); + bio.bi_iter.bi_sector = zw->entry * (PAGE_SIZE >> 9); + __bio_add_page(&bio, zw->page, PAGE_SIZE, 0); + submit_bio_wait(&bio); } /* @@ -805,14 +790,13 @@ static void zram_sync_read(struct work_s * use a worker thread context. */ static int read_from_bdev_sync(struct zram *zram, struct page *page, - unsigned long entry, struct bio *bio) + unsigned long entry) { struct zram_work work; work.page = page; work.zram = zram; work.entry = entry; - work.bio = bio; INIT_WORK_ONSTACK(&work.work, zram_sync_read); queue_work(system_unbound_wq, &work.work); @@ -823,13 +807,13 @@ static int read_from_bdev_sync(struct zr } static int read_from_bdev(struct zram *zram, struct page *page, - unsigned long entry, struct bio *parent, bool sync) + unsigned long entry, struct bio *parent) { atomic64_inc(&zram->stats.bd_reads); - if (sync) { + if (!parent) { if (WARN_ON_ONCE(!IS_ENABLED(ZRAM_PARTIAL_IO))) return -EIO; - return read_from_bdev_sync(zram, page, entry, parent); + return read_from_bdev_sync(zram, page, entry); } read_from_bdev_async(zram, page, entry, parent); return 1; @@ -837,7 +821,7 @@ static int read_from_bdev(struct zram *z #else static inline void reset_bdev(struct zram *zram) {}; static int read_from_bdev(struct zram *zram, struct page *page, - unsigned long entry, struct bio *parent, bool sync) + unsigned long entry, struct bio *parent) { return -EIO; } @@ -1370,7 +1354,7 @@ static int zram_read_from_zspool(struct } static int zram_read_page(struct zram *zram, struct page *page, u32 index, - struct bio *bio, bool partial_io) + struct bio *parent) { int ret; @@ -1387,7 +1371,7 @@ static int zram_read_page(struct zram *z zram_slot_unlock(zram, index); ret = read_from_bdev(zram, page, zram_get_element(zram, index), - bio, partial_io); + parent); } /* Should NEVER happen. Return bio error if it does. */ @@ -1402,14 +1386,14 @@ static int zram_read_page(struct zram *z * always expects a full page for the output. */ static int zram_bvec_read_partial(struct zram *zram, struct bio_vec *bvec, - u32 index, int offset, struct bio *bio) + u32 index, int offset) { struct page *page = alloc_page(GFP_NOIO); int ret; if (!page) return -ENOMEM; - ret = zram_read_page(zram, page, index, bio, true); + ret = zram_read_page(zram, page, index, NULL); if (likely(!ret)) memcpy_to_bvec(bvec, page_address(page) + offset); __free_page(page); @@ -1420,8 +1404,8 @@ static int zram_bvec_read(struct zram *z u32 index, int offset, struct bio *bio) { if (is_partial_io(bvec)) - return zram_bvec_read_partial(zram, bvec, index, offset, bio); - return zram_read_page(zram, bvec->bv_page, index, bio, false); + return zram_bvec_read_partial(zram, bvec, index, offset); + return zram_read_page(zram, bvec->bv_page, index, bio); } static int zram_write_page(struct zram *zram, struct page *page, u32 index) @@ -1561,7 +1545,7 @@ static int zram_bvec_write_partial(struc if (!page) return -ENOMEM; - ret = zram_read_page(zram, page, index, bio, true); + ret = zram_read_page(zram, page, index, bio); if (!ret) { memcpy_from_bvec(page_address(page) + offset, bvec); ret = zram_write_page(zram, page, index); _ Patches currently in -mm which might be from hch@lst.de are zram-return-errors-from-read_from_bdev_sync.patch