Skip to contentSkip to conversation

f2fs: introduce F2FS_MAX_BLOCKS

PATCH In review Chao Yu 2 participants 4 messages Dec 29, 2015 – Dec 30, 2015 F2FS file system

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs: introduce F2FS_MAX_BLOCKS

Introduce a macro named F2FS_MAX_BLOCKS to indicate maximum block index in f2fs, it could be used to avoid unneeded calculation in runtime.

---
 fs/f2fs/data.c          |  2 +-
 fs/f2fs/f2fs.h          |  1 -
 fs/f2fs/super.c         | 19 ++-----------------
 include/linux/f2fs_fs.h |  5 +++++
 4 files changed, 8 insertions(+), 19 deletions(-)
fs/f2fs/data.c +1 -1
index 7175d33..a366a4c 100644
@@ -762,7 +762,7 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock,
 			struct buffer_head *bh_result, int create)
 {
 	/* Block number less than F2FS MAX BLOCKS */
-	if (unlikely(iblock > max_file_size(0)))
+	if (unlikely(iblock > F2FS_MAX_BLOCKS))
 		return -EFBIG;
 
 	return __get_data_block(inode, iblock, bh_result, create,
fs/f2fs/f2fs.h +0 -1
index 9ba6a09..95c6f38 100644
@@ -1731,7 +1731,6 @@ static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
  * super.c
  */
 int f2fs_commit_super(struct f2fs_sb_info *, bool);
-loff_t max_file_size(unsigned bits);
 int f2fs_sync_fs(struct super_block *, int);
 extern __printf(3, 4)
 void f2fs_msg(struct super_block *, const char *, const char *, ...);
fs/f2fs/super.c +2 -17
index f474355..5f7e632 100644
@@ -909,24 +909,9 @@ static const struct export_operations f2fs_export_ops = {
 	.get_parent = f2fs_get_parent,
 };
 
-loff_t max_file_size(unsigned bits)
+static loff_t max_file_size(unsigned bits)
 {
-	loff_t result = (DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS);
-	loff_t leaf_count = ADDRS_PER_BLOCK;
-
-	/* two direct node blocks */
-	result += (leaf_count * 2);
-
-	/* two indirect node blocks */
-	leaf_count *= NIDS_PER_BLOCK;
-	result += (leaf_count * 2);
-
-	/* one double indirect node block */
-	leaf_count *= NIDS_PER_BLOCK;
-	result += leaf_count;
-
-	result <<= bits;
-	return result;
+	return ((loff_t)F2FS_MAX_BLOCKS << bits);
 }
 
 static inline bool sanity_check_area_boundary(struct super_block *sb,
include/linux/f2fs_fs.h +5 -0
index e59c3be..814c471 100644
@@ -189,6 +189,11 @@ struct f2fs_extent {
 #define F2FS_DATA_EXIST		0x08	/* file inline data exist flag */
 #define F2FS_INLINE_DOTS	0x10	/* file having implicit dot dentries */
 
+#define F2FS_MAX_BLOCKS		((DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS) + \
+				ADDRS_PER_BLOCK * 2 + ADDRS_PER_BLOCK * \
+				NIDS_PER_BLOCK * 2 + ADDRS_PER_BLOCK * \
+				NIDS_PER_BLOCK * NIDS_PER_BLOCK)
+
 #define MAX_INLINE_DATA		(sizeof(__le32) * (DEF_ADDRS_PER_INODE - \
 						F2FS_INLINE_XATTR_ADDRS - 1))
 
Signature · 1 line
2.6.3
maintainer
#1 lore raw

Hi Chao,

Quoted 2 lines · Chao Yu

Introduce a macro named F2FS_MAX_BLOCKS to indicate maximum block index in f2fs, it could be used to avoid unneeded calculation in runtime.

It's not so different from previous one.

How about adding something like:

static loff_t max_file_size(unsigned bits)
{
}

...

sbi->max_file_blocks = max_file_size(0);
sb->max_file_size =

	sbi->max_file_blocks << le32_to_cpu(raw_super->log_blocksize);

...

Thanks,

Quoted 84 lines
---
 fs/f2fs/data.c          |  2 +-
 fs/f2fs/f2fs.h          |  1 -
 fs/f2fs/super.c         | 19 ++-----------------
 include/linux/f2fs_fs.h |  5 +++++
 4 files changed, 8 insertions(+), 19 deletions(-)
fs/f2fs/data.c +1 -1
index 7175d33..a366a4c 100644
@@ -762,7 +762,7 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock,
 			struct buffer_head *bh_result, int create)
 {
 	/* Block number less than F2FS MAX BLOCKS */
-	if (unlikely(iblock > max_file_size(0)))
+	if (unlikely(iblock > F2FS_MAX_BLOCKS))
 		return -EFBIG;
 
 	return __get_data_block(inode, iblock, bh_result, create,
fs/f2fs/f2fs.h +0 -1
index 9ba6a09..95c6f38 100644
@@ -1731,7 +1731,6 @@ static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
  * super.c
  */
 int f2fs_commit_super(struct f2fs_sb_info *, bool);
-loff_t max_file_size(unsigned bits);
 int f2fs_sync_fs(struct super_block *, int);
 extern __printf(3, 4)
 void f2fs_msg(struct super_block *, const char *, const char *, ...);
fs/f2fs/super.c +2 -17
index f474355..5f7e632 100644
@@ -909,24 +909,9 @@ static const struct export_operations f2fs_export_ops = {
 	.get_parent = f2fs_get_parent,
 };
 
-loff_t max_file_size(unsigned bits)
+static loff_t max_file_size(unsigned bits)
 {
-	loff_t result = (DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS);
-	loff_t leaf_count = ADDRS_PER_BLOCK;
-
-	/* two direct node blocks */
-	result += (leaf_count * 2);
-
-	/* two indirect node blocks */
-	leaf_count *= NIDS_PER_BLOCK;
-	result += (leaf_count * 2);
-
-	/* one double indirect node block */
-	leaf_count *= NIDS_PER_BLOCK;
-	result += leaf_count;
-
-	result <<= bits;
-	return result;
+	return ((loff_t)F2FS_MAX_BLOCKS << bits);
 }
 
 static inline bool sanity_check_area_boundary(struct super_block *sb,
include/linux/f2fs_fs.h +5 -0
index e59c3be..814c471 100644
@@ -189,6 +189,11 @@ struct f2fs_extent {
 #define F2FS_DATA_EXIST		0x08	/* file inline data exist flag */
 #define F2FS_INLINE_DOTS	0x10	/* file having implicit dot dentries */
 
+#define F2FS_MAX_BLOCKS		((DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS) + \
+				ADDRS_PER_BLOCK * 2 + ADDRS_PER_BLOCK * \
+				NIDS_PER_BLOCK * 2 + ADDRS_PER_BLOCK * \
+				NIDS_PER_BLOCK * NIDS_PER_BLOCK)
+
 #define MAX_INLINE_DATA		(sizeof(__le32) * (DEF_ADDRS_PER_INODE - \
 						F2FS_INLINE_XATTR_ADDRS - 1))
 
Signature · 1 line
2.6.3
author
#2 lore raw

Hi Jaegeuk,

Quoted 7 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Wednesday, December 30, 2015 9:14 AM
To: Chao Yu
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] f2fs: introduce F2FS_MAX_BLOCKS

