Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1714847ybi; Wed, 17 Jul 2019 20:38:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1aMwBaaHbIhuDozko9z4dZKfylqWgmp6l9hVFXIs8XLoPUWCYksXOmCP9DAWAph5/zKQT X-Received: by 2002:a63:b20f:: with SMTP id x15mr46624371pge.453.1563421096429; Wed, 17 Jul 2019 20:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563421096; cv=none; d=google.com; s=arc-20160816; b=vHYfEqnL3hHsGBwJkFUyCU3hpUd+x5iXddPUzRqAF38yeePgUwlU857MM58QAggxis 62+P2B4gNGqq/a8BFLRYLLsUpCPV68pSBxErxYgIsuZGxWsNH8GaqGntUjeHNyhTcALU R3LBN+QhWecwMlthMFyBmvyF8Lx0rqCoU0Q/jZLp5HMwqP82V4o2OCDMbY8s81psM/54 2M7FtJbMBEdRlQ5d1CVUI9t4XFgDs0eD5vcepsuTq+jHJ2Zls+xpM7qwucoGJMIl00VK X23FFzQmgoZ6kbBSSyrZfWVRalRC4pvjD3ny1tl1KyCXwmUNOAbPzMfat+0Fym/dyJB5 qI3w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:to:from:subject; bh=azqD8jToE21x8nZvA+edyL1CZmc7hyWs7tES9sxg67w=; b=HV8dkEf75fUPrBvuaJDwOFgvaRJqFwiVwcKAByXOxdXzMI45/FzkaowWx9OQucsZiU P6QOCA3Zr5tN7nLRdYZ7GtImY2iG450OjW/SAie8BSQa5lIf4I/1w1IzzoetTeNShC/V q4nNyex8g5AxN5xgfuk0ui8lXOD/Oza3PRQoAS1Af0/1zMk45DVaXMDtJU6KxhIehthG bmwE7Ii8BfPe1GG121kyKa3vZ3JrjWYJJ8P8RQ9jZLPO3MofWOGOEdzMGAEKUJTUMZL6 1Qw5Hq9FBatsC7VDb0PmI639vayygnEbOTvyOmP8V+j/DQKXbfKxPe5001w1Cd7p8Dg+ zTnw== 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 f26si1052900pga.117.2019.07.17.20.37.58; Wed, 17 Jul 2019 20:38:16 -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 S2389214AbfGRDfl (ORCPT + 99 others); Wed, 17 Jul 2019 23:35:41 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2281 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732771AbfGRDfk (ORCPT ); Wed, 17 Jul 2019 23:35:40 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 074D541368B53B7E6E6E; Thu, 18 Jul 2019 11:35:39 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 18 Jul 2019 11:35:36 +0800 Subject: Re: [f2fs-dev] [PATCH v2] f2fs: fix to read source block before invalidating it From: Chao Yu To: Jaegeuk Kim , , References: <20190718013718.70335-1-jaegeuk@kernel.org> <20190718031214.GA78336@jaegeuk-macbookpro.roam.corp.google.com> <19a25101-da74-de98-6ca4-a9fd9fa09ef2@huawei.com> Message-ID: Date: Thu, 18 Jul 2019 11:35:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <19a25101-da74-de98-6ca4-a9fd9fa09ef2@huawei.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/7/18 11:30, Chao Yu wrote: > On 2019/7/18 11:12, Jaegeuk Kim wrote: >> f2fs_allocate_data_block() invalidates old block address and enable new block >> address. Then, if we try to read old block by f2fs_submit_page_bio(), it will >> give WARN due to reading invalid blocks. >> >> Let's make the order sanely back. > > Hmm.. to avoid WARM, we may suffer one more memcpy, I suspect this can reduce > online resize or foreground gc ioctl performance... > > Can we just relief to use DATA_GENERIC_ENHANCE_READ for this case...? It's rare case, we can ignore this. :) Thanks, > >> >> Signed-off-by: Jaegeuk Kim > > Except performance, I'm okay with this change. > > Reviewed-by: Chao Yu > > Thanks, > >> --- >> v2: >> I was fixing the comments. :) >> >> fs/f2fs/gc.c | 70 +++++++++++++++++++++++++--------------------------- >> 1 file changed, 34 insertions(+), 36 deletions(-) >> >> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c >> index 6691f526fa40..8974672db78f 100644 >> --- a/fs/f2fs/gc.c >> +++ b/fs/f2fs/gc.c >> @@ -796,6 +796,29 @@ static int move_data_block(struct inode *inode, block_t bidx, >> if (lfs_mode) >> down_write(&fio.sbi->io_order_lock); >> >> + mpage = f2fs_grab_cache_page(META_MAPPING(fio.sbi), >> + fio.old_blkaddr, false); >> + if (!mpage) >> + goto up_out; >> + >> + fio.encrypted_page = mpage; >> + >> + /* read source block in mpage */ >> + if (!PageUptodate(mpage)) { >> + err = f2fs_submit_page_bio(&fio); >> + if (err) { >> + f2fs_put_page(mpage, 1); >> + goto up_out; >> + } >> + lock_page(mpage); >> + if (unlikely(mpage->mapping != META_MAPPING(fio.sbi) || >> + !PageUptodate(mpage))) { >> + err = -EIO; >> + f2fs_put_page(mpage, 1); >> + goto up_out; >> + } >> + } >> + >> f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr, >> &sum, CURSEG_COLD_DATA, NULL, false); >> >> @@ -803,44 +826,18 @@ static int move_data_block(struct inode *inode, block_t bidx, >> newaddr, FGP_LOCK | FGP_CREAT, GFP_NOFS); >> if (!fio.encrypted_page) { >> err = -ENOMEM; >> - goto recover_block; >> - } >> - >> - mpage = f2fs_pagecache_get_page(META_MAPPING(fio.sbi), >> - fio.old_blkaddr, FGP_LOCK, GFP_NOFS); >> - if (mpage) { >> - bool updated = false; >> - >> - if (PageUptodate(mpage)) { >> - memcpy(page_address(fio.encrypted_page), >> - page_address(mpage), PAGE_SIZE); >> - updated = true; >> - } >> f2fs_put_page(mpage, 1); >> - invalidate_mapping_pages(META_MAPPING(fio.sbi), >> - fio.old_blkaddr, fio.old_blkaddr); >> - if (updated) >> - goto write_page; >> - } >> - >> - err = f2fs_submit_page_bio(&fio); >> - if (err) >> - goto put_page_out; >> - >> - /* write page */ >> - lock_page(fio.encrypted_page); >> - >> - if (unlikely(fio.encrypted_page->mapping != META_MAPPING(fio.sbi))) { >> - err = -EIO; >> - goto put_page_out; >> - } >> - if (unlikely(!PageUptodate(fio.encrypted_page))) { >> - err = -EIO; >> - goto put_page_out; >> + goto recover_block; >> } >> >> -write_page: >> + /* write target block */ >> f2fs_wait_on_page_writeback(fio.encrypted_page, DATA, true, true); >> + memcpy(page_address(fio.encrypted_page), >> + page_address(mpage), PAGE_SIZE); >> + f2fs_put_page(mpage, 1); >> + invalidate_mapping_pages(META_MAPPING(fio.sbi), >> + fio.old_blkaddr, fio.old_blkaddr); >> + >> set_page_dirty(fio.encrypted_page); >> if (clear_page_dirty_for_io(fio.encrypted_page)) >> dec_page_count(fio.sbi, F2FS_DIRTY_META); >> @@ -871,11 +868,12 @@ static int move_data_block(struct inode *inode, block_t bidx, >> put_page_out: >> f2fs_put_page(fio.encrypted_page, 1); >> recover_block: >> - if (lfs_mode) >> - up_write(&fio.sbi->io_order_lock); >> if (err) >> f2fs_do_replace_block(fio.sbi, &sum, newaddr, fio.old_blkaddr, >> true, true); >> +up_out: >> + if (lfs_mode) >> + up_write(&fio.sbi->io_order_lock); >> put_out: >> f2fs_put_dnode(&dn); >> out: >> > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > . >