Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp1691242ybs; Tue, 26 May 2020 00:56:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynDOj7h9GPfApRYoK/tVojr4bCx7u7mXmWSL5EKSNKNMFWytoMh1vHsAFAP6mnZiouD6Ec X-Received: by 2002:a17:906:44f:: with SMTP id e15mr40916eja.161.1590479810228; Tue, 26 May 2020 00:56:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590479810; cv=none; d=google.com; s=arc-20160816; b=wyyedTe8kMd7IZJZ7NoDKF6dAQAvNwMIEfbbqSjPZKwCyk/ok59VzTropvMBlmh28L I5ME3K/vqMBKd76izEna9EYhE/i+OrN/eKIKBKWn4zDQAqFlz4enIWvgdK34ZXXeRs6K PQ38qK5K2XlvdRYdVUgRwft0WbRM06S5kt+Xu9pu+/+/ouHpjJIimIjjN+XHPV8lmnyb TUEV6Mu9oBQRUebUsGxTTHgPTxtkVAla6wvGo77Db2bCMb7wBhmkY6WUfHb1YhxzGD1u 3BaqmDU/7jBzQXrt9HHjnFBtuj9lBy+AwL5srsWTmzoq/iChXLFuRncTt0bnn8yKZa2q T3TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+tTf0gSkeWSPC8VZlPSkgWiHsPKfGwCtyha/qEq4s7s=; b=OHrZYfCU8A70jwVWC/+MidQcHwe4cSm9xmlaiPSj58RrDsl/IzpGEadxtehJCIQ/TH mh0/Ns2HKYpvt6GkfVvmlJBXIrEmfVC9DUFV5p+GijbDuxJxbeXTEfVZz3/6uIfmZ7ZK HHCcPpzj7IZG1i4QE6bbHrXyUAvczddde+54ppvutGixxYLq7x9Zy9RUlLss/SmWcxE3 YdkYU9tqT835Pb+KSlnlfcwjnUXjDjE1M5sFfxlFLMs8mqnu8WvUI3WVUY94c9Nh8cm2 tXYUkDz/pxopW6cXPqY/8VHXwxBctiq99DIbS+0M0bzj2jncHiZIHXrSkzKpnHkBcSlB A1WQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d31si11832437edd.95.2020.05.26.00.56.27; Tue, 26 May 2020 00:56:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730430AbgEZHTY (ORCPT + 99 others); Tue, 26 May 2020 03:19:24 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5334 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730426AbgEZHTV (ORCPT ); Tue, 26 May 2020 03:19:21 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 087809FD67E4CC8E91E9; Tue, 26 May 2020 15:19:20 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Tue, 26 May 2020 15:19:10 +0800 From: "zhangyi (F)" To: CC: , , , , Subject: [PATCH 08/10] ext4: replace sb_breadahead() with ext4_sb_breadahead() Date: Tue, 26 May 2020 15:17:52 +0800 Message-ID: <20200526071754.33819-9-yi.zhang@huawei.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200526071754.33819-1-yi.zhang@huawei.com> References: <20200526071754.33819-1-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org For the cases of read ahead blocks, we also need to check the write io error flag to prevent reading block from disk if it is actually uptodate. Add a new wrapper ext4_sb_breadahead() to check the uptodate flag and prevent unnecessary read operation, and replace all sb_breadahead(). Signed-off-by: zhangyi (F) --- fs/ext4/ext4.h | 11 +++++------ fs/ext4/inode.c | 2 +- fs/ext4/super.c | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 81c1bdfb9397..cafa2617a093 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2767,6 +2767,8 @@ extern struct buffer_head *__ext4_sb_getblk(struct super_block *sb, extern struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb, sector_t block, int op_flags, gfp_t gfp); +extern void ext4_sb_breadahead_unmovable(struct super_block *sb, + sector_t block); extern int ext4_seq_options_show(struct seq_file *seq, void *offset); extern int ext4_calculate_overhead(struct super_block *sb); extern void ext4_superblock_csum_set(struct super_block *sb); @@ -3533,13 +3535,10 @@ static inline int ext4_buffer_uptodate(struct buffer_head *bh) { /* * If the buffer has the write error flag, we have failed - * to write out data in the block. In this case, we don't - * have to read the block because we may read the old data - * successfully. + * to write out this metadata block. In this case, the data + * in this block is uptodate. */ - if (!buffer_uptodate(bh) && buffer_write_io_error(bh)) - set_buffer_uptodate(bh); - return buffer_uptodate(bh); + return buffer_uptodate(bh) || buffer_write_io_error(bh); } #endif /* __KERNEL__ */ diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 4989a9633fc7..7354edb444c5 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4351,7 +4351,7 @@ static int __ext4_get_inode_loc(struct inode *inode, if (end > table) end = table; while (b <= end) - sb_breadahead_unmovable(sb, b++); + ext4_sb_breadahead_unmovable(sb, b++); } /* diff --git a/fs/ext4/super.c b/fs/ext4/super.c index b9aab334a5d0..d25a0fe44bec 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -218,6 +218,23 @@ __ext4_sb_bread_gfp(struct super_block *sb, sector_t block, return ERR_PTR(-EIO); } +/* + * This works like sb_breadahead_unmovable() except it use + * ext4_buffer_uptodate() instead of buffer_uptodate() to check the + * metadata buffer is actually uptodate or not. The buffer should be + * considered as actually uptodate for the case of it has been + * failed to write out. + */ +void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block) +{ + struct buffer_head *bh = ext4_sb_getblk_gfp(sb, block, 0); + + if (likely(bh) && !ext4_buffer_uptodate(bh)) { + ll_rw_block(REQ_OP_READ, REQ_META | REQ_RAHEAD, 1, &bh); + brelse(bh); + } +} + static int ext4_verify_csum_type(struct super_block *sb, struct ext4_super_block *es) { @@ -4395,7 +4412,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) /* Pre-read the descriptors into the buffer cache */ for (i = 0; i < db_count; i++) { block = descriptor_loc(sb, logical_sb_block, i); - sb_breadahead_unmovable(sb, block); + ext4_sb_breadahead_unmovable(sb, block); } for (i = 0; i < db_count; i++) { -- 2.21.3