Quoted 7 lines

Hi Chao,

Quoted 2 lines · Chao Yu

Introduce a macro named F2FS_MAX_BLOCKS to indicate maximum block index in f2fs, it could be used to avoid unneeded calculation in runtime.

It's not so different from previous one.

Yes, just save some time of calculation in max_file_size if it is used in bmap frequently.

Quoted 4 lines

How about adding something like:

static loff_t max_file_size(unsigned bits)

@bits will no longer be used, how about remove this parameter?

Quoted 6 lines

{
}

...

sbi->max_file_blocks = max_file_size(0);

If max_file_size return max block index of file, how about rename it to max_file_blocks() for readability?

Thanks,

Quoted 92 lines

sb->max_file_size =

	sbi->max_file_blocks << le32_to_cpu(raw_super->log_blocksize);

...

Thanks,

fs/f2fs/f2fs.h static inline int f2fs_add_link(struct dentry *dentry, struct inode

Quoted 27 lines
---
 fs/f2fs/data.c          |  2 +-
 fs/f2fs/f2fs.h          |  1 -
 fs/f2fs/super.c         | 19 ++-----------------
 include/linux/f2fs_fs.h |  5 +++++
 4 files changed, 8 insertions(+), 19 deletions(-)
fs/f2fs/data.c +1 -1
index 7175d33..a366a4c 100644
@@ -762,7 +762,7 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock,
 			struct buffer_head *bh_result, int create)
 {
 	/* Block number less than F2FS MAX BLOCKS */
-	if (unlikely(iblock > max_file_size(0)))
+	if (unlikely(iblock > F2FS_MAX_BLOCKS))
 		return -EFBIG;
 
 	return __get_data_block(inode, iblock, bh_result, create,
fs/f2fs/f2fs.h +0 -0
index 9ba6a09..95c6f38 100644
@@ -1731,7 +1731,6 @@ static inline int f2fs_add_link(struct dentry *dentry, struct inode

*inode)

Quoted 57 lines
fs/f2fs/f2fs.h +0 -1
  * super.c
  */
 int f2fs_commit_super(struct f2fs_sb_info *, bool);
-loff_t max_file_size(unsigned bits);
 int f2fs_sync_fs(struct super_block *, int);
 extern __printf(3, 4)
 void f2fs_msg(struct super_block *, const char *, const char *, ...);
fs/f2fs/super.c +2 -17
index f474355..5f7e632 100644
@@ -909,24 +909,9 @@ static const struct export_operations f2fs_export_ops = {
 	.get_parent = f2fs_get_parent,
 };
 
-loff_t max_file_size(unsigned bits)
+static loff_t max_file_size(unsigned bits)
 {
-	loff_t result = (DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS);
-	loff_t leaf_count = ADDRS_PER_BLOCK;
-
-	/* two direct node blocks */
-	result += (leaf_count * 2);
-
-	/* two indirect node blocks */
-	leaf_count *= NIDS_PER_BLOCK;
-	result += (leaf_count * 2);
-
-	/* one double indirect node block */
-	leaf_count *= NIDS_PER_BLOCK;
-	result += leaf_count;
-
-	result <<= bits;
-	return result;
+	return ((loff_t)F2FS_MAX_BLOCKS << bits);
 }
 
 static inline bool sanity_check_area_boundary(struct super_block *sb,
include/linux/f2fs_fs.h +5 -1
index e59c3be..814c471 100644
@@ -189,6 +189,11 @@ struct f2fs_extent {
 #define F2FS_DATA_EXIST		0x08	/* file inline data exist flag */
 #define F2FS_INLINE_DOTS	0x10	/* file having implicit dot dentries */
 
+#define F2FS_MAX_BLOCKS		((DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS) + \
+				ADDRS_PER_BLOCK * 2 + ADDRS_PER_BLOCK * \
+				NIDS_PER_BLOCK * 2 + ADDRS_PER_BLOCK * \
+				NIDS_PER_BLOCK * NIDS_PER_BLOCK)
+
 #define MAX_INLINE_DATA		(sizeof(__le32) * (DEF_ADDRS_PER_INODE - \
 						F2FS_INLINE_XATTR_ADDRS - 1))
 
--

2.6.3

maintainer
#3 lore raw

Hi Chao,

Quoted 30 lines · Chao Yu

Hi Jaegeuk,

Quoted 7 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Wednesday, December 30, 2015 9:14 AM
To: Chao Yu
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] f2fs: introduce F2FS_MAX_BLOCKS

