Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp951250ybt; Tue, 7 Jul 2020 04:22:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg80WkO8FVS8KFp5VmxT/Wb7wMrbRHAistkHQQ6adBM9i+N5e1NHl7vwYkNE8UVVQw82zh X-Received: by 2002:a05:6402:b79:: with SMTP id cb25mr40051321edb.154.1594120951541; Tue, 07 Jul 2020 04:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594120951; cv=none; d=google.com; s=arc-20160816; b=pPyEDw+x+3YIje/RbpBoEEwO1m/7nfjCNWE8LlrDxSK0u+UZ/fT8cAhwwO+4cqSRPG GT3/dqM53IMQTc84+ZvMIxMQt4h+MGr4EYuqSmwv66R8U+iXGuS9+l25hEkrqONFUGfd QNj3l5L26oEthRn2e5H0kmBVgugORfDT+nYrK9mGACUSuHvdlox9/IiDolzliyfQwXYc xbtSuMEQoOTBiR1dmFcu3/l1i8tF+7lkvaOmPHzVbhPB9UNH5NmyUlqgCzI+NyjrG9LG 7jnnT1SF+H15fZkVHwwBdxv+hT0WDADj9NtHF3kgeLnyvEoueO9InEm1KbGhc2JEa/vN lQrg== 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=n84N7M6ll973nCmT+bT4PV1uyN1mDR1TL1DwqZKaqpI=; b=v1CHXlzCByPHysxKM9f8LjUDS4hKGEzfZM+liorgqIo0xv8euMrkcxb6qXPWbEdywk WkxcvFQCB1eBqPNfkEPrtYxiV4WXo7kkZjGMLsgDhFePIVpo2S43Y5+ZH6zyCTXmwvrY xXR53MNwVp3+n4bPHkLqzXYkE7xxGwjKUYFE/DsD4hW9ir4vztyYwTlR8Dza3d1NnO+s VuZ25sZAo8/speGQgFH+oxFxnXH4/U2nhbXm4G1A4ltkOUsm91RB9y9KxdPrLFD5LmXA 9W2I5SrTXh8oaL7vzmctej77KoKaNyIpusYioQBc4xt3RCx9QJa8epmJGJw5iVVtDeqr 32Yw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 sb27si15107141ejb.538.2020.07.07.04.22.08; Tue, 07 Jul 2020 04:22:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728290AbgGGLV4 (ORCPT + 99 others); Tue, 7 Jul 2020 07:21:56 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7264 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726763AbgGGLVz (ORCPT ); Tue, 7 Jul 2020 07:21:55 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 33509EE35359BBB50C41; Tue, 7 Jul 2020 19:21:53 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Tue, 7 Jul 2020 19:21:44 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH 2/5] f2fs: record average update time of segment Date: Tue, 7 Jul 2020 19:21:25 +0800 Message-ID: <20200707112128.89136-3-yuchao0@huawei.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707112128.89136-1-yuchao0@huawei.com> References: <20200707112128.89136-1-yuchao0@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 Previously, once we update one block in segment, we will update mtime of segment to last time, making aged segment becoming freshest, result in that GC with cost benefit algorithm missing such segment, So this patch changes to record mtime as average block updating time instead of last updating time. It's not needed to reset mtime for prefree segment, as se->valid_blocks is zero, then old se->mtime won't take any weight with below calculation: se->mtime = div_u64(se->mtime * se->valid_blocks + mtime, se->valid_blocks + 1); Signed-off-by: Chao Yu --- fs/f2fs/segment.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 7419aa07cf08..9d10285932f9 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2150,6 +2150,22 @@ static void __set_sit_entry_type(struct f2fs_sb_info *sbi, int type, __mark_sit_entry_dirty(sbi, segno); } +static void update_segment_mtime(struct f2fs_sb_info *sbi, block_t blkaddr) +{ + unsigned int segno = GET_SEGNO(sbi, blkaddr); + struct seg_entry *se = get_seg_entry(sbi, segno); + unsigned long long mtime = get_mtime(sbi, false); + + if (!se->mtime) + se->mtime = mtime; + else + se->mtime = div_u64(se->mtime * se->valid_blocks + mtime, + se->valid_blocks + 1); + + if (mtime > SIT_I(sbi)->max_mtime) + SIT_I(sbi)->max_mtime = mtime; +} + static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) { struct seg_entry *se; @@ -2169,10 +2185,9 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) f2fs_bug_on(sbi, (new_vblocks >> (sizeof(unsigned short) << 3) || (new_vblocks > sbi->blocks_per_seg))); + update_segment_mtime(sbi, blkaddr); + se->valid_blocks = new_vblocks; - se->mtime = get_mtime(sbi, false); - if (se->mtime > SIT_I(sbi)->max_mtime) - SIT_I(sbi)->max_mtime = se->mtime; /* Update valid block bitmap */ if (del > 0) { -- 2.26.2