linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH v1 0/2] f2fs: modify the calculation method of mtime
@ 2024-09-11  2:40 liuderong--- via Linux-f2fs-devel
  2024-09-11  2:40 ` [f2fs-dev] [PATCH v1 1/2] f2fs: remove unused parameters liuderong--- via Linux-f2fs-devel
  2024-09-11  2:40 ` [f2fs-dev] [PATCH v1 2/2] f2fs: introduce get_section_mtime liuderong--- via Linux-f2fs-devel
  0 siblings, 2 replies; 6+ messages in thread
From: liuderong--- via Linux-f2fs-devel @ 2024-09-11  2:40 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-kernel, linux-f2fs-devel

From: liuderong <liuderong@oppo.com>

In cost-benefit GC algorithm, mtime will affect
the selection of victim segment.For a large section,
mtime should be the mean value of valid segments,
in order to select correct victim segment,
it needs to modify the calculation method of mtime.

liuderong (2):
  f2fs: remove unused parameters
  f2fs: introduce get_section_mtime

 fs/f2fs/f2fs.h    |  5 +++--
 fs/f2fs/gc.c      | 21 +++++----------------
 fs/f2fs/segment.c | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
 fs/f2fs/segment.h |  4 ++--
 4 files changed, 55 insertions(+), 27 deletions(-)

--
2.7.4

________________________________
OPPO

±¾µç×ÓÓʼþ¼°Æä¸½¼þº¬ÓÐOPPO¹«Ë¾µÄ±£ÃÜÐÅÏ¢£¬½öÏÞÓÚÓʼþÖ¸Ã÷µÄÊÕ¼þÈË£¨°üº¬¸öÈ˼°Èº×飩ʹÓ᣽ûÖ¹ÈκÎÈËÔÚδ¾­ÊÚȨµÄÇé¿öÏÂÒÔÈκÎÐÎʽʹÓá£Èç¹ûÄú´íÊÕÁ˱¾Óʼþ£¬ÇÐÎð´«²¥¡¢·Ö·¢¡¢¸´ÖÆ¡¢Ó¡Ë¢»òʹÓñ¾ÓʼþÖ®Èκβ¿·Ö»òÆäËùÔØÖ®ÈκÎÄÚÈÝ£¬²¢ÇëÁ¢¼´ÒÔµç×ÓÓʼþ֪ͨ·¢¼þÈ˲¢É¾³ý±¾Óʼþ¼°Æä¸½¼þ¡£
ÍøÂçͨѶ¹ÌÓÐȱÏÝ¿ÉÄܵ¼ÖÂÓʼþ±»½ØÁô¡¢Ð޸ġ¢¶ªÊ§¡¢ÆÆ»µ»ò°üº¬¼ÆËã»ú²¡¶¾µÈ²»°²È«Çé¿ö£¬OPPO¶Ô´ËÀà´íÎó»òÒÅ©¶øÒýÖÂÖ®ÈκÎËðʧ¸Å²»³Ðµ£ÔðÈβ¢±£ÁôÓë±¾ÓʼþÏà¹ØÖ®Ò»ÇÐȨÀû¡£
³ý·ÇÃ÷ȷ˵Ã÷£¬±¾Óʼþ¼°Æä¸½¼þÎÞÒâ×÷ΪÔÚÈκιú¼Ò»òµØÇøÖ®ÒªÔ¼¡¢ÕÐÀ¿»ò³Ðŵ£¬ÒàÎÞÒâ×÷ΪÈκν»Ò×»òºÏ֮ͬÕýʽȷÈÏ¡£ ·¢¼þÈË¡¢ÆäËùÊô»ú¹¹»òËùÊô»ú¹¹Ö®¹ØÁª»ú¹¹»òÈκÎÉÏÊö»ú¹¹Ö®¹É¶«¡¢¶­Ê¡¢¸ß¼¶¹ÜÀíÈËÔ±¡¢Ô±¹¤»òÆäËûÈκÎÈË£¨ÒÔϳơ°·¢¼þÈË¡±»ò¡°OPPO¡±£©²»Òò±¾ÓʼþÖ®ÎóËͶø·ÅÆúÆäËùÏíÖ®ÈκÎȨÀû£¬Ò಻¶ÔÒò¹ÊÒâ»ò¹ýʧʹÓøõÈÐÅÏ¢¶øÒý·¢»ò¿ÉÄÜÒý·¢µÄËðʧ³Ðµ£ÈκÎÔðÈΡ£
ÎÄ»¯²îÒìÅû¶£ºÒòÈ«ÇòÎÄ»¯²îÒìÓ°Ï죬µ¥´¿ÒÔYES\OK»òÆäËû¼òµ¥´Ê»ãµÄ»Ø¸´²¢²»¹¹³É·¢¼þÈ˶ÔÈκν»Ò×»òºÏ֮ͬÕýʽȷÈÏ»ò½ÓÊÜ£¬ÇëÓë·¢¼þÈËÔÙ´ÎÈ·ÈÏÒÔ»ñµÃÃ÷È·ÊéÃæÒâ¼û¡£·¢¼þÈ˲»¶ÔÈκÎÊÜÎÄ»¯²îÒìÓ°Ïì¶øµ¼Ö¹ÊÒâ»ò´íÎóʹÓøõÈÐÅÏ¢ËùÔì³ÉµÄÈκÎÖ±½Ó»ò¼ä½ÓË𺦳е£ÔðÈΡ£
This e-mail and its attachments contain confidential information from OPPO, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you are not the intended recipient, please do not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.
Electronic communications may contain computer viruses or other defects inherently, may not be accurately and/or timely transmitted to other systems, or may be intercepted, modified ,delayed, deleted or interfered. OPPO shall not be liable for any damages that arise or may arise from such matter and reserves all rights in connection with the email.
Unless expressly stated, this e-mail and its attachments are provided without any warranty, acceptance or promise of any kind in any country or region, nor constitute a formal confirmation or acceptance of any transaction or contract. The sender, together with its affiliates or any shareholder, director, officer, employee or any other person of any such institution (hereinafter referred to as "sender" or "OPPO") does not waive any rights and shall not be liable for any damages that arise or may arise from the intentional or negligent use of such information.
Cultural Differences Disclosure: Due to global cultural differences, any reply with only YES\OK or other simple words does not constitute any confirmation or acceptance of any transaction or contract, please confirm with the sender again to ensure clear opinion in written form. The sender shall not be responsible for any direct or indirect damages resulting from the intentional or misuse of such information.
________________________________
OPPO

