Browse Source

UBIFS: use bit-fields to store compression type

Save a 4 bytes of RAM per 'struct inode' by stroring inode
compression type in bit-filed, instead of using 'int'.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Artem Bityutskiy 16 năm trước cách đây
mục cha
commit
a1dc080c27
2 tập tin đã thay đổi với 11 bổ sung3 xóa
  1. 8 0
      fs/ubifs/super.c
  2. 3 3
      fs/ubifs/ubifs.h

+ 8 - 0
fs/ubifs/super.c

@@ -2020,6 +2020,14 @@ static int __init ubifs_init(void)
 	BUILD_BUG_ON(UBIFS_INO_NODE_SZ != 160);
 	BUILD_BUG_ON(UBIFS_INO_NODE_SZ != 160);
 	BUILD_BUG_ON(UBIFS_REF_NODE_SZ != 64);
 	BUILD_BUG_ON(UBIFS_REF_NODE_SZ != 64);
 
 
+	/*
+	 * We use 2 bit wide bit-fields to store compression type, which should
+	 * be amended if more compressors are added. The bit-fields are:
+	 * @compr_type in 'struct ubifs_inode' and @default_compr in
+	 * 'struct ubifs_info'.
+	 */
+	BUILD_BUG_ON(UBIFS_COMPR_TYPES_CNT > 4);
+
 	/*
 	/*
 	 * We require that PAGE_CACHE_SIZE is greater-than-or-equal-to
 	 * We require that PAGE_CACHE_SIZE is greater-than-or-equal-to
 	 * UBIFS_BLOCK_SIZE. It is assumed that both are powers of 2.
 	 * UBIFS_BLOCK_SIZE. It is assumed that both are powers of 2.

+ 3 - 3
fs/ubifs/ubifs.h

@@ -386,12 +386,12 @@ struct ubifs_inode {
 	unsigned int dirty:1;
 	unsigned int dirty:1;
 	unsigned int xattr:1;
 	unsigned int xattr:1;
 	unsigned int bulk_read:1;
 	unsigned int bulk_read:1;
+	unsigned int compr_type:2;
 	struct mutex ui_mutex;
 	struct mutex ui_mutex;
 	spinlock_t ui_lock;
 	spinlock_t ui_lock;
 	loff_t synced_i_size;
 	loff_t synced_i_size;
 	loff_t ui_size;
 	loff_t ui_size;
 	int flags;
 	int flags;
-	int compr_type;
 	pgoff_t last_page_read;
 	pgoff_t last_page_read;
 	pgoff_t read_in_a_row;
 	pgoff_t read_in_a_row;
 	int data_len;
 	int data_len;
@@ -946,6 +946,7 @@ struct ubifs_mount_opts {
  * @no_chk_data_crc: do not check CRCs when reading data nodes (except during
  * @no_chk_data_crc: do not check CRCs when reading data nodes (except during
  *                   recovery)
  *                   recovery)
  * @bulk_read: enable bulk-reads
  * @bulk_read: enable bulk-reads
+ * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
  *
  *
  * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and
  * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and
  *             @calc_idx_sz
  *             @calc_idx_sz
@@ -986,7 +987,6 @@ struct ubifs_mount_opts {
  * @main_lebs: count of LEBs in the main area
  * @main_lebs: count of LEBs in the main area
  * @main_first: first LEB of the main area
  * @main_first: first LEB of the main area
  * @main_bytes: main area size in bytes
  * @main_bytes: main area size in bytes
- * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
  *
  *
  * @key_hash_type: type of the key hash
  * @key_hash_type: type of the key hash
  * @key_hash: direntry key hash function
  * @key_hash: direntry key hash function
@@ -1196,6 +1196,7 @@ struct ubifs_info {
 	unsigned int big_lpt:1;
 	unsigned int big_lpt:1;
 	unsigned int no_chk_data_crc:1;
 	unsigned int no_chk_data_crc:1;
 	unsigned int bulk_read:1;
 	unsigned int bulk_read:1;
+	unsigned int default_compr:2;
 
 
 	struct mutex tnc_mutex;
 	struct mutex tnc_mutex;
 	struct ubifs_zbranch zroot;
 	struct ubifs_zbranch zroot;
@@ -1237,7 +1238,6 @@ struct ubifs_info {
 	int main_lebs;
 	int main_lebs;
 	int main_first;
 	int main_first;
 	long long main_bytes;
 	long long main_bytes;
-	int default_compr;
 
 
 	uint8_t key_hash_type;
 	uint8_t key_hash_type;
 	uint32_t (*key_hash)(const char *str, int len);
 	uint32_t (*key_hash)(const char *str, int len);