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

Merge tag 'for-f2fs-4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

Pull f2fs updates from Jaegeuk Kim:
"This round introduces several interesting features such as on-disk NAT
bitmaps, IO alignment, and a discard thread. And it includes a couple
of major bug fixes as below.

Enhancements:

- introduce on-disk bitmaps to avoid scanning NAT blocks when getting
free nids

- support IO alignment to prepare open-channel SSD integration in
future

- introduce a discard thread to avoid long latency during checkpoint
and fstrim

- use SSR for warm node and enable inline_xattr by default

- introduce in-memory bitmaps to check FS consistency for debugging

- improve write_begin by avoiding needless read IO

Bug fixes:

- fix broken zone_reset behavior for SMR drive

- fix wrong victim selection policy during GC

- fix missing behavior when preparing discard commands

- fix bugs in atomic write support and fiemap

- workaround to handle multiple f2fs_add_link calls having same name

... and it includes a bunch of clean-up patches as well"

* tag 'for-f2fs-4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (97 commits)
f2fs: avoid to flush nat journal entries
f2fs: avoid to issue redundant discard commands
f2fs: fix a plint compile warning
f2fs: add f2fs_drop_inode tracepoint
f2fs: Fix zoned block device support
f2fs: remove redundant set_page_dirty()
f2fs: fix to enlarge size of write_io_dummy mempool
f2fs: fix memory leak of write_io_dummy mempool during umount
f2fs: fix to update F2FS_{CP_}WB_DATA count correctly
f2fs: use MAX_FREE_NIDS for the free nids target
f2fs: introduce free nid bitmap
f2fs: new helper cur_cp_crc() getting crc in f2fs_checkpoint
f2fs: update the comment of default nr_pages to skipping
f2fs: drop the duplicate pval in f2fs_getxattr
f2fs: Don't update the xattr data that same as the exist
f2fs: kill __is_extent_same
f2fs: avoid bggc->fggc when enough free segments are avaliable after cp
f2fs: select target segment with closer temperature in SSR mode
f2fs: show simple call stack in fault injection message
f2fs: no need lock_op in f2fs_write_inline_data
...