本电子邮件及其附件含有OPPO公司的保密信息,仅限于邮件指明的收件人(包含个人及群组)使用。禁止任何人在未经授权的情况下以任何形式使用。如果您错收了本邮件,切勿传播、分发、复制、印刷或使用本邮件之任何部分或其所载之任何内容,并请立即以电子邮件通知发件人并删除本邮件及其附件。
网络通讯固有缺陷可能导致邮件被截留、修改、丢失、破坏或包含计算机病毒等不安全情况,OPPO对此类错误或遗漏而引致之任何损失概不承担责任并保留与本邮件相关之一切权利。
除非明确说明,本邮件及其附件无意作为在任何国家或地区之要约、招揽或承诺,亦无意作为任何交易或合同之正式确认。 发件人、其所属机构或所属机构之关联机构或任何上述机构之股东、董事、高级管理人员、员工或其他任何人(以下称“发件人”或“OPPO”)不因本邮件之误送而放弃其所享之任何权利,亦不对因故意或过失使用该等信息而引发或可能引发的损失承担任何责任。
文化差异披露:因全球文化差异影响,单纯以YES\OK或其他简单词汇的回复并不构成发件人对任何交易或合同之正式确认或接受,请与发件人再次确认以获得明确书面意见。发件人不对任何受文化差异影响而导致故意或错误使用该等信息所造成的任何直接或间接损害承担责任。
This e-mail and its attachments contain confidential information from OPPO, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you are not the intended recipient, please do not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.
Electronic communications may contain computer viruses or other defects inherently, may not be accurately and/or timely transmitted to other systems, or may be intercepted, modified ,delayed, deleted or interfered. OPPO shall not be liable for any damages that arise or may arise from such matter and reserves all rights in connection with the email.
Unless expressly stated, this e-mail and its attachments are provided without any warranty, acceptance or promise of any kind in any country or region, nor constitute a formal confirmation or acceptance of any transaction or contract. The sender, together with its affiliates or any shareholder, director, officer, employee or any other person of any such institution (hereinafter referred to as "sender" or "OPPO") does not waive any rights and shall not be liable for any damages that arise or may arise from the intentional or negligent use of such information.
Cultural Differences Disclosure: Due to global cultural differences, any reply with only YES\OK or other simple words does not constitute any confirmation or acceptance of any transaction or contract, please confirm with the sender again to ensure clear opinion in written form. The sender shall not be responsible for any direct or indirect damages resulting from the intentional or misuse of such information.


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [f2fs-dev] [PATCH v1 1/2] f2fs: remove unused parameters
  2024-09-11  2:40 [f2fs-dev] [PATCH v1 0/2] f2fs: modify the calculation method of mtime liuderong--- via Linux-f2fs-devel
