Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp622859ybi; Fri, 12 Jul 2019 01:57:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFjPyBwBu1m8hhm56HcEcpvQbfTO1oRML3SELnzv2KtOn+tyd63n31hf1fxUExQNSv2JtM X-Received: by 2002:a17:902:8546:: with SMTP id d6mr9850733plo.207.1562921860920; Fri, 12 Jul 2019 01:57:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562921860; cv=none; d=google.com; s=arc-20160816; b=qSz0IwzYGoudTyO6SWh/D49hdUsriATZo+Np0D8e13BGd+hSn1XARlqfTNFYcd3pdj FLz3gPXB/rZzVZeswlMDVLAytw79DqKFUGAsdHczPd2JnfA+vk0mBYCAFtue9aJmkEnE JqMtB9ccTTPKcuwADMpSefgxH3kPEsol1oTUX/eHHg1AQRYdBcSIf1Be3X7dWM2bJRNE Od+9iBicwdgm+3BCaB/qLKtMlGvOtAI9KIas1h1GQPCasnQ8CLYYFxjFOmurYalEn2/F k+p9VF0X5u5qd2hFftX4dEe31/deXb0v88Bpix/j4OXd+F2LW0QCdmPfY8fX2ZeLt7im LmTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=oI4rZvs8OPcAARFXVGndiehAGENyCZgz/MF60HenOgo=; b=jVqTkenkMe6iqKAWxNyy1xQ6rtR6vMnVtSpG7deLuDsfaBnbyv+xbZSNPTYoFMlEi9 w0tSCGG0Id8DWWBSWTpgbC7S4a/924iIca9DdOJt209kcO2Qv1RGF4gjq8yiZ7AD8kZS +BRj9bS9lWLMGA8Wp5/rPPn+9LAls9kbEFg2KIKRMqfm9b4Cea6ucIiKEEbCGPGWHOyn /bR4chU+am5CBJrA4QGv1RK/SWQ+4XyWAbzSWmOolPyYkqCMD9ZdHbPof/bFTPnpEoY/ Ggr14h774urbvYuBMdLKf5CP+H4mSQw8ABOypMi5T9v8G0C5z8JA6ioe6LHVB5V2xqx2 TXOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m12si7827131pfa.81.2019.07.12.01.57.25; Fri, 12 Jul 2019 01:57:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726165AbfGLI4L (ORCPT + 99 others); Fri, 12 Jul 2019 04:56:11 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2266 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726118AbfGLI4L (ORCPT ); Fri, 12 Jul 2019 04:56:11 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 2A8D9F139BDF4E021E17; Fri, 12 Jul 2019 16:56:09 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.439.0; Fri, 12 Jul 2019 16:56:00 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH 1/2] f2fs: introduce {page,io}_is_mergeable() for readability Date: Fri, 12 Jul 2019 16:55:41 +0800 Message-ID: <20190712085542.4068-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wrap merge condition into function for readability, no logic change. Signed-off-by: Chao Yu --- v2: remove bio validation check in page_is_mergeable(). fs/f2fs/data.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 6a8db4abdf5f..f1e401f9fc13 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -482,6 +482,33 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) return 0; } +static bool page_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio, + block_t last_blkaddr, block_t cur_blkaddr) +{ + if (last_blkaddr != cur_blkaddr) + return false; + return __same_bdev(sbi, cur_blkaddr, bio); +} + +static bool io_type_is_mergeable(struct f2fs_bio_info *io, + struct f2fs_io_info *fio) +{ + if (io->fio.op != fio->op) + return false; + return io->fio.op_flags == fio->op_flags; +} + +static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio, + struct f2fs_bio_info *io, + struct f2fs_io_info *fio, + block_t last_blkaddr, + block_t cur_blkaddr) +{ + if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr)) + return false; + return io_type_is_mergeable(io, fio); +} + int f2fs_merge_page_bio(struct f2fs_io_info *fio) { struct bio *bio = *fio->bio; @@ -495,8 +522,8 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) trace_f2fs_submit_page_bio(page, fio); f2fs_trace_ios(fio, 0); - if (bio && (*fio->last_block + 1 != fio->new_blkaddr || - !__same_bdev(fio->sbi, fio->new_blkaddr, bio))) { + if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block, + fio->new_blkaddr)) { __submit_bio(fio->sbi, bio, fio->type); bio = NULL; } @@ -569,9 +596,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) inc_page_count(sbi, WB_DATA_TYPE(bio_page)); - if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 || - (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) || - !__same_bdev(sbi, fio->new_blkaddr, io->bio))) + if (io->bio && !io_is_mergeable(sbi, io->bio, io, fio, + io->last_block_in_bio, fio->new_blkaddr)) __submit_merged_bio(io); alloc_new: if (io->bio == NULL) { @@ -1643,8 +1669,8 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, * This page will go to BIO. Do we need to send this * BIO off first? */ - if (bio && (*last_block_in_bio != block_nr - 1 || - !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) { + if (bio && !page_is_mergeable(F2FS_I_SB(inode), bio, + *last_block_in_bio, block_nr - 1)) { submit_and_realloc: __submit_bio(F2FS_I_SB(inode), bio, DATA); bio = NULL; -- 2.18.0.rc1