From patchwork Mon Jan 16 03:08:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: qixiaoyu1 X-Patchwork-Id: 13102509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63E94C46467 for ; Mon, 16 Jan 2023 03:12:09 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pHFup-00013p-2f; Mon, 16 Jan 2023 03:12:06 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pHFun-00013j-H9 for linux-f2fs-devel@lists.sourceforge.net; Mon, 16 Jan 2023 03:12:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=+uvWnxWMZEBIPVCCWshuAk5p9GxmhTM+KlXSt0OWDlo=; b=BTXMqUoYNmMQ3V5M97AiIUXvLF mNrUweDZthlroPBc49bxmlvnKRGVnbtyN7aKgcRq5LUytxeT4qmG3Qww1wFYgsTUA/stjzt3VPpV7 wdFnfhoHi8JrCobmPHGUAGNgiBVh1ncmi7jshkguiTPvYzt8OaWQAmOZKev9s9upP5Yk=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=+uvWnxWMZEBIPVCCWshuAk5p9GxmhTM+KlXSt0OWDlo=; b=arpN7kX+/iz0g2e3tKAWxqEaz+ P2aagjve8RZD/PLtk/49QRaZ4Dm9vw9X5db1duqAiEf8bAo24RS+wnYRDeobiz4Y4O9bz5rPD04P8 Y3u0MMdLhH8pYOgTVse84U2CQ1OGK6acYuBXq0LBkt9NA/UtOhk07FFkgp99O/2QGttM=; Received: from mail-pl1-f178.google.com ([209.85.214.178]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1pHFuh-0006jY-Ll for linux-f2fs-devel@lists.sourceforge.net; Mon, 16 Jan 2023 03:12:04 +0000 Received: by mail-pl1-f178.google.com with SMTP id jl4so28968876plb.8 for ; Sun, 15 Jan 2023 19:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+uvWnxWMZEBIPVCCWshuAk5p9GxmhTM+KlXSt0OWDlo=; b=e9J/PhiX3rq8foVglCMKTK1MRLHL40bGSnRCohcD26yDRznHcBNM1F24x8vJ3tbdtZ pLRH/B+MYdUSzxuh5nLa5vi/NOm4Z+EG4zPSja/UKyhEyrtAP6TPpAQFM/Jz0bUJaWyG 8jPAmPnnzI36C8JpFcNdXhOCWZbZXX03Ff0DsH22t7iJx+G1bNOGeX9ltcPnDYGiCRgD AWNnAoxbGesfPyxEmcDfgdCV0TzFIQ+lNI7UfpffLOV85fp0xzPJpfR6Y2rd7adindM9 Bzgy5/nFaLx4pW5ORpKVN0rUGFRXO7Tp2lGqCLG8U7QVaQcjYSmuNWkHXSyYuCyuX0cL 1ETg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+uvWnxWMZEBIPVCCWshuAk5p9GxmhTM+KlXSt0OWDlo=; b=oRKH+aWQfKW1g2w6lNIXuSu6kg+QG5hP7OCDT5ZeRPLMOLYzq3rFRgeLKmPJ4JLf+c ew9TU6Ynvs5no0WqXHa8ZBjJcxsoWmR9amW46oYpgX7qh1Ryzb8ovM49SjV8qAftTiyQ DCLLFWMjWoMH7ASq+5rEg1JCCv3Zr+Iro0jmHtVOxF/NVsg3LV6ltQ6UIT1Z4k3bAEXT mNKHwIgnMJkiSdwvQfmuxLwGokX+mqdscwxJtzh4htFUSF/iJlJO4Bv30kO4MfnWw9nB fHEUdQfJflZBCXarVaOph7cLO6Eg/MdhJ9cejnMJJTX78t+bOon34JUZCokZWF8z3+2t 9bWA== X-Gm-Message-State: AFqh2ko/PcR15MIi3lGsy/6r/Du06rDLrUlblmRUd/lkFUicyDi1+2G3 yR4/e9n5YXfmJvdNxnd98Q8= X-Google-Smtp-Source: AMrXdXuF2b9j/acNhKWm3eKdgl1Kz9pOPdAae3xJR8x+uVyVFiK8BPcplWdJZN/qW3mTaUcx5sjONw== X-Received: by 2002:a17:903:24a:b0:194:480d:6afc with SMTP id j10-20020a170903024a00b00194480d6afcmr20913024plh.48.1673838714072; Sun, 15 Jan 2023 19:11:54 -0800 (PST) Received: from mi-HP-ProDesk-680-G4-MT.mioffice.cn ([43.224.245.252]) by smtp.gmail.com with ESMTPSA id m3-20020a170902db0300b0018980f14ecfsm15326458plx.115.2023.01.15.19.11.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Jan 2023 19:11:53 -0800 (PST) From: qixiaoyu1 X-Google-Original-From: qixiaoyu1 To: Jaegeuk Kim , Chao Yu Date: Mon, 16 Jan 2023 11:08:49 +0800 Message-Id: <20230116030850.20260-1-qixiaoyu1@xiaomi.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230113125859.15651-1-qixiaoyu1@xiaomi.com> References: <20230113125859.15651-1-qixiaoyu1@xiaomi.com> MIME-Version: 1.0 X-Headers-End: 1pHFuh-0006jY-Ll Subject: [f2fs-dev] [PATCH 1/2 v2] f2fs: fix wrong calculation of block age X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xiongping1@xiaomi.com, qixiaoyu1@xiaomi.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Currently we wrongly calculate the new block age to old * LAST_AGE_WEIGHT / 100. Fix it to new * (100 - LAST_AGE_WEIGHT) / 100 + old * LAST_AGE_WEIGHT / 100. Signed-off-by: qixiaoyu1 Signed-off-by: xiongping1 --- Change log v1 -> v2: - fix udiv fs/f2fs/extent_cache.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index 342af24b2f8c..ad5533f178fd 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -874,11 +874,8 @@ void f2fs_update_read_extent_tree_range_compressed(struct inode *inode, static unsigned long long __calculate_block_age(unsigned long long new, unsigned long long old) { - unsigned long long diff; - - diff = (new >= old) ? new - (new - old) : new + (old - new); - - return div_u64(diff * LAST_AGE_WEIGHT, 100); + return div_u64(new, 100) * (100 - LAST_AGE_WEIGHT) + + div_u64(old, 100) * LAST_AGE_WEIGHT; } /* This returns a new age and allocated blocks in ei */ From patchwork Mon Jan 16 03:08:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: qixiaoyu1 X-Patchwork-Id: 13102510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 87B31C3DA78 for ; Mon, 16 Jan 2023 03:12:12 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pHFuv-0001qV-Ec; Mon, 16 Jan 2023 03:12:12 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pHFuu-0001qO-3j for linux-f2fs-devel@lists.sourceforge.net; Mon, 16 Jan 2023 03:12:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=70wWPTTRf45yo4TsZOfmJlWbWf/vWiaM4qlj+SV+zPg=; b=TvGZnHZymnhVsmlcPP+C6GbK0J zyNrdJREV/RnSwLlOxbVXSsf+jGNcLV26iUpy7QJUDvSk0vorI83ca33ycw6ZJkJUTXUMlW64OR2e BYmlSP68NnAcNIaOJnXq0J0xPSmx7tLfVLFa7Edhz5eRbC3bGU5TFMJ9ZzIevszQ1GZk=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=70wWPTTRf45yo4TsZOfmJlWbWf/vWiaM4qlj+SV+zPg=; b=gO4TqaZz6+2qvN+sT8ouDDGkrO etYfh5klyZq+d+jTDgxSA41ckKhBRAx8EPs/ykxKVxAQ0wqKtJHyznJCTArvatoOOvclre43NYX7i CuPC2C6wyEM7X9tpUYa+wBhU1/qLCsPiAOD/OYyAmiH10dyJq+E7VjgQXy657bPmpkiY=; Received: from mail-pj1-f48.google.com ([209.85.216.48]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1pHFuq-0006jg-JB for linux-f2fs-devel@lists.sourceforge.net; Mon, 16 Jan 2023 03:12:10 +0000 Received: by mail-pj1-f48.google.com with SMTP id bj3so24582133pjb.0 for ; Sun, 15 Jan 2023 19:12:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=70wWPTTRf45yo4TsZOfmJlWbWf/vWiaM4qlj+SV+zPg=; b=jdJ20l8M/RfczWorTmdZeOFh4qbp8AttwUMlGoseZpFA99uR1fLBekTrptX9mXE2Pe dUj2C5MLSdTl043rgpqSZyRqfYpkGBjy07xu1uR2Vo7t0tFgh1nD3O/nu2XMpirVmdp5 TnfEUG/dPp+NMjAOyTBb8y7B5qUeDJcV4SX22jaPX6bf9G+mFM9dtLuyAYnkKMhWvL9B tT/7c0kd5n4fZ+1iqdo3+iN/2H7cZ16orrtA7/Tao4s9FK/UD3n+w7U/9pas5tWu36kM To7nmCu/P8U5UMPeAYZC4573/dQmc8vqlWnlWyQmTCb8AS08cGwGWvXNcVC0adJ+5m8f bNfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=70wWPTTRf45yo4TsZOfmJlWbWf/vWiaM4qlj+SV+zPg=; b=TMVer725QsfdJa7JvhcLv/RydjJEyX0i60zjGuev4eGp7ZbMlAStT78Qfm3RxpsFeu tsylghZl8LP3yTrBBH44I3eceBLLrcs9kHQopBFesF0EuVaqt++yWrPYVsCAGuVbQebh C8ircFFRwSQ2Ux8SoTi3ouZLk+2UPAWezPRCJgDACNp9Sh0z0BQoDOcOhvf4pMdNFIGk uKVq9/e5WjYAT7PJ/GocKkkGgwLg42hf+eivS4jhFaxO8WdfbrpCEynBs1+sGy1vSwlH J8Nyv4gSoUJC7JkUR2MT6XzQ6qsZsaF3t1fo4wJRK+y+Jw2PGpPAigbp08JjQZ2UbEu5 Fdng== X-Gm-Message-State: AFqh2kow2fDWzKIBnkQo9n9r14igfW/R9+h++gbHghvHr/DsW6dUbKmk klc2N5SLmm1FVmkvSSldhYA= X-Google-Smtp-Source: AMrXdXvA54E+I6eaQGmDNC76CiN85SNIgGPjufJgIykCbBHVbvEqcj0PxpI9DLtqU6sOD6x4wddI1Q== X-Received: by 2002:a17:902:9303:b0:194:8bd7:3236 with SMTP id bc3-20020a170902930300b001948bd73236mr4145106plb.45.1673838722991; Sun, 15 Jan 2023 19:12:02 -0800 (PST) Received: from mi-HP-ProDesk-680-G4-MT.mioffice.cn ([43.224.245.252]) by smtp.gmail.com with ESMTPSA id m3-20020a170902db0300b0018980f14ecfsm15326458plx.115.2023.01.15.19.12.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Jan 2023 19:12:02 -0800 (PST) From: qixiaoyu1 X-Google-Original-From: qixiaoyu1 To: Jaegeuk Kim , Chao Yu Date: Mon, 16 Jan 2023 11:08:50 +0800 Message-Id: <20230116030850.20260-2-qixiaoyu1@xiaomi.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230116030850.20260-1-qixiaoyu1@xiaomi.com> References: <20230113125859.15651-1-qixiaoyu1@xiaomi.com> <20230116030850.20260-1-qixiaoyu1@xiaomi.com> MIME-Version: 1.0 X-Headers-End: 1pHFuq-0006jg-JB Subject: [f2fs-dev] [PATCH 2/2 v2] f2fs: add sysfs nodes to set last_age_weight X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xiongping1@xiaomi.com, qixiaoyu1@xiaomi.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Signed-off-by: qixiaoyu1 Signed-off-by: xiongping1 --- Documentation/ABI/testing/sysfs-fs-f2fs | 5 +++++ fs/f2fs/extent_cache.c | 12 +++++++----- fs/f2fs/f2fs.h | 1 + fs/f2fs/sysfs.c | 11 +++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 9e3756625a81..11af7dbb6bc9 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -669,3 +669,8 @@ Contact: "Ping Xiong" Description: When DATA SEPARATION is on, it controls the age threshold to indicate the data blocks as warm. By default it was initialized as 2621440 blocks (equals to 10GB). + +What: /sys/fs/f2fs//last_age_weight +Date: January 2023 +Contact: "Ping Xiong" +Description: When DATA SEPARATION is on, it controls the weight of last data block age. diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index ad5533f178fd..f081f4edae78 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -871,11 +871,12 @@ void f2fs_update_read_extent_tree_range_compressed(struct inode *inode, } #endif -static unsigned long long __calculate_block_age(unsigned long long new, - unsigned long long old) +static unsigned long long __calculate_block_age(struct f2fs_sb_info *sbi, + unsigned long long new, unsigned long long old) { - return div_u64(new, 100) * (100 - LAST_AGE_WEIGHT) - + div_u64(old, 100) * LAST_AGE_WEIGHT; + unsigned int weight = sbi->last_age_weight; + + return div_u64(new, 100) * (100 - weight) + div_u64(old, 100) * weight; } /* This returns a new age and allocated blocks in ei */ @@ -907,7 +908,7 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei, cur_age = ULLONG_MAX - tei.last_blocks + cur_blocks; if (tei.age) - ei->age = __calculate_block_age(cur_age, tei.age); + ei->age = __calculate_block_age(sbi, cur_age, tei.age); else ei->age = cur_age; ei->last_blocks = cur_blocks; @@ -1223,6 +1224,7 @@ void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi) atomic64_set(&sbi->allocated_data_blocks, 0); sbi->hot_data_age_threshold = DEF_HOT_DATA_AGE_THRESHOLD; sbi->warm_data_age_threshold = DEF_WARM_DATA_AGE_THRESHOLD; + sbi->last_age_weight = LAST_AGE_WEIGHT; } int __init f2fs_create_extent_cache(void) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index e8953c3dc81a..c3609cbc28c7 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1679,6 +1679,7 @@ struct f2fs_sb_info { /* The threshold used for hot and warm data seperation*/ unsigned int hot_data_age_threshold; unsigned int warm_data_age_threshold; + unsigned int last_age_weight; /* basic filesystem units */ unsigned int log_sectors_per_block; /* log2 sectors per block */ diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 83a366f3ee80..a70cf674d8e7 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -686,6 +686,15 @@ static ssize_t __sbi_store(struct f2fs_attr *a, return count; } + if (!strcmp(a->attr.name, "last_age_weight")) { + if (t <= 0 || t >= 100) + return -EINVAL; + if (t == *ui) + return count; + *ui = (unsigned int)t; + return count; + } + *ui = (unsigned int)t; return count; @@ -944,6 +953,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block) /* For block age extent cache */ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold); +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, last_age_weight, last_age_weight); #define ATTR_LIST(name) (&f2fs_attr_##name.attr) static struct attribute *f2fs_attrs[] = { @@ -1042,6 +1052,7 @@ static struct attribute *f2fs_attrs[] = { ATTR_LIST(revoked_atomic_block), ATTR_LIST(hot_data_age_threshold), ATTR_LIST(warm_data_age_threshold), + ATTR_LIST(last_age_weight), NULL, }; ATTRIBUTE_GROUPS(f2fs);