f2fs: merge two uchar variable in struct node_info to reduce memory cost
authorChao Yu <chao2.yu@samsung.com>
Thu, 18 Dec 2014 09:37:21 +0000 (17:37 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sat, 10 Jan 2015 01:02:23 +0000 (17:02 -0800)
This patch moves one member of struct nat_entry: _flag_ to struct node_info,
so _version_ in struct node_info and _flag_ which are unsigned char type will
merge to one 32-bit space in register/memory. So the size of nat_entry will be
reduced from 28 bytes to 24 bytes (for 64-bit machine, reduce its size from 40
bytes to 32 bytes) and then slab memory using by f2fs will be reduced.

changes from v2:
 o update description of memory usage gain for 64-bit machine suggested by
   Changman Lee.
changes from v1:
 o introduce inline copy_node_info() to copy valid data from node info suggested
   by Jaegeuk Kim, it can avoid bug.

Reviewed-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/node.c
fs/f2fs/node.h

index cabecee88377fefed9dc3ffa3302121d123a9375..e565b9638971a676763367f929f572347b5626ef 100644 (file)
@@ -269,7 +269,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni,
        e = __lookup_nat_cache(nm_i, ni->nid);
        if (!e) {
                e = grab_nat_entry(nm_i, ni->nid);
-               e->ni = *ni;
+               copy_node_info(&e->ni, ni);
                f2fs_bug_on(sbi, ni->blk_addr == NEW_ADDR);
        } else if (new_blkaddr == NEW_ADDR) {
                /*
@@ -277,7 +277,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni,
                 * previous nat entry can be remained in nat cache.
                 * So, reinitialize it with new information.
                 */
-               e->ni = *ni;
+               copy_node_info(&e->ni, ni);
                f2fs_bug_on(sbi, ni->blk_addr != NULL_ADDR);
        }
 
index 036b887176ff0d016cf4b60923373d093d3628cb..fa6f95968b425ec609f87615c855927f04f422cd 100644 (file)
 /* return value for read_node_page */
 #define LOCKED_PAGE    1
 
+/* For flag in struct node_info */
+enum {
+       IS_CHECKPOINTED,        /* is it checkpointed before? */
+       HAS_FSYNCED_INODE,      /* is the inode fsynced before? */
+       HAS_LAST_FSYNC,         /* has the latest node fsync mark? */
+       IS_DIRTY,               /* this nat entry is dirty? */
+};
+
 /*
  * For node information
  */
@@ -37,18 +45,11 @@ struct node_info {
        nid_t ino;              /* inode number of the node's owner */
        block_t blk_addr;       /* block address of the node */
        unsigned char version;  /* version of the node */
-};
-
-enum {
-       IS_CHECKPOINTED,        /* is it checkpointed before? */
-       HAS_FSYNCED_INODE,      /* is the inode fsynced before? */
-       HAS_LAST_FSYNC,         /* has the latest node fsync mark? */
-       IS_DIRTY,               /* this nat entry is dirty? */
+       unsigned char flag;     /* for node information bits */
 };
 
 struct nat_entry {
        struct list_head list;  /* for clean or dirty nat list */
-       unsigned char flag;     /* for node information bits */
        struct node_info ni;    /* in-memory node information */
 };
 
@@ -63,20 +64,30 @@ struct nat_entry {
 
 #define inc_node_version(version)      (++version)
 
+static inline void copy_node_info(struct node_info *dst,
+                                               struct node_info *src)
+{
+       dst->nid = src->nid;
+       dst->ino = src->ino;
+       dst->blk_addr = src->blk_addr;
+       dst->version = src->version;
+       /* should not copy flag here */
+}
+
 static inline void set_nat_flag(struct nat_entry *ne,
                                unsigned int type, bool set)
 {
        unsigned char mask = 0x01 << type;
        if (set)
-               ne->flag |= mask;
+               ne->ni.flag |= mask;
        else
-               ne->flag &= ~mask;
+               ne->ni.flag &= ~mask;
 }
 
 static inline bool get_nat_flag(struct nat_entry *ne, unsigned int type)
 {
        unsigned char mask = 0x01 << type;
-       return ne->flag & mask;
+       return ne->ni.flag & mask;
 }
 
 static inline void nat_reset_flag(struct nat_entry *ne)
This page took 0.03179 seconds and 5 git commands to generate.