Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3448319ybt; Tue, 30 Jun 2020 03:05:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMk7/1NM4CwsaeQfvh3pV7YkT2aiH0pC1+ZWGrJi1NXbIJeV4sbhgtkODUWe787FXt1jLk X-Received: by 2002:a17:906:970a:: with SMTP id k10mr18312104ejx.236.1593511524205; Tue, 30 Jun 2020 03:05:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593511524; cv=none; d=google.com; s=arc-20160816; b=B887HOZ/AONuU9LSKTP9fRwXRy4zgdk2tscT+fgJ+mlG20V5zGCf2QY2uPqTFcwNHq x7EXPlCEsxf7hDG8Q8hhj2k3W/PvhyQxr3+JkxfYIK7D2/7dZSHILym/xgx/hPMgBs5u EZebpF+EEdxJAn5V54U/907ZBXCcgj9HPM3ku4S/VA8UMYUI1D9syoJYFYJNoJDz6BIc e48e/da2K/duoddVkPpZiW0Jk7fcDnkYGmCV6nHINL6pLwcsV71wKNhDDSe1JaWXLrDh +hbP6YZ708MElSd7wpqtUphQAmSwLusq9U7BMR9OLmyPaMJy+zop6AAMfCqNr+TEO5gI Gssg== 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=0jj43jltZh+E/8+dQWUKsKZAkqr3NdcTw+nDI2pq3bg=; b=qtRo+e5AwzCuG9qi96JLOLMxXfjhONu7j6NYAlYqAHZ4HV1ZgaAxB1Q4gAbrFXkLR9 cUkYc4TdgvS6W8GgM/APMT8fsNVJt4+GFa/JoFYRe93R8VVw1E4wr8PKVz/68giPeKuv PzyH390beHaUneh6Ey95TBlB31DoNNhXgrDTj3d/Y4Zszdgv7PD7lx8j6Hc2amJhN2fZ dmhhkk173h0JspIwhVSZS5plN0DcDYacEpomU1dmRTem4Z2YA7DhUmaJ2PHnICzA4+Ax gLvTE0MRhRAWmtzVKh7EYcha2PzjGuC3QXlzvC8TjidOw8OEB8/ZwsYUnOHgBb4K/hRu 1blw== 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 dn21si1404982edb.48.2020.06.30.03.05.00; Tue, 30 Jun 2020 03:05:24 -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 S1732117AbgF3KEq (ORCPT + 99 others); Tue, 30 Jun 2020 06:04:46 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:54192 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730237AbgF3KEp (ORCPT ); Tue, 30 Jun 2020 06:04:45 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 3BA0BC1F9C3760ACAEC7; Tue, 30 Jun 2020 18:04:42 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Tue, 30 Jun 2020 18:04:35 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH RFC 2/5] f2fs: record average update time of segment Date: Tue, 30 Jun 2020 18:04:25 +0800 Message-ID: <20200630100428.19105-2-yuchao0@huawei.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200630100428.19105-1-yuchao0@huawei.com> References: <20200630100428.19105-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 = (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 863ec6f1fb87..906c313835ad 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 = (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