@ 2024-09-11  2:40 ` liuderong--- via Linux-f2fs-devel
  2024-09-11 10:11   ` Chao Yu via Linux-f2fs-devel
  2024-09-11  2:40 ` [f2fs-dev] [PATCH v1 2/2] f2fs: introduce get_section_mtime liuderong--- via Linux-f2fs-devel
  1 sibling, 1 reply; 6+ messages in thread
From: liuderong--- via Linux-f2fs-devel @ 2024-09-11  2:40 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-kernel, linux-f2fs-devel

From: liuderong <liuderong@oppo.com>

Remove unused parameter segno from f2fs_usable_segs_in_sec.

Signed-off-by: liuderong <liuderong@oppo.com>
---
 fs/f2fs/f2fs.h    | 3 +--
 fs/f2fs/gc.c      | 6 +++---
 fs/f2fs/segment.c | 3 +--
 fs/f2fs/segment.h | 4 ++--
 4 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index ac19c61..4dcdcdd 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3759,8 +3759,7 @@ void f2fs_destroy_segment_manager_caches(void);
 int f2fs_rw_hint_to_seg_type(struct f2fs_sb_info *sbi, enum rw_hint hint);
 enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi,
                        enum page_type type, enum temp_type temp);
-unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi,
-                       unsigned int segno);
+unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi);
 unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi,
                        unsigned int segno);

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 724bbcb..6299639 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -339,7 +339,7 @@ static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, unsigned int segno)
        unsigned char age = 0;
        unsigned char u;
        unsigned int i;
-       unsigned int usable_segs_per_sec = f2fs_usable_segs_in_sec(sbi, segno);
+       unsigned int usable_segs_per_sec = f2fs_usable_segs_in_sec(sbi);

        for (i = 0; i < usable_segs_per_sec; i++)
                mtime += get_seg_entry(sbi, start + i)->mtime;
@@ -1707,7 +1707,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
         */
        if (f2fs_sb_has_blkzoned(sbi))
                end_segno -= SEGS_PER_SEC(sbi) -
-                                       f2fs_usable_segs_in_sec(sbi, segno);
+                                       f2fs_usable_segs_in_sec(sbi);

        sanity_check_seg_type(sbi, get_seg_entry(sbi, segno)->type);

@@ -1881,7 +1881,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)

        total_freed += seg_freed;

-       if (seg_freed == f2fs_usable_segs_in_sec(sbi, segno)) {
+       if (seg_freed == f2fs_usable_segs_in_sec(sbi)) {
                sec_freed++;
                total_sec_freed++;
        }
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 78c3198..6627394 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -5381,8 +5381,7 @@ unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi,
        return BLKS_PER_SEG(sbi);
 }

-unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi,
-                                       unsigned int segno)
+unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi)
 {
        if (f2fs_sb_has_blkzoned(sbi))
                return CAP_SEGS_PER_SEC(sbi);
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index bfc01a5..9e61ded 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -430,7 +430,7 @@ static inline void __set_free(struct f2fs_sb_info *sbi, unsigned int segno)
        unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
        unsigned int start_segno = GET_SEG_FROM_SEC(sbi, secno);
        unsigned int next;
-       unsigned int usable_segs = f2fs_usable_segs_in_sec(sbi, segno);
+       unsigned int usable_segs = f2fs_usable_segs_in_sec(sbi);

        spin_lock(&free_i->segmap_lock);
        clear_bit(segno, free_i->free_segmap);
@@ -464,7 +464,7 @@ static inline void __set_test_and_free(struct f2fs_sb_info *sbi,
        unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
        unsigned int start_segno = GET_SEG_FROM_SEC(sbi, secno);
        unsigned int next;
-       unsigned int usable_segs = f2fs_usable_segs_in_sec(sbi, segno);
+       unsigned int usable_segs = f2fs_usable_segs_in_sec(sbi);

        spin_lock(&free_i->segmap_lock);
        if (test_and_clear_bit(segno, free_i->free_segmap)) {
--
2.7.4

________________________________
OPPO

±¾µç×ÓÓʼþ¼°Æä¸½¼þº¬ÓÐOPPO¹«Ë¾µÄ±£ÃÜÐÅÏ¢£¬½öÏÞÓÚÓʼþÖ¸Ã÷µÄÊÕ¼þÈË£¨°üº¬¸öÈ˼°Èº×飩ʹÓ᣽ûÖ¹ÈκÎÈËÔÚδ¾­ÊÚȨµÄÇé¿öÏÂÒÔÈκÎÐÎʽʹÓá£Èç¹ûÄú´íÊÕÁ˱¾Óʼþ£¬ÇÐÎð´«²¥¡¢·Ö·¢¡¢¸´ÖÆ¡¢Ó¡Ë¢»òʹÓñ¾ÓʼþÖ®Èκβ¿·Ö»òÆäËùÔØÖ®ÈκÎÄÚÈÝ£¬²¢ÇëÁ¢¼´ÒÔµç×ÓÓʼþ֪ͨ·¢¼þÈ˲¢É¾³ý±¾Óʼþ¼°Æä¸½¼þ¡£
ÍøÂçͨѶ¹ÌÓÐȱÏÝ¿ÉÄܵ¼ÖÂÓʼþ±»½ØÁô¡¢Ð޸ġ¢¶ªÊ§¡¢ÆÆ»µ»ò°üº¬¼ÆËã»ú²¡¶¾µÈ²»°²È«Çé¿ö£¬OPPO¶Ô´ËÀà´íÎó»òÒÅ©¶øÒýÖÂÖ®ÈκÎËðʧ¸Å²»³Ðµ£ÔðÈβ¢±£ÁôÓë±¾ÓʼþÏà¹ØÖ®Ò»ÇÐȨÀû¡£
³ý·ÇÃ÷ȷ˵Ã÷£¬±¾Óʼþ¼°Æä¸½¼þÎÞÒâ×÷ΪÔÚÈκιú¼Ò»òµØÇøÖ®ÒªÔ¼¡¢ÕÐÀ¿»ò³Ðŵ£¬ÒàÎÞÒâ×÷ΪÈκν»Ò×»òºÏ֮ͬÕýʽȷÈÏ¡£ ·¢¼þÈË¡¢ÆäËùÊô»ú¹¹»òËùÊô»ú¹¹Ö®¹ØÁª»ú¹¹»òÈκÎÉÏÊö»ú¹¹Ö®¹É¶«¡¢¶­Ê¡¢¸ß¼¶¹ÜÀíÈËÔ±¡¢Ô±¹¤»òÆäËûÈκÎÈË£¨ÒÔϳơ°·¢¼þÈË¡±»ò¡°OPPO¡±£©²»Òò±¾ÓʼþÖ®ÎóËͶø·ÅÆúÆäËùÏíÖ®ÈκÎȨÀû£¬Ò಻¶ÔÒò¹ÊÒâ»ò¹ýʧʹÓøõÈÐÅÏ¢¶øÒý·¢»ò¿ÉÄÜÒý·¢µÄËðʧ³Ðµ£ÈκÎÔðÈΡ£
ÎÄ»¯²îÒìÅû¶£ºÒòÈ«ÇòÎÄ»¯²îÒìÓ°Ï죬µ¥´¿ÒÔYES\OK»òÆäËû¼òµ¥´Ê»ãµÄ»Ø¸´²¢²»¹¹³É·¢¼þÈ˶ÔÈκν»Ò×»òºÏ֮ͬÕýʽȷÈÏ»ò½ÓÊÜ£¬ÇëÓë·¢¼þÈËÔÙ´ÎÈ·ÈÏÒÔ»ñµÃÃ÷È·ÊéÃæÒâ¼û¡£·¢¼þÈ˲»¶ÔÈκÎÊÜÎÄ»¯²îÒìÓ°Ïì¶øµ¼Ö¹ÊÒâ»ò´íÎóʹÓøõÈÐÅÏ¢ËùÔì³ÉµÄÈκÎÖ±½Ó»ò¼ä½ÓË𺦳е£ÔðÈΡ£
This e-mail and its attachments contain confidential information from OPPO, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you are not the intended recipient, please do not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.
Electronic communications may contain computer viruses or other defects inherently, may not be accurately and/or timely transmitted to other systems, or may be intercepted, modified ,delayed, deleted or interfered. OPPO shall not be liable for any damages that arise or may arise from such matter and reserves all rights in connection with the email.
Unless expressly stated, this e-mail and its attachments are provided without any warranty, acceptance or promise of any kind in any country or region, nor constitute a formal confirmation or acceptance of any transaction or contract. The sender, together with its affiliates or any shareholder, director, officer, employee or any other person of any such institution (hereinafter referred to as "sender" or "OPPO") does not waive any rights and shall not be liable for any damages that arise or may arise from the intentional or negligent use of such information.
Cultural Differences Disclosure: Due to global cultural differences, any reply with only YES\OK or other simple words does not constitute any confirmation or acceptance of any transaction or contract, please confirm with the sender again to ensure clear opinion in written form. The sender shall not be responsible for any direct or indirect damages resulting from the intentional or misuse of such information.
________________________________
OPPO

本电子邮件及其附件含有OPPO公司的保密信息,仅限于邮件指明的收件人(包含个人及群组)使用。禁止任何人在未经授权的情况下以任何形式使用。如果您错收了本邮件,切勿传播、分发、复制、印刷或使用本邮件之任何部分或其所载之任何内容,并请立即以电子邮件通知发件人并删除本邮件及其附件。
网络通讯固有缺陷可能导致邮件被截留、修改、丢失、破坏或包含计算机病毒等不安全情况,OPPO对此类错误或遗漏而引致之任何损失概不承担责任并保留与本邮件相关之一切权利。
除非明确说明,本邮件及其附件无意作为在任何国家或地区之要约、招揽或承诺,亦无意作为任何交易或合同之正式确认。 发件人、其所属机构或所属机构之关联机构或任何上述机构之股东、董事、高级管理人员、员工或其他任何人(以下称“发件人”或“OPPO”)不因本邮件之误送而放弃其所享之任何权利,亦不对因故意或过失使用该等信息而引发或可能引发的损失承担任何责任。
文化差异披露:因全球文化差异影响,单纯以YES\OK或其他简单词汇的回复并不构成发件人对任何交易或合同之正式确认或接受,请与发件人再次确认以获得明确书面意见。发件人不对任何受文化差异影响而导致故意或错误使用该等信息所造成的任何直接或间接损害承担责任。
This e-mail and its attachments contain confidential information from OPPO, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you are not the intended recipient, please do not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.
Electronic communications may contain computer viruses or other defects inherently, may not be accurately and/or timely transmitted to other systems, or may be intercepted, modified ,delayed, deleted or interfered. OPPO shall not be liable for any damages that arise or may arise from such matter and reserves all rights in connection with the email.
Unless expressly stated, this e-mail and its attachments are provided without any warranty, acceptance or promise of any kind in any country or region, nor constitute a formal confirmation or acceptance of any transaction or contract. The sender, together with its affiliates or any shareholder, director, officer, employee or any other person of any such institution (hereinafter referred to as "sender" or "OPPO") does not waive any rights and shall not be liable for any damages that arise or may arise from the intentional or negligent use of such information.
Cultural Differences Disclosure: Due to global cultural differences, any reply with only YES\OK or other simple words does not constitute any confirmation or acceptance of any transaction or contract, please confirm with the sender again to ensure clear opinion in written form. The sender shall not be responsible for any direct or indirect damages resulting from the intentional or misuse of such information.


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [f2fs-dev] [PATCH v1 2/2] f2fs: introduce get_section_mtime
  2024-09-11  2:40 [f2fs-dev] [PATCH v1 0/2] f2fs: modify the calculation method of mtime liuderong--- via Linux-f2fs-devel
  2024-09-11  2:40 ` [f2fs-dev] [PATCH v1 1/2] f2fs: remove unused parameters liuderong--- via Linux-f2fs-devel