Quoted 7 lines

Hi Chao,

Quoted 2 lines · Chao Yu

Introduce a macro named F2FS_MAX_BLOCKS to indicate maximum block index in f2fs, it could be used to avoid unneeded calculation in runtime.

It's not so different from previous one.

Yes, just save some time of calculation in max_file_size if it is used in bmap frequently.

Quoted 4 lines

How about adding something like:

static loff_t max_file_size(unsigned bits)

@bits will no longer be used, how about remove this parameter?

Quoted 3 lines

{
}

Quoted 6 lines
Quoted 3 lines

...

sbi->max_file_blocks = max_file_size(0);

If max_file_size return max block index of file, how about rename it to max_file_blocks() for readability?

Fairly agreed.

Thanks,

Quoted 95 lines

Thanks,

Quoted 92 lines

sb->max_file_size =

	sbi->max_file_blocks << le32_to_cpu(raw_super->log_blocksize);

...

Thanks,

fs/f2fs/f2fs.h static inline int f2fs_add_link(struct dentry *dentry, struct inode

Quoted 27 lines
---
 fs/f2fs/data.c          |  2 +-
 fs/f2fs/f2fs.h          |  1 -
 fs/f2fs/super.c         | 19 ++-----------------
 include/linux/f2fs_fs.h |  5 +++++
 4 files changed, 8 insertions(+), 19 deletions(-)
fs/f2fs/data.c +1 -1
index 7175d33..a366a4c 100644
@@ -762,7 +762,7 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock,
 			struct buffer_head *bh_result, int create)
 {
 	/* Block number less than F2FS MAX BLOCKS */
-	if (unlikely(iblock > max_file_size(0)))
+	if (unlikely(iblock > F2FS_MAX_BLOCKS))
 		return -EFBIG;
 
 	return __get_data_block(inode, iblock, bh_result, create,
fs/f2fs/f2fs.h +0 -0
index 9ba6a09..95c6f38 100644
@@ -1731,7 +1731,6 @@ static inline int f2fs_add_link(struct dentry *dentry, struct inode

*inode)

Quoted 57 lines
fs/f2fs/f2fs.h +0 -1
  * super.c
  */
 int f2fs_commit_super(struct f2fs_sb_info *, bool);
-loff_t max_file_size(unsigned bits);
 int f2fs_sync_fs(struct super_block *, int);
 extern __printf(3, 4)
 void f2fs_msg(struct super_block *, const char *, const char *, ...);
fs/f2fs/super.c +2 -17
index f474355..5f7e632 100644
@@ -909,24 +909,9 @@ static const struct export_operations f2fs_export_ops = {
 	.get_parent = f2fs_get_parent,
 };
 
-loff_t max_file_size(unsigned bits)
+static loff_t max_file_size(unsigned bits)
 {
-	loff_t result = (DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS);
-	loff_t leaf_count = ADDRS_PER_BLOCK;
-
-	/* two direct node blocks */
-	result += (leaf_count * 2);
-
-	/* two indirect node blocks */
-	leaf_count *= NIDS_PER_BLOCK;
-	result += (leaf_count * 2);
-
-	/* one double indirect node block */
-	leaf_count *= NIDS_PER_BLOCK;
-	result += leaf_count;
-
-	result <<= bits;
-	return result;
+	return ((loff_t)F2FS_MAX_BLOCKS << bits);
 }
 
 static inline bool sanity_check_area_boundary(struct super_block *sb,
include/linux/f2fs_fs.h +5 -1
index e59c3be..814c471 100644
@@ -189,6 +189,11 @@ struct f2fs_extent {
 #define F2FS_DATA_EXIST		0x08	/* file inline data exist flag */
 #define F2FS_INLINE_DOTS	0x10	/* file having implicit dot dentries */
 
+#define F2FS_MAX_BLOCKS		((DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS) + \
+				ADDRS_PER_BLOCK * 2 + ADDRS_PER_BLOCK * \
+				NIDS_PER_BLOCK * 2 + ADDRS_PER_BLOCK * \
+				NIDS_PER_BLOCK * NIDS_PER_BLOCK)
+
 #define MAX_INLINE_DATA		(sizeof(__le32) * (DEF_ADDRS_PER_INODE - \
 						F2FS_INLINE_XATTR_ADDRS - 1))
 
--

2.6.3