From patchwork Thu Feb 2 08:20:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: qixiaoyu1 X-Patchwork-Id: 13125497 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 DBC73C05027 for ; Thu, 2 Feb 2023 08:20:54 +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 1pNUpw-0005e2-OA; Thu, 02 Feb 2023 08:20:52 +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 1pNUpv-0005dw-JQ for linux-f2fs-devel@lists.sourceforge.net; Thu, 02 Feb 2023 08:20:50 +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=DIcuUiiD/SBGnIgaWh9h7tdpch/KAXjOE7i0nNR5sBg=; b=L0by/zxL5NEGaeiAeGr5uoHMkZ zs4N/UjWKAsea6FoxvNmAvkgXYVOnT+zIEHGCAtnE3m5xqFn/ueUzCYATcbBujGLkUmN22+UotGet zimcfvXVPPuNe/ANrGdEDUyazfDLqbM5zTVfe19r5Nx+vopk30yb1QLzarhew5HpbmYM=; 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=DIcuUiiD/SBGnIgaWh9h7tdpch/KAXjOE7i0nNR5sBg=; b=UJhAS2RT1D492+TXpDWykRRqdI SaV5+FVGFq2GAwFNRjowUz3fncWaNKIsNtLf8u9tmXVgw7i9KBzoBCk6J606Mjap/Kr5IhESsTAo0 OtHgAqr+NFbyUXWAyIrjgzuF26tjJq/eqIsWhYcTglM0Q0A8P70z7KUGIQiJ1usM1bBo=; Received: from mail-pj1-f54.google.com ([209.85.216.54]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1pNUpt-0002TD-HK for linux-f2fs-devel@lists.sourceforge.net; Thu, 02 Feb 2023 08:20:50 +0000 Received: by mail-pj1-f54.google.com with SMTP id j5so1185930pjn.5 for ; Thu, 02 Feb 2023 00:20:50 -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=DIcuUiiD/SBGnIgaWh9h7tdpch/KAXjOE7i0nNR5sBg=; b=bavLq+RrC+kxjPPcdrbN+TxKPZ/oy996YNrl+gPTSl6aIelDmWWiK0ZbnTy9P5lVRf TR9VXV1ywAjmK5xeA6iau58arLHAdcP/4ubbpDPnj8RyIUEsCWVaGT9dF1Papgp6rQig ZeMLiWJNzKwOL2QfJPiwee0zLKmjomIIWm8QlU6mdQcWS/MA4DO9br58WxkoNrNg1h9v yyw18cifRidBJ8uDKXnCvwdHfMtjyVHjVoFRy0JQKAZ1e14Kuij2wSlLyaxflNute/mb I4ughYaQEffqcPOATrx6wWXX1roQB9e51llMaB/nIMKZsTc/TVRekFbWDp9hlP3j06e1 Wpmw== 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=DIcuUiiD/SBGnIgaWh9h7tdpch/KAXjOE7i0nNR5sBg=; b=ylTBYzcj2YVpSCijgrRmzUrpYENiu8bkG0++zHBUVO9g+ShcJdhLGYhXr3e5vk279K Pc0YJXhhhSO/ThI5tn6vybNws6dKIJEpztjlKHUXu4M84F5VX3DdbKqcWEhlR68Kfx2G xN8NQkryDhU5E9EM0oFMelqp5YAsHDjqAJ+XiF1xHPe/Zc4CUllazwchXQfo/7TY1Rha a9PPUKDkMjb79O0SL1cTt62AOk6whhkjHlJeX3kENek/Pq1b+YHMC/S4PMF8kwL9iN36 AF1y4ryH9+dd02MjyZ5m3GuvgRe2OUCww3Hs+D/VfNXTyPLQaBWDR70z+pJMn3YieVUd N39A== X-Gm-Message-State: AO0yUKUtIbe2ooyGR7mRwgT2fM1wTtPmaAkfWHU4gA9/tsQqWtARbOIZ I2P9jY+1ug3RpxwF9GB7im4= X-Google-Smtp-Source: AK7set9h/+kDyAmkJhJAUwYxodSQR95dRZRvKb1M0umFvwFLRRIcZIkStEhQCdTLV3UVW0WnmsUqtw== X-Received: by 2002:a17:90a:bf04:b0:22c:90bd:18a4 with SMTP id c4-20020a17090abf0400b0022c90bd18a4mr5658032pjs.22.1675326044732; Thu, 02 Feb 2023 00:20:44 -0800 (PST) Received: from mi-HP-ProDesk-680-G4-MT.mioffice.cn ([43.224.245.237]) by smtp.gmail.com with ESMTPSA id j5-20020a17090a694500b0022c2e29cadbsm2578563pjm.45.2023.02.02.00.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 00:20:44 -0800 (PST) From: qixiaoyu1 X-Google-Original-From: qixiaoyu1 To: Jaegeuk Kim , Chao Yu Date: Thu, 2 Feb 2023 16:20:27 +0800 Message-Id: <20230202082028.9013-1-qixiaoyu1@xiaomi.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <938a8e61-4e47-1acc-938c-c90d213d2c86@kernel.org> References: <938a8e61-4e47-1acc-938c-c90d213d2c86@kernel.org> MIME-Version: 1.0 X-Headers-End: 1pNUpt-0002TD-HK Subject: [f2fs-dev] [PATCH 1/2 v3] 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: Ping Xiong , Xiaoyu Qi , 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 Reviewed-by: Chao Yu --- Change log v1 -> v2: - fix udiv Change log v2 -> v3: - keep the accuracy with div_u64_rem fs/f2fs/extent_cache.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index 342af24b2f8c..d9f12f404beb 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -874,11 +874,18 @@ 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; + unsigned int rem_old, rem_new; + unsigned long long res; - diff = (new >= old) ? new - (new - old) : new + (old - new); + res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT) + + div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT; - return div_u64(diff * LAST_AGE_WEIGHT, 100); + if (rem_new) + res += rem_new * (100 - LAST_AGE_WEIGHT) / 100; + if (rem_old) + res += rem_old * LAST_AGE_WEIGHT / 100; + + return res; } /* This returns a new age and allocated blocks in ei */ From patchwork Thu Feb 2 08:20:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: qixiaoyu1 X-Patchwork-Id: 13125498 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 0C3F3C05027 for ; Thu, 2 Feb 2023 08:21:06 +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 1pNUqA-000424-8L; Thu, 02 Feb 2023 08:21:04 +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 1pNUq6-00041k-Kf for linux-f2fs-devel@lists.sourceforge.net; Thu, 02 Feb 2023 08:21:01 +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=Eautq1iIC0hDwNml5uf79FOlObXCfjHIXPRVUyN4Rz8=; b=fjbsCLIY43CXxRxgc+LDzAWZt2 uPaD2vdotNOln3vRy/1rTCugBaRkdvxrxnqzDNkhoVs42oaVVdQyA5XwZGek1iIodH9GPriKowvT6 x5zRdA+Cyyzoc6IRpUN5m+rvz2PCKpPpnMBBcJ9nmxt9igR0fuioAnYvjlplrOIfw2+Y=; 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=Eautq1iIC0hDwNml5uf79FOlObXCfjHIXPRVUyN4Rz8=; b=G9f7fgg5tX6878HrwkyWSHZ8bS 5JLnn7K1IlBl5H4SsbtFVtAWI6DXax95cE7rj0zFU0oqvbspB0KDMjU58rOXetRljZiU0BXT+E298 440TR3JS9C4SKdMyUJ5/G4j3KVPULmNPoegxaZ+fmsmrrlolBsdy/8unagqEu4yGhzTI=; Received: from mail-pj1-f51.google.com ([209.85.216.51]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1pNUq1-008GMu-0I for linux-f2fs-devel@lists.sourceforge.net; Thu, 02 Feb 2023 08:21:01 +0000 Received: by mail-pj1-f51.google.com with SMTP id pj3so1216857pjb.1 for ; Thu, 02 Feb 2023 00:20:56 -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=Eautq1iIC0hDwNml5uf79FOlObXCfjHIXPRVUyN4Rz8=; b=BjA4n44s+6Sc15/jKkRvZ+cXGCK584TEzsQQkHK7X0WzK0r49dCwPB+MO0TD1j/5OH XczKi8pnrQ26T0b/1/UEk7bdFRvVI5A+yLzmcVG+XFQutjJpDt22jkYiW9pRI/IfUfck Zh81n37WC0xirz5eEMpI0FXnWtBAXF/x0MoMK+XMQOXPQEAyNJ7ibJHg/AX9vjARr1wE ULWXepaEvDWnNEEH+80H+SPvKaXowZICBBjIkdu5w+wN01wtWcZw2OSvj3WGdjlGZXqs oZYza3vhjsS3hMhWHpiIP9AORF2QtOw1TKsg6HjVaZL1xd4/RS3OJ2EmlaQHNRSsnsvh Aodw== 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=Eautq1iIC0hDwNml5uf79FOlObXCfjHIXPRVUyN4Rz8=; b=3g2UNc3FyPpQqpIG1pyEPT7ACUiw30ozHq/7LntU42mmu2qyk4D6lm1+gX5fjjq2zZ uhpNTYaEJ5/vkrvqdco88I8iUYrufsjqNNbU/347/0Y36ugIW6bbivb3RTn9zI2mEe2w MfahtOHSj35/M23yHwMLexDa2J/JDCIQlaxXvaDI1WNWL4XiJ+h7cU+cBI7jmhgcUTJ+ jOjb45LB448etX+5m9A6jVEHbqhhnNkedd11s6Qa8EWPZ3r3P5dKqxdjK5emyv8xiuP+ /CTkWeyacJhSN3xOGLIW9HRZCFEJNap81urrKoIaW8fycVb12Mf+0hdNV4fzvqgaEldn Ys9Q== X-Gm-Message-State: AO0yUKVPIT+nHUAgrJV/mtmqjNTxZIObZu07bynYoshxwc8KRUb/jvOa WQCQ7If4Wg8zHBybfKQpXw4= X-Google-Smtp-Source: AK7set8o9F+PN4bVCE43tV8LiRfUMrMAyMFMd1QlFC4JGZ8dONn8Iee6EjuZBdJFijgbRZJPUixvtg== X-Received: by 2002:a17:90b:3a85:b0:22c:b9e8:48d with SMTP id om5-20020a17090b3a8500b0022cb9e8048dmr5549757pjb.0.1675326051423; Thu, 02 Feb 2023 00:20:51 -0800 (PST) Received: from mi-HP-ProDesk-680-G4-MT.mioffice.cn ([43.224.245.237]) by smtp.gmail.com with ESMTPSA id j5-20020a17090a694500b0022c2e29cadbsm2578563pjm.45.2023.02.02.00.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 00:20:50 -0800 (PST) From: qixiaoyu1 X-Google-Original-From: qixiaoyu1 To: Jaegeuk Kim , Chao Yu Date: Thu, 2 Feb 2023 16:20:28 +0800 Message-Id: <20230202082028.9013-2-qixiaoyu1@xiaomi.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230202082028.9013-1-qixiaoyu1@xiaomi.com> References: <938a8e61-4e47-1acc-938c-c90d213d2c86@kernel.org> <20230202082028.9013-1-qixiaoyu1@xiaomi.com> MIME-Version: 1.0 X-Headers-End: 1pNUq1-008GMu-0I Subject: [f2fs-dev] [PATCH 2/2 v3] 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: Ping Xiong , Xiaoyu Qi , 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 | 15 +++++++++------ fs/f2fs/f2fs.h | 1 + fs/f2fs/sysfs.c | 11 +++++++++++ 4 files changed, 26 insertions(+), 6 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 d9f12f404beb..ce99882ba81c 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -871,19 +871,21 @@ void f2fs_update_read_extent_tree_range_compressed(struct inode *inode, } #endif -static unsigned long long __calculate_block_age(unsigned long long new, +static unsigned long long __calculate_block_age(struct f2fs_sb_info *sbi, + unsigned long long new, unsigned long long old) { unsigned int rem_old, rem_new; unsigned long long res; + unsigned int weight = sbi->last_age_weight; - res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT) - + div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT; + res = div_u64_rem(new, 100, &rem_new) * (100 - weight) + + div_u64_rem(old, 100, &rem_old) * weight; if (rem_new) - res += rem_new * (100 - LAST_AGE_WEIGHT) / 100; + res += rem_new * (100 - weight) / 100; if (rem_old) - res += rem_old * LAST_AGE_WEIGHT / 100; + res += rem_old * weight / 100; return res; } @@ -917,7 +919,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; @@ -1233,6 +1235,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);