+1969 -813
+5 -2
Documentation/filesystems/f2fs.txt
··· 125 125 disable_ext_identify Disable the extension list configured by mkfs, so f2fs 126 126 does not aware of cold files such as media files. 127 127 inline_xattr Enable the inline xattrs feature. 128 + noinline_xattr Disable the inline xattrs feature. 128 129 inline_data Enable the inline data feature: New created small(<~3.4k) 129 130 files can be written into inode block. 130 131 inline_dentry Enable the inline dir feature: data in new created 131 132 directory entries can be written into inode block. The 132 133 space of inode block which is used to store inline 133 134 dentries is limited to ~3.4k. 134 - noinline_dentry Diable the inline dentry feature. 135 + noinline_dentry Disable the inline dentry feature. 135 136 flush_merge Merge concurrent cache_flush commands as much as possible 136 137 to eliminate redundant command issues. If the underlying 137 138 device handles the cache_flush command relatively slowly, ··· 158 157 mode=%s Control block allocation mode which supports "adaptive" 159 158 and "lfs". In "lfs" mode, there should be no random 160 159 writes towards main area. 160 + io_bits=%u Set the bit size of write IO requests. It should be set 161 + with "mode=lfs". 161 162 162 163 ================================================================================ 163 164 DEBUGFS ENTRIES ··· 177 174 SYSFS ENTRIES 178 175 ================================================================================ 179 176 180 - Information about mounted f2f2 file systems can be found in 177 + Information about mounted f2fs file systems can be found in 181 178 /sys/fs/f2fs. Each mounted filesystem will have a directory in 182 179 /sys/fs/f2fs based on its device name (i.e., /sys/fs/f2fs/sda). 183 180 The files in each per-device directory are shown in table below.
+49 -21
fs/f2fs/checkpoint.c
··· 249 249 dec_page_count(sbi, F2FS_DIRTY_META); 250 250 251 251 if (wbc->for_reclaim) 252 - f2fs_submit_merged_bio_cond(sbi, NULL, page, 0, META, WRITE); 252 + f2fs_submit_merged_bio_cond(sbi, page->mapping->host, 253 + 0, page->index, META, WRITE); 253 254 254 255 unlock_page(page); 255 256 ··· 494 493 #ifdef CONFIG_F2FS_FAULT_INJECTION 495 494 if (time_to_inject(sbi, FAULT_ORPHAN)) { 496 495 spin_unlock(&im->ino_lock); 496 + f2fs_show_injection_info(FAULT_ORPHAN); 497 497 return -ENOSPC; 498 498 } 499 499 #endif ··· 683 681 return -EINVAL; 684 682 } 685 683 686 - crc = le32_to_cpu(*((__le32 *)((unsigned char *)*cp_block 687 - + crc_offset))); 684 + crc = cur_cp_crc(*cp_block); 688 685 if (!f2fs_crc_valid(sbi, crc, *cp_block, crc_offset)) { 689 686 f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value"); 690 687 return -EINVAL; ··· 892 891 F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA)); 893 892 return 0; 894 893 } 895 - fi = list_entry(head->next, struct f2fs_inode_info, dirty_list); 894 + fi = list_first_entry(head, struct f2fs_inode_info, dirty_list); 896 895 inode = igrab(&fi->vfs_inode); 897 896 spin_unlock(&sbi->inode_lock[type]); 898 897 if (inode) { ··· 925 924 spin_unlock(&sbi->inode_lock[DIRTY_META]); 926 925 return 0; 927 926 } 928 - fi = list_entry(head->next, struct f2fs_inode_info, 927 + fi = list_first_entry(head, struct f2fs_inode_info, 929 928 gdirty_list); 930 929 inode = igrab(&fi->vfs_inode); 931 930 spin_unlock(&sbi->inode_lock[DIRTY_META]); ··· 999 998 static void unblock_operations(struct f2fs_sb_info *sbi) 1000 999 { 1001 1000 up_write(&sbi->node_write); 1002 - 1003 - build_free_nids(sbi, false); 1004 1001 f2fs_unlock_all(sbi); 1005 1002 } 1006 1003 ··· 1023 1024 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1024 1025 1025 1026 spin_lock(&sbi->cp_lock); 1027 + 1028 + if (cpc->reason == CP_UMOUNT && ckpt->cp_pack_total_block_count > 1029 + sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks) 1030 + disable_nat_bits(sbi, false); 1026 1031 1027 1032 if (cpc->reason == CP_UMOUNT) 1028 1033 __set_ckpt_flags(ckpt, CP_UMOUNT_FLAG); ··· 1140 1137 1141 1138 start_blk = __start_cp_next_addr(sbi); 1142 1139 1140 + /* write nat bits */ 1141 + if (enabled_nat_bits(sbi, cpc)) { 1142 + __u64 cp_ver = cur_cp_version(ckpt); 1143 + unsigned int i; 1144 + block_t blk; 1145 + 1146 + cp_ver |= ((__u64)crc32 << 32); 1147 + *(__le64 *)nm_i->nat_bits = cpu_to_le64(cp_ver); 1148 + 1149 + blk = start_blk + sbi->blocks_per_seg - nm_i->nat_bits_blocks; 1150 + for (i = 0; i < nm_i->nat_bits_blocks; i++) 1151 + update_meta_page(sbi, nm_i->nat_bits + 1152 + (i << F2FS_BLKSIZE_BITS), blk + i); 1153 + 1154 + /* Flush all the NAT BITS pages */ 1155 + while (get_pages(sbi, F2FS_DIRTY_META)) { 1156 + sync_meta_pages(sbi, META, LONG_MAX); 1157 + if (unlikely(f2fs_cp_error(sbi))) 1158 + return -EIO; 1159 + } 1160 + } 1161 + 1143 1162 /* need to wait for end_io results */ 1144 1163 wait_on_all_pages_writeback(sbi); 1145 1164 if (unlikely(f2fs_cp_error(sbi))) ··· 1273 1248 f2fs_flush_merged_bios(sbi); 1274 1249 1275 1250 /* this is the case of multiple fstrims without any changes */ 1276 - if (cpc->reason == CP_DISCARD && !is_sbi_flag_set(sbi, SBI_IS_DIRTY)) { 1277 - f2fs_bug_on(sbi, NM_I(sbi)->dirty_nat_cnt); 1278 - f2fs_bug_on(sbi, SIT_I(sbi)->dirty_sentries); 1279 - f2fs_bug_on(sbi, prefree_segments(sbi)); 1280 - flush_sit_entries(sbi, cpc); 1281 - clear_prefree_segments(sbi, cpc); 1282 - f2fs_wait_all_discard_bio(sbi); 1283 - unblock_operations(sbi); 1284 - goto out; 1251 + if (cpc->reason == CP_DISCARD) { 1252 + if (!exist_trim_candidates(sbi, cpc)) { 1253 + unblock_operations(sbi); 1254 + goto out; 1255 + } 1256 + 1257 + if (NM_I(sbi)->dirty_nat_cnt == 0 && 1258 + SIT_I(sbi)->dirty_sentries == 0 && 1259 + prefree_segments(sbi) == 0) { 1260 + flush_sit_entries(sbi, cpc); 1261 + clear_prefree_segments(sbi, cpc); 1262 + unblock_operations(sbi); 1263 + goto out; 1264 + } 1285 1265 } 1286 1266 1287 1267 /* ··· 1298 1268 ckpt->checkpoint_ver = cpu_to_le64(++ckpt_ver); 1299 1269 1300 1270 /* write cached NAT/SIT entries to NAT/SIT area */ 1301 - flush_nat_entries(sbi); 1271 + flush_nat_entries(sbi, cpc); 1302 1272 flush_sit_entries(sbi, cpc); 1303 1273 1304 1274 /* unlock all the fs_lock[] in do_checkpoint() */ 1305 1275 err = do_checkpoint(sbi, cpc); 1306 - if (err) { 1276 + if (err) 1307 1277 release_discard_addrs(sbi); 1308 - } else { 1278 + else 1309 1279 clear_prefree_segments(sbi, cpc); 1310 - f2fs_wait_all_discard_bio(sbi); 1311 - } 1312 1280 1313 1281 unblock_operations(sbi); 1314 1282 stat_inc_cp_count(sbi->stat_info);
+143 -50
fs/f2fs/data.c
··· 55 55 int i; 56 56 57 57 #ifdef CONFIG_F2FS_FAULT_INJECTION 58 - if (time_to_inject(F2FS_P_SB(bio->bi_io_vec->bv_page), FAULT_IO)) 58 + if (time_to_inject(F2FS_P_SB(bio->bi_io_vec->bv_page), FAULT_IO)) { 59 + f2fs_show_injection_info(FAULT_IO); 59 60 bio->bi_error = -EIO; 61 + } 60 62 #endif 61 63 62 64 if (f2fs_bio_encrypted(bio)) { ··· 94 92 bio_for_each_segment_all(bvec, bio, i) { 95 93 struct page *page = bvec->bv_page; 96 94 enum count_type type = WB_DATA_TYPE(page); 95 + 96 + if (IS_DUMMY_WRITTEN_PAGE(page)) { 97 + set_page_private(page, (unsigned long)NULL); 98 + ClearPagePrivate(page); 99 + unlock_page(page); 100 + mempool_free(page, sbi->write_io_dummy); 101 + 102 + if (unlikely(bio->bi_error)) 103 + f2fs_stop_checkpoint(sbi, true); 104 + continue; 105 + } 97 106 98 107 fscrypt_pullback_bio_page(&page, true); 99 108 ··· 184 171 struct bio *bio, enum page_type type) 185 172 { 186 173 if (!is_read_io(bio_op(bio))) { 174 + unsigned int start; 175 + 187 176 if (f2fs_sb_mounted_blkzoned(sbi->sb) && 188 177 current->plug && (type == DATA || type == NODE)) 189 178 blk_finish_plug(current->plug); 179 + 180 + if (type != DATA && type != NODE) 181 + goto submit_io; 182 + 183 + start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS; 184 + start %= F2FS_IO_SIZE(sbi); 185 + 186 + if (start == 0) 187 + goto submit_io; 188 + 189 + /* fill dummy pages */ 190 + for (; start < F2FS_IO_SIZE(sbi); start++) { 191 + struct page *page = 192 + mempool_alloc(sbi->write_io_dummy, 193 + GFP_NOIO | __GFP_ZERO | __GFP_NOFAIL); 194 + f2fs_bug_on(sbi, !page); 195 + 196 + SetPagePrivate(page); 197 + set_page_private(page, (unsigned long)DUMMY_WRITTEN_PAGE); 198 + lock_page(page); 199 + if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) 200 + f2fs_bug_on(sbi, 1); 201 + } 202 + /* 203 + * In the NODE case, we lose next block address chain. So, we 204 + * need to do checkpoint in f2fs_sync_file. 205 + */ 206 + if (type == NODE) 207 + set_sbi_flag(sbi, SBI_NEED_CP); 190 208 } 209 + submit_io: 210 + if (is_read_io(bio_op(bio))) 211 + trace_f2fs_submit_read_bio(sbi->sb, type, bio); 212 + else 213 + trace_f2fs_submit_write_bio(sbi->sb, type, bio); 191 214 submit_bio(bio); 192 215 } 193 216 ··· 234 185 if (!io->bio) 235 186 return; 236 187 237 - if (is_read_io(fio->op)) 238 - trace_f2fs_submit_read_bio(io->sbi->sb, fio, io->bio); 239 - else 240 - trace_f2fs_submit_write_bio(io->sbi->sb, fio, io->bio); 241 - 242 188 bio_set_op_attrs(io->bio, fio->op, fio->op_flags); 189 + 190 + if (is_read_io(fio->op)) 191 + trace_f2fs_prepare_read_bio(io->sbi->sb, fio->type, io->bio); 192 + else 193 + trace_f2fs_prepare_write_bio(io->sbi->sb, fio->type, io->bio); 243 194 244 195 __submit_bio(io->sbi, io->bio, fio->type); 245 196 io->bio = NULL; 246 197 } 247 198 248 - static bool __has_merged_page(struct f2fs_bio_info *io, struct inode *inode, 249 - struct page *page, nid_t ino) 199 + static bool __has_merged_page(struct f2fs_bio_info *io, 200 + struct inode *inode, nid_t ino, pgoff_t idx) 250 201 { 251 202 struct bio_vec *bvec; 252 203 struct page *target; ··· 255 206 if (!io->bio) 256 207 return false; 257 208 258 - if (!inode && !page && !ino) 209 + if (!inode && !ino) 259 210 return true; 260 211 261 212 bio_for_each_segment_all(bvec, io->bio, i) { ··· 265 216 else 266 217 target = fscrypt_control_page(bvec->bv_page); 267 218 219 + if (idx != target->index) 220 + continue; 221 + 268 222 if (inode && inode == target->mapping->host) 269 - return true; 270 - if (page && page == target) 271 223 return true; 272 224 if (ino && ino == ino_of_node(target)) 273 225 return true; ··· 278 228 } 279 229 280 230 static bool has_merged_page(struct f2fs_sb_info *sbi, struct inode *inode, 281 - struct page *page, nid_t ino, 282 - enum page_type type) 231 + nid_t ino, pgoff_t idx, enum page_type type) 283 232 { 284 233 enum page_type btype = PAGE_TYPE_OF_BIO(type); 285 234 struct f2fs_bio_info *io = &sbi->write_io[btype]; 286 235 bool ret; 287 236 288 237 down_read(&io->io_rwsem); 289 - ret = __has_merged_page(io, inode, page, ino); 238 + ret = __has_merged_page(io, inode, ino, idx); 290 239 up_read(&io->io_rwsem); 291 240 return ret; 292 241 } 293 242 294 243 static void __f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, 295 - struct inode *inode, struct page *page, 296 - nid_t ino, enum page_type type, int rw) 244 + struct inode *inode, nid_t ino, pgoff_t idx, 245 + enum page_type type, int rw) 297 246 { 298 247 enum page_type btype = PAGE_TYPE_OF_BIO(type); 299 248 struct f2fs_bio_info *io; ··· 301 252 302 253 down_write(&io->io_rwsem); 303 254 304 - if (!__has_merged_page(io, inode, page, ino)) 255 + if (!__has_merged_page(io, inode, ino, idx)) 305 256 goto out; 306 257 307 258 /* change META to META_FLUSH in the checkpoint procedure */ 308 259 if (type >= META_FLUSH) { 309 260 io->fio.type = META_FLUSH; 310 261 io->fio.op = REQ_OP_WRITE; 311 - io->fio.op_flags = REQ_PREFLUSH | REQ_META | REQ_PRIO; 262 + io->fio.op_flags = REQ_META | REQ_PRIO; 312 263 if (!test_opt(sbi, NOBARRIER)) 313 - io->fio.op_flags |= REQ_FUA; 264 + io->fio.op_flags |= REQ_PREFLUSH | REQ_FUA; 314 265 } 315 266 __submit_merged_bio(io); 316 267 out: ··· 320 271 void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 321 272 int rw) 322 273 { 323 - __f2fs_submit_merged_bio(sbi, NULL, NULL, 0, type, rw); 274 + __f2fs_submit_merged_bio(sbi, NULL, 0, 0, type, rw); 324 275 } 325 276 326 277 void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, 327 - struct inode *inode, struct page *page, 328 - nid_t ino, enum page_type type, int rw) 278 + struct inode *inode, nid_t ino, pgoff_t idx, 279 + enum page_type type, int rw) 329 280 { 330 - if (has_merged_page(sbi, inode, page, ino, type)) 331 - __f2fs_submit_merged_bio(sbi, inode, page, ino, type, rw); 281 + if (has_merged_page(sbi, inode, ino, idx, type)) 282 + __f2fs_submit_merged_bio(sbi, inode, ino, idx, type, rw); 332 283 } 333 284 334 285 void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi) ··· 364 315 return 0; 365 316 } 366 317 367 - void f2fs_submit_page_mbio(struct f2fs_io_info *fio) 318 + int f2fs_submit_page_mbio(struct f2fs_io_info *fio) 368 319 { 369 320 struct f2fs_sb_info *sbi = fio->sbi; 370 321 enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); 371 322 struct f2fs_bio_info *io; 372 323 bool is_read = is_read_io(fio->op); 373 324 struct page *bio_page; 325 + int err = 0; 374 326 375 327 io = is_read ? &sbi->read_io : &sbi->write_io[btype]; 376 328 ··· 380 330 verify_block_addr(sbi, fio->new_blkaddr); 381 331 382 332 bio_page = fio->encrypted_page ? fio->encrypted_page : fio->page; 333 + 334 + /* set submitted = 1 as a return value */ 335 + fio->submitted = 1; 383 336 384 337 if (!is_read) 385 338 inc_page_count(sbi, WB_DATA_TYPE(bio_page)); ··· 395 342 __submit_merged_bio(io); 396 343 alloc_new: 397 344 if (io->bio == NULL) { 345 + if ((fio->type == DATA || fio->type == NODE) && 346 + fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { 347 + err = -EAGAIN; 348 + if (!is_read) 349 + dec_page_count(sbi, WB_DATA_TYPE(bio_page)); 350 + goto out_fail; 351 + } 398 352 io->bio = __bio_alloc(sbi, fio->new_blkaddr, 399 353 BIO_MAX_PAGES, is_read); 400 354 io->fio = *fio; ··· 415 355 416 356 io->last_block_in_bio = fio->new_blkaddr; 417 357 f2fs_trace_ios(fio, 0); 418 - 358 + out_fail: 419 359 up_write(&io->io_rwsem); 420 360 trace_f2fs_submit_page_mbio(fio->page, fio); 361 + return err; 421 362 } 422 363 423 364 static void __set_data_blkaddr(struct dnode_of_data *dn) ··· 514 453 515 454 int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index) 516 455 { 517 - struct extent_info ei; 456 + struct extent_info ei = {0,0,0}; 518 457 struct inode *inode = dn->inode; 519 458 520 459 if (f2fs_lookup_extent_cache(inode, index, &ei)) { ··· 531 470 struct address_space *mapping = inode->i_mapping; 532 471 struct dnode_of_data dn; 533 472 struct page *page; 534 - struct extent_info ei; 473 + struct extent_info ei = {0,0,0}; 535 474 int err; 536 475 struct f2fs_io_info fio = { 537 476 .sbi = F2FS_I_SB(inode), ··· 755 694 struct f2fs_map_blocks map; 756 695 int err = 0; 757 696 697 + if (is_inode_flag_set(inode, FI_NO_PREALLOC)) 698 + return 0; 699 + 758 700 map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos); 759 701 map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from)); 760 702 if (map.m_len > map.m_lblk) ··· 806 742 int err = 0, ofs = 1; 807 743 unsigned int ofs_in_node, last_ofs_in_node; 808 744 blkcnt_t prealloc; 809 - struct extent_info ei; 745 + struct extent_info ei = {0,0,0}; 810 746 block_t blkaddr; 811 747 812 748 if (!maxblocks) ··· 870 806 } 871 807 if (err) 872 808 goto sync_out; 873 - map->m_flags = F2FS_MAP_NEW; 809 + map->m_flags |= F2FS_MAP_NEW; 874 810 blkaddr = dn.data_blkaddr; 875 811 } else { 876 812 if (flag == F2FS_GET_BLOCK_BMAP) { ··· 970 906 if (!err) { 971 907 map_bh(bh, inode->i_sb, map.m_pblk); 972 908 bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags; 973 - bh->b_size = map.m_len << inode->i_blkbits; 909 + bh->b_size = (u64)map.m_len << inode->i_blkbits; 974 910 } 975 911 return err; 976 912 } ··· 1152 1088 1153 1089 prefetchw(&page->flags); 1154 1090 if (pages) { 1155 - page = list_entry(pages->prev, struct page, lru); 1091 + page = list_last_entry(pages, struct page, lru); 1156 1092 list_del(&page->lru); 1157 1093 if (add_to_page_cache_lru(page, mapping, 1158 1094 page->index, ··· 1271 1207 struct list_head *pages, unsigned nr_pages) 1272 1208 { 1273 1209 struct inode *inode = file->f_mapping->host; 1274 - struct page *page = list_entry(pages->prev, struct page, lru); 1210 + struct page *page = list_last_entry(pages, struct page, lru); 1275 1211 1276 1212 trace_f2fs_readpages(inode, page, nr_pages); 1277 1213 ··· 1352 1288 return err; 1353 1289 } 1354 1290 1355 - static int f2fs_write_data_page(struct page *page, 1356 - struct writeback_control *wbc) 1291 + static int __write_data_page(struct page *page, bool *submitted, 1292 + struct writeback_control *wbc) 1357 1293 { 1358 1294 struct inode *inode = page->mapping->host; 1359 1295 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); ··· 1371 1307 .op_flags = wbc_to_write_flags(wbc), 1372 1308 .page = page, 1373 1309 .encrypted_page = NULL, 1310 + .submitted = false, 1374 1311 }; 1375 1312 1376 1313 trace_f2fs_writepage(page, DATA); ··· 1417 1352 goto redirty_out; 1418 1353 1419 1354 err = -EAGAIN; 1420 - f2fs_lock_op(sbi); 1421 - if (f2fs_has_inline_data(inode)) 1355 + if (f2fs_has_inline_data(inode)) { 1422 1356 err = f2fs_write_inline_data(inode, page); 1357 + if (!err) 1358 + goto out; 1359 + } 1360 + f2fs_lock_op(sbi); 1423 1361 if (err == -EAGAIN) 1424 1362 err = do_write_data_page(&fio); 1425 1363 if (F2FS_I(inode)->last_disk_size < psize) ··· 1438 1370 ClearPageUptodate(page); 1439 1371 1440 1372 if (wbc->for_reclaim) { 1441 - f2fs_submit_merged_bio_cond(sbi, NULL, page, 0, DATA, WRITE); 1373 + f2fs_submit_merged_bio_cond(sbi, inode, 0, page->index, 1374 + DATA, WRITE); 1442 1375 remove_dirty_inode(inode); 1376 + submitted = NULL; 1443 1377 } 1444 1378 1445 1379 unlock_page(page); 1446 1380 f2fs_balance_fs(sbi, need_balance_fs); 1447 1381 1448 - if (unlikely(f2fs_cp_error(sbi))) 1382 + if (unlikely(f2fs_cp_error(sbi))) { 1449 1383 f2fs_submit_merged_bio(sbi, DATA, WRITE); 1384 + submitted = NULL; 1385 + } 1386 + 1387 + if (submitted) 1388 + *submitted = fio.submitted; 1450 1389 1451 1390 return 0; 1452 1391 ··· 1463 1388 return AOP_WRITEPAGE_ACTIVATE; 1464 1389 unlock_page(page); 1465 1390 return err; 1391 + } 1392 + 1393 + static int f2fs_write_data_page(struct page *page, 1394 + struct writeback_control *wbc) 1395 + { 1396 + return __write_data_page(page, NULL, wbc); 1466 1397 } 1467 1398 1468 1399 /* ··· 1487 1406 pgoff_t index; 1488 1407 pgoff_t end; /* Inclusive */ 1489 1408 pgoff_t done_index; 1409 + pgoff_t last_idx = ULONG_MAX; 1490 1410 int cycled; 1491 1411 int range_whole = 0; 1492 1412 int tag; 1493 - int nwritten = 0; 1494 1413 1495 1414 pagevec_init(&pvec, 0); 1496 1415 ··· 1527 1446 1528 1447 for (i = 0; i < nr_pages; i++) { 1529 1448 struct page *page = pvec.pages[i]; 1449 + bool submitted = false; 1530 1450 1531 1451 if (page->index > end) { 1532 1452 done = 1; ··· 1561 1479 if (!clear_page_dirty_for_io(page)) 1562 1480 goto continue_unlock; 1563 1481 1564 - ret = mapping->a_ops->writepage(page, wbc); 1482 + ret = __write_data_page(page, &submitted, wbc); 1565 1483 if (unlikely(ret)) { 1566 1484 /* 1567 1485 * keep nr_to_write, since vfs uses this to ··· 1575 1493 done_index = page->index + 1; 1576 1494 done = 1; 1577 1495 break; 1578 - } else { 1579 - nwritten++; 1496 + } else if (submitted) { 1497 + last_idx = page->index; 1580 1498 } 1581 1499 1582 1500 if (--wbc->nr_to_write <= 0 && ··· 1598 1516 if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) 1599 1517 mapping->writeback_index = done_index; 1600 1518 1601 - if (nwritten) 1519 + if (last_idx != ULONG_MAX) 1602 1520 f2fs_submit_merged_bio_cond(F2FS_M_SB(mapping), mapping->host, 1603 - NULL, 0, DATA, WRITE); 1521 + 0, last_idx, DATA, WRITE); 1604 1522 1605 1523 return ret; 1606 1524 } ··· 1673 1591 struct dnode_of_data dn; 1674 1592 struct page *ipage; 1675 1593 bool locked = false; 1676 - struct extent_info ei; 1594 + struct extent_info ei = {0,0,0}; 1677 1595 int err = 0; 1678 1596 1679 1597 /* 1680 1598 * we already allocated all the blocks, so we don't need to get 1681 1599 * the block addresses when there is no need to fill the page. 1682 1600 */ 1683 - if (!f2fs_has_inline_data(inode) && len == PAGE_SIZE) 1601 + if (!f2fs_has_inline_data(inode) && len == PAGE_SIZE && 1602 + !is_inode_flag_set(inode, FI_NO_PREALLOC)) 1684 1603 return 0; 1685 1604 1686 1605 if (f2fs_has_inline_data(inode) || ··· 1765 1682 goto fail; 1766 1683 } 1767 1684 repeat: 1768 - page = grab_cache_page_write_begin(mapping, index, flags); 1685 + /* 1686 + * Do not use grab_cache_page_write_begin() to avoid deadlock due to 1687 + * wait_for_stable_page. Will wait that below with our IO control. 1688 + */ 1689 + page = pagecache_get_page(mapping, index, 1690 + FGP_LOCK | FGP_WRITE | FGP_CREAT, GFP_NOFS); 1769 1691 if (!page) { 1770 1692 err = -ENOMEM; 1771 1693 goto fail; ··· 1802 1714 1803 1715 if (len == PAGE_SIZE || PageUptodate(page)) 1804 1716 return 0; 1717 + 1718 + if (!(pos & (PAGE_SIZE - 1)) && (pos + len) >= i_size_read(inode)) { 1719 + zero_user_segment(page, len, PAGE_SIZE); 1720 + return 0; 1721 + } 1805 1722 1806 1723 if (blkaddr == NEW_ADDR) { 1807 1724 zero_user_segment(page, 0, PAGE_SIZE); ··· 1861 1768 * let generic_perform_write() try to copy data again through copied=0. 1862 1769 */ 1863 1770 if (!PageUptodate(page)) { 1864 - if (unlikely(copied != PAGE_SIZE)) 1771 + if (unlikely(copied != len)) 1865 1772 copied = 0; 1866 1773 else 1867 1774 SetPageUptodate(page); ··· 2010 1917 if (!PageUptodate(page)) 2011 1918 SetPageUptodate(page); 2012 1919 2013 - if (f2fs_is_atomic_file(inode)) { 1920 + if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) { 2014 1921 if (!IS_ATOMIC_WRITTEN_PAGE(page)) { 2015 1922 register_inmem_page(inode, page); 2016 1923 return 1;
+26 -5
fs/f2fs/debug.c
··· 50 50 si->ndirty_files = sbi->ndirty_inode[FILE_INODE]; 51 51 si->ndirty_all = sbi->ndirty_inode[DIRTY_META]; 52 52 si->inmem_pages = get_pages(sbi, F2FS_INMEM_PAGES); 53 + si->aw_cnt = atomic_read(&sbi->aw_cnt); 54 + si->max_aw_cnt = atomic_read(&sbi->max_aw_cnt); 53 55 si->nr_wb_cp_data = get_pages(sbi, F2FS_WB_CP_DATA); 54 56 si->nr_wb_data = get_pages(sbi, F2FS_WB_DATA); 57 + if (SM_I(sbi) && SM_I(sbi)->fcc_info) 58 + si->nr_flush = 59 + atomic_read(&SM_I(sbi)->fcc_info->submit_flush); 60 + if (SM_I(sbi) && SM_I(sbi)->dcc_info) 61 + si->nr_discard = 62 + atomic_read(&SM_I(sbi)->dcc_info->submit_discard); 55 63 si->total_count = (int)sbi->user_block_count / sbi->blocks_per_seg; 56 64 si->rsvd_segs = reserved_segments(sbi); 57 65 si->overp_segs = overprovision_segments(sbi); ··· 70 62 si->inline_xattr = atomic_read(&sbi->inline_xattr); 71 63 si->inline_inode = atomic_read(&sbi->inline_inode); 72 64 si->inline_dir = atomic_read(&sbi->inline_dir); 65 + si->append = sbi->im[APPEND_INO].ino_num; 66 + si->update = sbi->im[UPDATE_INO].ino_num; 73 67 si->orphans = sbi->im[ORPHAN_INO].ino_num; 74 68 si->utilization = utilization(sbi); 75 69 ··· 193 183 /* build nm */ 194 184 si->base_mem += sizeof(struct f2fs_nm_info); 195 185 si->base_mem += __bitmap_size(sbi, NAT_BITMAP); 186 + si->base_mem += (NM_I(sbi)->nat_bits_blocks << F2FS_BLKSIZE_BITS); 187 + si->base_mem += NM_I(sbi)->nat_blocks * NAT_ENTRY_BITMAP_SIZE; 188 + si->base_mem += NM_I(sbi)->nat_blocks / 8; 196 189 197 190 get_cache: 198 191 si->cache_mem = 0; ··· 205 192 si->cache_mem += sizeof(struct f2fs_gc_kthread); 206 193 207 194 /* build merge flush thread */ 208 - if (SM_I(sbi)->cmd_control_info) 195 + if (SM_I(sbi)->fcc_info) 209 196 si->cache_mem += sizeof(struct flush_cmd_control); 197 + if (SM_I(sbi)->dcc_info) 198 + si->cache_mem += sizeof(struct discard_cmd_control); 210 199 211 200 /* free nids */ 212 201 si->cache_mem += (NM_I(sbi)->nid_cnt[FREE_NID_LIST] + ··· 269 254 si->inline_inode); 270 255 seq_printf(s, " - Inline_dentry Inode: %u\n", 271 256 si->inline_dir); 272 - seq_printf(s, " - Orphan Inode: %u\n", 273 - si->orphans); 257 + seq_printf(s, " - Orphan/Append/Update Inode: %u, %u, %u\n", 258 + si->orphans, si->append, si->update); 274 259 seq_printf(s, "\nMain area: %d segs, %d secs %d zones\n", 275 260 si->main_area_segs, si->main_area_sections, 276 261 si->main_area_zones); ··· 329 314 seq_printf(s, " - Inner Struct Count: tree: %d(%d), node: %d\n", 330 315 si->ext_tree, si->zombie_tree, si->ext_node); 331 316 seq_puts(s, "\nBalancing F2FS Async:\n"); 332 - seq_printf(s, " - inmem: %4d, wb_cp_data: %4d, wb_data: %4d\n", 333 - si->inmem_pages, si->nr_wb_cp_data, si->nr_wb_data); 317 + seq_printf(s, " - IO (CP: %4d, Data: %4d, Flush: %4d, Discard: %4d)\n", 318 + si->nr_wb_cp_data, si->nr_wb_data, 319 + si->nr_flush, si->nr_discard); 320 + seq_printf(s, " - inmem: %4d, atomic IO: %4d (Max. %4d)\n", 321 + si->inmem_pages, si->aw_cnt, si->max_aw_cnt); 334 322 seq_printf(s, " - nodes: %4d in %4d\n", 335 323 si->ndirty_node, si->node_pages); 336 324 seq_printf(s, " - dents: %4d in dirs:%4d (%4d)\n", ··· 431 413 atomic_set(&sbi->inline_inode, 0); 432 414 atomic_set(&sbi->inline_dir, 0); 433 415 atomic_set(&sbi->inplace_count, 0); 416 + 417 + atomic_set(&sbi->aw_cnt, 0); 418 + atomic_set(&sbi->max_aw_cnt, 0); 434 419 435 420 mutex_lock(&f2fs_stat_mutex); 436 421 list_add_tail(&si->stat_list, &f2fs_stat_list);
+32 -6
fs/f2fs/dir.c
··· 207 207 f2fs_put_page(dentry_page, 0); 208 208 } 209 209 210 - if (!de && room && F2FS_I(dir)->chash != namehash) { 211 - F2FS_I(dir)->chash = namehash; 212 - F2FS_I(dir)->clevel = level; 210 + /* This is to increase the speed of f2fs_create */ 211 + if (!de && room) { 212 + F2FS_I(dir)->task = current; 213 + if (F2FS_I(dir)->chash != namehash) { 214 + F2FS_I(dir)->chash = namehash; 215 + F2FS_I(dir)->clevel = level; 216 + } 213 217 } 214 218 215 219 return de; ··· 552 548 553 549 start: 554 550 #ifdef CONFIG_F2FS_FAULT_INJECTION 555 - if (time_to_inject(F2FS_I_SB(dir), FAULT_DIR_DEPTH)) 551 + if (time_to_inject(F2FS_I_SB(dir), FAULT_DIR_DEPTH)) { 552 + f2fs_show_injection_info(FAULT_DIR_DEPTH); 556 553 return -ENOSPC; 554 + } 557 555 #endif 558 556 if (unlikely(current_depth == MAX_DIR_HASH_DEPTH)) 559 557 return -ENOSPC; ··· 652 646 struct inode *inode, nid_t ino, umode_t mode) 653 647 { 654 648 struct fscrypt_name fname; 649 + struct page *page = NULL; 650 + struct f2fs_dir_entry *de = NULL; 655 651 int err; 656 652 657 653 err = fscrypt_setup_filename(dir, name, 0, &fname); 658 654 if (err) 659 655 return err; 660 656 661 - err = __f2fs_do_add_link(dir, &fname, inode, ino, mode); 662 - 657 + /* 658 + * An immature stakable filesystem shows a race condition between lookup 659 + * and create. If we have same task when doing lookup and create, it's 660 + * definitely fine as expected by VFS normally. Otherwise, let's just 661 + * verify on-disk dentry one more time, which guarantees filesystem 662 + * consistency more. 663 + */ 664 + if (current != F2FS_I(dir)->task) { 665 + de = __f2fs_find_entry(dir, &fname, &page); 666 + F2FS_I(dir)->task = NULL; 667 + } 668 + if (de) { 669 + f2fs_dentry_kunmap(dir, page); 670 + f2fs_put_page(page, 0); 671 + err = -EEXIST; 672 + } else if (IS_ERR(page)) { 673 + err = PTR_ERR(page); 674 + } else { 675 + err = __f2fs_do_add_link(dir, &fname, inode, ino, mode); 676 + } 663 677 fscrypt_free_filename(&fname); 664 678 return err; 665 679 }
+23 -29
fs/f2fs/extent_cache.c
··· 77 77 struct extent_tree *et; 78 78 nid_t ino = inode->i_ino; 79 79 80 - down_write(&sbi->extent_tree_lock); 80 + mutex_lock(&sbi->extent_tree_lock); 81 81 et = radix_tree_lookup(&sbi->extent_tree_root, ino); 82 82 if (!et) { 83 83 et = f2fs_kmem_cache_alloc(extent_tree_slab, GFP_NOFS); ··· 94 94 atomic_dec(&sbi->total_zombie_tree); 95 95 list_del_init(&et->list); 96 96 } 97 - up_write(&sbi->extent_tree_lock); 97 + mutex_unlock(&sbi->extent_tree_lock); 98 98 99 99 /* never died until evict_inode */ 100 100 F2FS_I(inode)->extent_tree = et; ··· 311 311 tmp_node = parent; 312 312 if (parent && fofs > en->ei.fofs) 313 313 tmp_node = rb_next(parent); 314 - *next_ex = tmp_node ? 315 - rb_entry(tmp_node, struct extent_node, rb_node) : NULL; 314 + *next_ex = rb_entry_safe(tmp_node, struct extent_node, rb_node); 316 315 317 316 tmp_node = parent; 318 317 if (parent && fofs < en->ei.fofs) 319 318 tmp_node = rb_prev(parent); 320 - *prev_ex = tmp_node ? 321 - rb_entry(tmp_node, struct extent_node, rb_node) : NULL; 319 + *prev_ex = rb_entry_safe(tmp_node, struct extent_node, rb_node); 322 320 return NULL; 323 321 324 322 lookup_neighbors: 325 323 if (fofs == en->ei.fofs) { 326 324 /* lookup prev node for merging backward later */ 327 325 tmp_node = rb_prev(&en->rb_node); 328 - *prev_ex = tmp_node ? 329 - rb_entry(tmp_node, struct extent_node, rb_node) : NULL; 326 + *prev_ex = rb_entry_safe(tmp_node, struct extent_node, rb_node); 330 327 } 331 328 if (fofs == en->ei.fofs + en->ei.len - 1) { 332 329 /* lookup next node for merging frontward later */ 333 330 tmp_node = rb_next(&en->rb_node); 334 - *next_ex = tmp_node ? 335 - rb_entry(tmp_node, struct extent_node, rb_node) : NULL; 331 + *next_ex = rb_entry_safe(tmp_node, struct extent_node, rb_node); 336 332 } 337 333 return en; 338 334 } ··· 348 352 } 349 353 350 354 if (next_ex && __is_front_mergeable(ei, &next_ex->ei)) { 351 - if (en) 352 - __release_extent_node(sbi, et, prev_ex); 353 355 next_ex->ei.fofs = ei->fofs; 354 356 next_ex->ei.blk = ei->blk; 355 357 next_ex->ei.len += ei->len; 358 + if (en) 359 + __release_extent_node(sbi, et, prev_ex); 360 + 356 361 en = next_ex; 357 362 } 358 363 ··· 413 416 return en; 414 417 } 415 418 416 - static unsigned int f2fs_update_extent_tree_range(struct inode *inode, 419 + static void f2fs_update_extent_tree_range(struct inode *inode, 417 420 pgoff_t fofs, block_t blkaddr, unsigned int len) 418 421 { 419 422 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); ··· 426 429 unsigned int pos = (unsigned int)fofs; 427 430 428 431 if (!et) 429 - return false; 432 + return; 430 433 431 434 trace_f2fs_update_extent_tree_range(inode, fofs, blkaddr, len); 432 435 ··· 434 437 435 438 if (is_inode_flag_set(inode, FI_NO_EXTENT)) { 436 439 write_unlock(&et->lock); 437 - return false; 440 + return; 438 441 } 439 442 440 443 prev = et->largest; ··· 489 492 if (!next_en) { 490 493 struct rb_node *node = rb_next(&en->rb_node); 491 494 492 - next_en = node ? 493 - rb_entry(node, struct extent_node, rb_node) 494 - : NULL; 495 + next_en = rb_entry_safe(node, struct extent_node, 496 + rb_node); 495 497 } 496 498 497 499 if (parts) ··· 531 535 __free_extent_tree(sbi, et); 532 536 533 537 write_unlock(&et->lock); 534 - 535 - return !__is_extent_same(&prev, &et->largest); 536 538 } 537 539 538 540 unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink) ··· 546 552 if (!atomic_read(&sbi->total_zombie_tree)) 547 553 goto free_node; 548 554 549 - if (!down_write_trylock(&sbi->extent_tree_lock)) 555 + if (!mutex_trylock(&sbi->extent_tree_lock)) 550 556 goto out; 551 557 552 558 /* 1. remove unreferenced extent tree */ ··· 568 574 goto unlock_out; 569 575 cond_resched(); 570 576 } 571 - up_write(&sbi->extent_tree_lock); 577 + mutex_unlock(&sbi->extent_tree_lock); 572 578 573 579 free_node: 574 580 /* 2. remove LRU extent entries */ 575 - if (!down_write_trylock(&sbi->extent_tree_lock)) 581 + if (!mutex_trylock(&sbi->extent_tree_lock)) 576 582 goto out; 577 583 578 584 remained = nr_shrink - (node_cnt + tree_cnt); ··· 602 608 spin_unlock(&sbi->extent_lock); 603 609 604 610 unlock_out: 605 - up_write(&sbi->extent_tree_lock); 611 + mutex_unlock(&sbi->extent_tree_lock); 606 612 out: 607 613 trace_f2fs_shrink_extent_tree(sbi, node_cnt, tree_cnt); 608 614 ··· 649 655 650 656 if (inode->i_nlink && !is_bad_inode(inode) && 651 657 atomic_read(&et->node_cnt)) { 652 - down_write(&sbi->extent_tree_lock); 658 + mutex_lock(&sbi->extent_tree_lock); 653 659 list_add_tail(&et->list, &sbi->zombie_list); 654 660 atomic_inc(&sbi->total_zombie_tree); 655 - up_write(&sbi->extent_tree_lock); 661 + mutex_unlock(&sbi->extent_tree_lock); 656 662 return; 657 663 } 658 664 ··· 660 666 node_cnt = f2fs_destroy_extent_node(inode); 661 667 662 668 /* delete extent tree entry in radix tree */ 663 - down_write(&sbi->extent_tree_lock); 669 + mutex_lock(&sbi->extent_tree_lock); 664 670 f2fs_bug_on(sbi, atomic_read(&et->node_cnt)); 665 671 radix_tree_delete(&sbi->extent_tree_root, inode->i_ino); 666 672 kmem_cache_free(extent_tree_slab, et); 667 673 atomic_dec(&sbi->total_ext_tree); 668 - up_write(&sbi->extent_tree_lock); 674 + mutex_unlock(&sbi->extent_tree_lock); 669 675 670 676 F2FS_I(inode)->extent_tree = NULL; 671 677 ··· 712 718 void init_extent_cache_info(struct f2fs_sb_info *sbi) 713 719 { 714 720 INIT_RADIX_TREE(&sbi->extent_tree_root, GFP_NOIO); 715 - init_rwsem(&sbi->extent_tree_lock); 721 + mutex_init(&sbi->extent_tree_lock); 716 722 INIT_LIST_HEAD(&sbi->extent_list); 717 723 spin_lock_init(&sbi->extent_lock); 718 724 atomic_set(&sbi->total_ext_tree, 0);
+386 -258
fs/f2fs/f2fs.h
··· 112 112 #define F2FS_HAS_FEATURE(sb, mask) \ 113 113 ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 114 114 #define F2FS_SET_FEATURE(sb, mask) \ 115 - F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) 115 + (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 116 116 #define F2FS_CLEAR_FEATURE(sb, mask) \ 117 - F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) 117 + (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 118 118 119 119 /* 120 120 * For checkpoint manager ··· 132 132 CP_DISCARD, 133 133 }; 134 134 135 - #define DEF_BATCHED_TRIM_SECTIONS 2 135 + #define DEF_BATCHED_TRIM_SECTIONS 2048 136 136 #define BATCHED_TRIM_SEGMENTS(sbi) \ 137 137 (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 138 138 #define BATCHED_TRIM_BLOCKS(sbi) \ 139 139 (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 140 + #define MAX_DISCARD_BLOCKS(sbi) \ 141 + ((1 << (sbi)->log_blocks_per_seg) * (sbi)->segs_per_sec) 142 + #define DISCARD_ISSUE_RATE 8 140 143 #define DEF_CP_INTERVAL 60 /* 60 secs */ 141 144 #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 142 145 ··· 188 185 int len; /* # of consecutive blocks of the discard */ 189 186 }; 190 187 191 - struct bio_entry { 192 - struct list_head list; 193 - struct bio *bio; 194 - struct completion event; 195 - int error; 188 + enum { 189 + D_PREP, 190 + D_SUBMIT, 191 + D_DONE, 192 + }; 193 + 194 + struct discard_cmd { 195 + struct list_head list; /* command list */ 196 + struct completion wait; /* compleation */ 197 + block_t lstart; /* logical start address */ 198 + block_t len; /* length */ 199 + struct bio *bio; /* bio */ 200 + int state; /* state */ 201 + }; 202 + 203 + struct discard_cmd_control { 204 + struct task_struct *f2fs_issue_discard; /* discard thread */ 205 + struct list_head discard_entry_list; /* 4KB discard entry list */ 206 + int nr_discards; /* # of discards in the list */ 207 + struct list_head discard_cmd_list; /* discard cmd list */ 208 + wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 209 + struct mutex cmd_lock; 210 + int max_discards; /* max. discards to be issued */ 211 + atomic_t submit_discard; /* # of issued discard */ 196 212 }; 197 213 198 214 /* for the list of fsync inodes, used only during recovery */ ··· 236 214 static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 237 215 { 238 216 int before = nats_in_cursum(journal); 217 + 239 218 journal->n_nats = cpu_to_le16(before + i); 240 219 return before; 241 220 } ··· 244 221 static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 245 222 { 246 223 int before = sits_in_cursum(journal); 224 + 247 225 journal->n_sits = cpu_to_le16(before + i); 248 226 return before; 249 227 } ··· 330 306 331 307 if (type == 1) { 332 308 struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 309 + 333 310 d->max = NR_DENTRY_IN_BLOCK; 334 311 d->bitmap = &t->dentry_bitmap; 335 312 d->dentry = t->dentry; 336 313 d->filename = t->filename; 337 314 } else { 338 315 struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 316 + 339 317 d->max = NR_INLINE_DENTRY; 340 318 d->bitmap = &t->dentry_bitmap; 341 319 d->dentry = t->dentry; ··· 464 438 atomic_t dirty_pages; /* # of dirty pages */ 465 439 f2fs_hash_t chash; /* hash value of given file name */ 466 440 unsigned int clevel; /* maximum level of given file name */ 441 + struct task_struct *task; /* lookup and create consistency */ 467 442 nid_t i_xattr_nid; /* node id that contains xattrs */ 468 - unsigned long long xattr_ver; /* cp version of xattr modification */ 469 443 loff_t last_disk_size; /* lastly written file size */ 470 444 471 445 struct list_head dirty_list; /* dirty list for dirs and files */ ··· 500 474 ei->len = len; 501 475 } 502 476 503 - static inline bool __is_extent_same(struct extent_info *ei1, 504 - struct extent_info *ei2) 505 - { 506 - return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 507 - ei1->len == ei2->len); 508 - } 509 - 510 477 static inline bool __is_extent_mergeable(struct extent_info *back, 511 478 struct extent_info *front) 512 479 { ··· 519 500 return __is_extent_mergeable(cur, front); 520 501 } 521 502 522 - extern void f2fs_mark_inode_dirty_sync(struct inode *, bool); 503 + extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 523 504 static inline void __try_update_largest_extent(struct inode *inode, 524 505 struct extent_tree *et, struct extent_node *en) 525 506 { ··· 551 532 struct list_head nat_entries; /* cached nat entry list (clean) */ 552 533 unsigned int nat_cnt; /* the # of cached nat entries */ 553 534 unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 535 + unsigned int nat_blocks; /* # of nat blocks */ 554 536 555 537 /* free node ids management */ 556 538 struct radix_tree_root free_nid_root;/* root of the free_nid cache */ ··· 559 539 unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 560 540 spinlock_t nid_list_lock; /* protect nid lists ops */ 561 541 struct mutex build_lock; /* lock for build free nids */ 542 + unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 543 + unsigned char *nat_block_bitmap; 562 544 563 545 /* for checkpoint */ 564 546 char *nat_bitmap; /* NAT bitmap pointer */ 547 + 548 + unsigned int nat_bits_blocks; /* # of nat bits blocks */ 549 + unsigned char *nat_bits; /* NAT bits blocks */ 550 + unsigned char *full_nat_bits; /* full NAT pages */ 551 + unsigned char *empty_nat_bits; /* empty NAT pages */ 552 + #ifdef CONFIG_F2FS_CHECK_FS 553 + char *nat_bitmap_mir; /* NAT bitmap mirror */ 554 + #endif 565 555 int bitmap_size; /* bitmap size */ 566 556 }; 567 557 ··· 662 632 /* a threshold to reclaim prefree segments */ 663 633 unsigned int rec_prefree_segments; 664 634 665 - /* for small discard management */ 666 - struct list_head discard_list; /* 4KB discard list */ 667 - struct list_head wait_list; /* linked with issued discard bio */ 668 - int nr_discards; /* # of discards in the list */ 669 - int max_discards; /* max. discards to be issued */ 670 - 671 635 /* for batched trimming */ 672 636 unsigned int trim_sections; /* # of sections to trim */ 673 637 ··· 672 648 unsigned int min_fsync_blocks; /* threshold for fsync */ 673 649 674 650 /* for flush command control */ 675 - struct flush_cmd_control *cmd_control_info; 651 + struct flush_cmd_control *fcc_info; 676 652 653 + /* for discard command control */ 654 + struct discard_cmd_control *dcc_info; 677 655 }; 678 656 679 657 /* ··· 734 708 block_t old_blkaddr; /* old block address before Cow */ 735 709 struct page *page; /* page to be written */ 736 710 struct page *encrypted_page; /* encrypted page */ 711 + bool submitted; /* indicate IO submission */ 737 712 }; 738 713 739 714 #define is_read_io(rw) (rw == READ) ··· 814 787 struct f2fs_bio_info read_io; /* for read bios */ 815 788 struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 816 789 struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ 790 + int write_io_size_bits; /* Write IO size bits */ 791 + mempool_t *write_io_dummy; /* Dummy pages */ 817 792 818 793 /* for checkpoint */ 819 794 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ ··· 840 811 841 812 /* for extent tree cache */ 842 813 struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 843 - struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 814 + struct mutex extent_tree_lock; /* locking extent radix tree */ 844 815 struct list_head extent_list; /* lru list for shrinker */ 845 816 spinlock_t extent_lock; /* locking extent lru list */ 846 817 atomic_t total_ext_tree; /* extent tree count */ ··· 887 858 struct f2fs_gc_kthread *gc_thread; /* GC thread */ 888 859 unsigned int cur_victim_sec; /* current victim section num */ 889 860 861 + /* threshold for converting bg victims for fg */ 862 + u64 fggc_threshold; 863 + 890 864 /* maximum # of trials to find a victim segment for SSR and GC */ 891 865 unsigned int max_victim_search; 892 866 ··· 909 877 atomic_t inline_xattr; /* # of inline_xattr inodes */ 910 878 atomic_t inline_inode; /* # of inline_data inodes */ 911 879 atomic_t inline_dir; /* # of inline_dentry inodes */ 880 + atomic_t aw_cnt; /* # of atomic writes */ 881 + atomic_t max_aw_cnt; /* max # of atomic writes */ 912 882 int bg_gc; /* background gc calls */ 913 883 unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 914 884 #endif ··· 942 908 }; 943 909 944 910 #ifdef CONFIG_F2FS_FAULT_INJECTION 911 + #define f2fs_show_injection_info(type) \ 912 + printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 913 + KERN_INFO, fault_name[type], \ 914 + __func__, __builtin_return_address(0)) 945 915 static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 946 916 { 947 917 struct f2fs_fault_info *ffi = &sbi->fault_info; ··· 959 921 atomic_inc(&ffi->inject_ops); 960 922 if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 961 923 atomic_set(&ffi->inject_ops, 0); 962 - printk("%sF2FS-fs : inject %s in %pF\n", 963 - KERN_INFO, 964 - fault_name[type], 965 - __builtin_return_address(0)); 966 924 return true; 967 925 } 968 926 return false; ··· 1123 1089 return le64_to_cpu(cp->checkpoint_ver); 1124 1090 } 1125 1091 1092 + static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1093 + { 1094 + size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1095 + return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1096 + } 1097 + 1126 1098 static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1127 1099 { 1128 1100 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); ··· 1171 1131 spin_lock(&sbi->cp_lock); 1172 1132 __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1173 1133 spin_unlock(&sbi->cp_lock); 1134 + } 1135 + 1136 + static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 1137 + { 1138 + set_sbi_flag(sbi, SBI_NEED_FSCK); 1139 + 1140 + if (lock) 1141 + spin_lock(&sbi->cp_lock); 1142 + __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 1143 + kfree(NM_I(sbi)->nat_bits); 1144 + NM_I(sbi)->nat_bits = NULL; 1145 + if (lock) 1146 + spin_unlock(&sbi->cp_lock); 1147 + } 1148 + 1149 + static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 1150 + struct cp_control *cpc) 1151 + { 1152 + bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 1153 + 1154 + return (cpc) ? (cpc->reason == CP_UMOUNT) && set : set; 1174 1155 } 1175 1156 1176 1157 static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) ··· 1273 1212 blkcnt_t diff; 1274 1213 1275 1214 #ifdef CONFIG_F2FS_FAULT_INJECTION 1276 - if (time_to_inject(sbi, FAULT_BLOCK)) 1215 + if (time_to_inject(sbi, FAULT_BLOCK)) { 1216 + f2fs_show_injection_info(FAULT_BLOCK); 1277 1217 return false; 1218 + } 1278 1219 #endif 1279 1220 /* 1280 1221 * let's increase this in prior to actual block count change in order ··· 1512 1449 { 1513 1450 #ifdef CONFIG_F2FS_FAULT_INJECTION 1514 1451 struct page *page = find_lock_page(mapping, index); 1452 + 1515 1453 if (page) 1516 1454 return page; 1517 1455 1518 - if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) 1456 + if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 1457 + f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1519 1458 return NULL; 1459 + } 1520 1460 #endif 1521 1461 if (!for_write) 1522 1462 return grab_cache_page(mapping, index); ··· 1598 1532 static inline bool IS_INODE(struct page *page) 1599 1533 { 1600 1534 struct f2fs_node *p = F2FS_NODE(page); 1535 + 1601 1536 return RAW_IS_INODE(p); 1602 1537 } 1603 1538 ··· 1612 1545 { 1613 1546 struct f2fs_node *raw_node; 1614 1547 __le32 *addr_array; 1548 + 1615 1549 raw_node = F2FS_NODE(node_page); 1616 1550 addr_array = blkaddr_in_node(raw_node); 1617 1551 return le32_to_cpu(addr_array[offset]); ··· 1696 1628 FI_UPDATE_WRITE, /* inode has in-place-update data */ 1697 1629 FI_NEED_IPU, /* used for ipu per file */ 1698 1630 FI_ATOMIC_FILE, /* indicate atomic file */ 1631 + FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 1699 1632 FI_VOLATILE_FILE, /* indicate volatile file */ 1700 1633 FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 1701 1634 FI_DROP_CACHE, /* drop dirty page cache */ ··· 1704 1635 FI_INLINE_DOTS, /* indicate inline dot dentries */ 1705 1636 FI_DO_DEFRAG, /* indicate defragment is running */ 1706 1637 FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 1638 + FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 1707 1639 }; 1708 1640 1709 1641 static inline void __mark_inode_dirty_flag(struct inode *inode, ··· 1849 1779 static inline void *inline_xattr_addr(struct page *page) 1850 1780 { 1851 1781 struct f2fs_inode *ri = F2FS_INODE(page); 1782 + 1852 1783 return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 1853 1784 F2FS_INLINE_XATTR_ADDRS]); 1854 1785 } ··· 1888 1817 return is_inode_flag_set(inode, FI_ATOMIC_FILE); 1889 1818 } 1890 1819 1820 + static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 1821 + { 1822 + return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 1823 + } 1824 + 1891 1825 static inline bool f2fs_is_volatile_file(struct inode *inode) 1892 1826 { 1893 1827 return is_inode_flag_set(inode, FI_VOLATILE_FILE); ··· 1911 1835 static inline void *inline_data_addr(struct page *page) 1912 1836 { 1913 1837 struct f2fs_inode *ri = F2FS_INODE(page); 1838 + 1914 1839 return (void *)&(ri->i_addr[1]); 1915 1840 } 1916 1841 ··· 1995 1918 size_t size, gfp_t flags) 1996 1919 { 1997 1920 #ifdef CONFIG_F2FS_FAULT_INJECTION 1998 - if (time_to_inject(sbi, FAULT_KMALLOC)) 1921 + if (time_to_inject(sbi, FAULT_KMALLOC)) { 1922 + f2fs_show_injection_info(FAULT_KMALLOC); 1999 1923 return NULL; 1924 + } 2000 1925 #endif 2001 1926 return kmalloc(size, flags); 2002 1927 } ··· 2036 1957 /* 2037 1958 * file.c 2038 1959 */ 2039 - int f2fs_sync_file(struct file *, loff_t, loff_t, int); 2040 - void truncate_data_blocks(struct dnode_of_data *); 2041 - int truncate_blocks(struct inode *, u64, bool); 2042 - int f2fs_truncate(struct inode *); 2043 - int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 2044 - int f2fs_setattr(struct dentry *, struct iattr *); 2045 - int truncate_hole(struct inode *, pgoff_t, pgoff_t); 2046 - int truncate_data_blocks_range(struct dnode_of_data *, int); 2047 - long f2fs_ioctl(struct file *, unsigned int, unsigned long); 2048 - long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 1960 + int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 1961 + void truncate_data_blocks(struct dnode_of_data *dn); 1962 + int truncate_blocks(struct inode *inode, u64 from, bool lock); 1963 + int f2fs_truncate(struct inode *inode); 1964 + int f2fs_getattr(struct vfsmount *mnt, struct dentry *dentry, 1965 + struct kstat *stat); 1966 + int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 1967 + int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 1968 + int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 1969 + long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 1970 + long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 2049 1971 2050 1972 /* 2051 1973 * inode.c 2052 1974 */ 2053 - void f2fs_set_inode_flags(struct inode *); 2054 - struct inode *f2fs_iget(struct super_block *, unsigned long); 2055 - struct inode *f2fs_iget_retry(struct super_block *, unsigned long); 2056 - int try_to_free_nats(struct f2fs_sb_info *, int); 2057 - int update_inode(struct inode *, struct page *); 2058 - int update_inode_page(struct inode *); 2059 - int f2fs_write_inode(struct inode *, struct writeback_control *); 2060 - void f2fs_evict_inode(struct inode *); 2061 - void handle_failed_inode(struct inode *); 1975 + void f2fs_set_inode_flags(struct inode *inode); 1976 + struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 1977 + struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 1978 + int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 1979 + int update_inode(struct inode *inode, struct page *node_page); 1980 + int update_inode_page(struct inode *inode); 1981 + int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 1982 + void f2fs_evict_inode(struct inode *inode); 1983 + void handle_failed_inode(struct inode *inode); 2062 1984 2063 1985 /* 2064 1986 * namei.c ··· 2069 1989 /* 2070 1990 * dir.c 2071 1991 */ 2072 - void set_de_type(struct f2fs_dir_entry *, umode_t); 2073 - unsigned char get_de_type(struct f2fs_dir_entry *); 2074 - struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *, 2075 - f2fs_hash_t, int *, struct f2fs_dentry_ptr *); 2076 - int f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 2077 - unsigned int, struct fscrypt_str *); 2078 - void do_make_empty_dir(struct inode *, struct inode *, 2079 - struct f2fs_dentry_ptr *); 2080 - struct page *init_inode_metadata(struct inode *, struct inode *, 2081 - const struct qstr *, const struct qstr *, struct page *); 2082 - void update_parent_metadata(struct inode *, struct inode *, unsigned int); 2083 - int room_for_filename(const void *, int, int); 2084 - void f2fs_drop_nlink(struct inode *, struct inode *); 2085 - struct f2fs_dir_entry *__f2fs_find_entry(struct inode *, struct fscrypt_name *, 2086 - struct page **); 2087 - struct f2fs_dir_entry *f2fs_find_entry(struct inode *, const struct qstr *, 2088 - struct page **); 2089 - struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 2090 - ino_t f2fs_inode_by_name(struct inode *, const struct qstr *, struct page **); 2091 - void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 2092 - struct page *, struct inode *); 2093 - int update_dent_inode(struct inode *, struct inode *, const struct qstr *); 2094 - void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 2095 - const struct qstr *, f2fs_hash_t , unsigned int); 2096 - int f2fs_add_regular_entry(struct inode *, const struct qstr *, 2097 - const struct qstr *, struct inode *, nid_t, umode_t); 2098 - int __f2fs_do_add_link(struct inode *, struct fscrypt_name*, struct inode *, 2099 - nid_t, umode_t); 2100 - int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 2101 - umode_t); 2102 - void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 2103 - struct inode *); 2104 - int f2fs_do_tmpfile(struct inode *, struct inode *); 2105 - bool f2fs_empty_dir(struct inode *); 1992 + void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 1993 + unsigned char get_de_type(struct f2fs_dir_entry *de); 1994 + struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 1995 + f2fs_hash_t namehash, int *max_slots, 1996 + struct f2fs_dentry_ptr *d); 1997 + int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 1998 + unsigned int start_pos, struct fscrypt_str *fstr); 1999 + void do_make_empty_dir(struct inode *inode, struct inode *parent, 2000 + struct f2fs_dentry_ptr *d); 2001 + struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2002 + const struct qstr *new_name, 2003 + const struct qstr *orig_name, struct page *dpage); 2004 + void update_parent_metadata(struct inode *dir, struct inode *inode, 2005 + unsigned int current_depth); 2006 + int room_for_filename(const void *bitmap, int slots, int max_slots); 2007 + void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2008 + struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2009 + struct fscrypt_name *fname, struct page **res_page); 2010 + struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2011 + const struct qstr *child, struct page **res_page); 2012 + struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2013 + ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2014 + struct page **page); 2015 + void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2016 + struct page *page, struct inode *inode); 2017 + int update_dent_inode(struct inode *inode, struct inode *to, 2018 + const struct qstr *name); 2019 + void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2020 + const struct qstr *name, f2fs_hash_t name_hash, 2021 + unsigned int bit_pos); 2022 + int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2023 + const struct qstr *orig_name, 2024 + struct inode *inode, nid_t ino, umode_t mode); 2025 + int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2026 + struct inode *inode, nid_t ino, umode_t mode); 2027 + int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2028 + struct inode *inode, nid_t ino, umode_t mode); 2029 + void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2030 + struct inode *dir, struct inode *inode); 2031 + int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2032 + bool f2fs_empty_dir(struct inode *dir); 2106 2033 2107 2034 static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2108 2035 { ··· 2120 2033 /* 2121 2034 * super.c 2122 2035 */ 2123 - int f2fs_inode_dirtied(struct inode *, bool); 2124 - void f2fs_inode_synced(struct inode *); 2125 - int f2fs_commit_super(struct f2fs_sb_info *, bool); 2126 - int f2fs_sync_fs(struct super_block *, int); 2036 + int f2fs_inode_dirtied(struct inode *inode, bool sync); 2037 + void f2fs_inode_synced(struct inode *inode); 2038 + int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2039 + int f2fs_sync_fs(struct super_block *sb, int sync); 2127 2040 extern __printf(3, 4) 2128 - void f2fs_msg(struct super_block *, const char *, const char *, ...); 2041 + void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2129 2042 int sanity_check_ckpt(struct f2fs_sb_info *sbi); 2130 2043 2131 2044 /* 2132 2045 * hash.c 2133 2046 */ 2134 - f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 2047 + f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info); 2135 2048 2136 2049 /* 2137 2050 * node.c ··· 2139 2052 struct dnode_of_data; 2140 2053 struct node_info; 2141 2054 2142 - bool available_free_memory(struct f2fs_sb_info *, int); 2143 - int need_dentry_mark(struct f2fs_sb_info *, nid_t); 2144 - bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 2145 - bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 2146 - void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 2147 - pgoff_t get_next_page_offset(struct dnode_of_data *, pgoff_t); 2148 - int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 2149 - int truncate_inode_blocks(struct inode *, pgoff_t); 2150 - int truncate_xattr_node(struct inode *, struct page *); 2151 - int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 2152 - int remove_inode_page(struct inode *); 2153 - struct page *new_inode_page(struct inode *); 2154 - struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 2155 - void ra_node_page(struct f2fs_sb_info *, nid_t); 2156 - struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 2157 - struct page *get_node_page_ra(struct page *, int); 2158 - void move_node_page(struct page *, int); 2159 - int fsync_node_pages(struct f2fs_sb_info *, struct inode *, 2160 - struct writeback_control *, bool); 2161 - int sync_node_pages(struct f2fs_sb_info *, struct writeback_control *); 2162 - void build_free_nids(struct f2fs_sb_info *, bool); 2163 - bool alloc_nid(struct f2fs_sb_info *, nid_t *); 2164 - void alloc_nid_done(struct f2fs_sb_info *, nid_t); 2165 - void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 2166 - int try_to_free_nids(struct f2fs_sb_info *, int); 2167 - void recover_inline_xattr(struct inode *, struct page *); 2168 - void recover_xattr_data(struct inode *, struct page *, block_t); 2169 - int recover_inode_page(struct f2fs_sb_info *, struct page *); 2170 - int restore_node_summary(struct f2fs_sb_info *, unsigned int, 2171 - struct f2fs_summary_block *); 2172 - void flush_nat_entries(struct f2fs_sb_info *); 2173 - int build_node_manager(struct f2fs_sb_info *); 2174 - void destroy_node_manager(struct f2fs_sb_info *); 2055 + bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2056 + int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2057 + bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2058 + bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2059 + void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2060 + pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2061 + int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2062 + int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2063 + int truncate_xattr_node(struct inode *inode, struct page *page); 2064 + int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2065 + int remove_inode_page(struct inode *inode); 2066 + struct page *new_inode_page(struct inode *inode); 2067 + struct page *new_node_page(struct dnode_of_data *dn, 2068 + unsigned int ofs, struct page *ipage); 2069 + void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2070 + struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2071 + struct page *get_node_page_ra(struct page *parent, int start); 2072 + void move_node_page(struct page *node_page, int gc_type); 2073 + int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2074 + struct writeback_control *wbc, bool atomic); 2075 + int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc); 2076 + void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2077 + bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2078 + void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2079 + void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2080 + int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2081 + void recover_inline_xattr(struct inode *inode, struct page *page); 2082 + int recover_xattr_data(struct inode *inode, struct page *page, 2083 + block_t blkaddr); 2084 + int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2085 + int restore_node_summary(struct f2fs_sb_info *sbi, 2086 + unsigned int segno, struct f2fs_summary_block *sum); 2087 + void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2088 + int build_node_manager(struct f2fs_sb_info *sbi); 2089 + void destroy_node_manager(struct f2fs_sb_info *sbi); 2175 2090 int __init create_node_manager_caches(void); 2176 2091 void destroy_node_manager_caches(void); 2177 2092 2178 2093 /* 2179 2094 * segment.c 2180 2095 */ 2181 - void register_inmem_page(struct inode *, struct page *); 2182 - void drop_inmem_pages(struct inode *); 2183 - int commit_inmem_pages(struct inode *); 2184 - void f2fs_balance_fs(struct f2fs_sb_info *, bool); 2185 - void f2fs_balance_fs_bg(struct f2fs_sb_info *); 2186 - int f2fs_issue_flush(struct f2fs_sb_info *); 2187 - int create_flush_cmd_control(struct f2fs_sb_info *); 2188 - void destroy_flush_cmd_control(struct f2fs_sb_info *, bool); 2189 - void invalidate_blocks(struct f2fs_sb_info *, block_t); 2190 - bool is_checkpointed_data(struct f2fs_sb_info *, block_t); 2191 - void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 2192 - void f2fs_wait_all_discard_bio(struct f2fs_sb_info *); 2193 - void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 2194 - void release_discard_addrs(struct f2fs_sb_info *); 2195 - int npages_for_summary_flush(struct f2fs_sb_info *, bool); 2196 - void allocate_new_segments(struct f2fs_sb_info *); 2197 - int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 2198 - struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 2199 - void update_meta_page(struct f2fs_sb_info *, void *, block_t); 2200 - void write_meta_page(struct f2fs_sb_info *, struct page *); 2201 - void write_node_page(unsigned int, struct f2fs_io_info *); 2202 - void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 2203 - void rewrite_data_page(struct f2fs_io_info *); 2204 - void __f2fs_replace_block(struct f2fs_sb_info *, struct f2fs_summary *, 2205 - block_t, block_t, bool, bool); 2206 - void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *, 2207 - block_t, block_t, unsigned char, bool, bool); 2208 - void allocate_data_block(struct f2fs_sb_info *, struct page *, 2209 - block_t, block_t *, struct f2fs_summary *, int); 2210 - void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool); 2211 - void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t); 2212 - void write_data_summaries(struct f2fs_sb_info *, block_t); 2213 - void write_node_summaries(struct f2fs_sb_info *, block_t); 2214 - int lookup_journal_in_cursum(struct f2fs_journal *, int, unsigned int, int); 2215 - void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 2216 - int build_segment_manager(struct f2fs_sb_info *); 2217 - void destroy_segment_manager(struct f2fs_sb_info *); 2096 + void register_inmem_page(struct inode *inode, struct page *page); 2097 + void drop_inmem_pages(struct inode *inode); 2098 + int commit_inmem_pages(struct inode *inode); 2099 + void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2100 + void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2101 + int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2102 + int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2103 + void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2104 + void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2105 + bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2106 + void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2107 + void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr); 2108 + void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2109 + void release_discard_addrs(struct f2fs_sb_info *sbi); 2110 + int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2111 + void allocate_new_segments(struct f2fs_sb_info *sbi); 2112 + int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2113 + bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2114 + struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2115 + void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2116 + void write_meta_page(struct f2fs_sb_info *sbi, struct page *page); 2117 + void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2118 + void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2119 + void rewrite_data_page(struct f2fs_io_info *fio); 2120 + void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2121 + block_t old_blkaddr, block_t new_blkaddr, 2122 + bool recover_curseg, bool recover_newaddr); 2123 + void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2124 + block_t old_addr, block_t new_addr, 2125 + unsigned char version, bool recover_curseg, 2126 + bool recover_newaddr); 2127 + void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2128 + block_t old_blkaddr, block_t *new_blkaddr, 2129 + struct f2fs_summary *sum, int type); 2130 + void f2fs_wait_on_page_writeback(struct page *page, 2131 + enum page_type type, bool ordered); 2132 + void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2133 + block_t blkaddr); 2134 + void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2135 + void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2136 + int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2137 + unsigned int val, int alloc); 2138 + void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2139 + int build_segment_manager(struct f2fs_sb_info *sbi); 2140 + void destroy_segment_manager(struct f2fs_sb_info *sbi); 2218 2141 int __init create_segment_manager_caches(void); 2219 2142 void destroy_segment_manager_caches(void); 2220 2143 2221 2144 /* 2222 2145 * checkpoint.c 2223 2146 */ 2224 - void f2fs_stop_checkpoint(struct f2fs_sb_info *, bool); 2225 - struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 2226 - struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 2227 - struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t); 2228 - bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 2229 - int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool); 2230 - void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 2231 - long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 2232 - void add_ino_entry(struct f2fs_sb_info *, nid_t, int type); 2233 - void remove_ino_entry(struct f2fs_sb_info *, nid_t, int type); 2234 - void release_ino_entry(struct f2fs_sb_info *, bool); 2235 - bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 2236 - int f2fs_sync_inode_meta(struct f2fs_sb_info *); 2237 - int acquire_orphan_inode(struct f2fs_sb_info *); 2238 - void release_orphan_inode(struct f2fs_sb_info *); 2239 - void add_orphan_inode(struct inode *); 2240 - void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 2241 - int recover_orphan_inodes(struct f2fs_sb_info *); 2242 - int get_valid_checkpoint(struct f2fs_sb_info *); 2243 - void update_dirty_page(struct inode *, struct page *); 2244 - void remove_dirty_inode(struct inode *); 2245 - int sync_dirty_inodes(struct f2fs_sb_info *, enum inode_type); 2246 - int write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 2247 - void init_ino_entry_info(struct f2fs_sb_info *); 2147 + void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2148 + struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2149 + struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2150 + struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2151 + bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2152 + int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2153 + int type, bool sync); 2154 + void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2155 + long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2156 + long nr_to_write); 2157 + void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2158 + void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2159 + void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2160 + bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2161 + int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2162 + int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2163 + void release_orphan_inode(struct f2fs_sb_info *sbi); 2164 + void add_orphan_inode(struct inode *inode); 2165 + void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2166 + int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2167 + int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2168 + void update_dirty_page(struct inode *inode, struct page *page); 2169 + void remove_dirty_inode(struct inode *inode); 2170 + int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2171 + int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2172 + void init_ino_entry_info(struct f2fs_sb_info *sbi); 2248 2173 int __init create_checkpoint_caches(void); 2249 2174 void destroy_checkpoint_caches(void); 2250 2175 2251 2176 /* 2252 2177 * data.c 2253 2178 */ 2254 - void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 2255 - void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *, struct inode *, 2256 - struct page *, nid_t, enum page_type, int); 2257 - void f2fs_flush_merged_bios(struct f2fs_sb_info *); 2258 - int f2fs_submit_page_bio(struct f2fs_io_info *); 2259 - void f2fs_submit_page_mbio(struct f2fs_io_info *); 2260 - struct block_device *f2fs_target_device(struct f2fs_sb_info *, 2261 - block_t, struct bio *); 2262 - int f2fs_target_device_index(struct f2fs_sb_info *, block_t); 2263 - void set_data_blkaddr(struct dnode_of_data *); 2264 - void f2fs_update_data_blkaddr(struct dnode_of_data *, block_t); 2265 - int reserve_new_blocks(struct dnode_of_data *, blkcnt_t); 2266 - int reserve_new_block(struct dnode_of_data *); 2267 - int f2fs_get_block(struct dnode_of_data *, pgoff_t); 2268 - int f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *); 2269 - int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 2270 - struct page *get_read_data_page(struct inode *, pgoff_t, int, bool); 2271 - struct page *find_data_page(struct inode *, pgoff_t); 2272 - struct page *get_lock_data_page(struct inode *, pgoff_t, bool); 2273 - struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 2274 - int do_write_data_page(struct f2fs_io_info *); 2275 - int f2fs_map_blocks(struct inode *, struct f2fs_map_blocks *, int, int); 2276 - int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 2277 - void f2fs_set_page_dirty_nobuffers(struct page *); 2278 - void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 2279 - int f2fs_release_page(struct page *, gfp_t); 2179 + void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 2180 + int rw); 2181 + void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, 2182 + struct inode *inode, nid_t ino, pgoff_t idx, 2183 + enum page_type type, int rw); 2184 + void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi); 2185 + int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2186 + int f2fs_submit_page_mbio(struct f2fs_io_info *fio); 2187 + struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2188 + block_t blk_addr, struct bio *bio); 2189 + int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2190 + void set_data_blkaddr(struct dnode_of_data *dn); 2191 + void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2192 + int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2193 + int reserve_new_block(struct dnode_of_data *dn); 2194 + int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2195 + int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2196 + int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2197 + struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2198 + int op_flags, bool for_write); 2199 + struct page *find_data_page(struct inode *inode, pgoff_t index); 2200 + struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2201 + bool for_write); 2202 + struct page *get_new_data_page(struct inode *inode, 2203 + struct page *ipage, pgoff_t index, bool new_i_size); 2204 + int do_write_data_page(struct f2fs_io_info *fio); 2205 + int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2206 + int create, int flag); 2207 + int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2208 + u64 start, u64 len); 2209 + void f2fs_set_page_dirty_nobuffers(struct page *page); 2210 + void f2fs_invalidate_page(struct page *page, unsigned int offset, 2211 + unsigned int length); 2212 + int f2fs_release_page(struct page *page, gfp_t wait); 2280 2213 #ifdef CONFIG_MIGRATION 2281 - int f2fs_migrate_page(struct address_space *, struct page *, struct page *, 2282 - enum migrate_mode); 2214 + int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2215 + struct page *page, enum migrate_mode mode); 2283 2216 #endif 2284 2217 2285 2218 /* 2286 2219 * gc.c 2287 2220 */ 2288 - int start_gc_thread(struct f2fs_sb_info *); 2289 - void stop_gc_thread(struct f2fs_sb_info *); 2290 - block_t start_bidx_of_node(unsigned int, struct inode *); 2291 - int f2fs_gc(struct f2fs_sb_info *, bool, bool); 2292 - void build_gc_manager(struct f2fs_sb_info *); 2221 + int start_gc_thread(struct f2fs_sb_info *sbi); 2222 + void stop_gc_thread(struct f2fs_sb_info *sbi); 2223 + block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2224 + int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background); 2225 + void build_gc_manager(struct f2fs_sb_info *sbi); 2293 2226 2294 2227 /* 2295 2228 * recovery.c 2296 2229 */ 2297 - int recover_fsync_data(struct f2fs_sb_info *, bool); 2298 - bool space_for_roll_forward(struct f2fs_sb_info *); 2230 + int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2231 + bool space_for_roll_forward(struct f2fs_sb_info *sbi); 2299 2232 2300 2233 /* 2301 2234 * debug.c ··· 2334 2227 unsigned int ndirty_dirs, ndirty_files, ndirty_all; 2335 2228 int nats, dirty_nats, sits, dirty_sits, free_nids, alloc_nids; 2336 2229 int total_count, utilization; 2337 - int bg_gc, nr_wb_cp_data, nr_wb_data; 2338 - int inline_xattr, inline_inode, inline_dir, orphans; 2230 + int bg_gc, nr_wb_cp_data, nr_wb_data, nr_flush, nr_discard; 2231 + int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2232 + int aw_cnt, max_aw_cnt; 2339 2233 unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 2340 2234 unsigned int bimodal, avg_vblocks; 2341 2235 int util_free, util_valid, util_invalid; ··· 2408 2300 ((sbi)->block_count[(curseg)->alloc_type]++) 2409 2301 #define stat_inc_inplace_blocks(sbi) \ 2410 2302 (atomic_inc(&(sbi)->inplace_count)) 2303 + #define stat_inc_atomic_write(inode) \ 2304 + (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 2305 + #define stat_dec_atomic_write(inode) \ 2306 + (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 2307 + #define stat_update_max_atomic_write(inode) \ 2308 + do { \ 2309 + int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 2310 + int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 2311 + if (cur > max) \ 2312 + atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 2313 + } while (0) 2411 2314 #define stat_inc_seg_count(sbi, type, gc_type) \ 2412 2315 do { \ 2413 2316 struct f2fs_stat_info *si = F2FS_STAT(sbi); \ ··· 2451 2332 si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 2452 2333 } while (0) 2453 2334 2454 - int f2fs_build_stats(struct f2fs_sb_info *); 2455 - void f2fs_destroy_stats(struct f2fs_sb_info *); 2335 + int f2fs_build_stats(struct f2fs_sb_info *sbi); 2336 + void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2456 2337 int __init f2fs_create_root_stats(void); 2457 2338 void f2fs_destroy_root_stats(void); 2458 2339 #else ··· 2472 2353 #define stat_dec_inline_inode(inode) 2473 2354 #define stat_inc_inline_dir(inode) 2474 2355 #define stat_dec_inline_dir(inode) 2356 + #define stat_inc_atomic_write(inode) 2357 + #define stat_dec_atomic_write(inode) 2358 + #define stat_update_max_atomic_write(inode) 2475 2359 #define stat_inc_seg_type(sbi, curseg) 2476 2360 #define stat_inc_block_count(sbi, curseg) 2477 2361 #define stat_inc_inplace_blocks(sbi) ··· 2504 2382 /* 2505 2383 * inline.c 2506 2384 */ 2507 - bool f2fs_may_inline_data(struct inode *); 2508 - bool f2fs_may_inline_dentry(struct inode *); 2509 - void read_inline_data(struct page *, struct page *); 2510 - bool truncate_inline_inode(struct page *, u64); 2511 - int f2fs_read_inline_data(struct inode *, struct page *); 2512 - int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 2513 - int f2fs_convert_inline_inode(struct inode *); 2514 - int f2fs_write_inline_data(struct inode *, struct page *); 2515 - bool recover_inline_data(struct inode *, struct page *); 2516 - struct f2fs_dir_entry *find_in_inline_dir(struct inode *, 2517 - struct fscrypt_name *, struct page **); 2518 - int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 2519 - int f2fs_add_inline_entry(struct inode *, const struct qstr *, 2520 - const struct qstr *, struct inode *, nid_t, umode_t); 2521 - void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 2522 - struct inode *, struct inode *); 2523 - bool f2fs_empty_inline_dir(struct inode *); 2524 - int f2fs_read_inline_dir(struct file *, struct dir_context *, 2525 - struct fscrypt_str *); 2526 - int f2fs_inline_data_fiemap(struct inode *, 2527 - struct fiemap_extent_info *, __u64, __u64); 2385 + bool f2fs_may_inline_data(struct inode *inode); 2386 + bool f2fs_may_inline_dentry(struct inode *inode); 2387 + void read_inline_data(struct page *page, struct page *ipage); 2388 + bool truncate_inline_inode(struct page *ipage, u64 from); 2389 + int f2fs_read_inline_data(struct inode *inode, struct page *page); 2390 + int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2391 + int f2fs_convert_inline_inode(struct inode *inode); 2392 + int f2fs_write_inline_data(struct inode *inode, struct page *page); 2393 + bool recover_inline_data(struct inode *inode, struct page *npage); 2394 + struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2395 + struct fscrypt_name *fname, struct page **res_page); 2396 + int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2397 + struct page *ipage); 2398 + int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2399 + const struct qstr *orig_name, 2400 + struct inode *inode, nid_t ino, umode_t mode); 2401 + void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2402 + struct inode *dir, struct inode *inode); 2403 + bool f2fs_empty_inline_dir(struct inode *dir); 2404 + int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2405 + struct fscrypt_str *fstr); 2406 + int f2fs_inline_data_fiemap(struct inode *inode, 2407 + struct fiemap_extent_info *fieinfo, 2408 + __u64 start, __u64 len); 2528 2409 2529 2410 /* 2530 2411 * shrinker.c 2531 2412 */ 2532 - unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *); 2533 - unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *); 2534 - void f2fs_join_shrinker(struct f2fs_sb_info *); 2535 - void f2fs_leave_shrinker(struct f2fs_sb_info *); 2413 + unsigned long f2fs_shrink_count(struct shrinker *shrink, 2414 + struct shrink_control *sc); 2415 + unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2416 + struct shrink_control *sc); 2417 + void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2418 + void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 2536 2419 2537 2420 /* 2538 2421 * extent_cache.c 2539 2422 */ 2540 - unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 2541 - bool f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 2542 - void f2fs_drop_extent_tree(struct inode *); 2543 - unsigned int f2fs_destroy_extent_node(struct inode *); 2544 - void f2fs_destroy_extent_tree(struct inode *); 2545 - bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *); 2546 - void f2fs_update_extent_cache(struct dnode_of_data *); 2423 + unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2424 + bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2425 + void f2fs_drop_extent_tree(struct inode *inode); 2426 + unsigned int f2fs_destroy_extent_node(struct inode *inode); 2427 + void f2fs_destroy_extent_tree(struct inode *inode); 2428 + bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2429 + struct extent_info *ei); 2430 + void f2fs_update_extent_cache(struct dnode_of_data *dn); 2547 2431 void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2548 - pgoff_t, block_t, unsigned int); 2549 - void init_extent_cache_info(struct f2fs_sb_info *); 2432 + pgoff_t fofs, block_t blkaddr, unsigned int len); 2433 + void init_extent_cache_info(struct f2fs_sb_info *sbi); 2550 2434 int __init create_extent_cache(void); 2551 2435 void destroy_extent_cache(void); 2552 2436
+24 -14
fs/f2fs/file.c
··· 20 20 #include <linux/uaccess.h> 21 21 #include <linux/mount.h> 22 22 #include <linux/pagevec.h> 23 + #include <linux/uio.h> 23 24 #include <linux/uuid.h> 24 25 #include <linux/file.h> 25 26 ··· 141 140 need_cp = true; 142 141 else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino)) 143 142 need_cp = true; 144 - else if (F2FS_I(inode)->xattr_ver == cur_cp_version(F2FS_CKPT(sbi))) 145 - need_cp = true; 146 143 else if (test_opt(sbi, FASTBOOT)) 147 144 need_cp = true; 148 145 else if (sbi->active_logs == 2) ··· 166 167 nid_t pino; 167 168 168 169 down_write(&fi->i_sem); 169 - fi->xattr_ver = 0; 170 170 if (file_wrong_pino(inode) && inode->i_nlink == 1 && 171 171 get_parent_ino(inode, &pino)) { 172 172 f2fs_i_pino_write(inode, pino); ··· 274 276 flush_out: 275 277 remove_ino_entry(sbi, ino, UPDATE_INO); 276 278 clear_inode_flag(inode, FI_UPDATE_WRITE); 277 - ret = f2fs_issue_flush(sbi); 279 + if (!atomic) 280 + ret = f2fs_issue_flush(sbi); 278 281 f2fs_update_time(sbi, REQ_TIME); 279 282 out: 280 283 trace_f2fs_sync_file_exit(inode, need_cp, datasync, ret); ··· 566 567 } 567 568 568 569 if (f2fs_has_inline_data(inode)) { 569 - if (truncate_inline_inode(ipage, from)) 570 - set_page_dirty(ipage); 570 + truncate_inline_inode(ipage, from); 571 + if (from == 0) 572 + clear_inode_flag(inode, FI_DATA_EXIST); 571 573 f2fs_put_page(ipage, 1); 572 574 truncate_page = true; 573 575 goto out; ··· 1541 1541 if (ret) 1542 1542 clear_inode_flag(inode, FI_ATOMIC_FILE); 1543 1543 out: 1544 + stat_inc_atomic_write(inode); 1545 + stat_update_max_atomic_write(inode); 1544 1546 inode_unlock(inode); 1545 1547 mnt_drop_write_file(filp); 1546 1548 return ret; ··· 1566 1564 goto err_out; 1567 1565 1568 1566 if (f2fs_is_atomic_file(inode)) { 1569 - clear_inode_flag(inode, FI_ATOMIC_FILE); 1570 1567 ret = commit_inmem_pages(inode); 1571 - if (ret) { 1572 - set_inode_flag(inode, FI_ATOMIC_FILE); 1568 + if (ret) 1573 1569 goto err_out; 1574 - } 1575 - } 1576 1570 1577 - ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true); 1571 + ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true); 1572 + if (!ret) { 1573 + clear_inode_flag(inode, FI_ATOMIC_FILE); 1574 + stat_dec_atomic_write(inode); 1575 + } 1576 + } else { 1577 + ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true); 1578 + } 1578 1579 err_out: 1579 1580 inode_unlock(inode); 1580 1581 mnt_drop_write_file(filp); ··· 1875 1870 { 1876 1871 struct inode *inode = file_inode(filp); 1877 1872 struct f2fs_map_blocks map = { .m_next_pgofs = NULL }; 1878 - struct extent_info ei; 1873 + struct extent_info ei = {0,0,0}; 1879 1874 pgoff_t pg_start, pg_end; 1880 1875 unsigned int blk_per_seg = sbi->blocks_per_seg; 1881 1876 unsigned int total = 0, sec_num; ··· 2255 2250 inode_lock(inode); 2256 2251 ret = generic_write_checks(iocb, from); 2257 2252 if (ret > 0) { 2258 - int err = f2fs_preallocate_blocks(iocb, from); 2253 + int err; 2259 2254 2255 + if (iov_iter_fault_in_readable(from, iov_iter_count(from))) 2256 + set_inode_flag(inode, FI_NO_PREALLOC); 2257 + 2258 + err = f2fs_preallocate_blocks(iocb, from); 2260 2259 if (err) { 2261 2260 inode_unlock(inode); 2262 2261 return err; ··· 2268 2259 blk_start_plug(&plug); 2269 2260 ret = __generic_file_write_iter(iocb, from); 2270 2261 blk_finish_plug(&plug); 2262 + clear_inode_flag(inode, FI_NO_PREALLOC); 2271 2263 } 2272 2264 inode_unlock(inode); 2273 2265
+53 -26
fs/f2fs/gc.c
··· 48 48 } 49 49 50 50 #ifdef CONFIG_F2FS_FAULT_INJECTION 51 - if (time_to_inject(sbi, FAULT_CHECKPOINT)) 51 + if (time_to_inject(sbi, FAULT_CHECKPOINT)) { 52 + f2fs_show_injection_info(FAULT_CHECKPOINT); 52 53 f2fs_stop_checkpoint(sbi, false); 54 + } 53 55 #endif 54 56 55 57 /* ··· 168 166 p->ofs_unit = sbi->segs_per_sec; 169 167 } 170 168 171 - if (p->max_search > sbi->max_victim_search) 169 + /* we need to check every dirty segments in the FG_GC case */ 170 + if (gc_type != FG_GC && p->max_search > sbi->max_victim_search) 172 171 p->max_search = sbi->max_victim_search; 173 172 174 173 p->offset = sbi->last_victim[p->gc_mode]; ··· 202 199 for_each_set_bit(secno, dirty_i->victim_secmap, MAIN_SECS(sbi)) { 203 200 if (sec_usage_check(sbi, secno)) 204 201 continue; 202 + 203 + if (no_fggc_candidate(sbi, secno)) 204 + continue; 205 + 205 206 clear_bit(secno, dirty_i->victim_secmap); 206 207 return secno * sbi->segs_per_sec; 207 208 } ··· 244 237 return UINT_MAX - ((100 * (100 - u) * age) / (100 + u)); 245 238 } 246 239 240 + static unsigned int get_greedy_cost(struct f2fs_sb_info *sbi, 241 + unsigned int segno) 242 + { 243 + unsigned int valid_blocks = 244 + get_valid_blocks(sbi, segno, sbi->segs_per_sec); 245 + 246 + return IS_DATASEG(get_seg_entry(sbi, segno)->type) ? 247 + valid_blocks * 2 : valid_blocks; 248 + } 249 + 247 250 static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi, 248 251 unsigned int segno, struct victim_sel_policy *p) 249 252 { ··· 262 245 263 246 /* alloc_mode == LFS */ 264 247 if (p->gc_mode == GC_GREEDY) 265 - return get_valid_blocks(sbi, segno, sbi->segs_per_sec); 248 + return get_greedy_cost(sbi, segno); 266 249 else 267 250 return get_cb_cost(sbi, segno); 268 251 } ··· 339 322 nsearched++; 340 323 } 341 324 342 - 343 325 secno = GET_SECNO(sbi, segno); 344 326 345 327 if (sec_usage_check(sbi, secno)) 346 328 goto next; 347 329 if (gc_type == BG_GC && test_bit(secno, dirty_i->victim_secmap)) 330 + goto next; 331 + if (gc_type == FG_GC && p.alloc_mode == LFS && 332 + no_fggc_candidate(sbi, secno)) 348 333 goto next; 349 334 350 335 cost = get_gc_cost(sbi, segno, &p); ··· 588 569 if (!check_valid_map(F2FS_I_SB(inode), segno, off)) 589 570 goto out; 590 571 572 + if (f2fs_is_atomic_file(inode)) 573 + goto out; 574 + 591 575 set_new_dnode(&dn, inode, NULL, NULL, 0); 592 576 err = get_dnode_of_data(&dn, bidx, LOOKUP_NODE); 593 577 if (err) ··· 681 659 return; 682 660 683 661 if (!check_valid_map(F2FS_I_SB(inode), segno, off)) 662 + goto out; 663 + 664 + if (f2fs_is_atomic_file(inode)) 684 665 goto out; 685 666 686 667 if (gc_type == BG_GC) { ··· 946 921 947 922 cpc.reason = __get_cp_reason(sbi); 948 923 gc_more: 949 - segno = NULL_SEGNO; 950 - 951 924 if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE))) 952 925 goto stop; 953 926 if (unlikely(f2fs_cp_error(sbi))) { ··· 953 930 goto stop; 954 931 } 955 932 956 - if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed, 0)) { 957 - gc_type = FG_GC; 933 + if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) { 958 934 /* 959 - * If there is no victim and no prefree segment but still not 960 - * enough free sections, we should flush dent/node blocks and do 961 - * garbage collections. 935 + * For example, if there are many prefree_segments below given 936 + * threshold, we can make them free by checkpoint. Then, we 937 + * secure free segments which doesn't need fggc any more. 962 938 */ 963 - if (__get_victim(sbi, &segno, gc_type) || 964 - prefree_segments(sbi)) { 965 - ret = write_checkpoint(sbi, &cpc); 966 - if (ret) 967 - goto stop; 968 - segno = NULL_SEGNO; 969 - } else if (has_not_enough_free_secs(sbi, 0, 0)) { 970 - ret = write_checkpoint(sbi, &cpc); 971 - if (ret) 972 - goto stop; 973 - } 974 - } else if (gc_type == BG_GC && !background) { 975 - /* f2fs_balance_fs doesn't need to do BG_GC in critical path. */ 976 - goto stop; 939 + ret = write_checkpoint(sbi, &cpc); 940 + if (ret) 941 + goto stop; 942 + if (has_not_enough_free_secs(sbi, 0, 0)) 943 + gc_type = FG_GC; 977 944 } 978 945 979 - if (segno == NULL_SEGNO && !__get_victim(sbi, &segno, gc_type)) 946 + /* f2fs_balance_fs doesn't need to do BG_GC in critical path. */ 947 + if (gc_type == BG_GC && !background) 948 + goto stop; 949 + if (!__get_victim(sbi, &segno, gc_type)) 980 950 goto stop; 981 951 ret = 0; 982 952 ··· 999 983 1000 984 void build_gc_manager(struct f2fs_sb_info *sbi) 1001 985 { 986 + u64 main_count, resv_count, ovp_count, blocks_per_sec; 987 + 1002 988 DIRTY_I(sbi)->v_ops = &default_v_ops; 989 + 990 + /* threshold of # of valid blocks in a section for victims of FG_GC */ 991 + main_count = SM_I(sbi)->main_segments << sbi->log_blocks_per_seg; 992 + resv_count = SM_I(sbi)->reserved_segments << sbi->log_blocks_per_seg; 993 + ovp_count = SM_I(sbi)->ovp_segments << sbi->log_blocks_per_seg; 994 + blocks_per_sec = sbi->blocks_per_seg * sbi->segs_per_sec; 995 + 996 + sbi->fggc_threshold = div64_u64((main_count - ovp_count) * blocks_per_sec, 997 + (main_count - resv_count)); 1003 998 }
+3 -1
fs/f2fs/inode.c
··· 373 373 goto no_delete; 374 374 375 375 #ifdef CONFIG_F2FS_FAULT_INJECTION 376 - if (time_to_inject(sbi, FAULT_EVICT_INODE)) 376 + if (time_to_inject(sbi, FAULT_EVICT_INODE)) { 377 + f2fs_show_injection_info(FAULT_EVICT_INODE); 377 378 goto no_delete; 379 + } 378 380 #endif 379 381 380 382 remove_ino_entry(sbi, inode->i_ino, APPEND_INO);
+15 -3
fs/f2fs/namei.c
··· 321 321 if (err) 322 322 goto err_out; 323 323 } 324 - if (!IS_ERR(inode) && f2fs_encrypted_inode(dir) && 325 - (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) && 326 - !fscrypt_has_permitted_context(dir, inode)) { 324 + if (f2fs_encrypted_inode(dir) && 325 + (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) && 326 + !fscrypt_has_permitted_context(dir, inode)) { 327 327 bool nokey = f2fs_encrypted_inode(inode) && 328 328 !fscrypt_has_encryption_key(inode); 329 329 err = nokey ? -ENOKEY : -EPERM; ··· 663 663 bool is_old_inline = f2fs_has_inline_dentry(old_dir); 664 664 int err = -ENOENT; 665 665 666 + if ((f2fs_encrypted_inode(old_dir) && 667 + !fscrypt_has_encryption_key(old_dir)) || 668 + (f2fs_encrypted_inode(new_dir) && 669 + !fscrypt_has_encryption_key(new_dir))) 670 + return -ENOKEY; 671 + 666 672 if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) && 667 673 !fscrypt_has_permitted_context(new_dir, old_inode)) { 668 674 err = -EPERM; ··· 848 842 struct f2fs_dir_entry *old_entry, *new_entry; 849 843 int old_nlink = 0, new_nlink = 0; 850 844 int err = -ENOENT; 845 + 846 + if ((f2fs_encrypted_inode(old_dir) && 847 + !fscrypt_has_encryption_key(old_dir)) || 848 + (f2fs_encrypted_inode(new_dir) && 849 + !fscrypt_has_encryption_key(new_dir))) 850 + return -ENOKEY; 851 851 852 852 if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) && 853 853 (old_dir != new_dir) &&
+436 -124
fs/f2fs/node.c
··· 245 245 return need_update; 246 246 } 247 247 248 - static struct nat_entry *grab_nat_entry(struct f2fs_nm_info *nm_i, nid_t nid) 248 + static struct nat_entry *grab_nat_entry(struct f2fs_nm_info *nm_i, nid_t nid, 249 + bool no_fail) 249 250 { 250 251 struct nat_entry *new; 251 252 252 - new = f2fs_kmem_cache_alloc(nat_entry_slab, GFP_NOFS); 253 - f2fs_radix_tree_insert(&nm_i->nat_root, nid, new); 253 + if (no_fail) { 254 + new = f2fs_kmem_cache_alloc(nat_entry_slab, GFP_NOFS); 255 + f2fs_radix_tree_insert(&nm_i->nat_root, nid, new); 256 + } else { 257 + new = kmem_cache_alloc(nat_entry_slab, GFP_NOFS); 258 + if (!new) 259 + return NULL; 260 + if (radix_tree_insert(&nm_i->nat_root, nid, new)) { 261 + kmem_cache_free(nat_entry_slab, new); 262 + return NULL; 263 + } 264 + } 265 + 254 266 memset(new, 0, sizeof(struct nat_entry)); 255 267 nat_set_nid(new, nid); 256 268 nat_reset_flag(new); ··· 279 267 280 268 e = __lookup_nat_cache(nm_i, nid); 281 269 if (!e) { 282 - e = grab_nat_entry(nm_i, nid); 283 - node_info_from_raw_nat(&e->ni, ne); 270 + e = grab_nat_entry(nm_i, nid, false); 271 + if (e) 272 + node_info_from_raw_nat(&e->ni, ne); 284 273 } else { 285 274 f2fs_bug_on(sbi, nat_get_ino(e) != le32_to_cpu(ne->ino) || 286 275 nat_get_blkaddr(e) != ··· 299 286 down_write(&nm_i->nat_tree_lock); 300 287 e = __lookup_nat_cache(nm_i, ni->nid); 301 288 if (!e) { 302 - e = grab_nat_entry(nm_i, ni->nid); 289 + e = grab_nat_entry(nm_i, ni->nid, true); 303 290 copy_node_info(&e->ni, ni); 304 291 f2fs_bug_on(sbi, ni->blk_addr == NEW_ADDR); 305 292 } else if (new_blkaddr == NEW_ADDR) { ··· 337 324 if (new_blkaddr == NEW_ADDR || new_blkaddr == NULL_ADDR) 338 325 set_nat_flag(e, IS_CHECKPOINTED, false); 339 326 __set_nat_cache_dirty(nm_i, e); 327 + 328 + if (enabled_nat_bits(sbi, NULL) && new_blkaddr == NEW_ADDR) 329 + clear_bit_le(NAT_BLOCK_OFFSET(ni->nid), nm_i->empty_nat_bits); 340 330 341 331 /* update fsync_mark if its inode nat entry is still alive */ 342 332 if (ni->nid != ni->ino) ··· 974 958 975 959 f2fs_i_xnid_write(inode, 0); 976 960 977 - /* need to do checkpoint during fsync */ 978 - F2FS_I(inode)->xattr_ver = cur_cp_version(F2FS_CKPT(sbi)); 979 - 980 961 set_new_dnode(&dn, inode, page, npage, nid); 981 962 982 963 if (page) ··· 1031 1018 unsigned int ofs, struct page *ipage) 1032 1019 { 1033 1020 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); 1034 - struct node_info old_ni, new_ni; 1021 + struct node_info new_ni; 1035 1022 struct page *page; 1036 1023 int err; 1037 1024 ··· 1046 1033 err = -ENOSPC; 1047 1034 goto fail; 1048 1035 } 1049 - 1050 - get_node_info(sbi, dn->nid, &old_ni); 1051 - 1052 - /* Reinitialize old_ni with new node page */ 1053 - f2fs_bug_on(sbi, old_ni.blk_addr != NULL_ADDR); 1054 - new_ni = old_ni; 1036 + #ifdef CONFIG_F2FS_CHECK_FS 1037 + get_node_info(sbi, dn->nid, &new_ni); 1038 + f2fs_bug_on(sbi, new_ni.blk_addr != NULL_ADDR); 1039 + #endif 1040 + new_ni.nid = dn->nid; 1055 1041 new_ni.ino = dn->inode->i_ino; 1042 + new_ni.blk_addr = NULL_ADDR; 1043 + new_ni.flag = 0; 1044 + new_ni.version = 0; 1056 1045 set_node_addr(sbi, &new_ni, NEW_ADDR, false); 1057 1046 1058 1047 f2fs_wait_on_page_writeback(page, NODE, true); ··· 1320 1305 return last_page; 1321 1306 } 1322 1307 1308 + static int __write_node_page(struct page *page, bool atomic, bool *submitted, 1309 + struct writeback_control *wbc) 1310 + { 1311 + struct f2fs_sb_info *sbi = F2FS_P_SB(page); 1312 + nid_t nid; 1313 + struct node_info ni; 1314 + struct f2fs_io_info fio = { 1315 + .sbi = sbi, 1316 + .type = NODE, 1317 + .op = REQ_OP_WRITE, 1318 + .op_flags = wbc_to_write_flags(wbc), 1319 + .page = page, 1320 + .encrypted_page = NULL, 1321 + .submitted = false, 1322 + }; 1323 + 1324 + trace_f2fs_writepage(page, NODE); 1325 + 1326 + if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 1327 + goto redirty_out; 1328 + if (unlikely(f2fs_cp_error(sbi))) 1329 + goto redirty_out; 1330 + 1331 + /* get old block addr of this node page */ 1332 + nid = nid_of_node(page); 1333 + f2fs_bug_on(sbi, page->index != nid); 1334 + 1335 + if (wbc->for_reclaim) { 1336 + if (!down_read_trylock(&sbi->node_write)) 1337 + goto redirty_out; 1338 + } else { 1339 + down_read(&sbi->node_write); 1340 + } 1341 + 1342 + get_node_info(sbi, nid, &ni); 1343 + 1344 + /* This page is already truncated */ 1345 + if (unlikely(ni.blk_addr == NULL_ADDR)) { 1346 + ClearPageUptodate(page); 1347 + dec_page_count(sbi, F2FS_DIRTY_NODES); 1348 + up_read(&sbi->node_write); 1349 + unlock_page(page); 1350 + return 0; 1351 + } 1352 + 1353 + if (atomic && !test_opt(sbi, NOBARRIER)) 1354 + fio.op_flags |= REQ_PREFLUSH | REQ_FUA; 1355 + 1356 + set_page_writeback(page); 1357 + fio.old_blkaddr = ni.blk_addr; 1358 + write_node_page(nid, &fio); 1359 + set_node_addr(sbi, &ni, fio.new_blkaddr, is_fsync_dnode(page)); 1360 + dec_page_count(sbi, F2FS_DIRTY_NODES); 1361 + up_read(&sbi->node_write); 1362 + 1363 + if (wbc->for_reclaim) { 1364 + f2fs_submit_merged_bio_cond(sbi, page->mapping->host, 0, 1365 + page->index, NODE, WRITE); 1366 + submitted = NULL; 1367 + } 1368 + 1369 + unlock_page(page); 1370 + 1371 + if (unlikely(f2fs_cp_error(sbi))) { 1372 + f2fs_submit_merged_bio(sbi, NODE, WRITE); 1373 + submitted = NULL; 1374 + } 1375 + if (submitted) 1376 + *submitted = fio.submitted; 1377 + 1378 + return 0; 1379 + 1380 + redirty_out: 1381 + redirty_page_for_writepage(wbc, page); 1382 + return AOP_WRITEPAGE_ACTIVATE; 1383 + } 1384 + 1385 + static int f2fs_write_node_page(struct page *page, 1386 + struct writeback_control *wbc) 1387 + { 1388 + return __write_node_page(page, false, NULL, wbc); 1389 + } 1390 + 1323 1391 int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 1324 1392 struct writeback_control *wbc, bool atomic) 1325 1393 { 1326 1394 pgoff_t index, end; 1395 + pgoff_t last_idx = ULONG_MAX; 1327 1396 struct pagevec pvec; 1328 1397 int ret = 0; 1329 1398 struct page *last_page = NULL; 1330 1399 bool marked = false; 1331 1400 nid_t ino = inode->i_ino; 1332 - int nwritten = 0; 1333 1401 1334 1402 if (atomic) { 1335 1403 last_page = last_fsync_dnode(sbi, ino); ··· 1434 1336 1435 1337 for (i = 0; i < nr_pages; i++) { 1436 1338 struct page *page = pvec.pages[i]; 1339 + bool submitted = false; 1437 1340 1438 1341 if (unlikely(f2fs_cp_error(sbi))) { 1439 1342 f2fs_put_page(last_page, 0); ··· 1483 1384 if (!clear_page_dirty_for_io(page)) 1484 1385 goto continue_unlock; 1485 1386 1486 - ret = NODE_MAPPING(sbi)->a_ops->writepage(page, wbc); 1387 + ret = __write_node_page(page, atomic && 1388 + page == last_page, 1389 + &submitted, wbc); 1487 1390 if (ret) { 1488 1391 unlock_page(page); 1489 1392 f2fs_put_page(last_page, 0); 1490 1393 break; 1491 - } else { 1492 - nwritten++; 1394 + } else if (submitted) { 1395 + last_idx = page->index; 1493 1396 } 1494 1397 1495 1398 if (page == last_page) { ··· 1517 1416 goto retry; 1518 1417 } 1519 1418 out: 1520 - if (nwritten) 1521 - f2fs_submit_merged_bio_cond(sbi, NULL, NULL, ino, NODE, WRITE); 1419 + if (last_idx != ULONG_MAX) 1420 + f2fs_submit_merged_bio_cond(sbi, NULL, ino, last_idx, 1421 + NODE, WRITE); 1522 1422 return ret ? -EIO: 0; 1523 1423 } 1524 1424 ··· 1547 1445 1548 1446 for (i = 0; i < nr_pages; i++) { 1549 1447 struct page *page = pvec.pages[i]; 1448 + bool submitted = false; 1550 1449 1551 1450 if (unlikely(f2fs_cp_error(sbi))) { 1552 1451 pagevec_release(&pvec); ··· 1601 1498 set_fsync_mark(page, 0); 1602 1499 set_dentry_mark(page, 0); 1603 1500 1604 - if (NODE_MAPPING(sbi)->a_ops->writepage(page, wbc)) 1501 + ret = __write_node_page(page, false, &submitted, wbc); 1502 + if (ret) 1605 1503 unlock_page(page); 1606 - else 1504 + else if (submitted) 1607 1505 nwritten++; 1608 1506 1609 1507 if (--wbc->nr_to_write == 0) ··· 1666 1562 if (!ret) 1667 1563 ret = ret2; 1668 1564 return ret; 1669 - } 1670 - 1671 - static int f2fs_write_node_page(struct page *page, 1672 - struct writeback_control *wbc) 1673 - { 1674 - struct f2fs_sb_info *sbi = F2FS_P_SB(page); 1675 - nid_t nid; 1676 - struct node_info ni; 1677 - struct f2fs_io_info fio = { 1678 - .sbi = sbi, 1679 - .type = NODE, 1680 - .op = REQ_OP_WRITE, 1681 - .op_flags = wbc_to_write_flags(wbc), 1682 - .page = page, 1683 - .encrypted_page = NULL, 1684 - }; 1685 - 1686 - trace_f2fs_writepage(page, NODE); 1687 - 1688 - if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 1689 - goto redirty_out; 1690 - if (unlikely(f2fs_cp_error(sbi))) 1691 - goto redirty_out; 1692 - 1693 - /* get old block addr of this node page */ 1694 - nid = nid_of_node(page); 1695 - f2fs_bug_on(sbi, page->index != nid); 1696 - 1697 - if (wbc->for_reclaim) { 1698 - if (!down_read_trylock(&sbi->node_write)) 1699 - goto redirty_out; 1700 - } else { 1701 - down_read(&sbi->node_write); 1702 - } 1703 - 1704 - get_node_info(sbi, nid, &ni); 1705 - 1706 - /* This page is already truncated */ 1707 - if (unlikely(ni.blk_addr == NULL_ADDR)) { 1708 - ClearPageUptodate(page); 1709 - dec_page_count(sbi, F2FS_DIRTY_NODES); 1710 - up_read(&sbi->node_write); 1711 - unlock_page(page); 1712 - return 0; 1713 - } 1714 - 1715 - set_page_writeback(page); 1716 - fio.old_blkaddr = ni.blk_addr; 1717 - write_node_page(nid, &fio); 1718 - set_node_addr(sbi, &ni, fio.new_blkaddr, is_fsync_dnode(page)); 1719 - dec_page_count(sbi, F2FS_DIRTY_NODES); 1720 - up_read(&sbi->node_write); 1721 - 1722 - if (wbc->for_reclaim) 1723 - f2fs_submit_merged_bio_cond(sbi, NULL, page, 0, NODE, WRITE); 1724 - 1725 - unlock_page(page); 1726 - 1727 - if (unlikely(f2fs_cp_error(sbi))) 1728 - f2fs_submit_merged_bio(sbi, NODE, WRITE); 1729 - 1730 - return 0; 1731 - 1732 - redirty_out: 1733 - redirty_page_for_writepage(wbc, page); 1734 - return AOP_WRITEPAGE_ACTIVATE; 1735 1565 } 1736 1566 1737 1567 static int f2fs_write_node_pages(struct address_space *mapping, ··· 1765 1727 radix_tree_delete(&nm_i->free_nid_root, i->nid); 1766 1728 } 1767 1729 1768 - static int add_free_nid(struct f2fs_sb_info *sbi, nid_t nid, bool build) 1730 + /* return if the nid is recognized as free */ 1731 + static bool add_free_nid(struct f2fs_sb_info *sbi, nid_t nid, bool build) 1769 1732 { 1770 1733 struct f2fs_nm_info *nm_i = NM_I(sbi); 1771 1734 struct free_nid *i; ··· 1775 1736 1776 1737 /* 0 nid should not be used */ 1777 1738 if (unlikely(nid == 0)) 1778 - return 0; 1739 + return false; 1779 1740 1780 1741 if (build) { 1781 1742 /* do not add allocated nids */ 1782 1743 ne = __lookup_nat_cache(nm_i, nid); 1783 1744 if (ne && (!get_nat_flag(ne, IS_CHECKPOINTED) || 1784 1745 nat_get_blkaddr(ne) != NULL_ADDR)) 1785 - return 0; 1746 + return false; 1786 1747 } 1787 1748 1788 1749 i = f2fs_kmem_cache_alloc(free_nid_slab, GFP_NOFS); ··· 1791 1752 1792 1753 if (radix_tree_preload(GFP_NOFS)) { 1793 1754 kmem_cache_free(free_nid_slab, i); 1794 - return 0; 1755 + return true; 1795 1756 } 1796 1757 1797 1758 spin_lock(&nm_i->nid_list_lock); ··· 1800 1761 radix_tree_preload_end(); 1801 1762 if (err) { 1802 1763 kmem_cache_free(free_nid_slab, i); 1803 - return 0; 1764 + return true; 1804 1765 } 1805 - return 1; 1766 + return true; 1806 1767 } 1807 1768 1808 1769 static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid) ··· 1823 1784 kmem_cache_free(free_nid_slab, i); 1824 1785 } 1825 1786 1787 + void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid, bool set) 1788 + { 1789 + struct f2fs_nm_info *nm_i = NM_I(sbi); 1790 + unsigned int nat_ofs = NAT_BLOCK_OFFSET(nid); 1791 + unsigned int nid_ofs = nid - START_NID(nid); 1792 + 1793 + if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap)) 1794 + return; 1795 + 1796 + if (set) 1797 + set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); 1798 + else 1799 + clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); 1800 + } 1801 + 1826 1802 static void scan_nat_page(struct f2fs_sb_info *sbi, 1827 1803 struct page *nat_page, nid_t start_nid) 1828 1804 { 1829 1805 struct f2fs_nm_info *nm_i = NM_I(sbi); 1830 1806 struct f2fs_nat_block *nat_blk = page_address(nat_page); 1831 1807 block_t blk_addr; 1808 + unsigned int nat_ofs = NAT_BLOCK_OFFSET(start_nid); 1832 1809 int i; 1810 + 1811 + set_bit_le(nat_ofs, nm_i->nat_block_bitmap); 1833 1812 1834 1813 i = start_nid % NAT_ENTRY_PER_BLOCK; 1835 1814 1836 1815 for (; i < NAT_ENTRY_PER_BLOCK; i++, start_nid++) { 1816 + bool freed = false; 1837 1817 1838 1818 if (unlikely(start_nid >= nm_i->max_nid)) 1839 1819 break; ··· 1860 1802 blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr); 1861 1803 f2fs_bug_on(sbi, blk_addr == NEW_ADDR); 1862 1804 if (blk_addr == NULL_ADDR) 1863 - add_free_nid(sbi, start_nid, true); 1805 + freed = add_free_nid(sbi, start_nid, true); 1806 + update_free_nid_bitmap(sbi, start_nid, freed); 1864 1807 } 1865 1808 } 1866 1809 1867 - static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync) 1810 + static void scan_free_nid_bits(struct f2fs_sb_info *sbi) 1811 + { 1812 + struct f2fs_nm_info *nm_i = NM_I(sbi); 1813 + struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); 1814 + struct f2fs_journal *journal = curseg->journal; 1815 + unsigned int i, idx; 1816 + 1817 + down_read(&nm_i->nat_tree_lock); 1818 + 1819 + for (i = 0; i < nm_i->nat_blocks; i++) { 1820 + if (!test_bit_le(i, nm_i->nat_block_bitmap)) 1821 + continue; 1822 + for (idx = 0; idx < NAT_ENTRY_PER_BLOCK; idx++) { 1823 + nid_t nid; 1824 + 1825 + if (!test_bit_le(idx, nm_i->free_nid_bitmap[i])) 1826 + continue; 1827 + 1828 + nid = i * NAT_ENTRY_PER_BLOCK + idx; 1829 + add_free_nid(sbi, nid, true); 1830 + 1831 + if (nm_i->nid_cnt[FREE_NID_LIST] >= MAX_FREE_NIDS) 1832 + goto out; 1833 + } 1834 + } 1835 + out: 1836 + down_read(&curseg->journal_rwsem); 1837 + for (i = 0; i < nats_in_cursum(journal); i++) { 1838 + block_t addr; 1839 + nid_t nid; 1840 + 1841 + addr = le32_to_cpu(nat_in_journal(journal, i).block_addr); 1842 + nid = le32_to_cpu(nid_in_journal(journal, i)); 1843 + if (addr == NULL_ADDR) 1844 + add_free_nid(sbi, nid, true); 1845 + else 1846 + remove_free_nid(sbi, nid); 1847 + } 1848 + up_read(&curseg->journal_rwsem); 1849 + up_read(&nm_i->nat_tree_lock); 1850 + } 1851 + 1852 + static int scan_nat_bits(struct f2fs_sb_info *sbi) 1853 + { 1854 + struct f2fs_nm_info *nm_i = NM_I(sbi); 1855 + struct page *page; 1856 + unsigned int i = 0; 1857 + nid_t nid; 1858 + 1859 + if (!enabled_nat_bits(sbi, NULL)) 1860 + return -EAGAIN; 1861 + 1862 + down_read(&nm_i->nat_tree_lock); 1863 + check_empty: 1864 + i = find_next_bit_le(nm_i->empty_nat_bits, nm_i->nat_blocks, i); 1865 + if (i >= nm_i->nat_blocks) { 1866 + i = 0; 1867 + goto check_partial; 1868 + } 1869 + 1870 + for (nid = i * NAT_ENTRY_PER_BLOCK; nid < (i + 1) * NAT_ENTRY_PER_BLOCK; 1871 + nid++) { 1872 + if (unlikely(nid >= nm_i->max_nid)) 1873 + break; 1874 + add_free_nid(sbi, nid, true); 1875 + } 1876 + 1877 + if (nm_i->nid_cnt[FREE_NID_LIST] >= MAX_FREE_NIDS) 1878 + goto out; 1879 + i++; 1880 + goto check_empty; 1881 + 1882 + check_partial: 1883 + i = find_next_zero_bit_le(nm_i->full_nat_bits, nm_i->nat_blocks, i); 1884 + if (i >= nm_i->nat_blocks) { 1885 + disable_nat_bits(sbi, true); 1886 + up_read(&nm_i->nat_tree_lock); 1887 + return -EINVAL; 1888 + } 1889 + 1890 + nid = i * NAT_ENTRY_PER_BLOCK; 1891 + page = get_current_nat_page(sbi, nid); 1892 + scan_nat_page(sbi, page, nid); 1893 + f2fs_put_page(page, 1); 1894 + 1895 + if (nm_i->nid_cnt[FREE_NID_LIST] < MAX_FREE_NIDS) { 1896 + i++; 1897 + goto check_partial; 1898 + } 1899 + out: 1900 + up_read(&nm_i->nat_tree_lock); 1901 + return 0; 1902 + } 1903 + 1904 + static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) 1868 1905 { 1869 1906 struct f2fs_nm_info *nm_i = NM_I(sbi); 1870 1907 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); ··· 1973 1820 1974 1821 if (!sync && !available_free_memory(sbi, FREE_NIDS)) 1975 1822 return; 1823 + 1824 + if (!mount) { 1825 + /* try to find free nids in free_nid_bitmap */ 1826 + scan_free_nid_bits(sbi); 1827 + 1828 + if (nm_i->nid_cnt[FREE_NID_LIST]) 1829 + return; 1830 + 1831 + /* try to find free nids with nat_bits */ 1832 + if (!scan_nat_bits(sbi) && nm_i->nid_cnt[FREE_NID_LIST]) 1833 + return; 1834 + } 1835 + 1836 + /* find next valid candidate */ 1837 + if (enabled_nat_bits(sbi, NULL)) { 1838 + int idx = find_next_zero_bit_le(nm_i->full_nat_bits, 1839 + nm_i->nat_blocks, 0); 1840 + 1841 + if (idx >= nm_i->nat_blocks) 1842 + set_sbi_flag(sbi, SBI_NEED_FSCK); 1843 + else 1844 + nid = idx * NAT_ENTRY_PER_BLOCK; 1845 + } 1976 1846 1977 1847 /* readahead nat pages to be scanned */ 1978 1848 ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), FREE_NID_PAGES, ··· 2039 1863 nm_i->ra_nid_pages, META_NAT, false); 2040 1864 } 2041 1865 2042 - void build_free_nids(struct f2fs_sb_info *sbi, bool sync) 1866 + void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) 2043 1867 { 2044 1868 mutex_lock(&NM_I(sbi)->build_lock); 2045 - __build_free_nids(sbi, sync); 1869 + __build_free_nids(sbi, sync, mount); 2046 1870 mutex_unlock(&NM_I(sbi)->build_lock); 2047 1871 } 2048 1872 ··· 2057 1881 struct free_nid *i = NULL; 2058 1882 retry: 2059 1883 #ifdef CONFIG_F2FS_FAULT_INJECTION 2060 - if (time_to_inject(sbi, FAULT_ALLOC_NID)) 1884 + if (time_to_inject(sbi, FAULT_ALLOC_NID)) { 1885 + f2fs_show_injection_info(FAULT_ALLOC_NID); 2061 1886 return false; 1887 + } 2062 1888 #endif 2063 1889 spin_lock(&nm_i->nid_list_lock); 2064 1890 ··· 2080 1902 i->state = NID_ALLOC; 2081 1903 __insert_nid_to_list(sbi, i, ALLOC_NID_LIST, false); 2082 1904 nm_i->available_nids--; 1905 + 1906 + update_free_nid_bitmap(sbi, *nid, false); 1907 + 2083 1908 spin_unlock(&nm_i->nid_list_lock); 2084 1909 return true; 2085 1910 } 2086 1911 spin_unlock(&nm_i->nid_list_lock); 2087 1912 2088 1913 /* Let's scan nat pages and its caches to get free nids */ 2089 - build_free_nids(sbi, true); 1914 + build_free_nids(sbi, true, false); 2090 1915 goto retry; 2091 1916 } 2092 1917 ··· 2136 1955 } 2137 1956 2138 1957 nm_i->available_nids++; 1958 + 1959 + update_free_nid_bitmap(sbi, nid, true); 2139 1960 2140 1961 spin_unlock(&nm_i->nid_list_lock); 2141 1962 ··· 2201 2018 f2fs_put_page(ipage, 1); 2202 2019 } 2203 2020 2204 - void recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr) 2021 + int recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr) 2205 2022 { 2206 2023 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2207 2024 nid_t prev_xnid = F2FS_I(inode)->i_xattr_nid; 2208 2025 nid_t new_xnid = nid_of_node(page); 2209 2026 struct node_info ni; 2027 + struct page *xpage; 2210 2028 2211 - /* 1: invalidate the previous xattr nid */ 2212 2029 if (!prev_xnid) 2213 2030 goto recover_xnid; 2214 2031 2215 - /* Deallocate node address */ 2032 + /* 1: invalidate the previous xattr nid */ 2216 2033 get_node_info(sbi, prev_xnid, &ni); 2217 2034 f2fs_bug_on(sbi, ni.blk_addr == NULL_ADDR); 2218 2035 invalidate_blocks(sbi, ni.blk_addr); ··· 2220 2037 set_node_addr(sbi, &ni, NULL_ADDR, false); 2221 2038 2222 2039 recover_xnid: 2223 - /* 2: allocate new xattr nid */ 2040 + /* 2: update xattr nid in inode */ 2041 + remove_free_nid(sbi, new_xnid); 2042 + f2fs_i_xnid_write(inode, new_xnid); 2224 2043 if (unlikely(!inc_valid_node_count(sbi, inode))) 2225 2044 f2fs_bug_on(sbi, 1); 2045 + update_inode_page(inode); 2226 2046 2227 - remove_free_nid(sbi, new_xnid); 2047 + /* 3: update and set xattr node page dirty */ 2048 + xpage = grab_cache_page(NODE_MAPPING(sbi), new_xnid); 2049 + if (!xpage) 2050 + return -ENOMEM; 2051 + 2052 + memcpy(F2FS_NODE(xpage), F2FS_NODE(page), PAGE_SIZE); 2053 + 2228 2054 get_node_info(sbi, new_xnid, &ni); 2229 2055 ni.ino = inode->i_ino; 2230 2056 set_node_addr(sbi, &ni, NEW_ADDR, false); 2231 - f2fs_i_xnid_write(inode, new_xnid); 2057 + set_page_dirty(xpage); 2058 + f2fs_put_page(xpage, 1); 2232 2059 2233 - /* 3: update xattr blkaddr */ 2234 - refresh_sit_entry(sbi, NEW_ADDR, blkaddr); 2235 - set_node_addr(sbi, &ni, blkaddr, false); 2060 + return 0; 2236 2061 } 2237 2062 2238 2063 int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page) ··· 2343 2152 2344 2153 ne = __lookup_nat_cache(nm_i, nid); 2345 2154 if (!ne) { 2346 - ne = grab_nat_entry(nm_i, nid); 2155 + ne = grab_nat_entry(nm_i, nid, true); 2347 2156 node_info_from_raw_nat(&ne->ni, &raw_ne); 2348 2157 } 2349 2158 ··· 2383 2192 list_add_tail(&nes->set_list, head); 2384 2193 } 2385 2194 2195 + void __update_nat_bits(struct f2fs_sb_info *sbi, nid_t start_nid, 2196 + struct page *page) 2197 + { 2198 + struct f2fs_nm_info *nm_i = NM_I(sbi); 2199 + unsigned int nat_index = start_nid / NAT_ENTRY_PER_BLOCK; 2200 + struct f2fs_nat_block *nat_blk = page_address(page); 2201 + int valid = 0; 2202 + int i; 2203 + 2204 + if (!enabled_nat_bits(sbi, NULL)) 2205 + return; 2206 + 2207 + for (i = 0; i < NAT_ENTRY_PER_BLOCK; i++) { 2208 + if (start_nid == 0 && i == 0) 2209 + valid++; 2210 + if (nat_blk->entries[i].block_addr) 2211 + valid++; 2212 + } 2213 + if (valid == 0) { 2214 + set_bit_le(nat_index, nm_i->empty_nat_bits); 2215 + clear_bit_le(nat_index, nm_i->full_nat_bits); 2216 + return; 2217 + } 2218 + 2219 + clear_bit_le(nat_index, nm_i->empty_nat_bits); 2220 + if (valid == NAT_ENTRY_PER_BLOCK) 2221 + set_bit_le(nat_index, nm_i->full_nat_bits); 2222 + else 2223 + clear_bit_le(nat_index, nm_i->full_nat_bits); 2224 + } 2225 + 2386 2226 static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, 2387 - struct nat_entry_set *set) 2227 + struct nat_entry_set *set, struct cp_control *cpc) 2388 2228 { 2389 2229 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); 2390 2230 struct f2fs_journal *journal = curseg->journal; ··· 2430 2208 * #1, flush nat entries to journal in current hot data summary block. 2431 2209 * #2, flush nat entries to nat page. 2432 2210 */ 2433 - if (!__has_cursum_space(journal, set->entry_cnt, NAT_JOURNAL)) 2211 + if (enabled_nat_bits(sbi, cpc) || 2212 + !__has_cursum_space(journal, set->entry_cnt, NAT_JOURNAL)) 2434 2213 to_journal = false; 2435 2214 2436 2215 if (to_journal) { ··· 2467 2244 add_free_nid(sbi, nid, false); 2468 2245 spin_lock(&NM_I(sbi)->nid_list_lock); 2469 2246 NM_I(sbi)->available_nids++; 2247 + update_free_nid_bitmap(sbi, nid, true); 2248 + spin_unlock(&NM_I(sbi)->nid_list_lock); 2249 + } else { 2250 + spin_lock(&NM_I(sbi)->nid_list_lock); 2251 + update_free_nid_bitmap(sbi, nid, false); 2470 2252 spin_unlock(&NM_I(sbi)->nid_list_lock); 2471 2253 } 2472 2254 } 2473 2255 2474 - if (to_journal) 2256 + if (to_journal) { 2475 2257 up_write(&curseg->journal_rwsem); 2476 - else 2258 + } else { 2259 + __update_nat_bits(sbi, start_nid, page); 2477 2260 f2fs_put_page(page, 1); 2261 + } 2478 2262 2479 2263 f2fs_bug_on(sbi, set->entry_cnt); 2480 2264 ··· 2492 2262 /* 2493 2263 * This function is called during the checkpointing process. 2494 2264 */ 2495 - void flush_nat_entries(struct f2fs_sb_info *sbi) 2265 + void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) 2496 2266 { 2497 2267 struct f2fs_nm_info *nm_i = NM_I(sbi); 2498 2268 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); ··· 2513 2283 * entries, remove all entries from journal and merge them 2514 2284 * into nat entry set. 2515 2285 */ 2516 - if (!__has_cursum_space(journal, nm_i->dirty_nat_cnt, NAT_JOURNAL)) 2286 + if (enabled_nat_bits(sbi, cpc) || 2287 + !__has_cursum_space(journal, nm_i->dirty_nat_cnt, NAT_JOURNAL)) 2517 2288 remove_nats_in_journal(sbi); 2518 2289 2519 2290 while ((found = __gang_lookup_nat_set(nm_i, ··· 2528 2297 2529 2298 /* flush dirty nats in nat entry set */ 2530 2299 list_for_each_entry_safe(set, tmp, &sets, set_list) 2531 - __flush_nat_entry_set(sbi, set); 2300 + __flush_nat_entry_set(sbi, set, cpc); 2532 2301 2533 2302 up_write(&nm_i->nat_tree_lock); 2534 2303 2535 2304 f2fs_bug_on(sbi, nm_i->dirty_nat_cnt); 2305 + } 2306 + 2307 + static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) 2308 + { 2309 + struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 2310 + struct f2fs_nm_info *nm_i = NM_I(sbi); 2311 + unsigned int nat_bits_bytes = nm_i->nat_blocks / BITS_PER_BYTE; 2312 + unsigned int i; 2313 + __u64 cp_ver = cur_cp_version(ckpt); 2314 + block_t nat_bits_addr; 2315 + 2316 + if (!enabled_nat_bits(sbi, NULL)) 2317 + return 0; 2318 + 2319 + nm_i->nat_bits_blocks = F2FS_BYTES_TO_BLK((nat_bits_bytes << 1) + 8 + 2320 + F2FS_BLKSIZE - 1); 2321 + nm_i->nat_bits = kzalloc(nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, 2322 + GFP_KERNEL); 2323 + if (!nm_i->nat_bits) 2324 + return -ENOMEM; 2325 + 2326 + nat_bits_addr = __start_cp_addr(sbi) + sbi->blocks_per_seg - 2327 + nm_i->nat_bits_blocks; 2328 + for (i = 0; i < nm_i->nat_bits_blocks; i++) { 2329 + struct page *page = get_meta_page(sbi, nat_bits_addr++); 2330 + 2331 + memcpy(nm_i->nat_bits + (i << F2FS_BLKSIZE_BITS), 2332 + page_address(page), F2FS_BLKSIZE); 2333 + f2fs_put_page(page, 1); 2334 + } 2335 + 2336 + cp_ver |= (cur_cp_crc(ckpt) << 32); 2337 + if (cpu_to_le64(cp_ver) != *(__le64 *)nm_i->nat_bits) { 2338 + disable_nat_bits(sbi, true); 2339 + return 0; 2340 + } 2341 + 2342 + nm_i->full_nat_bits = nm_i->nat_bits + 8; 2343 + nm_i->empty_nat_bits = nm_i->full_nat_bits + nat_bits_bytes; 2344 + 2345 + f2fs_msg(sbi->sb, KERN_NOTICE, "Found nat_bits in checkpoint"); 2346 + return 0; 2536 2347 } 2537 2348 2538 2349 static int init_node_manager(struct f2fs_sb_info *sbi) ··· 2582 2309 struct f2fs_super_block *sb_raw = F2FS_RAW_SUPER(sbi); 2583 2310 struct f2fs_nm_info *nm_i = NM_I(sbi); 2584 2311 unsigned char *version_bitmap; 2585 - unsigned int nat_segs, nat_blocks; 2312 + unsigned int nat_segs; 2313 + int err; 2586 2314 2587 2315 nm_i->nat_blkaddr = le32_to_cpu(sb_raw->nat_blkaddr); 2588 2316 2589 2317 /* segment_count_nat includes pair segment so divide to 2. */ 2590 2318 nat_segs = le32_to_cpu(sb_raw->segment_count_nat) >> 1; 2591 - nat_blocks = nat_segs << le32_to_cpu(sb_raw->log_blocks_per_seg); 2592 - 2593 - nm_i->max_nid = NAT_ENTRY_PER_BLOCK * nat_blocks; 2319 + nm_i->nat_blocks = nat_segs << le32_to_cpu(sb_raw->log_blocks_per_seg); 2320 + nm_i->max_nid = NAT_ENTRY_PER_BLOCK * nm_i->nat_blocks; 2594 2321 2595 2322 /* not used nids: 0, node, meta, (and root counted as valid node) */ 2596 2323 nm_i->available_nids = nm_i->max_nid - sbi->total_valid_node_count - ··· 2623 2350 GFP_KERNEL); 2624 2351 if (!nm_i->nat_bitmap) 2625 2352 return -ENOMEM; 2353 + 2354 + err = __get_nat_bitmaps(sbi); 2355 + if (err) 2356 + return err; 2357 + 2358 + #ifdef CONFIG_F2FS_CHECK_FS 2359 + nm_i->nat_bitmap_mir = kmemdup(version_bitmap, nm_i->bitmap_size, 2360 + GFP_KERNEL); 2361 + if (!nm_i->nat_bitmap_mir) 2362 + return -ENOMEM; 2363 + #endif 2364 + 2365 + return 0; 2366 + } 2367 + 2368 + int init_free_nid_cache(struct f2fs_sb_info *sbi) 2369 + { 2370 + struct f2fs_nm_info *nm_i = NM_I(sbi); 2371 + 2372 + nm_i->free_nid_bitmap = f2fs_kvzalloc(nm_i->nat_blocks * 2373 + NAT_ENTRY_BITMAP_SIZE, GFP_KERNEL); 2374 + if (!nm_i->free_nid_bitmap) 2375 + return -ENOMEM; 2376 + 2377 + nm_i->nat_block_bitmap = f2fs_kvzalloc(nm_i->nat_blocks / 8, 2378 + GFP_KERNEL); 2379 + if (!nm_i->nat_block_bitmap) 2380 + return -ENOMEM; 2626 2381 return 0; 2627 2382 } 2628 2383 ··· 2666 2365 if (err) 2667 2366 return err; 2668 2367 2669 - build_free_nids(sbi, true); 2368 + err = init_free_nid_cache(sbi); 2369 + if (err) 2370 + return err; 2371 + 2372 + build_free_nids(sbi, true, true); 2670 2373 return 0; 2671 2374 } 2672 2375 ··· 2728 2423 } 2729 2424 up_write(&nm_i->nat_tree_lock); 2730 2425 2426 + kvfree(nm_i->nat_block_bitmap); 2427 + kvfree(nm_i->free_nid_bitmap); 2428 + 2731 2429 kfree(nm_i->nat_bitmap); 2430 + kfree(nm_i->nat_bits); 2431 + #ifdef CONFIG_F2FS_CHECK_FS 2432 + kfree(nm_i->nat_bitmap_mir); 2433 + #endif 2732 2434 sbi->nm_info = NULL; 2733 2435 kfree(nm_i); 2734 2436 }
+18 -15
fs/f2fs/node.h
··· 174 174 spin_unlock(&nm_i->nid_list_lock); 175 175 return; 176 176 } 177 - fnid = list_entry(nm_i->nid_list[FREE_NID_LIST].next, 177 + fnid = list_first_entry(&nm_i->nid_list[FREE_NID_LIST], 178 178 struct free_nid, list); 179 179 *nid = fnid->nid; 180 180 spin_unlock(&nm_i->nid_list_lock); ··· 186 186 static inline void get_nat_bitmap(struct f2fs_sb_info *sbi, void *addr) 187 187 { 188 188 struct f2fs_nm_info *nm_i = NM_I(sbi); 189 + 190 + #ifdef CONFIG_F2FS_CHECK_FS 191 + if (memcmp(nm_i->nat_bitmap, nm_i->nat_bitmap_mir, 192 + nm_i->bitmap_size)) 193 + f2fs_bug_on(sbi, 1); 194 + #endif 189 195 memcpy(addr, nm_i->nat_bitmap, nm_i->bitmap_size); 190 196 } 191 197 ··· 234 228 unsigned int block_off = NAT_BLOCK_OFFSET(start_nid); 235 229 236 230 f2fs_change_bit(block_off, nm_i->nat_bitmap); 231 + #ifdef CONFIG_F2FS_CHECK_FS 232 + f2fs_change_bit(block_off, nm_i->nat_bitmap_mir); 233 + #endif 237 234 } 238 235 239 236 static inline nid_t ino_of_node(struct page *node_page) ··· 300 291 { 301 292 struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page)); 302 293 struct f2fs_node *rn = F2FS_NODE(page); 303 - size_t crc_offset = le32_to_cpu(ckpt->checksum_offset); 304 - __u64 cp_ver = le64_to_cpu(ckpt->checkpoint_ver); 294 + __u64 cp_ver = cur_cp_version(ckpt); 305 295 306 - if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) { 307 - __u64 crc = le32_to_cpu(*((__le32 *) 308 - ((unsigned char *)ckpt + crc_offset))); 309 - cp_ver |= (crc << 32); 310 - } 296 + if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) 297 + cp_ver |= (cur_cp_crc(ckpt) << 32); 298 + 311 299 rn->footer.cp_ver = cpu_to_le64(cp_ver); 312 300 rn->footer.next_blkaddr = cpu_to_le32(blkaddr); 313 301 } ··· 312 306 static inline bool is_recoverable_dnode(struct page *page) 313 307 { 314 308 struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page)); 315 - size_t crc_offset = le32_to_cpu(ckpt->checksum_offset); 316 309 __u64 cp_ver = cur_cp_version(ckpt); 317 310 318 - if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) { 319 - __u64 crc = le32_to_cpu(*((__le32 *) 320 - ((unsigned char *)ckpt + crc_offset))); 321 - cp_ver |= (crc << 32); 322 - } 311 + if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) 312 + cp_ver |= (cur_cp_crc(ckpt) << 32); 313 + 323 314 return cp_ver == cpver_of_node(page); 324 315 } 325 316 ··· 346 343 unsigned int ofs = ofs_of_node(node_page); 347 344 348 345 if (f2fs_has_xattr_block(ofs)) 349 - return false; 346 + return true; 350 347 351 348 if (ofs == 3 || ofs == 4 + NIDS_PER_BLOCK || 352 349 ofs == 5 + 2 * NIDS_PER_BLOCK)
+6 -11
fs/f2fs/recovery.c
··· 378 378 if (IS_INODE(page)) { 379 379 recover_inline_xattr(inode, page); 380 380 } else if (f2fs_has_xattr_block(ofs_of_node(page))) { 381 - /* 382 - * Deprecated; xattr blocks should be found from cold log. 383 - * But, we should remain this for backward compatibility. 384 - */ 385 - recover_xattr_data(inode, page, blkaddr); 381 + err = recover_xattr_data(inode, page, blkaddr); 382 + if (!err) 383 + recovered++; 386 384 goto out; 387 385 } 388 386 ··· 426 428 } 427 429 428 430 if (!file_keep_isize(inode) && 429 - (i_size_read(inode) <= (start << PAGE_SHIFT))) 430 - f2fs_i_size_write(inode, (start + 1) << PAGE_SHIFT); 431 + (i_size_read(inode) <= ((loff_t)start << PAGE_SHIFT))) 432 + f2fs_i_size_write(inode, 433 + (loff_t)(start + 1) << PAGE_SHIFT); 431 434 432 435 /* 433 436 * dest is reserved block, invalidate src block ··· 551 552 552 553 int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only) 553 554 { 554 - struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_WARM_NODE); 555 555 struct list_head inode_list; 556 556 struct list_head dir_list; 557 - block_t blkaddr; 558 557 int err; 559 558 int ret = 0; 560 559 bool need_writecp = false; ··· 567 570 568 571 /* prevent checkpoint */ 569 572 mutex_lock(&sbi->cp_mutex); 570 - 571 - blkaddr = NEXT_FREE_BLKADDR(sbi, curseg); 572 573 573 574 /* step #1: find fsynced inode numbers */ 574 575 err = find_fsync_dnodes(sbi, &inode_list);
+366 -139
fs/f2fs/segment.c
··· 26 26 #define __reverse_ffz(x) __reverse_ffs(~(x)) 27 27 28 28 static struct kmem_cache *discard_entry_slab; 29 - static struct kmem_cache *bio_entry_slab; 29 + static struct kmem_cache *discard_cmd_slab; 30 30 static struct kmem_cache *sit_entry_set_slab; 31 31 static struct kmem_cache *inmem_entry_slab; 32 32 ··· 242 242 { 243 243 struct f2fs_inode_info *fi = F2FS_I(inode); 244 244 245 - clear_inode_flag(inode, FI_ATOMIC_FILE); 246 - 247 245 mutex_lock(&fi->inmem_lock); 248 246 __revoke_inmem_pages(inode, &fi->inmem_pages, true, false); 249 247 mutex_unlock(&fi->inmem_lock); 248 + 249 + clear_inode_flag(inode, FI_ATOMIC_FILE); 250 + stat_dec_atomic_write(inode); 250 251 } 251 252 252 253 static int __commit_inmem_pages(struct inode *inode, ··· 263 262 .op_flags = REQ_SYNC | REQ_PRIO, 264 263 .encrypted_page = NULL, 265 264 }; 266 - bool submit_bio = false; 265 + pgoff_t last_idx = ULONG_MAX; 267 266 int err = 0; 268 267 269 268 list_for_each_entry_safe(cur, tmp, &fi->inmem_pages, list) { ··· 289 288 290 289 /* record old blkaddr for revoking */ 291 290 cur->old_addr = fio.old_blkaddr; 292 - 293 - submit_bio = true; 291 + last_idx = page->index; 294 292 } 295 293 unlock_page(page); 296 294 list_move_tail(&cur->list, revoke_list); 297 295 } 298 296 299 - if (submit_bio) 300 - f2fs_submit_merged_bio_cond(sbi, inode, NULL, 0, DATA, WRITE); 297 + if (last_idx != ULONG_MAX) 298 + f2fs_submit_merged_bio_cond(sbi, inode, 0, last_idx, 299 + DATA, WRITE); 301 300 302 301 if (!err) 303 302 __revoke_inmem_pages(inode, revoke_list, false, false); ··· 315 314 INIT_LIST_HEAD(&revoke_list); 316 315 f2fs_balance_fs(sbi, true); 317 316 f2fs_lock_op(sbi); 317 + 318 + set_inode_flag(inode, FI_ATOMIC_COMMIT); 318 319 319 320 mutex_lock(&fi->inmem_lock); 320 321 err = __commit_inmem_pages(inode, &revoke_list); ··· 339 336 } 340 337 mutex_unlock(&fi->inmem_lock); 341 338 339 + clear_inode_flag(inode, FI_ATOMIC_COMMIT); 340 + 342 341 f2fs_unlock_op(sbi); 343 342 return err; 344 343 } ··· 352 347 void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) 353 348 { 354 349 #ifdef CONFIG_F2FS_FAULT_INJECTION 355 - if (time_to_inject(sbi, FAULT_CHECKPOINT)) 350 + if (time_to_inject(sbi, FAULT_CHECKPOINT)) { 351 + f2fs_show_injection_info(FAULT_CHECKPOINT); 356 352 f2fs_stop_checkpoint(sbi, false); 353 + } 357 354 #endif 358 355 359 356 if (!need) ··· 388 381 if (!available_free_memory(sbi, FREE_NIDS)) 389 382 try_to_free_nids(sbi, MAX_FREE_NIDS); 390 383 else 391 - build_free_nids(sbi, false); 384 + build_free_nids(sbi, false, false); 392 385 393 386 if (!is_idle(sbi)) 394 387 return; ··· 430 423 431 424 if (sbi->s_ndevs && !ret) { 432 425 for (i = 1; i < sbi->s_ndevs; i++) { 426 + trace_f2fs_issue_flush(FDEV(i).bdev, 427 + test_opt(sbi, NOBARRIER), 428 + test_opt(sbi, FLUSH_MERGE)); 433 429 ret = __submit_flush_wait(FDEV(i).bdev); 434 430 if (ret) 435 431 break; ··· 444 434 static int issue_flush_thread(void *data) 445 435 { 446 436 struct f2fs_sb_info *sbi = data; 447 - struct flush_cmd_control *fcc = SM_I(sbi)->cmd_control_info; 437 + struct flush_cmd_control *fcc = SM_I(sbi)->fcc_info; 448 438 wait_queue_head_t *q = &fcc->flush_wait_queue; 449 439 repeat: 450 440 if (kthread_should_stop()) ··· 473 463 474 464 int f2fs_issue_flush(struct f2fs_sb_info *sbi) 475 465 { 476 - struct flush_cmd_control *fcc = SM_I(sbi)->cmd_control_info; 466 + struct flush_cmd_control *fcc = SM_I(sbi)->fcc_info; 477 467 struct flush_cmd cmd; 478 - 479 - trace_f2fs_issue_flush(sbi->sb, test_opt(sbi, NOBARRIER), 480 - test_opt(sbi, FLUSH_MERGE)); 481 468 482 469 if (test_opt(sbi, NOBARRIER)) 483 470 return 0; 484 471 485 - if (!test_opt(sbi, FLUSH_MERGE) || !atomic_read(&fcc->submit_flush)) { 472 + if (!test_opt(sbi, FLUSH_MERGE)) 473 + return submit_flush_wait(sbi); 474 + 475 + if (!atomic_read(&fcc->submit_flush)) { 486 476 int ret; 487 477 488 478 atomic_inc(&fcc->submit_flush); ··· 516 506 struct flush_cmd_control *fcc; 517 507 int err = 0; 518 508 519 - if (SM_I(sbi)->cmd_control_info) { 520 - fcc = SM_I(sbi)->cmd_control_info; 509 + if (SM_I(sbi)->fcc_info) { 510 + fcc = SM_I(sbi)->fcc_info; 521 511 goto init_thread; 522 512 } 523 513 ··· 527 517 atomic_set(&fcc->submit_flush, 0); 528 518 init_waitqueue_head(&fcc->flush_wait_queue); 529 519 init_llist_head(&fcc->issue_list); 530 - SM_I(sbi)->cmd_control_info = fcc; 520 + SM_I(sbi)->fcc_info = fcc; 531 521 init_thread: 532 522 fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi, 533 523 "f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev)); 534 524 if (IS_ERR(fcc->f2fs_issue_flush)) { 535 525 err = PTR_ERR(fcc->f2fs_issue_flush); 536 526 kfree(fcc); 537 - SM_I(sbi)->cmd_control_info = NULL; 527 + SM_I(sbi)->fcc_info = NULL; 538 528 return err; 539 529 } 540 530 ··· 543 533 544 534 void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free) 545 535 { 546 - struct flush_cmd_control *fcc = SM_I(sbi)->cmd_control_info; 536 + struct flush_cmd_control *fcc = SM_I(sbi)->fcc_info; 547 537 548 538 if (fcc && fcc->f2fs_issue_flush) { 549 539 struct task_struct *flush_thread = fcc->f2fs_issue_flush; ··· 553 543 } 554 544 if (free) { 555 545 kfree(fcc); 556 - SM_I(sbi)->cmd_control_info = NULL; 546 + SM_I(sbi)->fcc_info = NULL; 557 547 } 558 548 } 559 549 ··· 633 623 mutex_unlock(&dirty_i->seglist_lock); 634 624 } 635 625 636 - static struct bio_entry *__add_bio_entry(struct f2fs_sb_info *sbi, 637 - struct bio *bio) 626 + static void __add_discard_cmd(struct f2fs_sb_info *sbi, 627 + struct bio *bio, block_t lstart, block_t len) 638 628 { 639 - struct list_head *wait_list = &(SM_I(sbi)->wait_list); 640 - struct bio_entry *be = f2fs_kmem_cache_alloc(bio_entry_slab, GFP_NOFS); 629 + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 630 + struct list_head *cmd_list = &(dcc->discard_cmd_list); 631 + struct discard_cmd *dc; 641 632 642 - INIT_LIST_HEAD(&be->list); 643 - be->bio = bio; 644 - init_completion(&be->event); 645 - list_add_tail(&be->list, wait_list); 633 + dc = f2fs_kmem_cache_alloc(discard_cmd_slab, GFP_NOFS); 634 + INIT_LIST_HEAD(&dc->list); 635 + dc->bio = bio; 636 + bio->bi_private = dc; 637 + dc->lstart = lstart; 638 + dc->len = len; 639 + dc->state = D_PREP; 640 + init_completion(&dc->wait); 646 641 647 - return be; 642 + mutex_lock(&dcc->cmd_lock); 643 + list_add_tail(&dc->list, cmd_list); 644 + mutex_unlock(&dcc->cmd_lock); 648 645 } 649 646 650 - void f2fs_wait_all_discard_bio(struct f2fs_sb_info *sbi) 647 + static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc) 651 648 { 652 - struct list_head *wait_list = &(SM_I(sbi)->wait_list); 653 - struct bio_entry *be, *tmp; 649 + int err = dc->bio->bi_error; 654 650 655 - list_for_each_entry_safe(be, tmp, wait_list, list) { 656 - struct bio *bio = be->bio; 657 - int err; 651 + if (dc->state == D_DONE) 652 + atomic_dec(&(SM_I(sbi)->dcc_info->submit_discard)); 658 653 659 - wait_for_completion_io(&be->event); 660 - err = be->error; 661 - if (err == -EOPNOTSUPP) 662 - err = 0; 654 + if (err == -EOPNOTSUPP) 655 + err = 0; 663 656 664 - if (err) 665 - f2fs_msg(sbi->sb, KERN_INFO, 657 + if (err) 658 + f2fs_msg(sbi->sb, KERN_INFO, 666 659 "Issue discard failed, ret: %d", err); 667 - 668 - bio_put(bio); 669 - list_del(&be->list); 670 - kmem_cache_free(bio_entry_slab, be); 671 - } 660 + bio_put(dc->bio); 661 + list_del(&dc->list); 662 + kmem_cache_free(discard_cmd_slab, dc); 672 663 } 673 664 674 - static void f2fs_submit_bio_wait_endio(struct bio *bio) 665 + /* This should be covered by global mutex, &sit_i->sentry_lock */ 666 + void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr) 675 667 { 676 - struct bio_entry *be = (struct bio_entry *)bio->bi_private; 668 + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 669 + struct list_head *wait_list = &(dcc->discard_cmd_list); 670 + struct discard_cmd *dc, *tmp; 671 + struct blk_plug plug; 677 672 678 - be->error = bio->bi_error; 679 - complete(&be->event); 673 + mutex_lock(&dcc->cmd_lock); 674 + 675 + blk_start_plug(&plug); 676 + 677 + list_for_each_entry_safe(dc, tmp, wait_list, list) { 678 + 679 + if (blkaddr == NULL_ADDR) { 680 + if (dc->state == D_PREP) { 681 + dc->state = D_SUBMIT; 682 + submit_bio(dc->bio); 683 + atomic_inc(&dcc->submit_discard); 684 + } 685 + continue; 686 + } 687 + 688 + if (dc->lstart <= blkaddr && blkaddr < dc->lstart + dc->len) { 689 + if (dc->state == D_SUBMIT) 690 + wait_for_completion_io(&dc->wait); 691 + else 692 + __remove_discard_cmd(sbi, dc); 693 + } 694 + } 695 + blk_finish_plug(&plug); 696 + 697 + /* this comes from f2fs_put_super */ 698 + if (blkaddr == NULL_ADDR) { 699 + list_for_each_entry_safe(dc, tmp, wait_list, list) { 700 + wait_for_completion_io(&dc->wait); 701 + __remove_discard_cmd(sbi, dc); 702 + } 703 + } 704 + mutex_unlock(&dcc->cmd_lock); 680 705 } 706 + 707 + static void f2fs_submit_discard_endio(struct bio *bio) 708 + { 709 + struct discard_cmd *dc = (struct discard_cmd *)bio->bi_private; 710 + 711 + complete(&dc->wait); 712 + dc->state = D_DONE; 713 + } 714 + 715 + static int issue_discard_thread(void *data) 716 + { 717 + struct f2fs_sb_info *sbi = data; 718 + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 719 + wait_queue_head_t *q = &dcc->discard_wait_queue; 720 + struct list_head *cmd_list = &dcc->discard_cmd_list; 721 + struct discard_cmd *dc, *tmp; 722 + struct blk_plug plug; 723 + int iter = 0; 724 + repeat: 725 + if (kthread_should_stop()) 726 + return 0; 727 + 728 + blk_start_plug(&plug); 729 + 730 + mutex_lock(&dcc->cmd_lock); 731 + list_for_each_entry_safe(dc, tmp, cmd_list, list) { 732 + if (dc->state == D_PREP) { 733 + dc->state = D_SUBMIT; 734 + submit_bio(dc->bio); 735 + atomic_inc(&dcc->submit_discard); 736 + if (iter++ > DISCARD_ISSUE_RATE) 737 + break; 738 + } else if (dc->state == D_DONE) { 739 + __remove_discard_cmd(sbi, dc); 740 + } 741 + } 742 + mutex_unlock(&dcc->cmd_lock); 743 + 744 + blk_finish_plug(&plug); 745 + 746 + iter = 0; 747 + congestion_wait(BLK_RW_SYNC, HZ/50); 748 + 749 + wait_event_interruptible(*q, 750 + kthread_should_stop() || !list_empty(&dcc->discard_cmd_list)); 751 + goto repeat; 752 + } 753 + 681 754 682 755 /* this function is copied from blkdev_issue_discard from block/blk-lib.c */ 683 756 static int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi, 684 757 struct block_device *bdev, block_t blkstart, block_t blklen) 685 758 { 686 759 struct bio *bio = NULL; 760 + block_t lblkstart = blkstart; 687 761 int err; 688 762 689 - trace_f2fs_issue_discard(sbi->sb, blkstart, blklen); 763 + trace_f2fs_issue_discard(bdev, blkstart, blklen); 690 764 691 765 if (sbi->s_ndevs) { 692 766 int devi = f2fs_target_device_index(sbi, blkstart); ··· 782 688 SECTOR_FROM_BLOCK(blklen), 783 689 GFP_NOFS, 0, &bio); 784 690 if (!err && bio) { 785 - struct bio_entry *be = __add_bio_entry(sbi, bio); 786 - 787 - bio->bi_private = be; 788 - bio->bi_end_io = f2fs_submit_bio_wait_endio; 691 + bio->bi_end_io = f2fs_submit_discard_endio; 789 692 bio->bi_opf |= REQ_SYNC; 790 - submit_bio(bio); 791 - } 792 693 694 + __add_discard_cmd(sbi, bio, lblkstart, blklen); 695 + wake_up(&SM_I(sbi)->dcc_info->discard_wait_queue); 696 + } 793 697 return err; 794 698 } 795 699 ··· 795 703 static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi, 796 704 struct block_device *bdev, block_t blkstart, block_t blklen) 797 705 { 798 - sector_t nr_sects = SECTOR_FROM_BLOCK(blklen); 799 - sector_t sector; 706 + sector_t sector, nr_sects; 800 707 int devi = 0; 801 708 802 709 if (sbi->s_ndevs) { 803 710 devi = f2fs_target_device_index(sbi, blkstart); 804 711 blkstart -= FDEV(devi).start_blk; 805 - } 806 - sector = SECTOR_FROM_BLOCK(blkstart); 807 - 808 - if (sector & (bdev_zone_sectors(bdev) - 1) || 809 - nr_sects != bdev_zone_sectors(bdev)) { 810 - f2fs_msg(sbi->sb, KERN_INFO, 811 - "(%d) %s: Unaligned discard attempted (block %x + %x)", 812 - devi, sbi->s_ndevs ? FDEV(devi).path: "", 813 - blkstart, blklen); 814 - return -EIO; 815 712 } 816 713 817 714 /* ··· 816 735 return __f2fs_issue_discard_async(sbi, bdev, blkstart, blklen); 817 736 case BLK_ZONE_TYPE_SEQWRITE_REQ: 818 737 case BLK_ZONE_TYPE_SEQWRITE_PREF: 819 - trace_f2fs_issue_reset_zone(sbi->sb, blkstart); 738 + sector = SECTOR_FROM_BLOCK(blkstart); 739 + nr_sects = SECTOR_FROM_BLOCK(blklen); 740 + 741 + if (sector & (bdev_zone_sectors(bdev) - 1) || 742 + nr_sects != bdev_zone_sectors(bdev)) { 743 + f2fs_msg(sbi->sb, KERN_INFO, 744 + "(%d) %s: Unaligned discard attempted (block %x + %x)", 745 + devi, sbi->s_ndevs ? FDEV(devi).path: "", 746 + blkstart, blklen); 747 + return -EIO; 748 + } 749 + trace_f2fs_issue_reset_zone(bdev, blkstart); 820 750 return blkdev_reset_zones(bdev, sector, 821 751 nr_sects, GFP_NOFS); 822 752 default: ··· 892 800 struct cp_control *cpc, struct seg_entry *se, 893 801 unsigned int start, unsigned int end) 894 802 { 895 - struct list_head *head = &SM_I(sbi)->discard_list; 803 + struct list_head *head = &SM_I(sbi)->dcc_info->discard_entry_list; 896 804 struct discard_entry *new, *last; 897 805 898 806 if (!list_empty(head)) { 899 807 last = list_last_entry(head, struct discard_entry, list); 900 808 if (START_BLOCK(sbi, cpc->trim_start) + start == 901 - last->blkaddr + last->len) { 809 + last->blkaddr + last->len && 810 + last->len < MAX_DISCARD_BLOCKS(sbi)) { 902 811 last->len += end - start; 903 812 goto done; 904 813 } ··· 911 818 new->len = end - start; 912 819 list_add_tail(&new->list, head); 913 820 done: 914 - SM_I(sbi)->nr_discards += end - start; 821 + SM_I(sbi)->dcc_info->nr_discards += end - start; 915 822 } 916 823 917 - static void add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc) 824 + static bool add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc, 825 + bool check_only) 918 826 { 919 827 int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long); 920 828 int max_blocks = sbi->blocks_per_seg; ··· 929 835 int i; 930 836 931 837 if (se->valid_blocks == max_blocks || !f2fs_discard_en(sbi)) 932 - return; 838 + return false; 933 839 934 840 if (!force) { 935 841 if (!test_opt(sbi, DISCARD) || !se->valid_blocks || 936 - SM_I(sbi)->nr_discards >= SM_I(sbi)->max_discards) 937 - return; 842 + SM_I(sbi)->dcc_info->nr_discards >= 843 + SM_I(sbi)->dcc_info->max_discards) 844 + return false; 938 845 } 939 846 940 847 /* SIT_VBLOCK_MAP_SIZE should be multiple of sizeof(unsigned long) */ ··· 943 848 dmap[i] = force ? ~ckpt_map[i] & ~discard_map[i] : 944 849 (cur_map[i] ^ ckpt_map[i]) & ckpt_map[i]; 945 850 946 - while (force || SM_I(sbi)->nr_discards <= SM_I(sbi)->max_discards) { 851 + while (force || SM_I(sbi)->dcc_info->nr_discards <= 852 + SM_I(sbi)->dcc_info->max_discards) { 947 853 start = __find_rev_next_bit(dmap, max_blocks, end + 1); 948 854 if (start >= max_blocks) 949 855 break; ··· 954 858 && (end - start) < cpc->trim_minlen) 955 859 continue; 956 860 861 + if (check_only) 862 + return true; 863 + 957 864 __add_discard_entry(sbi, cpc, se, start, end); 958 865 } 866 + return false; 959 867 } 960 868 961 869 void release_discard_addrs(struct f2fs_sb_info *sbi) 962 870 { 963 - struct list_head *head = &(SM_I(sbi)->discard_list); 871 + struct list_head *head = &(SM_I(sbi)->dcc_info->discard_entry_list); 964 872 struct discard_entry *entry, *this; 965 873 966 874 /* drop caches */ ··· 990 890 991 891 void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) 992 892 { 993 - struct list_head *head = &(SM_I(sbi)->discard_list); 893 + struct list_head *head = &(SM_I(sbi)->dcc_info->discard_entry_list); 994 894 struct discard_entry *entry, *this; 995 895 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); 996 - struct blk_plug plug; 997 896 unsigned long *prefree_map = dirty_i->dirty_segmap[PRE]; 998 897 unsigned int start = 0, end = -1; 999 898 unsigned int secno, start_segno; 1000 899 bool force = (cpc->reason == CP_DISCARD); 1001 - 1002 - blk_start_plug(&plug); 1003 900 1004 901 mutex_lock(&dirty_i->seglist_lock); 1005 902 ··· 1013 916 1014 917 dirty_i->nr_dirty[PRE] -= end - start; 1015 918 1016 - if (force || !test_opt(sbi, DISCARD)) 919 + if (!test_opt(sbi, DISCARD)) 1017 920 continue; 921 + 922 + if (force && start >= cpc->trim_start && 923 + (end - 1) <= cpc->trim_end) 924 + continue; 1018 925 1019 926 if (!test_opt(sbi, LFS) || sbi->segs_per_sec == 1) { 1020 927 f2fs_issue_discard(sbi, START_BLOCK(sbi, start), ··· 1036 935 start = start_segno + sbi->segs_per_sec; 1037 936 if (start < end) 1038 937 goto next; 938 + else 939 + end = start - 1; 1039 940 } 1040 941 mutex_unlock(&dirty_i->seglist_lock); 1041 942 ··· 1049 946 cpc->trimmed += entry->len; 1050 947 skip: 1051 948 list_del(&entry->list); 1052 - SM_I(sbi)->nr_discards -= entry->len; 949 + SM_I(sbi)->dcc_info->nr_discards -= entry->len; 1053 950 kmem_cache_free(discard_entry_slab, entry); 1054 951 } 952 + } 1055 953 1056 - blk_finish_plug(&plug); 954 + static int create_discard_cmd_control(struct f2fs_sb_info *sbi) 955 + { 956 + dev_t dev = sbi->sb->s_bdev->bd_dev; 957 + struct discard_cmd_control *dcc; 958 + int err = 0; 959 + 960 + if (SM_I(sbi)->dcc_info) { 961 + dcc = SM_I(sbi)->dcc_info; 962 + goto init_thread; 963 + } 964 + 965 + dcc = kzalloc(sizeof(struct discard_cmd_control), GFP_KERNEL); 966 + if (!dcc) 967 + return -ENOMEM; 968 + 969 + INIT_LIST_HEAD(&dcc->discard_entry_list); 970 + INIT_LIST_HEAD(&dcc->discard_cmd_list); 971 + mutex_init(&dcc->cmd_lock); 972 + atomic_set(&dcc->submit_discard, 0); 973 + dcc->nr_discards = 0; 974 + dcc->max_discards = 0; 975 + 976 + init_waitqueue_head(&dcc->discard_wait_queue); 977 + SM_I(sbi)->dcc_info = dcc; 978 + init_thread: 979 + dcc->f2fs_issue_discard = kthread_run(issue_discard_thread, sbi, 980 + "f2fs_discard-%u:%u", MAJOR(dev), MINOR(dev)); 981 + if (IS_ERR(dcc->f2fs_issue_discard)) { 982 + err = PTR_ERR(dcc->f2fs_issue_discard); 983 + kfree(dcc); 984 + SM_I(sbi)->dcc_info = NULL; 985 + return err; 986 + } 987 + 988 + return err; 989 + } 990 + 991 + static void destroy_discard_cmd_control(struct f2fs_sb_info *sbi, bool free) 992 + { 993 + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 994 + 995 + if (dcc && dcc->f2fs_issue_discard) { 996 + struct task_struct *discard_thread = dcc->f2fs_issue_discard; 997 + 998 + dcc->f2fs_issue_discard = NULL; 999 + kthread_stop(discard_thread); 1000 + } 1001 + if (free) { 1002 + kfree(dcc); 1003 + SM_I(sbi)->dcc_info = NULL; 1004 + } 1057 1005 } 1058 1006 1059 1007 static bool __mark_sit_entry_dirty(struct f2fs_sb_info *sbi, unsigned int segno) ··· 1149 995 1150 996 /* Update valid block bitmap */ 1151 997 if (del > 0) { 1152 - if (f2fs_test_and_set_bit(offset, se->cur_valid_map)) 998 + if (f2fs_test_and_set_bit(offset, se->cur_valid_map)) { 999 + #ifdef CONFIG_F2FS_CHECK_FS 1000 + if (f2fs_test_and_set_bit(offset, 1001 + se->cur_valid_map_mir)) 1002 + f2fs_bug_on(sbi, 1); 1003 + else 1004 + WARN_ON(1); 1005 + #else 1153 1006 f2fs_bug_on(sbi, 1); 1007 + #endif 1008 + } 1154 1009 if (f2fs_discard_en(sbi) && 1155 1010 !f2fs_test_and_set_bit(offset, se->discard_map)) 1156 1011 sbi->discard_blks--; 1157 1012 } else { 1158 - if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map)) 1013 + if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map)) { 1014 + #ifdef CONFIG_F2FS_CHECK_FS 1015 + if (!f2fs_test_and_clear_bit(offset, 1016 + se->cur_valid_map_mir)) 1017 + f2fs_bug_on(sbi, 1); 1018 + else 1019 + WARN_ON(1); 1020 + #else 1159 1021 f2fs_bug_on(sbi, 1); 1022 + #endif 1023 + } 1160 1024 if (f2fs_discard_en(sbi) && 1161 1025 f2fs_test_and_clear_bit(offset, se->discard_map)) 1162 1026 sbi->discard_blks++; ··· 1337 1165 1338 1166 set_page_dirty(page); 1339 1167 f2fs_put_page(page, 1); 1340 - } 1341 - 1342 - static int is_next_segment_free(struct f2fs_sb_info *sbi, int type) 1343 - { 1344 - struct curseg_info *curseg = CURSEG_I(sbi, type); 1345 - unsigned int segno = curseg->segno + 1; 1346 - struct free_segmap_info *free_i = FREE_I(sbi); 1347 - 1348 - if (segno < MAIN_SEGS(sbi) && segno % sbi->segs_per_sec) 1349 - return !test_bit(segno, free_i->free_segmap); 1350 - return 0; 1351 1168 } 1352 1169 1353 1170 /* ··· 1543 1382 { 1544 1383 struct curseg_info *curseg = CURSEG_I(sbi, type); 1545 1384 const struct victim_selection *v_ops = DIRTY_I(sbi)->v_ops; 1385 + int i, cnt; 1386 + bool reversed = false; 1546 1387 1547 - if (IS_NODESEG(type) || !has_not_enough_free_secs(sbi, 0, 0)) 1548 - return v_ops->get_victim(sbi, 1549 - &(curseg)->next_segno, BG_GC, type, SSR); 1388 + /* need_SSR() already forces to do this */ 1389 + if (v_ops->get_victim(sbi, &(curseg)->next_segno, BG_GC, type, SSR)) 1390 + return 1; 1550 1391 1551 - /* For data segments, let's do SSR more intensively */ 1552 - for (; type >= CURSEG_HOT_DATA; type--) 1392 + /* For node segments, let's do SSR more intensively */ 1393 + if (IS_NODESEG(type)) { 1394 + if (type >= CURSEG_WARM_NODE) { 1395 + reversed = true; 1396 + i = CURSEG_COLD_NODE; 1397 + } else { 1398 + i = CURSEG_HOT_NODE; 1399 + } 1400 + cnt = NR_CURSEG_NODE_TYPE; 1401 + } else { 1402 + if (type >= CURSEG_WARM_DATA) { 1403 + reversed = true; 1404 + i = CURSEG_COLD_DATA; 1405 + } else { 1406 + i = CURSEG_HOT_DATA; 1407 + } 1408 + cnt = NR_CURSEG_DATA_TYPE; 1409 + } 1410 + 1411 + for (; cnt-- > 0; reversed ? i-- : i++) { 1412 + if (i == type) 1413 + continue; 1553 1414 if (v_ops->get_victim(sbi, &(curseg)->next_segno, 1554 - BG_GC, type, SSR)) 1415 + BG_GC, i, SSR)) 1555 1416 return 1; 1417 + } 1556 1418 return 0; 1557 1419 } 1558 1420 ··· 1586 1402 static void allocate_segment_by_default(struct f2fs_sb_info *sbi, 1587 1403 int type, bool force) 1588 1404 { 1589 - struct curseg_info *curseg = CURSEG_I(sbi, type); 1590 - 1591 1405 if (force) 1592 1406 new_curseg(sbi, type, true); 1593 - else if (type == CURSEG_WARM_NODE) 1594 - new_curseg(sbi, type, false); 1595 - else if (curseg->alloc_type == LFS && is_next_segment_free(sbi, type)) 1407 + else if (!is_set_ckpt_flags(sbi, CP_CRC_RECOVERY_FLAG) && 1408 + type == CURSEG_WARM_NODE) 1596 1409 new_curseg(sbi, type, false); 1597 1410 else if (need_SSR(sbi) && get_ssr_segment(sbi, type)) 1598 1411 change_curseg(sbi, type, true); 1599 1412 else 1600 1413 new_curseg(sbi, type, false); 1601 1414 1602 - stat_inc_seg_type(sbi, curseg); 1415 + stat_inc_seg_type(sbi, CURSEG_I(sbi, type)); 1603 1416 } 1604 1417 1605 1418 void allocate_new_segments(struct f2fs_sb_info *sbi) ··· 1604 1423 struct curseg_info *curseg; 1605 1424 unsigned int old_segno; 1606 1425 int i; 1607 - 1608 - if (test_opt(sbi, LFS)) 1609 - return; 1610 1426 1611 1427 for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) { 1612 1428 curseg = CURSEG_I(sbi, i); ··· 1616 1438 static const struct segment_allocation default_salloc_ops = { 1617 1439 .allocate_segment = allocate_segment_by_default, 1618 1440 }; 1441 + 1442 + bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1443 + { 1444 + __u64 trim_start = cpc->trim_start; 1445 + bool has_candidate = false; 1446 + 1447 + mutex_lock(&SIT_I(sbi)->sentry_lock); 1448 + for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++) { 1449 + if (add_discard_addrs(sbi, cpc, true)) { 1450 + has_candidate = true; 1451 + break; 1452 + } 1453 + } 1454 + mutex_unlock(&SIT_I(sbi)->sentry_lock); 1455 + 1456 + cpc->trim_start = trim_start; 1457 + return has_candidate; 1458 + } 1619 1459 1620 1460 int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) 1621 1461 { ··· 1769 1573 1770 1574 *new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg); 1771 1575 1576 + f2fs_wait_discard_bio(sbi, *new_blkaddr); 1577 + 1772 1578 /* 1773 1579 * __add_sum_entry should be resided under the curseg_mutex 1774 1580 * because, this function updates a summary entry in the ··· 1782 1584 1783 1585 stat_inc_block_count(sbi, curseg); 1784 1586 1785 - if (!__has_curseg_space(sbi, type)) 1786 - sit_i->s_ops->allocate_segment(sbi, type, false); 1787 1587 /* 1788 1588 * SIT information should be updated before segment allocation, 1789 1589 * since SSR needs latest valid block information. 1790 1590 */ 1791 1591 refresh_sit_entry(sbi, old_blkaddr, *new_blkaddr); 1592 + 1593 + if (!__has_curseg_space(sbi, type)) 1594 + sit_i->s_ops->allocate_segment(sbi, type, false); 1792 1595 1793 1596 mutex_unlock(&sit_i->sentry_lock); 1794 1597 ··· 1802 1603 static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio) 1803 1604 { 1804 1605 int type = __get_segment_type(fio->page, fio->type); 1606 + int err; 1805 1607 1806 1608 if (fio->type == NODE || fio->type == DATA) 1807 1609 mutex_lock(&fio->sbi->wio_mutex[fio->type]); 1808 - 1610 + reallocate: 1809 1611 allocate_data_block(fio->sbi, fio->page, fio->old_blkaddr, 1810 1612 &fio->new_blkaddr, sum, type); 1811 1613 1812 1614 /* writeout dirty page into bdev */ 1813 - f2fs_submit_page_mbio(fio); 1615 + err = f2fs_submit_page_mbio(fio); 1616 + if (err == -EAGAIN) { 1617 + fio->old_blkaddr = fio->new_blkaddr; 1618 + goto reallocate; 1619 + } 1814 1620 1815 1621 if (fio->type == NODE || fio->type == DATA) 1816 1622 mutex_unlock(&fio->sbi->wio_mutex[fio->type]); ··· 1957 1753 if (PageWriteback(page)) { 1958 1754 struct f2fs_sb_info *sbi = F2FS_P_SB(page); 1959 1755 1960 - f2fs_submit_merged_bio_cond(sbi, NULL, page, 0, type, WRITE); 1756 + f2fs_submit_merged_bio_cond(sbi, page->mapping->host, 1757 + 0, page->index, type, WRITE); 1961 1758 if (ordered) 1962 1759 wait_on_page_writeback(page); 1963 1760 else ··· 2433 2228 /* add discard candidates */ 2434 2229 if (cpc->reason != CP_DISCARD) { 2435 2230 cpc->trim_start = segno; 2436 - add_discard_addrs(sbi, cpc); 2231 + add_discard_addrs(sbi, cpc, false); 2437 2232 } 2438 2233 2439 2234 if (to_journal) { ··· 2468 2263 f2fs_bug_on(sbi, sit_i->dirty_sentries); 2469 2264 out: 2470 2265 if (cpc->reason == CP_DISCARD) { 2266 + __u64 trim_start = cpc->trim_start; 2267 + 2471 2268 for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++) 2472 - add_discard_addrs(sbi, cpc); 2269 + add_discard_addrs(sbi, cpc, false); 2270 + 2271 + cpc->trim_start = trim_start; 2473 2272 } 2474 2273 mutex_unlock(&sit_i->sentry_lock); 2475 2274 ··· 2485 2276 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); 2486 2277 struct sit_info *sit_i; 2487 2278 unsigned int sit_segs, start; 2488 - char *src_bitmap, *dst_bitmap; 2279 + char *src_bitmap; 2489 2280 unsigned int bitmap_size; 2490 2281 2491 2282 /* allocate memory for SIT information */ ··· 2514 2305 !sit_i->sentries[start].ckpt_valid_map) 2515 2306 return -ENOMEM; 2516 2307 2308 + #ifdef CONFIG_F2FS_CHECK_FS 2309 + sit_i->sentries[start].cur_valid_map_mir 2310 + = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); 2311 + if (!sit_i->sentries[start].cur_valid_map_mir) 2312 + return -ENOMEM; 2313 + #endif 2314 + 2517 2315 if (f2fs_discard_en(sbi)) { 2518 2316 sit_i->sentries[start].discard_map 2519 2317 = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); ··· 2547 2331 bitmap_size = __bitmap_size(sbi, SIT_BITMAP); 2548 2332 src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP); 2549 2333 2550 - dst_bitmap = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL); 2551 - if (!dst_bitmap) 2334 + sit_i->sit_bitmap = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL); 2335 + if (!sit_i->sit_bitmap) 2552 2336 return -ENOMEM; 2337 + 2338 + #ifdef CONFIG_F2FS_CHECK_FS 2339 + sit_i->sit_bitmap_mir = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL); 2340 + if (!sit_i->sit_bitmap_mir) 2341 + return -ENOMEM; 2342 + #endif 2553 2343 2554 2344 /* init SIT information */ 2555 2345 sit_i->s_ops = &default_salloc_ops; ··· 2563 2341 sit_i->sit_base_addr = le32_to_cpu(raw_super->sit_blkaddr); 2564 2342 sit_i->sit_blocks = sit_segs << sbi->log_blocks_per_seg; 2565 2343 sit_i->written_valid_blocks = 0; 2566 - sit_i->sit_bitmap = dst_bitmap; 2567 2344 sit_i->bitmap_size = bitmap_size; 2568 2345 sit_i->dirty_sentries = 0; 2569 2346 sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK; ··· 2847 2626 sm_info->min_ipu_util = DEF_MIN_IPU_UTIL; 2848 2627 sm_info->min_fsync_blocks = DEF_MIN_FSYNC_BLOCKS; 2849 2628 2850 - INIT_LIST_HEAD(&sm_info->discard_list); 2851 - INIT_LIST_HEAD(&sm_info->wait_list); 2852 - sm_info->nr_discards = 0; 2853 - sm_info->max_discards = 0; 2854 - 2855 2629 sm_info->trim_sections = DEF_BATCHED_TRIM_SECTIONS; 2856 2630 2857 2631 INIT_LIST_HEAD(&sm_info->sit_entry_set); ··· 2856 2640 if (err) 2857 2641 return err; 2858 2642 } 2643 + 2644 + err = create_discard_cmd_control(sbi); 2645 + if (err) 2646 + return err; 2859 2647 2860 2648 err = build_sit_info(sbi); 2861 2649 if (err) ··· 2954 2734 if (sit_i->sentries) { 2955 2735 for (start = 0; start < MAIN_SEGS(sbi); start++) { 2956 2736 kfree(sit_i->sentries[start].cur_valid_map); 2737 + #ifdef CONFIG_F2FS_CHECK_FS 2738 + kfree(sit_i->sentries[start].cur_valid_map_mir); 2739 + #endif 2957 2740 kfree(sit_i->sentries[start].ckpt_valid_map); 2958 2741 kfree(sit_i->sentries[start].discard_map); 2959 2742 } ··· 2969 2746 2970 2747 SM_I(sbi)->sit_info = NULL; 2971 2748 kfree(sit_i->sit_bitmap); 2749 + #ifdef CONFIG_F2FS_CHECK_FS 2750 + kfree(sit_i->sit_bitmap_mir); 2751 + #endif 2972 2752 kfree(sit_i); 2973 2753 } 2974 2754 ··· 2982 2756 if (!sm_info) 2983 2757 return; 2984 2758 destroy_flush_cmd_control(sbi, true); 2759 + destroy_discard_cmd_control(sbi, true); 2985 2760 destroy_dirty_segmap(sbi); 2986 2761 destroy_curseg(sbi); 2987 2762 destroy_free_segmap(sbi); ··· 2998 2771 if (!discard_entry_slab) 2999 2772 goto fail; 3000 2773 3001 - bio_entry_slab = f2fs_kmem_cache_create("bio_entry", 3002 - sizeof(struct bio_entry)); 3003 - if (!bio_entry_slab) 2774 + discard_cmd_slab = f2fs_kmem_cache_create("discard_cmd", 2775 + sizeof(struct discard_cmd)); 2776 + if (!discard_cmd_slab) 3004 2777 goto destroy_discard_entry; 3005 2778 3006 2779 sit_entry_set_slab = f2fs_kmem_cache_create("sit_entry_set", 3007 2780 sizeof(struct sit_entry_set)); 3008 2781 if (!sit_entry_set_slab) 3009 - goto destroy_bio_entry; 2782 + goto destroy_discard_cmd; 3010 2783 3011 2784 inmem_entry_slab = f2fs_kmem_cache_create("inmem_page_entry", 3012 2785 sizeof(struct inmem_pages)); ··· 3016 2789 3017 2790 destroy_sit_entry_set: 3018 2791 kmem_cache_destroy(sit_entry_set_slab); 3019 - destroy_bio_entry: 3020 - kmem_cache_destroy(bio_entry_slab); 2792 + destroy_discard_cmd: 2793 + kmem_cache_destroy(discard_cmd_slab); 3021 2794 destroy_discard_entry: 3022 2795 kmem_cache_destroy(discard_entry_slab); 3023 2796 fail: ··· 3027 2800 void destroy_segment_manager_caches(void) 3028 2801 { 3029 2802 kmem_cache_destroy(sit_entry_set_slab); 3030 - kmem_cache_destroy(bio_entry_slab); 2803 + kmem_cache_destroy(discard_cmd_slab); 3031 2804 kmem_cache_destroy(discard_entry_slab); 3032 2805 kmem_cache_destroy(inmem_entry_slab); 3033 2806 }
+38 -2
fs/f2fs/segment.h
··· 164 164 unsigned int ckpt_valid_blocks:10; /* # of valid blocks last cp */ 165 165 unsigned int padding:6; /* padding */ 166 166 unsigned char *cur_valid_map; /* validity bitmap of blocks */ 167 + #ifdef CONFIG_F2FS_CHECK_FS 168 + unsigned char *cur_valid_map_mir; /* mirror of current valid bitmap */ 169 + #endif 167 170 /* 168 171 * # of valid blocks and the validity bitmap stored in the the last 169 172 * checkpoint pack. This information is used by the SSR mode. ··· 189 186 * the page is atomically written, and it is in inmem_pages list. 190 187 */ 191 188 #define ATOMIC_WRITTEN_PAGE ((unsigned long)-1) 189 + #define DUMMY_WRITTEN_PAGE ((unsigned long)-2) 192 190 193 191 #define IS_ATOMIC_WRITTEN_PAGE(page) \ 194 192 (page_private(page) == (unsigned long)ATOMIC_WRITTEN_PAGE) 193 + #define IS_DUMMY_WRITTEN_PAGE(page) \ 194 + (page_private(page) == (unsigned long)DUMMY_WRITTEN_PAGE) 195 195 196 196 struct inmem_pages { 197 197 struct list_head list; ··· 209 203 block_t sit_blocks; /* # of blocks used by SIT area */ 210 204 block_t written_valid_blocks; /* # of valid blocks in main area */ 211 205 char *sit_bitmap; /* SIT bitmap pointer */ 206 + #ifdef CONFIG_F2FS_CHECK_FS 207 + char *sit_bitmap_mir; /* SIT bitmap mirror */ 208 + #endif 212 209 unsigned int bitmap_size; /* SIT bitmap size */ 213 210 214 211 unsigned long *tmp_map; /* bitmap for temporal use */ ··· 326 317 se->ckpt_valid_blocks = GET_SIT_VBLOCKS(rs); 327 318 memcpy(se->cur_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE); 328 319 memcpy(se->ckpt_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE); 320 + #ifdef CONFIG_F2FS_CHECK_FS 321 + memcpy(se->cur_valid_map_mir, rs->valid_map, SIT_VBLOCK_MAP_SIZE); 322 + #endif 329 323 se->type = GET_SIT_TYPE(rs); 330 324 se->mtime = le64_to_cpu(rs->mtime); 331 325 } ··· 426 414 void *dst_addr) 427 415 { 428 416 struct sit_info *sit_i = SIT_I(sbi); 417 + 418 + #ifdef CONFIG_F2FS_CHECK_FS 419 + if (memcmp(sit_i->sit_bitmap, sit_i->sit_bitmap_mir, 420 + sit_i->bitmap_size)) 421 + f2fs_bug_on(sbi, 1); 422 + #endif 429 423 memcpy(dst_addr, sit_i->sit_bitmap, sit_i->bitmap_size); 430 424 } 431 425 ··· 652 634 653 635 check_seg_range(sbi, start); 654 636 637 + #ifdef CONFIG_F2FS_CHECK_FS 638 + if (f2fs_test_bit(offset, sit_i->sit_bitmap) != 639 + f2fs_test_bit(offset, sit_i->sit_bitmap_mir)) 640 + f2fs_bug_on(sbi, 1); 641 + #endif 642 + 655 643 /* calculate sit block address */ 656 644 if (f2fs_test_bit(offset, sit_i->sit_bitmap)) 657 645 blk_addr += sit_i->sit_blocks; ··· 683 659 unsigned int block_off = SIT_BLOCK_OFFSET(start); 684 660 685 661 f2fs_change_bit(block_off, sit_i->sit_bitmap); 662 + #ifdef CONFIG_F2FS_CHECK_FS 663 + f2fs_change_bit(block_off, sit_i->sit_bitmap_mir); 664 + #endif 686 665 } 687 666 688 667 static inline unsigned long long get_mtime(struct f2fs_sb_info *sbi) ··· 716 689 - (base + 1) + type; 717 690 } 718 691 692 + static inline bool no_fggc_candidate(struct f2fs_sb_info *sbi, 693 + unsigned int secno) 694 + { 695 + if (get_valid_blocks(sbi, secno, sbi->segs_per_sec) >= 696 + sbi->fggc_threshold) 697 + return true; 698 + return false; 699 + } 700 + 719 701 static inline bool sec_usage_check(struct f2fs_sb_info *sbi, unsigned int secno) 720 702 { 721 703 if (IS_CURSEC(sbi, secno) || (sbi->cur_victim_sec == secno)) ··· 736 700 * It is very important to gather dirty pages and write at once, so that we can 737 701 * submit a big bio without interfering other data writes. 738 702 * By default, 512 pages for directory data, 739 - * 512 pages (2MB) * 3 for three types of nodes, and 740 - * max_bio_blocks for meta are set. 703 + * 512 pages (2MB) * 8 for nodes, and 704 + * 256 pages * 8 for meta are set. 741 705 */ 742 706 static inline int nr_pages_to_skip(struct f2fs_sb_info *sbi, int type) 743 707 {
+110 -28
fs/f2fs/super.c
··· 89 89 Opt_active_logs, 90 90 Opt_disable_ext_identify, 91 91 Opt_inline_xattr, 92 + Opt_noinline_xattr, 92 93 Opt_inline_data, 93 94 Opt_inline_dentry, 94 95 Opt_noinline_dentry, ··· 102 101 Opt_noinline_data, 103 102 Opt_data_flush, 104 103 Opt_mode, 104 + Opt_io_size_bits, 105 105 Opt_fault_injection, 106 106 Opt_lazytime, 107 107 Opt_nolazytime, ··· 123 121 {Opt_active_logs, "active_logs=%u"}, 124 122 {Opt_disable_ext_identify, "disable_ext_identify"}, 125 123 {Opt_inline_xattr, "inline_xattr"}, 124 + {Opt_noinline_xattr, "noinline_xattr"}, 126 125 {Opt_inline_data, "inline_data"}, 127 126 {Opt_inline_dentry, "inline_dentry"}, 128 127 {Opt_noinline_dentry, "noinline_dentry"}, ··· 136 133 {Opt_noinline_data, "noinline_data"}, 137 134 {Opt_data_flush, "data_flush"}, 138 135 {Opt_mode, "mode=%s"}, 136 + {Opt_io_size_bits, "io_bits=%u"}, 139 137 {Opt_fault_injection, "fault_injection=%u"}, 140 138 {Opt_lazytime, "lazytime"}, 141 139 {Opt_nolazytime, "nolazytime"}, ··· 147 143 enum { 148 144 GC_THREAD, /* struct f2fs_gc_thread */ 149 145 SM_INFO, /* struct f2fs_sm_info */ 146 + DCC_INFO, /* struct discard_cmd_control */ 150 147 NM_INFO, /* struct f2fs_nm_info */ 151 148 F2FS_SBI, /* struct f2fs_sb_info */ 152 149 #ifdef CONFIG_F2FS_FAULT_INJECTION ··· 171 166 return (unsigned char *)sbi->gc_thread; 172 167 else if (struct_type == SM_INFO) 173 168 return (unsigned char *)SM_I(sbi); 169 + else if (struct_type == DCC_INFO) 170 + return (unsigned char *)SM_I(sbi)->dcc_info; 174 171 else if (struct_type == NM_INFO) 175 172 return (unsigned char *)NM_I(sbi); 176 173 else if (struct_type == F2FS_SBI) ··· 288 281 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); 289 282 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle); 290 283 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); 291 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, max_small_discards, max_discards); 284 + F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards); 292 285 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections); 293 286 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy); 294 287 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util); ··· 446 439 case Opt_inline_xattr: 447 440 set_opt(sbi, INLINE_XATTR); 448 441 break; 442 + case Opt_noinline_xattr: 443 + clear_opt(sbi, INLINE_XATTR); 444 + break; 449 445 #else 450 446 case Opt_user_xattr: 451 447 f2fs_msg(sb, KERN_INFO, ··· 461 451 case Opt_inline_xattr: 462 452 f2fs_msg(sb, KERN_INFO, 463 453 "inline_xattr options not supported"); 454 + break; 455 + case Opt_noinline_xattr: 456 + f2fs_msg(sb, KERN_INFO, 457 + "noinline_xattr options not supported"); 464 458 break; 465 459 #endif 466 460 #ifdef CONFIG_F2FS_FS_POSIX_ACL ··· 549 535 } 550 536 kfree(name); 551 537 break; 538 + case Opt_io_size_bits: 539 + if (args->from && match_int(args, &arg)) 540 + return -EINVAL; 541 + if (arg > __ilog2_u32(BIO_MAX_PAGES)) { 542 + f2fs_msg(sb, KERN_WARNING, 543 + "Not support %d, larger than %d", 544 + 1 << arg, BIO_MAX_PAGES); 545 + return -EINVAL; 546 + } 547 + sbi->write_io_size_bits = arg; 548 + break; 552 549 case Opt_fault_injection: 553 550 if (args->from && match_int(args, &arg)) 554 551 return -EINVAL; 555 552 #ifdef CONFIG_F2FS_FAULT_INJECTION 556 553 f2fs_build_fault_attr(sbi, arg); 554 + set_opt(sbi, FAULT_INJECTION); 557 555 #else 558 556 f2fs_msg(sb, KERN_INFO, 559 557 "FAULT_INJECTION was not selected"); ··· 583 557 p); 584 558 return -EINVAL; 585 559 } 560 + } 561 + 562 + if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) { 563 + f2fs_msg(sb, KERN_ERR, 564 + "Should set mode=lfs with %uKB-sized IO", 565 + F2FS_IO_SIZE_KB(sbi)); 566 + return -EINVAL; 586 567 } 587 568 return 0; 588 569 } ··· 624 591 625 592 static int f2fs_drop_inode(struct inode *inode) 626 593 { 594 + int ret; 627 595 /* 628 596 * This is to avoid a deadlock condition like below. 629 597 * writeback_single_inode(inode) ··· 657 623 spin_lock(&inode->i_lock); 658 624 atomic_dec(&inode->i_count); 659 625 } 626 + trace_f2fs_drop_inode(inode, 0); 660 627 return 0; 661 628 } 662 - 663 - return generic_drop_inode(inode); 629 + ret = generic_drop_inode(inode); 630 + trace_f2fs_drop_inode(inode, ret); 631 + return ret; 664 632 } 665 633 666 634 int f2fs_inode_dirtied(struct inode *inode, bool sync) ··· 786 750 write_checkpoint(sbi, &cpc); 787 751 } 788 752 753 + /* be sure to wait for any on-going discard commands */ 754 + f2fs_wait_discard_bio(sbi, NULL_ADDR); 755 + 789 756 /* write_checkpoint can update stat informaion */ 790 757 f2fs_destroy_stats(sbi); 791 758 ··· 821 782 kfree(sbi->raw_super); 822 783 823 784 destroy_device_list(sbi); 824 - 785 + mempool_destroy(sbi->write_io_dummy); 825 786 destroy_percpu_info(sbi); 826 787 kfree(sbi); 827 788 } ··· 921 882 seq_puts(seq, ",nouser_xattr"); 922 883 if (test_opt(sbi, INLINE_XATTR)) 923 884 seq_puts(seq, ",inline_xattr"); 885 + else 886 + seq_puts(seq, ",noinline_xattr"); 924 887 #endif 925 888 #ifdef CONFIG_F2FS_FS_POSIX_ACL 926 889 if (test_opt(sbi, POSIX_ACL)) ··· 959 918 else if (test_opt(sbi, LFS)) 960 919 seq_puts(seq, "lfs"); 961 920 seq_printf(seq, ",active_logs=%u", sbi->active_logs); 921 + if (F2FS_IO_SIZE_BITS(sbi)) 922 + seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi)); 923 + #ifdef CONFIG_F2FS_FAULT_INJECTION 924 + if (test_opt(sbi, FAULT_INJECTION)) 925 + seq_puts(seq, ",fault_injection"); 926 + #endif 962 927 963 928 return 0; 964 929 } ··· 1042 995 sbi->active_logs = NR_CURSEG_TYPE; 1043 996 1044 997 set_opt(sbi, BG_GC); 998 + set_opt(sbi, INLINE_XATTR); 1045 999 set_opt(sbi, INLINE_DATA); 1046 1000 set_opt(sbi, INLINE_DENTRY); 1047 1001 set_opt(sbi, EXTENT_CACHE); ··· 1734 1686 static int f2fs_scan_devices(struct f2fs_sb_info *sbi) 1735 1687 { 1736 1688 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); 1689 + unsigned int max_devices = MAX_DEVICES; 1737 1690 int i; 1738 1691 1739 - for (i = 0; i < MAX_DEVICES; i++) { 1740 - if (!RDEV(i).path[0]) 1692 + /* Initialize single device information */ 1693 + if (!RDEV(0).path[0]) { 1694 + if (!bdev_is_zoned(sbi->sb->s_bdev)) 1741 1695 return 0; 1696 + max_devices = 1; 1697 + } 1742 1698 1743 - if (i == 0) { 1744 - sbi->devs = kzalloc(sizeof(struct f2fs_dev_info) * 1745 - MAX_DEVICES, GFP_KERNEL); 1746 - if (!sbi->devs) 1747 - return -ENOMEM; 1748 - } 1699 + /* 1700 + * Initialize multiple devices information, or single 1701 + * zoned block device information. 1702 + */ 1703 + sbi->devs = kcalloc(max_devices, sizeof(struct f2fs_dev_info), 1704 + GFP_KERNEL); 1705 + if (!sbi->devs) 1706 + return -ENOMEM; 1749 1707 1750 - memcpy(FDEV(i).path, RDEV(i).path, MAX_PATH_LEN); 1751 - FDEV(i).total_segments = le32_to_cpu(RDEV(i).total_segments); 1752 - if (i == 0) { 1753 - FDEV(i).start_blk = 0; 1754 - FDEV(i).end_blk = FDEV(i).start_blk + 1755 - (FDEV(i).total_segments << 1756 - sbi->log_blocks_per_seg) - 1 + 1757 - le32_to_cpu(raw_super->segment0_blkaddr); 1758 - } else { 1759 - FDEV(i).start_blk = FDEV(i - 1).end_blk + 1; 1760 - FDEV(i).end_blk = FDEV(i).start_blk + 1761 - (FDEV(i).total_segments << 1762 - sbi->log_blocks_per_seg) - 1; 1763 - } 1708 + for (i = 0; i < max_devices; i++) { 1764 1709 1765 - FDEV(i).bdev = blkdev_get_by_path(FDEV(i).path, 1710 + if (i > 0 && !RDEV(i).path[0]) 1711 + break; 1712 + 1713 + if (max_devices == 1) { 1714 + /* Single zoned block device mount */ 1715 + FDEV(0).bdev = 1716 + blkdev_get_by_dev(sbi->sb->s_bdev->bd_dev, 1766 1717 sbi->sb->s_mode, sbi->sb->s_type); 1718 + } else { 1719 + /* Multi-device mount */ 1720 + memcpy(FDEV(i).path, RDEV(i).path, MAX_PATH_LEN); 1721 + FDEV(i).total_segments = 1722 + le32_to_cpu(RDEV(i).total_segments); 1723 + if (i == 0) { 1724 + FDEV(i).start_blk = 0; 1725 + FDEV(i).end_blk = FDEV(i).start_blk + 1726 + (FDEV(i).total_segments << 1727 + sbi->log_blocks_per_seg) - 1 + 1728 + le32_to_cpu(raw_super->segment0_blkaddr); 1729 + } else { 1730 + FDEV(i).start_blk = FDEV(i - 1).end_blk + 1; 1731 + FDEV(i).end_blk = FDEV(i).start_blk + 1732 + (FDEV(i).total_segments << 1733 + sbi->log_blocks_per_seg) - 1; 1734 + } 1735 + FDEV(i).bdev = blkdev_get_by_path(FDEV(i).path, 1736 + sbi->sb->s_mode, sbi->sb->s_type); 1737 + } 1767 1738 if (IS_ERR(FDEV(i).bdev)) 1768 1739 return PTR_ERR(FDEV(i).bdev); 1769 1740 ··· 1802 1735 "Failed to initialize F2FS blkzone information"); 1803 1736 return -EINVAL; 1804 1737 } 1738 + if (max_devices == 1) 1739 + break; 1805 1740 f2fs_msg(sbi->sb, KERN_INFO, 1806 1741 "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)", 1807 1742 i, FDEV(i).path, ··· 1820 1751 FDEV(i).total_segments, 1821 1752 FDEV(i).start_blk, FDEV(i).end_blk); 1822 1753 } 1754 + f2fs_msg(sbi->sb, KERN_INFO, 1755 + "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi)); 1823 1756 return 0; 1824 1757 } 1825 1758 ··· 1939 1868 if (err) 1940 1869 goto free_options; 1941 1870 1871 + if (F2FS_IO_SIZE(sbi) > 1) { 1872 + sbi->write_io_dummy = 1873 + mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); 1874 + if (!sbi->write_io_dummy) 1875 + goto free_options; 1876 + } 1877 + 1942 1878 /* get an inode for meta space */ 1943 1879 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); 1944 1880 if (IS_ERR(sbi->meta_inode)) { 1945 1881 f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode"); 1946 1882 err = PTR_ERR(sbi->meta_inode); 1947 - goto free_options; 1883 + goto free_io_dummy; 1948 1884 } 1949 1885 1950 1886 err = get_valid_checkpoint(sbi); ··· 2126 2048 sbi->valid_super_block ? 1 : 2, err); 2127 2049 } 2128 2050 2051 + f2fs_msg(sbi->sb, KERN_NOTICE, "Mounted with checkpoint version = %llx", 2052 + cur_cp_version(F2FS_CKPT(sbi))); 2129 2053 f2fs_update_time(sbi, CP_TIME); 2130 2054 f2fs_update_time(sbi, REQ_TIME); 2131 2055 return 0; ··· 2171 2091 free_meta_inode: 2172 2092 make_bad_inode(sbi->meta_inode); 2173 2093 iput(sbi->meta_inode); 2094 + free_io_dummy: 2095 + mempool_destroy(sbi->write_io_dummy); 2174 2096 free_options: 2175 2097 destroy_percpu_info(sbi); 2176 2098 kfree(options);
+130 -21
fs/f2fs/xattr.c
··· 217 217 return entry; 218 218 } 219 219 220 + static struct f2fs_xattr_entry *__find_inline_xattr(void *base_addr, 221 + void **last_addr, int index, 222 + size_t len, const char *name) 223 + { 224 + struct f2fs_xattr_entry *entry; 225 + unsigned int inline_size = F2FS_INLINE_XATTR_ADDRS << 2; 226 + 227 + list_for_each_xattr(entry, base_addr) { 228 + if ((void *)entry + sizeof(__u32) > base_addr + inline_size || 229 + (void *)XATTR_NEXT_ENTRY(entry) + sizeof(__u32) > 230 + base_addr + inline_size) { 231 + *last_addr = entry; 232 + return NULL; 233 + } 234 + if (entry->e_name_index != index) 235 + continue; 236 + if (entry->e_name_len != len) 237 + continue; 238 + if (!memcmp(entry->e_name, name, len)) 239 + break; 240 + } 241 + return entry; 242 + } 243 + 244 + static int lookup_all_xattrs(struct inode *inode, struct page *ipage, 245 + unsigned int index, unsigned int len, 246 + const char *name, struct f2fs_xattr_entry **xe, 247 + void **base_addr) 248 + { 249 + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 250 + void *cur_addr, *txattr_addr, *last_addr = NULL; 251 + nid_t xnid = F2FS_I(inode)->i_xattr_nid; 252 + unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0; 253 + unsigned int inline_size = 0; 254 + int err = 0; 255 + 256 + inline_size = inline_xattr_size(inode); 257 + 258 + if (!size && !inline_size) 259 + return -ENODATA; 260 + 261 + txattr_addr = kzalloc(inline_size + size + sizeof(__u32), 262 + GFP_F2FS_ZERO); 263 + if (!txattr_addr) 264 + return -ENOMEM; 265 + 266 + /* read from inline xattr */ 267 + if (inline_size) { 268 + struct page *page = NULL; 269 + void *inline_addr; 270 + 271 + if (ipage) { 272 + inline_addr = inline_xattr_addr(ipage); 273 + } else { 274 + page = get_node_page(sbi, inode->i_ino); 275 + if (IS_ERR(page)) { 276 + err = PTR_ERR(page); 277 + goto out; 278 + } 279 + inline_addr = inline_xattr_addr(page); 280 + } 281 + memcpy(txattr_addr, inline_addr, inline_size); 282 + f2fs_put_page(page, 1); 283 + 284 + *xe = __find_inline_xattr(txattr_addr, &last_addr, 285 + index, len, name); 286 + if (*xe) 287 + goto check; 288 + } 289 + 290 + /* read from xattr node block */ 291 + if (xnid) { 292 + struct page *xpage; 293 + void *xattr_addr; 294 + 295 + /* The inode already has an extended attribute block. */ 296 + xpage = get_node_page(sbi, xnid); 297 + if (IS_ERR(xpage)) { 298 + err = PTR_ERR(xpage); 299 + goto out; 300 + } 301 + 302 + xattr_addr = page_address(xpage); 303 + memcpy(txattr_addr + inline_size, xattr_addr, size); 304 + f2fs_put_page(xpage, 1); 305 + } 306 + 307 + if (last_addr) 308 + cur_addr = XATTR_HDR(last_addr) - 1; 309 + else 310 + cur_addr = txattr_addr; 311 + 312 + *xe = __find_xattr(cur_addr, index, len, name); 313 + check: 314 + if (IS_XATTR_LAST_ENTRY(*xe)) { 315 + err = -ENODATA; 316 + goto out; 317 + } 318 + 319 + *base_addr = txattr_addr; 320 + return 0; 321 + out: 322 + kzfree(txattr_addr); 323 + return err; 324 + } 325 + 220 326 static int read_all_xattrs(struct inode *inode, struct page *ipage, 221 327 void **base_addr) 222 328 { ··· 454 348 } 455 349 456 350 xattr_addr = page_address(xpage); 457 - memcpy(xattr_addr, txattr_addr + inline_size, PAGE_SIZE - 458 - sizeof(struct node_footer)); 351 + memcpy(xattr_addr, txattr_addr + inline_size, MAX_XATTR_BLOCK_SIZE); 459 352 set_page_dirty(xpage); 460 353 f2fs_put_page(xpage, 1); 461 354 462 - /* need to checkpoint during fsync */ 463 - F2FS_I(inode)->xattr_ver = cur_cp_version(F2FS_CKPT(sbi)); 464 355 return 0; 465 356 } 466 357 467 358 int f2fs_getxattr(struct inode *inode, int index, const char *name, 468 359 void *buffer, size_t buffer_size, struct page *ipage) 469 360 { 470 - struct f2fs_xattr_entry *entry; 471 - void *base_addr; 361 + struct f2fs_xattr_entry *entry = NULL; 472 362 int error = 0; 473 - size_t size, len; 363 + unsigned int size, len; 364 + void *base_addr = NULL; 474 365 475 366 if (name == NULL) 476 367 return -EINVAL; ··· 476 373 if (len > F2FS_NAME_LEN) 477 374 return -ERANGE; 478 375 479 - error = read_all_xattrs(inode, ipage, &base_addr); 376 + error = lookup_all_xattrs(inode, ipage, index, len, name, 377 + &entry, &base_addr); 480 378 if (error) 481 379 return error; 482 - 483 - entry = __find_xattr(base_addr, index, len, name); 484 - if (IS_XATTR_LAST_ENTRY(entry)) { 485 - error = -ENODATA; 486 - goto cleanup; 487 - } 488 380 489 381 size = le16_to_cpu(entry->e_value_size); 490 382 491 383 if (buffer && size > buffer_size) { 492 384 error = -ERANGE; 493 - goto cleanup; 385 + goto out; 494 386 } 495 387 496 388 if (buffer) { ··· 493 395 memcpy(buffer, pval, size); 494 396 } 495 397 error = size; 496 - 497 - cleanup: 398 + out: 498 399 kzfree(base_addr); 499 400 return error; 500 401 } ··· 542 445 return error; 543 446 } 544 447 448 + static bool f2fs_xattr_value_same(struct f2fs_xattr_entry *entry, 449 + const void *value, size_t size) 450 + { 451 + void *pval = entry->e_name + entry->e_name_len; 452 + return (entry->e_value_size == size) && !memcmp(pval, value, size); 453 + } 454 + 545 455 static int __f2fs_setxattr(struct inode *inode, int index, 546 456 const char *name, const void *value, size_t size, 547 457 struct page *ipage, int flags) ··· 583 479 584 480 found = IS_XATTR_LAST_ENTRY(here) ? 0 : 1; 585 481 586 - if ((flags & XATTR_REPLACE) && !found) { 482 + if (found) { 483 + if ((flags & XATTR_CREATE)) { 484 + error = -EEXIST; 485 + goto exit; 486 + } 487 + 488 + if (f2fs_xattr_value_same(here, value, size)) 489 + goto exit; 490 + } else if ((flags & XATTR_REPLACE)) { 587 491 error = -ENODATA; 588 - goto exit; 589 - } else if ((flags & XATTR_CREATE) && found) { 590 - error = -EEXIST; 591 492 goto exit; 592 493 } 593 494
+4 -3
fs/f2fs/xattr.h
··· 72 72 for (entry = XATTR_FIRST_ENTRY(addr);\ 73 73 !IS_XATTR_LAST_ENTRY(entry);\ 74 74 entry = XATTR_NEXT_ENTRY(entry)) 75 - 76 - #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + PAGE_SIZE - \ 77 - sizeof(struct node_footer) - sizeof(__u32)) 75 + #define MAX_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer)) 76 + #define VALID_XATTR_BLOCK_SIZE (MAX_XATTR_BLOCK_SIZE - sizeof(__u32)) 77 + #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \ 78 + VALID_XATTR_BLOCK_SIZE) 78 79 79 80 #define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \ 80 81 sizeof(struct f2fs_xattr_header) - \
+8
include/linux/f2fs_fs.h
··· 36 36 #define F2FS_NODE_INO(sbi) (sbi->node_ino_num) 37 37 #define F2FS_META_INO(sbi) (sbi->meta_ino_num) 38 38 39 + #define F2FS_IO_SIZE(sbi) (1 << (sbi)->write_io_size_bits) /* Blocks */ 40 + #define F2FS_IO_SIZE_KB(sbi) (1 << ((sbi)->write_io_size_bits + 2)) /* KB */ 41 + #define F2FS_IO_SIZE_BYTES(sbi) (1 << ((sbi)->write_io_size_bits + 12)) /* B */ 42 + #define F2FS_IO_SIZE_BITS(sbi) ((sbi)->write_io_size_bits) /* power of 2 */ 43 + #define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1) 44 + 39 45 /* This flag is used by node and meta inodes, and by recovery */ 40 46 #define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO) 41 47 #define GFP_F2FS_HIGH_ZERO (GFP_NOFS | __GFP_ZERO | __GFP_HIGHMEM) ··· 114 108 /* 115 109 * For checkpoint 116 110 */ 111 + #define CP_NAT_BITS_FLAG 0x00000080 117 112 #define CP_CRC_RECOVERY_FLAG 0x00000040 118 113 #define CP_FASTBOOT_FLAG 0x00000020 119 114 #define CP_FSCK_FLAG 0x00000010 ··· 279 272 * For NAT entries 280 273 */ 281 274 #define NAT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_nat_entry)) 275 + #define NAT_ENTRY_BITMAP_SIZE ((NAT_ENTRY_PER_BLOCK + 7) / 8) 282 276 283 277 struct f2fs_nat_entry { 284 278 __u8 version; /* latest version of cached nat entry */
+94 -55
include/trace/events/f2fs.h
··· 6 6 7 7 #include <linux/tracepoint.h> 8 8 9 - #define show_dev(entry) MAJOR(entry->dev), MINOR(entry->dev) 10 - #define show_dev_ino(entry) show_dev(entry), (unsigned long)entry->ino 9 + #define show_dev(dev) MAJOR(dev), MINOR(dev) 10 + #define show_dev_ino(entry) show_dev(entry->dev), (unsigned long)entry->ino 11 11 12 12 TRACE_DEFINE_ENUM(NODE); 13 13 TRACE_DEFINE_ENUM(DATA); ··· 55 55 { IPU, "IN-PLACE" }, \ 56 56 { OPU, "OUT-OF-PLACE" }) 57 57 58 - #define F2FS_BIO_FLAG_MASK(t) (t & (REQ_RAHEAD | REQ_PREFLUSH | REQ_FUA)) 59 - #define F2FS_BIO_EXTRA_MASK(t) (t & (REQ_META | REQ_PRIO)) 58 + #define F2FS_OP_FLAGS (REQ_RAHEAD | REQ_SYNC | REQ_PREFLUSH | REQ_META |\ 59 + REQ_PRIO) 60 + #define F2FS_BIO_FLAG_MASK(t) (t & F2FS_OP_FLAGS) 60 61 61 - #define show_bio_type(op_flags) show_bio_op_flags(op_flags), \ 62 - show_bio_extra(op_flags) 62 + #define show_bio_type(op,op_flags) show_bio_op(op), \ 63 + show_bio_op_flags(op_flags) 64 + 65 + #define show_bio_op(op) \ 66 + __print_symbolic(op, \ 67 + { REQ_OP_READ, "READ" }, \ 68 + { REQ_OP_WRITE, "WRITE" }, \ 69 + { REQ_OP_FLUSH, "FLUSH" }, \ 70 + { REQ_OP_DISCARD, "DISCARD" }, \ 71 + { REQ_OP_ZONE_REPORT, "ZONE_REPORT" }, \ 72 + { REQ_OP_SECURE_ERASE, "SECURE_ERASE" }, \ 73 + { REQ_OP_ZONE_RESET, "ZONE_RESET" }, \ 74 + { REQ_OP_WRITE_SAME, "WRITE_SAME" }, \ 75 + { REQ_OP_WRITE_ZEROES, "WRITE_ZEROES" }) 63 76 64 77 #define show_bio_op_flags(flags) \ 65 78 __print_symbolic(F2FS_BIO_FLAG_MASK(flags), \ 66 - { 0, "WRITE" }, \ 67 - { REQ_RAHEAD, "READAHEAD" }, \ 68 - { REQ_SYNC, "REQ_SYNC" }, \ 69 - { REQ_PREFLUSH, "REQ_PREFLUSH" }, \ 70 - { REQ_FUA, "REQ_FUA" }) 71 - 72 - #define show_bio_extra(type) \ 73 - __print_symbolic(F2FS_BIO_EXTRA_MASK(type), \ 79 + { REQ_RAHEAD, "(RA)" }, \ 80 + { REQ_SYNC, "(S)" }, \ 81 + { REQ_SYNC | REQ_PRIO, "(SP)" }, \ 74 82 { REQ_META, "(M)" }, \ 75 - { REQ_PRIO, "(P)" }, \ 76 83 { REQ_META | REQ_PRIO, "(MP)" }, \ 84 + { REQ_SYNC | REQ_PREFLUSH , "(SF)" }, \ 85 + { REQ_SYNC | REQ_META | REQ_PRIO, "(SMP)" }, \ 86 + { REQ_PREFLUSH | REQ_META | REQ_PRIO, "(FMP)" }, \ 77 87 { 0, " \b" }) 78 88 79 89 #define show_data_type(type) \ ··· 245 235 ), 246 236 247 237 TP_printk("dev = (%d,%d), superblock is %s, wait = %d", 248 - show_dev(__entry), 238 + show_dev(__entry->dev), 249 239 __entry->dirty ? "dirty" : "not dirty", 250 240 __entry->wait) 251 241 ); ··· 309 299 ); 310 300 311 301 DEFINE_EVENT(f2fs__inode_exit, f2fs_unlink_exit, 302 + 303 + TP_PROTO(struct inode *inode, int ret), 304 + 305 + TP_ARGS(inode, ret) 306 + ); 307 + 308 + DEFINE_EVENT(f2fs__inode_exit, f2fs_drop_inode, 312 309 313 310 TP_PROTO(struct inode *inode, int ret), 314 311 ··· 551 534 ), 552 535 553 536 TP_printk("dev = (%d,%d), wait_ms = %ld, prefree = %u, free = %u", 554 - show_dev(__entry), 537 + show_dev(__entry->dev), 555 538 __entry->wait_ms, 556 539 __entry->prefree, 557 540 __entry->free) ··· 572 555 __field(int, alloc_mode) 573 556 __field(int, gc_mode) 574 557 __field(unsigned int, victim) 558 + __field(unsigned int, cost) 575 559 __field(unsigned int, ofs_unit) 576 560 __field(unsigned int, pre_victim) 577 561 __field(unsigned int, prefree) ··· 586 568 __entry->alloc_mode = p->alloc_mode; 587 569 __entry->gc_mode = p->gc_mode; 588 570 __entry->victim = p->min_segno; 571 + __entry->cost = p->min_cost; 589 572 __entry->ofs_unit = p->ofs_unit; 590 573 __entry->pre_victim = pre_victim; 591 574 __entry->prefree = prefree; 592 575 __entry->free = free; 593 576 ), 594 577 595 - TP_printk("dev = (%d,%d), type = %s, policy = (%s, %s, %s), victim = %u " 596 - "ofs_unit = %u, pre_victim_secno = %d, prefree = %u, free = %u", 597 - show_dev(__entry), 578 + TP_printk("dev = (%d,%d), type = %s, policy = (%s, %s, %s), " 579 + "victim = %u, cost = %u, ofs_unit = %u, " 580 + "pre_victim_secno = %d, prefree = %u, free = %u", 581 + show_dev(__entry->dev), 598 582 show_data_type(__entry->type), 599 583 show_gc_type(__entry->gc_type), 600 584 show_alloc_mode(__entry->alloc_mode), 601 585 show_victim_policy(__entry->gc_mode), 602 586 __entry->victim, 587 + __entry->cost, 603 588 __entry->ofs_unit, 604 589 (int)__entry->pre_victim, 605 590 __entry->prefree, ··· 734 713 ), 735 714 736 715 TP_printk("dev = (%d,%d), nid = %u, ofs_in_node = %u, count = %llu", 737 - show_dev(__entry), 716 + show_dev(__entry->dev), 738 717 (unsigned int)__entry->nid, 739 718 __entry->ofs_in_node, 740 719 (unsigned long long)__entry->count) ··· 774 753 (unsigned long)__entry->index, 775 754 (unsigned long long)__entry->old_blkaddr, 776 755 (unsigned long long)__entry->new_blkaddr, 777 - show_bio_type(__entry->op_flags), 756 + show_bio_type(__entry->op, __entry->op_flags), 778 757 show_block_type(__entry->type)) 779 758 ); 780 759 ··· 796 775 TP_CONDITION(page->mapping) 797 776 ); 798 777 799 - DECLARE_EVENT_CLASS(f2fs__submit_bio, 778 + DECLARE_EVENT_CLASS(f2fs__bio, 800 779 801 - TP_PROTO(struct super_block *sb, struct f2fs_io_info *fio, 802 - struct bio *bio), 780 + TP_PROTO(struct super_block *sb, int type, struct bio *bio), 803 781 804 - TP_ARGS(sb, fio, bio), 782 + TP_ARGS(sb, type, bio), 805 783 806 784 TP_STRUCT__entry( 807 785 __field(dev_t, dev) 786 + __field(dev_t, target) 808 787 __field(int, op) 809 788 __field(int, op_flags) 810 789 __field(int, type) ··· 814 793 815 794 TP_fast_assign( 816 795 __entry->dev = sb->s_dev; 817 - __entry->op = fio->op; 818 - __entry->op_flags = fio->op_flags; 819 - __entry->type = fio->type; 796 + __entry->target = bio->bi_bdev->bd_dev; 797 + __entry->op = bio_op(bio); 798 + __entry->op_flags = bio->bi_opf; 799 + __entry->type = type; 820 800 __entry->sector = bio->bi_iter.bi_sector; 821 801 __entry->size = bio->bi_iter.bi_size; 822 802 ), 823 803 824 - TP_printk("dev = (%d,%d), rw = %s%s, %s, sector = %lld, size = %u", 825 - show_dev(__entry), 826 - show_bio_type(__entry->op_flags), 804 + TP_printk("dev = (%d,%d)/(%d,%d), rw = %s%s, %s, sector = %lld, size = %u", 805 + show_dev(__entry->target), 806 + show_dev(__entry->dev), 807 + show_bio_type(__entry->op, __entry->op_flags), 827 808 show_block_type(__entry->type), 828 809 (unsigned long long)__entry->sector, 829 810 __entry->size) 830 811 ); 831 812 832 - DEFINE_EVENT_CONDITION(f2fs__submit_bio, f2fs_submit_write_bio, 813 + DEFINE_EVENT_CONDITION(f2fs__bio, f2fs_prepare_write_bio, 833 814 834 - TP_PROTO(struct super_block *sb, struct f2fs_io_info *fio, 835 - struct bio *bio), 815 + TP_PROTO(struct super_block *sb, int type, struct bio *bio), 836 816 837 - TP_ARGS(sb, fio, bio), 817 + TP_ARGS(sb, type, bio), 838 818 839 819 TP_CONDITION(bio) 840 820 ); 841 821 842 - DEFINE_EVENT_CONDITION(f2fs__submit_bio, f2fs_submit_read_bio, 822 + DEFINE_EVENT_CONDITION(f2fs__bio, f2fs_prepare_read_bio, 843 823 844 - TP_PROTO(struct super_block *sb, struct f2fs_io_info *fio, 845 - struct bio *bio), 824 + TP_PROTO(struct super_block *sb, int type, struct bio *bio), 846 825 847 - TP_ARGS(sb, fio, bio), 826 + TP_ARGS(sb, type, bio), 827 + 828 + TP_CONDITION(bio) 829 + ); 830 + 831 + DEFINE_EVENT_CONDITION(f2fs__bio, f2fs_submit_read_bio, 832 + 833 + TP_PROTO(struct super_block *sb, int type, struct bio *bio), 834 + 835 + TP_ARGS(sb, type, bio), 836 + 837 + TP_CONDITION(bio) 838 + ); 839 + 840 + DEFINE_EVENT_CONDITION(f2fs__bio, f2fs_submit_write_bio, 841 + 842 + TP_PROTO(struct super_block *sb, int type, struct bio *bio), 843 + 844 + TP_ARGS(sb, type, bio), 848 845 849 846 TP_CONDITION(bio) 850 847 ); ··· 1121 1082 ), 1122 1083 1123 1084 TP_printk("dev = (%d,%d), checkpoint for %s, state = %s", 1124 - show_dev(__entry), 1085 + show_dev(__entry->dev), 1125 1086 show_cpreason(__entry->reason), 1126 1087 __entry->msg) 1127 1088 ); 1128 1089 1129 1090 TRACE_EVENT(f2fs_issue_discard, 1130 1091 1131 - TP_PROTO(struct super_block *sb, block_t blkstart, block_t blklen), 1092 + TP_PROTO(struct block_device *dev, block_t blkstart, block_t blklen), 1132 1093 1133 - TP_ARGS(sb, blkstart, blklen), 1094 + TP_ARGS(dev, blkstart, blklen), 1134 1095 1135 1096 TP_STRUCT__entry( 1136 1097 __field(dev_t, dev) ··· 1139 1100 ), 1140 1101 1141 1102 TP_fast_assign( 1142 - __entry->dev = sb->s_dev; 1103 + __entry->dev = dev->bd_dev; 1143 1104 __entry->blkstart = blkstart; 1144 1105 __entry->blklen = blklen; 1145 1106 ), 1146 1107 1147 1108 TP_printk("dev = (%d,%d), blkstart = 0x%llx, blklen = 0x%llx", 1148 - show_dev(__entry), 1109 + show_dev(__entry->dev), 1149 1110 (unsigned long long)__entry->blkstart, 1150 1111 (unsigned long long)__entry->blklen) 1151 1112 ); 1152 1113 1153 1114 TRACE_EVENT(f2fs_issue_reset_zone, 1154 1115 1155 - TP_PROTO(struct super_block *sb, block_t blkstart), 1116 + TP_PROTO(struct block_device *dev, block_t blkstart), 1156 1117 1157 - TP_ARGS(sb, blkstart), 1118 + TP_ARGS(dev, blkstart), 1158 1119 1159 1120 TP_STRUCT__entry( 1160 1121 __field(dev_t, dev) ··· 1162 1123 ), 1163 1124 1164 1125 TP_fast_assign( 1165 - __entry->dev = sb->s_dev; 1126 + __entry->dev = dev->bd_dev; 1166 1127 __entry->blkstart = blkstart; 1167 1128 ), 1168 1129 1169 1130 TP_printk("dev = (%d,%d), reset zone at block = 0x%llx", 1170 - show_dev(__entry), 1131 + show_dev(__entry->dev), 1171 1132 (unsigned long long)__entry->blkstart) 1172 1133 ); 1173 1134 1174 1135 TRACE_EVENT(f2fs_issue_flush, 1175 1136 1176 - TP_PROTO(struct super_block *sb, unsigned int nobarrier, 1137 + TP_PROTO(struct block_device *dev, unsigned int nobarrier, 1177 1138 unsigned int flush_merge), 1178 1139 1179 - TP_ARGS(sb, nobarrier, flush_merge), 1140 + TP_ARGS(dev, nobarrier, flush_merge), 1180 1141 1181 1142 TP_STRUCT__entry( 1182 1143 __field(dev_t, dev) ··· 1185 1146 ), 1186 1147 1187 1148 TP_fast_assign( 1188 - __entry->dev = sb->s_dev; 1149 + __entry->dev = dev->bd_dev; 1189 1150 __entry->nobarrier = nobarrier; 1190 1151 __entry->flush_merge = flush_merge; 1191 1152 ), 1192 1153 1193 1154 TP_printk("dev = (%d,%d), %s %s", 1194 - show_dev(__entry), 1155 + show_dev(__entry->dev), 1195 1156 __entry->nobarrier ? "skip (nobarrier)" : "issue", 1196 1157 __entry->flush_merge ? " with flush_merge" : "") 1197 1158 ); ··· 1306 1267 ), 1307 1268 1308 1269 TP_printk("dev = (%d,%d), shrunk: node_cnt = %u, tree_cnt = %u", 1309 - show_dev(__entry), 1270 + show_dev(__entry->dev), 1310 1271 __entry->node_cnt, 1311 1272 __entry->tree_cnt) 1312 1273 ); ··· 1353 1314 ), 1354 1315 1355 1316 TP_printk("dev = (%d,%d), %s, dirty count = %lld", 1356 - show_dev(__entry), 1317 + show_dev(__entry->dev), 1357 1318 show_file_type(__entry->type), 1358 1319 __entry->count) 1359 1320 );