f2fs: align memory boundary for bitops
authorJaegeuk Kim <jaegeuk@kernel.org>
Sat, 10 Mar 2018 01:42:28 +0000 (17:42 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sun, 8 Apr 2018 11:14:24 +0000 (04:14 -0700)
For example, in arm64, free_nid_bitmap should be aligned to word size in order
to use bit operations.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/node.c
include/linux/f2fs_fs.h

index 88f2b420de27906878430c0815e3b95b944f15fb..641b4b98d373aca4ff31f70c3a8935050a226b9b 100644 (file)
@@ -766,7 +766,7 @@ struct f2fs_nm_info {
        unsigned int nid_cnt[MAX_NID_STATE];    /* the number of free node id */
        spinlock_t nid_list_lock;       /* protect nid lists ops */
        struct mutex build_lock;        /* lock for build free nids */
-       unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE];
+       unsigned char **free_nid_bitmap;
        unsigned char *nat_block_bitmap;
        unsigned short *free_nid_count; /* free nid count of NAT block */
 
index 5ed28628d790082234ebce0f9e393de2a65107c6..91e31f7f7a4b471fc2cc0478c3d59257eb5770b3 100644 (file)
@@ -2727,12 +2727,20 @@ static int init_node_manager(struct f2fs_sb_info *sbi)
 static int init_free_nid_cache(struct f2fs_sb_info *sbi)
 {
        struct f2fs_nm_info *nm_i = NM_I(sbi);
+       int i;
 
-       nm_i->free_nid_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks *
-                                       NAT_ENTRY_BITMAP_SIZE, GFP_KERNEL);
+       nm_i->free_nid_bitmap = f2fs_kzalloc(sbi, nm_i->nat_blocks *
+                               sizeof(unsigned char *), GFP_KERNEL);
        if (!nm_i->free_nid_bitmap)
                return -ENOMEM;
 
+       for (i = 0; i < nm_i->nat_blocks; i++) {
+               nm_i->free_nid_bitmap[i] = f2fs_kvzalloc(sbi,
+                               NAT_ENTRY_BITMAP_SIZE_ALIGNED, GFP_KERNEL);
+               if (!nm_i->free_nid_bitmap)
+                       return -ENOMEM;
+       }
+
        nm_i->nat_block_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks / 8,
                                                                GFP_KERNEL);
        if (!nm_i->nat_block_bitmap)
@@ -2823,7 +2831,13 @@ void destroy_node_manager(struct f2fs_sb_info *sbi)
        up_write(&nm_i->nat_tree_lock);
 
        kvfree(nm_i->nat_block_bitmap);
-       kvfree(nm_i->free_nid_bitmap);
+       if (nm_i->free_nid_bitmap) {
+               int i;
+
+               for (i = 0; i < nm_i->nat_blocks; i++)
+                       kvfree(nm_i->free_nid_bitmap[i]);
+               kfree(nm_i->free_nid_bitmap);
+       }
        kvfree(nm_i->free_nid_count);
 
        kfree(nm_i->nat_bitmap);
index 124787e8db58a06e5399eb68d2e15d006de7d2f7..aa5db8b5521a589ae48cebd7c6119e315f45a460 100644 (file)
@@ -305,6 +305,10 @@ struct f2fs_node {
  */
 #define NAT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_nat_entry))
 #define NAT_ENTRY_BITMAP_SIZE  ((NAT_ENTRY_PER_BLOCK + 7) / 8)
+#define NAT_ENTRY_BITMAP_SIZE_ALIGNED                          \
+       ((NAT_ENTRY_BITMAP_SIZE + BITS_PER_LONG - 1) /          \
+       BITS_PER_LONG * BITS_PER_LONG)
+
 
 struct f2fs_nat_entry {
        __u8 version;           /* latest version of cached nat entry */