@ 2024-09-11  2:40 ` liuderong--- via Linux-f2fs-devel
  2024-09-11 10:22   ` Chao Yu via Linux-f2fs-devel
  1 sibling, 1 reply; 6+ messages in thread
From: liuderong--- via Linux-f2fs-devel @ 2024-09-11  2:40 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-kernel, linux-f2fs-devel

From: liuderong <liuderong@oppo.com>

When segs_per_sec is larger than 1, section may contain free segments,
mtime should be the mean value of each valid segments,
so introduce get_section_mtime to exclude free segments in a section.

Signed-off-by: liuderong <liuderong@oppo.com>
---
 fs/f2fs/f2fs.h    |  2 ++
 fs/f2fs/gc.c      | 15 ++-------------
 fs/f2fs/segment.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 48 insertions(+), 18 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 4dcdcdd..d6adf0f 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3762,6 +3762,8 @@ enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi,
 unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi);
 unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi,
                        unsigned int segno);
+unsigned long long get_section_mtime(struct f2fs_sb_info *sbi,
+                       unsigned int segno);

 #define DEF_FRAGMENT_SIZE      4
 #define MIN_FRAGMENT_SIZE      1
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 6299639..03c6117 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -332,20 +332,14 @@ static unsigned int check_bg_victims(struct f2fs_sb_info *sbi)
 static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, unsigned int segno)
 {
        struct sit_info *sit_i = SIT_I(sbi);
-       unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
-       unsigned int start = GET_SEG_FROM_SEC(sbi, secno);
        unsigned long long mtime = 0;
        unsigned int vblocks;
        unsigned char age = 0;
        unsigned char u;
-       unsigned int i;
        unsigned int usable_segs_per_sec = f2fs_usable_segs_in_sec(sbi);

-       for (i = 0; i < usable_segs_per_sec; i++)
-               mtime += get_seg_entry(sbi, start + i)->mtime;
+       mtime = get_section_mtime(sbi, segno);
        vblocks = get_valid_blocks(sbi, segno, true);
-
-       mtime = div_u64(mtime, usable_segs_per_sec);
        vblocks = div_u64(vblocks, usable_segs_per_sec);

        u = BLKS_TO_SEGS(sbi, vblocks * 100);
@@ -485,10 +479,7 @@ static void add_victim_entry(struct f2fs_sb_info *sbi,
                                struct victim_sel_policy *p, unsigned int segno)
 {
        struct sit_info *sit_i = SIT_I(sbi);
-       unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
-       unsigned int start = GET_SEG_FROM_SEC(sbi, secno);
        unsigned long long mtime = 0;
-       unsigned int i;

        if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
                if (p->gc_mode == GC_AT &&
@@ -496,9 +487,7 @@ static void add_victim_entry(struct f2fs_sb_info *sbi,
                        return;
        }

-       for (i = 0; i < SEGS_PER_SEC(sbi); i++)
-               mtime += get_seg_entry(sbi, start + i)->mtime;
-       mtime = div_u64(mtime, SEGS_PER_SEC(sbi));
+       mtime = get_section_mtime(sbi, segno);

        /* Handle if the system time has changed by the user */
        if (mtime < sit_i->min_mtime)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 6627394..b63f35fa 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -5389,6 +5389,49 @@ unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi)
        return SEGS_PER_SEC(sbi);
 }

+unsigned long long get_section_mtime(struct f2fs_sb_info *sbi,
+       unsigned int segno)
+{
+       unsigned int usable_segs_per_sec = f2fs_usable_segs_in_sec(sbi);
+       unsigned int secno = 0, start = 0;
+       struct free_segmap_info *free_i = FREE_I(sbi);
+       unsigned int valid_seg_count = 0;
+       unsigned long long mtime = 0;
+       unsigned int i;
+
+       if (segno == NULL_SEGNO)
+               return 0;
+
+       secno = GET_SEC_FROM_SEG(sbi, segno);
+       start = GET_SEG_FROM_SEC(sbi, secno);
+
+       for (i = 0; i < usable_segs_per_sec; i++) {
+               /* for large section, only check the mtime of valid segments */
+               if (__is_large_section(sbi)) {
+                       spin_lock(&free_i->segmap_lock);
+                       if (test_bit(start + i, free_i->free_segmap)) {
+                               mtime += get_seg_entry(sbi, start + i)->mtime;
+                               valid_seg_count++;
+                       }
+                       spin_unlock(&free_i->segmap_lock);
+               } else {
+                       mtime += get_seg_entry(sbi, start + i)->mtime;
+               }
+       }
+
+       if (__is_large_section(sbi)) {
+               if (!valid_seg_count)
+                       goto out;
+               mtime = div_u64(mtime, valid_seg_count);
+       } else {
+               mtime = div_u64(mtime, usable_segs_per_sec);
+       }
+
+out:
+       return mtime;
+}
+
 /*
  * Update min, max modified time for cost-benefit GC algorithm
  */
@@ -5402,13 +5445,9 @@ static void init_min_max_mtime(struct f2fs_sb_info *sbi)
        sit_i->min_mtime = ULLONG_MAX;

        for (segno = 0; segno < MAIN_SEGS(sbi); segno += SEGS_PER_SEC(sbi)) {
-               unsigned int i;
                unsigned long long mtime = 0;

-               for (i = 0; i < SEGS_PER_SEC(sbi); i++)
-                       mtime += get_seg_entry(sbi, segno + i)->mtime;
-
-               mtime = div_u64(mtime, SEGS_PER_SEC(sbi));
+               mtime = get_section_mtime(sbi, segno);

                if (sit_i->min_mtime > mtime)
                        sit_i->min_mtime = mtime;
--
2.7.4

________________________________
OPPO

±¾µç×ÓÓʼþ¼°Æä¸½¼þº¬ÓÐOPPO¹«Ë¾µÄ±£ÃÜÐÅÏ¢£¬½öÏÞÓÚÓʼþÖ¸Ã÷µÄÊÕ¼þÈË£¨°üº¬¸öÈ˼°Èº×飩ʹÓ᣽ûÖ¹ÈκÎÈËÔÚδ¾­ÊÚȨµÄÇé¿öÏÂÒÔÈκÎÐÎʽʹÓá£Èç¹ûÄú´íÊÕÁ˱¾Óʼþ£¬ÇÐÎð´«²¥¡¢·Ö·¢¡¢¸´ÖÆ¡¢Ó¡Ë¢»òʹÓñ¾ÓʼþÖ®Èκβ¿·Ö»òÆäËùÔØÖ®ÈκÎÄÚÈÝ£¬²¢ÇëÁ¢¼´ÒÔµç×ÓÓʼþ֪ͨ·¢¼þÈ˲¢É¾³ý±¾Óʼþ¼°Æä¸½¼þ¡£
ÍøÂçͨѶ¹ÌÓÐȱÏÝ¿ÉÄܵ¼ÖÂÓʼþ±»½ØÁô¡¢Ð޸ġ¢¶ªÊ§¡¢ÆÆ»µ»ò°üº¬¼ÆËã»ú²¡¶¾µÈ²»°²È«Çé¿ö£¬OPPO¶Ô´ËÀà´íÎó»òÒÅ©¶øÒýÖÂÖ®ÈκÎËðʧ¸Å²»³Ðµ£ÔðÈβ¢±£ÁôÓë±¾ÓʼþÏà¹ØÖ®Ò»ÇÐȨÀû¡£
³ý·ÇÃ÷ȷ˵Ã÷£¬±¾Óʼþ¼°Æä¸½¼þÎÞÒâ×÷ΪÔÚÈκιú¼Ò»òµØÇøÖ®ÒªÔ¼¡¢ÕÐÀ¿»ò³Ðŵ£¬ÒàÎÞÒâ×÷ΪÈκν»Ò×»òºÏ֮ͬÕýʽȷÈÏ¡£ ·¢¼þÈË¡¢ÆäËùÊô»ú¹¹»òËùÊô»ú¹¹Ö®¹ØÁª»ú¹¹»òÈκÎÉÏÊö»ú¹¹Ö®¹É¶«¡¢¶­Ê¡¢¸ß¼¶¹ÜÀíÈËÔ±¡¢Ô±¹¤»òÆäËûÈκÎÈË£¨ÒÔϳơ°·¢¼þÈË¡±»ò¡°OPPO¡±£©²»Òò±¾ÓʼþÖ®ÎóËͶø·ÅÆúÆäËùÏíÖ®ÈκÎȨÀû£¬Ò಻¶ÔÒò¹ÊÒâ»ò¹ýʧʹÓøõÈÐÅÏ¢¶øÒý·¢»ò¿ÉÄÜÒý·¢µÄËðʧ³Ðµ£ÈκÎÔðÈΡ£
ÎÄ»¯²îÒìÅû¶£ºÒòÈ«ÇòÎÄ»¯²îÒìÓ°Ï죬µ¥´¿ÒÔYES\OK»òÆäËû¼òµ¥´Ê»ãµÄ»Ø¸´²¢²»¹¹³É·¢¼þÈ˶ÔÈκν»Ò×»òºÏ֮ͬÕýʽȷÈÏ»ò½ÓÊÜ£¬ÇëÓë·¢¼þÈËÔÙ´ÎÈ·ÈÏÒÔ»ñµÃÃ÷È·ÊéÃæÒâ¼û¡£·¢¼þÈ˲»¶ÔÈκÎÊÜÎÄ»¯²îÒìÓ°Ïì¶øµ¼Ö¹ÊÒâ»ò´íÎóʹÓøõÈÐÅÏ¢ËùÔì³ÉµÄÈκÎÖ±½Ó»ò¼ä½ÓË𺦳е£ÔðÈΡ£
This e-mail and its attachments contain confidential information from OPPO, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you are not the intended recipient, please do not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.
Electronic communications may contain computer viruses or other defects inherently, may not be accurately and/or timely transmitted to other systems, or may be intercepted, modified ,delayed, deleted or interfered. OPPO shall not be liable for any damages that arise or may arise from such matter and reserves all rights in connection with the email.
Unless expressly stated, this e-mail and its attachments are provided without any warranty, acceptance or promise of any kind in any country or region, nor constitute a formal confirmation or acceptance of any transaction or contract. The sender, together with its affiliates or any shareholder, director, officer, employee or any other person of any such institution (hereinafter referred to as "sender" or "OPPO") does not waive any rights and shall not be liable for any damages that arise or may arise from the intentional or negligent use of such information.
Cultural Differences Disclosure: Due to global cultural differences, any reply with only YES\OK or other simple words does not constitute any confirmation or acceptance of any transaction or contract, please confirm with the sender again to ensure clear opinion in written form. The sender shall not be responsible for any direct or indirect damages resulting from the intentional or misuse of such information.
________________________________
OPPO

本电子邮件及其附件含有OPPO公司的保密信息,仅限于邮件指明的收件人(包含个人及群组)使用。禁止任何人在未经授权的情况下以任何形式使用。如果您错收了本邮件,切勿传播、分发、复制、印刷或使用本邮件之任何部分或其所载之任何内容,并请立即以电子邮件通知发件人并删除本邮件及其附件。
网络通讯固有缺陷可能导致邮件被截留、修改、丢失、破坏或包含计算机病毒等不安全情况,OPPO对此类错误或遗漏而引致之任何损失概不承担责任并保留与本邮件相关之一切权利。
除非明确说明,本邮件及其附件无意作为在任何国家或地区之要约、招揽或承诺,亦无意作为任何交易或合同之正式确认。 发件人、其所属机构或所属机构之关联机构或任何上述机构之股东、董事、高级管理人员、员工或其他任何人(以下称“发件人”或“OPPO”)不因本邮件之误送而放弃其所享之任何权利,亦不对因故意或过失使用该等信息而引发或可能引发的损失承担任何责任。
文化差异披露:因全球文化差异影响,单纯以YES\OK或其他简单词汇的回复并不构成发件人对任何交易或合同之正式确认或接受,请与发件人再次确认以获得明确书面意见。发件人不对任何受文化差异影响而导致故意或错误使用该等信息所造成的任何直接或间接损害承担责任。
This e-mail and its attachments contain confidential information from OPPO, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you are not the intended recipient, please do not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.
Electronic communications may contain computer viruses or other defects inherently, may not be accurately and/or timely transmitted to other systems, or may be intercepted, modified ,delayed, deleted or interfered. OPPO shall not be liable for any damages that arise or may arise from such matter and reserves all rights in connection with the email.
Unless expressly stated, this e-mail and its attachments are provided without any warranty, acceptance or promise of any kind in any country or region, nor constitute a formal confirmation or acceptance of any transaction or contract. The sender, together with its affiliates or any shareholder, director, officer, employee or any other person of any such institution (hereinafter referred to as "sender" or "OPPO") does not waive any rights and shall not be liable for any damages that arise or may arise from the intentional or negligent use of such information.
Cultural Differences Disclosure: Due to global cultural differences, any reply with only YES\OK or other simple words does not constitute any confirmation or acceptance of any transaction or contract, please confirm with the sender again to ensure clear opinion in written form. The sender shall not be responsible for any direct or indirect damages resulting from the intentional or misuse of such information.


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH v1 1/2] f2fs: remove unused parameters
  2024-09-11  2:40 ` [f2fs-dev] [PATCH v1 1/2] f2fs: remove unused parameters liuderong--- via Linux-f2fs-devel
@ 2024-09-11 10:11   ` Chao Yu via Linux-f2fs-devel
  0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2024-09-11 10:11 UTC (permalink / raw)
  To: liuderong, jaegeuk; +Cc: linux-kernel, linux-f2fs-devel

On 2024/9/11 10:40, liuderong@oppo.com wrote:
> From: liuderong <liuderong@oppo.com>
> 
> Remove unused parameter segno from f2fs_usable_segs_in_sec.
> 
> Signed-off-by: liuderong <liuderong@oppo.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH v1 2/2] f2fs: introduce get_section_mtime
  2024-09-11  2:40 ` [f2fs-dev] [PATCH v1 2/2] f2fs: introduce get_section_mtime liuderong--- via Linux-f2fs-devel
@ 2024-09-11 10:22   ` Chao Yu via Linux-f2fs-devel
  2024-09-12  5:16     ` liuderong via Linux-f2fs-devel
  0 siblings, 1 reply; 6+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2024-09-11 10:22 UTC (permalink / raw)
  To: liuderong, jaegeuk; +Cc: linux-kernel, linux-f2fs-devel

On 2024/9/11 10:40, liuderong@oppo.com wrote:
> From: liuderong <liuderong@oppo.com>
> 
> When segs_per_sec is larger than 1, section may contain free segments,
> mtime should be the mean value of each valid segments,
> so introduce get_section_mtime to exclude free segments in a section.
> 
> Signed-off-by: liuderong <liuderong@oppo.com>
> ---
>   fs/f2fs/f2fs.h    |  2 ++
>   fs/f2fs/gc.c      | 15 ++-------------
>   fs/f2fs/segment.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
>   3 files changed, 48 insertions(+), 18 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 4dcdcdd..d6adf0f 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -3762,6 +3762,8 @@ enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi,
>   unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi);
>   unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi,
>                          unsigned int segno);
> +unsigned long long get_section_mtime(struct f2fs_sb_info *sbi,
> +                       unsigned int segno);
> 
>   #define DEF_FRAGMENT_SIZE      4
>   #define MIN_FRAGMENT_SIZE      1
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index 6299639..03c6117 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -332,20 +332,14 @@ static unsigned int check_bg_victims(struct f2fs_sb_info *sbi)
>   static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, unsigned int segno)
>   {
>          struct sit_info *sit_i = SIT_I(sbi);
> -       unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
> -       unsigned int start = GET_SEG_FROM_SEC(sbi, secno);
>          unsigned long long mtime = 0;
>          unsigned int vblocks;
>          unsigned char age = 0;
>          unsigned char u;
> -       unsigned int i;
>          unsigned int usable_segs_per_sec = f2fs_usable_segs_in_sec(sbi);
> 
> -       for (i = 0; i < usable_segs_per_sec; i++)
> -               mtime += get_seg_entry(sbi, start + i)->mtime;
> +       mtime = get_section_mtime(sbi, segno);
>          vblocks = get_valid_blocks(sbi, segno, true);
> -
> -       mtime = div_u64(mtime, usable_segs_per_sec);
>          vblocks = div_u64(vblocks, usable_segs_per_sec);
> 
>          u = BLKS_TO_SEGS(sbi, vblocks * 100);
> @@ -485,10 +479,7 @@ static void add_victim_entry(struct f2fs_sb_info *sbi,
>                                  struct victim_sel_policy *p, unsigned int segno)
>   {
>          struct sit_info *sit_i = SIT_I(sbi);
> -       unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
> -       unsigned int start = GET_SEG_FROM_SEC(sbi, secno);
>          unsigned long long mtime = 0;
> -       unsigned int i;
> 
>          if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
>                  if (p->gc_mode == GC_AT &&
> @@ -496,9 +487,7 @@ static void add_victim_entry(struct f2fs_sb_info *sbi,
>                          return;
>          }
> 
> -       for (i = 0; i < SEGS_PER_SEC(sbi); i++)
> -               mtime += get_seg_entry(sbi, start + i)->mtime;
> -       mtime = div_u64(mtime, SEGS_PER_SEC(sbi));
> +       mtime = get_section_mtime(sbi, segno);
> 
>          /* Handle if the system time has changed by the user */
>          if (mtime < sit_i->min_mtime)
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 6627394..b63f35fa 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -5389,6 +5389,49 @@ unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi)
>          return SEGS_PER_SEC(sbi);
>   }
> 
> +unsigned long long get_section_mtime(struct f2fs_sb_info *sbi,
> +       unsigned int segno)
> +{
> +       unsigned int usable_segs_per_sec = f2fs_usable_segs_in_sec(sbi);
> +       unsigned int secno = 0, start = 0;
> +       struct free_segmap_info *free_i = FREE_I(sbi);
> +       unsigned int valid_seg_count = 0;
> +       unsigned long long mtime = 0;
> +       unsigned int i;
> +
> +       if (segno == NULL_SEGNO)
> +               return 0;
> +
> +       secno = GET_SEC_FROM_SEG(sbi, segno);
> +       start = GET_SEG_FROM_SEC(sbi, secno);
> +
> +       for (i = 0; i < usable_segs_per_sec; i++) {
> +               /* for large section, only check the mtime of valid segments */
> +               if (__is_large_section(sbi)) {
> +                       spin_lock(&free_i->segmap_lock);
> +                       if (test_bit(start + i, free_i->free_segmap)) {
> +                               mtime += get_seg_entry(sbi, start + i)->mtime;
> +                               valid_seg_count++;
> +                       }
> +                       spin_unlock(&free_i->segmap_lock);
> +               } else {
> +                       mtime += get_seg_entry(sbi, start + i)->mtime;
> +               }
> +       }
> +
> +       if (__is_large_section(sbi)) {
> +               if (!valid_seg_count)
> +                       goto out;
> +               mtime = div_u64(mtime, valid_seg_count);
> +       } else {
> +               mtime = div_u64(mtime, usable_segs_per_sec);
> +       }

What about:

if (!__is_large_section(sbi))
	return get_seg_entry(sbi, start + i)->mtime;

for (i = 0; i < usable_segs_per_sec; i++) {
	/* for large section, only check the mtime of valid segments */
	...
}

return div_u64(mtime, usable_segs_per_sec);

Thanks,

> +
> +out:
> +       return mtime;
> +}
> +
>   /*
>    * Update min, max modified time for cost-benefit GC algorithm
>    */
> @@ -5402,13 +5445,9 @@ static void init_min_max_mtime(struct f2fs_sb_info *sbi)
>          sit_i->min_mtime = ULLONG_MAX;
> 
>          for (segno = 0; segno < MAIN_SEGS(sbi); segno += SEGS_PER_SEC(sbi)) {
> -               unsigned int i;
>                  unsigned long long mtime = 0;
> 
> -               for (i = 0; i < SEGS_PER_SEC(sbi); i++)
> -                       mtime += get_seg_entry(sbi, segno + i)->mtime;
> -
> -               mtime = div_u64(mtime, SEGS_PER_SEC(sbi));
> +               mtime = get_section_mtime(sbi, segno);
> 
>                  if (sit_i->min_mtime > mtime)
>                          sit_i->min_mtime = mtime;
> --
> 2.7.4



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH v1 2/2] f2fs: introduce get_section_mtime
  2024-09-11 10:22   ` Chao Yu via Linux-f2fs-devel
