Skip to contentSkip to conversation

f2fs: simplify the way of calulating next nat address

PATCH In review Fan Li 2 participants 2 messages Jun 2, 2017 – Jun 3, 2017 1 message not in the archive F2FS file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20170602074702epcas5p2afcfc8a3bb05e1916f6d93abe1958a5a@epcas5p2.samsung.com

Fan Li

author
#1 lore raw

PATCH 1/1 f2fs: simplify the way of calulating next nat address

The index of segment which the next nat block is in has only one different bit than the current one, so to get the next nat address, we can simply alter that one bit.

---
 fs/f2fs/node.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/f2fs/node.h +1 -4
index 558048e..da0b21b 100644
@@ -224,10 +224,7 @@ static inline pgoff_t next_nat_addr(struct f2fs_sb_info *sbi,
        struct f2fs_nm_info *nm_i = NM_I(sbi);
 
        block_addr -= nm_i->nat_blkaddr;
-       if ((block_addr >> sbi->log_blocks_per_seg) % 2)
-               block_addr -= sbi->blocks_per_seg;
-       else
-               block_addr += sbi->blocks_per_seg;
+       block_addr ^= 1 << sbi->log_blocks_per_seg;
 
        return block_addr + nm_i->nat_blkaddr;
 }

--
2.7.4

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

maintainer Reviewed-by on v1 1/1
#2 lore raw
Quoted 5 lines · Fan Li

The index of segment which the next nat block is in has only one different bit than the current one, so to get the next nat address, we can simply alter that one bit.

Thanks,

Quoted 24 lines
---
 fs/f2fs/node.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/f2fs/node.h +1 -5
index 558048e..da0b21b 100644
@@ -224,10 +224,7 @@ static inline pgoff_t next_nat_addr(struct f2fs_sb_info *sbi,
        struct f2fs_nm_info *nm_i = NM_I(sbi);
 
        block_addr -= nm_i->nat_blkaddr;
-       if ((block_addr >> sbi->log_blocks_per_seg) % 2)
-               block_addr -= sbi->blocks_per_seg;
-       else
-               block_addr += sbi->blocks_per_seg;
+       block_addr ^= 1 << sbi->log_blocks_per_seg;
 
        return block_addr + nm_i->nat_blkaddr;
 }
--

2.7.4

Quoted 8 lines

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot