Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

f2fs: align memory boundary for bitops

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>

+22 -4
+1 -1
fs/f2fs/f2fs.h
··· 766 766 unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 767 767 spinlock_t nid_list_lock; /* protect nid lists ops */ 768 768 struct mutex build_lock; /* lock for build free nids */ 769 - unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 769 + unsigned char **free_nid_bitmap; 770 770 unsigned char *nat_block_bitmap; 771 771 unsigned short *free_nid_count; /* free nid count of NAT block */ 772 772
+17 -3
fs/f2fs/node.c
··· 2708 2708 static int init_free_nid_cache(struct f2fs_sb_info *sbi) 2709 2709 { 2710 2710 struct f2fs_nm_info *nm_i = NM_I(sbi); 2711 + int i; 2711 2712 2712 - nm_i->free_nid_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks * 2713 - NAT_ENTRY_BITMAP_SIZE, GFP_KERNEL); 2713 + nm_i->free_nid_bitmap = f2fs_kzalloc(sbi, nm_i->nat_blocks * 2714 + sizeof(unsigned char *), GFP_KERNEL); 2714 2715 if (!nm_i->free_nid_bitmap) 2715 2716 return -ENOMEM; 2717 + 2718 + for (i = 0; i < nm_i->nat_blocks; i++) { 2719 + nm_i->free_nid_bitmap[i] = f2fs_kvzalloc(sbi, 2720 + NAT_ENTRY_BITMAP_SIZE_ALIGNED, GFP_KERNEL); 2721 + if (!nm_i->free_nid_bitmap) 2722 + return -ENOMEM; 2723 + } 2716 2724 2717 2725 nm_i->nat_block_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks / 8, 2718 2726 GFP_KERNEL); ··· 2812 2804 up_write(&nm_i->nat_tree_lock); 2813 2805 2814 2806 kvfree(nm_i->nat_block_bitmap); 2815 - kvfree(nm_i->free_nid_bitmap); 2807 + if (nm_i->free_nid_bitmap) { 2808 + int i; 2809 + 2810 + for (i = 0; i < nm_i->nat_blocks; i++) 2811 + kvfree(nm_i->free_nid_bitmap[i]); 2812 + kfree(nm_i->free_nid_bitmap); 2813 + } 2816 2814 kvfree(nm_i->free_nid_count); 2817 2815 2818 2816 kfree(nm_i->nat_bitmap);
+4
include/linux/f2fs_fs.h
··· 305 305 */ 306 306 #define NAT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_nat_entry)) 307 307 #define NAT_ENTRY_BITMAP_SIZE ((NAT_ENTRY_PER_BLOCK + 7) / 8) 308 + #define NAT_ENTRY_BITMAP_SIZE_ALIGNED \ 309 + ((NAT_ENTRY_BITMAP_SIZE + BITS_PER_LONG - 1) / \ 310 + BITS_PER_LONG * BITS_PER_LONG) 311 + 308 312 309 313 struct f2fs_nat_entry { 310 314 __u8 version; /* latest version of cached nat entry */