@ 2024-09-12  5:16     ` liuderong via Linux-f2fs-devel
  0 siblings, 0 replies; 6+ messages in thread
From: liuderong via Linux-f2fs-devel @ 2024-09-12  5:16 UTC (permalink / raw)
  To: Chao Yu, jaegeuk; +Cc: linux-kernel, linux-f2fs-devel

On 2024/9/11 18:22, Chao Yu wrote:
> On 2024/9/11 10:40, liuderong@oppo.com wrote:
>> From: liuderong <liuderong@oppo.com>
>>
>> When segs_per_sec is larger than 1, section may contain free segments,
>> mtime should be the mean value of each valid segments,
>> so introduce get_section_mtime to exclude free segments in a section.
>>
>> Signed-off-by: liuderong <liuderong@oppo.com>
>> ---
>>   fs/f2fs/f2fs.h    |  2 ++
>>   fs/f2fs/gc.c      | 15 ++-------------
>>   fs/f2fs/segment.c | 49 
>> ++++++++++++++++++++++++++++++++++++++++++++-----
>>   3 files changed, 48 insertions(+), 18 deletions(-)
>>
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index 4dcdcdd..d6adf0f 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -3762,6 +3762,8 @@ enum rw_hint f2fs_io_type_to_rw_hint(struct 
>> f2fs_sb_info *sbi,
>>   unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi);
>>   unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi,
>>                          unsigned int segno);
>> +unsigned long long get_section_mtime(struct f2fs_sb_info *sbi,
>> +                       unsigned int segno);
>>
>>   #define DEF_FRAGMENT_SIZE      4
>>   #define MIN_FRAGMENT_SIZE      1
>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
>> index 6299639..03c6117 100644
>> --- a/fs/f2fs/gc.c
>> +++ b/fs/f2fs/gc.c
>> @@ -332,20 +332,14 @@ static unsigned int check_bg_victims(struct 
>> f2fs_sb_info *sbi)
>>   static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, unsigned 
>> int segno)
>>   {
>>          struct sit_info *sit_i = SIT_I(sbi);
>> -       unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
>> -       unsigned int start = GET_SEG_FROM_SEC(sbi, secno);
>>          unsigned long long mtime = 0;
>>          unsigned int vblocks;
>>          unsigned char age = 0;
>>          unsigned char u;
>> -       unsigned int i;
>>          unsigned int usable_segs_per_sec = 
>> f2fs_usable_segs_in_sec(sbi);
>>
>> -       for (i = 0; i < usable_segs_per_sec; i++)
>> -               mtime += get_seg_entry(sbi, start + i)->mtime;
>> +       mtime = get_section_mtime(sbi, segno);
>>          vblocks = get_valid_blocks(sbi, segno, true);
>> -
>> -       mtime = div_u64(mtime, usable_segs_per_sec);
>>          vblocks = div_u64(vblocks, usable_segs_per_sec);
>>
>>          u = BLKS_TO_SEGS(sbi, vblocks * 100);
>> @@ -485,10 +479,7 @@ static void add_victim_entry(struct f2fs_sb_info 
>> *sbi,
>>                                  struct victim_sel_policy *p, 
>> unsigned int segno)
>>   {
>>          struct sit_info *sit_i = SIT_I(sbi);
>> -       unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
>> -       unsigned int start = GET_SEG_FROM_SEC(sbi, secno);
>>          unsigned long long mtime = 0;
>> -       unsigned int i;
>>
>>          if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
>>                  if (p->gc_mode == GC_AT &&
>> @@ -496,9 +487,7 @@ static void add_victim_entry(struct f2fs_sb_info 
>> *sbi,
>>                          return;
>>          }
>>
>> -       for (i = 0; i < SEGS_PER_SEC(sbi); i++)
>> -               mtime += get_seg_entry(sbi, start + i)->mtime;
>> -       mtime = div_u64(mtime, SEGS_PER_SEC(sbi));
>> +       mtime = get_section_mtime(sbi, segno);
>>
>>          /* Handle if the system time has changed by the user */
>>          if (mtime < sit_i->min_mtime)
>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>> index 6627394..b63f35fa 100644
>> --- a/fs/f2fs/segment.c
>> +++ b/fs/f2fs/segment.c
>> @@ -5389,6 +5389,49 @@ unsigned int f2fs_usable_segs_in_sec(struct 
>> f2fs_sb_info *sbi)
>>          return SEGS_PER_SEC(sbi);
>>   }
>>
>> +unsigned long long get_section_mtime(struct f2fs_sb_info *sbi,
>> +       unsigned int segno)
>> +{
>> +       unsigned int usable_segs_per_sec = f2fs_usable_segs_in_sec(sbi);
>> +       unsigned int secno = 0, start = 0;
>> +       struct free_segmap_info *free_i = FREE_I(sbi);
>> +       unsigned int valid_seg_count = 0;
>> +       unsigned long long mtime = 0;
>> +       unsigned int i;
>> +
>> +       if (segno == NULL_SEGNO)
>> +               return 0;
>> +
>> +       secno = GET_SEC_FROM_SEG(sbi, segno);
>> +       start = GET_SEG_FROM_SEC(sbi, secno);
>> +
>> +       for (i = 0; i < usable_segs_per_sec; i++) {
>> +               /* for large section, only check the mtime of valid 
>> segments */
>> +               if (__is_large_section(sbi)) {
>> +                       spin_lock(&free_i->segmap_lock);
>> +                       if (test_bit(start + i, free_i->free_segmap)) {
>> +                               mtime += get_seg_entry(sbi, start + 
>> i)->mtime;
>> +                               valid_seg_count++;
>> +                       }
>> + spin_unlock(&free_i->segmap_lock);
>> +               } else {
>> +                       mtime += get_seg_entry(sbi, start + i)->mtime;
>> +               }
>> +       }
>> +
>> +       if (__is_large_section(sbi)) {
>> +               if (!valid_seg_count)
>> +                       goto out;
>> +               mtime = div_u64(mtime, valid_seg_count);
>> +       } else {
>> +               mtime = div_u64(mtime, usable_segs_per_sec);
>> +       }
>
> What about:
>
> if (!__is_large_section(sbi))
>        return get_seg_entry(sbi, start + i)->mtime;
>
> for (i = 0; i < usable_segs_per_sec; i++) {
>        /* for large section, only check the mtime of valid segments */
>        ...
> }
>
> return div_u64(mtime, usable_segs_per_sec);
>
> Thanks,
>
OK, I will modify the code.

Thanks,

Derong

>> +
>> +out:
>> +       return mtime;
>> +}
>> +
>>   /*
>>    * Update min, max modified time for cost-benefit GC algorithm
>>    */
>> @@ -5402,13 +5445,9 @@ static void init_min_max_mtime(struct 
>> f2fs_sb_info *sbi)
>>          sit_i->min_mtime = ULLONG_MAX;
>>
>>          for (segno = 0; segno < MAIN_SEGS(sbi); segno += 
>> SEGS_PER_SEC(sbi)) {
>> -               unsigned int i;
>>                  unsigned long long mtime = 0;
>>
>> -               for (i = 0; i < SEGS_PER_SEC(sbi); i++)
>> -                       mtime += get_seg_entry(sbi, segno + i)->mtime;
>> -
>> -               mtime = div_u64(mtime, SEGS_PER_SEC(sbi));
>> +               mtime = get_section_mtime(sbi, segno);
>>
>>                  if (sit_i->min_mtime > mtime)
>>                          sit_i->min_mtime = mtime;
>> -- 
>> 2.7.4
>


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-09-12  5:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-11  2:40 [f2fs-dev] [PATCH v1 0/2] f2fs: modify the calculation method of mtime liuderong--- via Linux-f2fs-devel
2024-09-11  2:40 ` [f2fs-dev] [PATCH v1 1/2] f2fs: remove unused parameters liuderong--- via Linux-f2fs-devel
2024-09-11 10:11   ` Chao Yu via Linux-f2fs-devel
2024-09-11  2:40 ` [f2fs-dev] [PATCH v1 2/2] f2fs: introduce get_section_mtime liuderong--- via Linux-f2fs-devel
2024-09-11 10:22   ` Chao Yu via Linux-f2fs-devel
2024-09-12  5:16     ` liuderong via Linux-f2fs-devel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).