This patch supports to map continuous holes to improve
performace of lookuping mapping info during fiemap.

[testcase]
truncate -s 1m hole && fsync hole
f2fs_io fiemap 0 256 hole

[before]
f2fs_map_blocks: dev = (254,54), ino = 18563, file offset = 0, start blkaddr = 
0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag 
= 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 18563, file offset = 1, start blkaddr = 
0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag 
= 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 18563, file offset = 2, start blkaddr = 
0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag 
= 1, err = 0
......
f2fs_map_blocks: dev = (254,54), ino = 18563, file offset = 863, start blkaddr 
= 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, 
flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 18563, file offset = 864, start blkaddr 
= 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, 
flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 18563, file offset = 1882, start blkaddr 
= 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, 
flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 18563, file offset = 2900, start blkaddr 
= 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, 
flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 18563, file offset = 1039224, start 
blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice 
= 0, flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 18563, file offset = 2075548, start 
blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice 
= 0, flag = 1, err = 0

[after]
f2fs_map_blocks: dev = (254,54), ino = 19959, file offset = 0, start blkaddr = 
0x0, len = 0x100, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, 
flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 19959, file offset = 256, start blkaddr 
= 0x0, len = 0x100, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, 
flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 19959, file offset = 512, start blkaddr 
= 0x0, len = 0x100, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, 
flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 19959, file offset = 768, start blkaddr 
= 0x0, len = 0x60, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, 
flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 19959, file offset = 1882, start blkaddr 
= 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, 
flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 19959, file offset = 2900, start blkaddr 
= 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, 
flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 19959, file offset = 1039224, start 
blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice 
= 0, flag = 1, err = 0
f2fs_map_blocks: dev = (254,54), ino = 19959, file offset = 2075548, start 
blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice 
= 0, flag = 1, err = 0

Signed-off-by: zangyangyang1 <zangyangya...@xiaomi.com>
---
 fs/f2fs/data.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index ee5614324df0..a7e82994e230 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1526,7 +1526,7 @@ static bool map_is_mergeable(struct f2fs_sb_info *sbi,
                return true;
        if (flag == F2FS_GET_BLOCK_PRE_DIO)
                return true;
-       if (flag == F2FS_GET_BLOCK_DIO &&
+       if ((flag == F2FS_GET_BLOCK_DIO || flag == F2FS_GET_BLOCK_FIEMAP) &&
                map->m_pblk == NULL_ADDR && blkaddr == NULL_ADDR)
                return true;
        return false;
@@ -1648,11 +1648,8 @@ int f2fs_map_blocks(struct inode *inode, struct 
f2fs_map_blocks *map, int flag)
                        map->m_pblk = 0;
                        goto sync_out;
                case F2FS_GET_BLOCK_FIEMAP:
-                       if (blkaddr == NULL_ADDR) {
-                               if (map->m_next_pgofs)
-                                       *map->m_next_pgofs = pgofs + 1;
-                               goto sync_out;
-                       }
+                       if (blkaddr == NULL_ADDR && map->m_next_pgofs)
+                               *map->m_next_pgofs = pgofs + 1;
                        break;
                case F2FS_GET_BLOCK_DIO:
                        if (map->m_next_pgofs)
@@ -1676,8 +1673,12 @@ int f2fs_map_blocks(struct inode *inode, struct 
f2fs_map_blocks *map, int flag)
                /* reserved delalloc block should be mapped for fiemap. */
                if (blkaddr == NEW_ADDR)
                        map->m_flags |= F2FS_MAP_DELALLOC;
-               /* DIO READ and hole case, should not map the blocks. */
-               if (!(flag == F2FS_GET_BLOCK_DIO && is_hole && 
!map->m_may_create))
+               /*
+                * DIO READ with hole case and fiemap with NULL address case,
+                * should not map the blocks.
+                */
+               if (!((flag == F2FS_GET_BLOCK_DIO && is_hole && 
!map->m_may_create) ||
+                   (flag == F2FS_GET_BLOCK_FIEMAP && blkaddr == NULL_ADDR)))
                        map->m_flags |= F2FS_MAP_MAPPED;

                map->m_pblk = blkaddr;
--
2.43.2

#/******±¾Óʼþ¼°Æä¸½¼þº¬ÓÐСÃ×¹«Ë¾µÄ±£ÃÜÐÅÏ¢£¬½öÏÞÓÚ·¢Ë͸øÉÏÃæµØÖ·ÖÐÁгöµÄ¸öÈË»òȺ×é¡£½ûÖ¹ÈÎºÎÆäËûÈËÒÔÈκÎÐÎʽʹÓ㨰üÀ¨µ«²»ÏÞÓÚÈ«²¿»ò²¿·ÖµØÐ¹Â¶¡¢¸´ÖÆ¡¢»òÉ¢·¢£©±¾ÓʼþÖеÄÐÅÏ¢¡£Èç¹ûÄú´íÊÕÁ˱¾Óʼþ£¬ÇëÄúÁ¢¼´µç»°»òÓʼþ֪ͨ·¢¼þÈ˲¢É¾³ý±¾Óʼþ£¡
 This e-mail and its attachments contain confidential information from XIAOMI, 
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 receive this 
e-mail in error, please notify the sender by phone or email immediately and 
delete it!******/#

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

Reply via email to