4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/f2fs_fs.h>
13 #include <linux/buffer_head.h>
14 #include <linux/mpage.h>
15 #include <linux/aio.h>
16 #include <linux/writeback.h>
17 #include <linux/backing-dev.h>
18 #include <linux/blkdev.h>
19 #include <linux/bio.h>
20 #include <linux/prefetch.h>
26 #include <trace/events/f2fs.h>
28 static struct kmem_cache
*extent_tree_slab
;
29 static struct kmem_cache
*extent_node_slab
;
31 static void f2fs_read_end_io(struct bio
*bio
, int err
)
36 bio_for_each_segment_all(bvec
, bio
, i
) {
37 struct page
*page
= bvec
->bv_page
;
40 SetPageUptodate(page
);
42 ClearPageUptodate(page
);
50 static void f2fs_write_end_io(struct bio
*bio
, int err
)
52 struct f2fs_sb_info
*sbi
= bio
->bi_private
;
56 bio_for_each_segment_all(bvec
, bio
, i
) {
57 struct page
*page
= bvec
->bv_page
;
61 set_bit(AS_EIO
, &page
->mapping
->flags
);
62 f2fs_stop_checkpoint(sbi
);
64 end_page_writeback(page
);
65 dec_page_count(sbi
, F2FS_WRITEBACK
);
68 if (!get_pages(sbi
, F2FS_WRITEBACK
) &&
69 !list_empty(&sbi
->cp_wait
.task_list
))
70 wake_up(&sbi
->cp_wait
);
76 * Low-level block read/write IO operations.
78 static struct bio
*__bio_alloc(struct f2fs_sb_info
*sbi
, block_t blk_addr
,
79 int npages
, bool is_read
)
83 /* No failure on bio allocation */
84 bio
= bio_alloc(GFP_NOIO
, npages
);
86 bio
->bi_bdev
= sbi
->sb
->s_bdev
;
87 bio
->bi_iter
.bi_sector
= SECTOR_FROM_BLOCK(blk_addr
);
88 bio
->bi_end_io
= is_read
? f2fs_read_end_io
: f2fs_write_end_io
;
89 bio
->bi_private
= sbi
;
94 static void __submit_merged_bio(struct f2fs_bio_info
*io
)
96 struct f2fs_io_info
*fio
= &io
->fio
;
101 if (is_read_io(fio
->rw
))
102 trace_f2fs_submit_read_bio(io
->sbi
->sb
, fio
, io
->bio
);
104 trace_f2fs_submit_write_bio(io
->sbi
->sb
, fio
, io
->bio
);
106 submit_bio(fio
->rw
, io
->bio
);
110 void f2fs_submit_merged_bio(struct f2fs_sb_info
*sbi
,
111 enum page_type type
, int rw
)
113 enum page_type btype
= PAGE_TYPE_OF_BIO(type
);
114 struct f2fs_bio_info
*io
;
116 io
= is_read_io(rw
) ? &sbi
->read_io
: &sbi
->write_io
[btype
];
118 down_write(&io
->io_rwsem
);
120 /* change META to META_FLUSH in the checkpoint procedure */
121 if (type
>= META_FLUSH
) {
122 io
->fio
.type
= META_FLUSH
;
123 if (test_opt(sbi
, NOBARRIER
))
124 io
->fio
.rw
= WRITE_FLUSH
| REQ_META
| REQ_PRIO
;
126 io
->fio
.rw
= WRITE_FLUSH_FUA
| REQ_META
| REQ_PRIO
;
128 __submit_merged_bio(io
);
129 up_write(&io
->io_rwsem
);
133 * Fill the locked page with data located in the block address.
134 * Return unlocked page.
136 int f2fs_submit_page_bio(struct f2fs_sb_info
*sbi
, struct page
*page
,
137 struct f2fs_io_info
*fio
)
141 trace_f2fs_submit_page_bio(page
, fio
);
142 f2fs_trace_ios(page
, fio
, 0);
144 /* Allocate a new bio */
145 bio
= __bio_alloc(sbi
, fio
->blk_addr
, 1, is_read_io(fio
->rw
));
147 if (bio_add_page(bio
, page
, PAGE_CACHE_SIZE
, 0) < PAGE_CACHE_SIZE
) {
149 f2fs_put_page(page
, 1);
153 submit_bio(fio
->rw
, bio
);
157 void f2fs_submit_page_mbio(struct f2fs_sb_info
*sbi
, struct page
*page
,
158 struct f2fs_io_info
*fio
)
160 enum page_type btype
= PAGE_TYPE_OF_BIO(fio
->type
);
161 struct f2fs_bio_info
*io
;
162 bool is_read
= is_read_io(fio
->rw
);
164 io
= is_read
? &sbi
->read_io
: &sbi
->write_io
[btype
];
166 verify_block_addr(sbi
, fio
->blk_addr
);
168 down_write(&io
->io_rwsem
);
171 inc_page_count(sbi
, F2FS_WRITEBACK
);
173 if (io
->bio
&& (io
->last_block_in_bio
!= fio
->blk_addr
- 1 ||
174 io
->fio
.rw
!= fio
->rw
))
175 __submit_merged_bio(io
);
177 if (io
->bio
== NULL
) {
178 int bio_blocks
= MAX_BIO_BLOCKS(sbi
);
180 io
->bio
= __bio_alloc(sbi
, fio
->blk_addr
, bio_blocks
, is_read
);
184 if (bio_add_page(io
->bio
, page
, PAGE_CACHE_SIZE
, 0) <
186 __submit_merged_bio(io
);
190 io
->last_block_in_bio
= fio
->blk_addr
;
191 f2fs_trace_ios(page
, fio
, 0);
193 up_write(&io
->io_rwsem
);
194 trace_f2fs_submit_page_mbio(page
, fio
);
198 * Lock ordering for the change of data block address:
201 * update block addresses in the node page
203 static void __set_data_blkaddr(struct dnode_of_data
*dn
)
205 struct f2fs_node
*rn
;
207 struct page
*node_page
= dn
->node_page
;
208 unsigned int ofs_in_node
= dn
->ofs_in_node
;
210 f2fs_wait_on_page_writeback(node_page
, NODE
);
212 rn
= F2FS_NODE(node_page
);
214 /* Get physical address of data block */
215 addr_array
= blkaddr_in_node(rn
);
216 addr_array
[ofs_in_node
] = cpu_to_le32(dn
->data_blkaddr
);
217 set_page_dirty(node_page
);
220 int reserve_new_block(struct dnode_of_data
*dn
)
222 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dn
->inode
);
224 if (unlikely(is_inode_flag_set(F2FS_I(dn
->inode
), FI_NO_ALLOC
)))
226 if (unlikely(!inc_valid_block_count(sbi
, dn
->inode
, 1)))
229 trace_f2fs_reserve_new_block(dn
->inode
, dn
->nid
, dn
->ofs_in_node
);
231 dn
->data_blkaddr
= NEW_ADDR
;
232 __set_data_blkaddr(dn
);
233 mark_inode_dirty(dn
->inode
);
238 int f2fs_reserve_block(struct dnode_of_data
*dn
, pgoff_t index
)
240 bool need_put
= dn
->inode_page
? false : true;
243 err
= get_dnode_of_data(dn
, index
, ALLOC_NODE
);
247 if (dn
->data_blkaddr
== NULL_ADDR
)
248 err
= reserve_new_block(dn
);
254 static void f2fs_map_bh(struct super_block
*sb
, pgoff_t pgofs
,
255 struct extent_info
*ei
, struct buffer_head
*bh_result
)
257 unsigned int blkbits
= sb
->s_blocksize_bits
;
260 set_buffer_new(bh_result
);
261 map_bh(bh_result
, sb
, ei
->blk
+ pgofs
- ei
->fofs
);
262 count
= ei
->fofs
+ ei
->len
- pgofs
;
263 if (count
< (UINT_MAX
>> blkbits
))
264 bh_result
->b_size
= (count
<< blkbits
);
266 bh_result
->b_size
= UINT_MAX
;
269 static bool lookup_extent_info(struct inode
*inode
, pgoff_t pgofs
,
270 struct extent_info
*ei
)
272 struct f2fs_inode_info
*fi
= F2FS_I(inode
);
273 pgoff_t start_fofs
, end_fofs
;
274 block_t start_blkaddr
;
276 if (is_inode_flag_set(fi
, FI_NO_EXTENT
))
279 read_lock(&fi
->ext_lock
);
280 if (fi
->ext
.len
== 0) {
281 read_unlock(&fi
->ext_lock
);
285 stat_inc_total_hit(inode
->i_sb
);
287 start_fofs
= fi
->ext
.fofs
;
288 end_fofs
= fi
->ext
.fofs
+ fi
->ext
.len
- 1;
289 start_blkaddr
= fi
->ext
.blk
;
291 if (pgofs
>= start_fofs
&& pgofs
<= end_fofs
) {
293 stat_inc_read_hit(inode
->i_sb
);
294 read_unlock(&fi
->ext_lock
);
297 read_unlock(&fi
->ext_lock
);
301 static bool update_extent_info(struct inode
*inode
, pgoff_t fofs
,
304 struct f2fs_inode_info
*fi
= F2FS_I(inode
);
305 pgoff_t start_fofs
, end_fofs
;
306 block_t start_blkaddr
, end_blkaddr
;
307 int need_update
= true;
309 if (is_inode_flag_set(fi
, FI_NO_EXTENT
))
312 write_lock(&fi
->ext_lock
);
314 start_fofs
= fi
->ext
.fofs
;
315 end_fofs
= fi
->ext
.fofs
+ fi
->ext
.len
- 1;
316 start_blkaddr
= fi
->ext
.blk
;
317 end_blkaddr
= fi
->ext
.blk
+ fi
->ext
.len
- 1;
319 /* Drop and initialize the matched extent */
320 if (fi
->ext
.len
== 1 && fofs
== start_fofs
)
324 if (fi
->ext
.len
== 0) {
325 if (blkaddr
!= NULL_ADDR
) {
327 fi
->ext
.blk
= blkaddr
;
334 if (fofs
== start_fofs
- 1 && blkaddr
== start_blkaddr
- 1) {
342 if (fofs
== end_fofs
+ 1 && blkaddr
== end_blkaddr
+ 1) {
347 /* Split the existing extent */
348 if (fi
->ext
.len
> 1 &&
349 fofs
>= start_fofs
&& fofs
<= end_fofs
) {
350 if ((end_fofs
- fofs
) < (fi
->ext
.len
>> 1)) {
351 fi
->ext
.len
= fofs
- start_fofs
;
353 fi
->ext
.fofs
= fofs
+ 1;
354 fi
->ext
.blk
= start_blkaddr
+ fofs
- start_fofs
+ 1;
355 fi
->ext
.len
-= fofs
- start_fofs
+ 1;
361 /* Finally, if the extent is very fragmented, let's drop the cache. */
362 if (fi
->ext
.len
< F2FS_MIN_EXTENT_LEN
) {
364 set_inode_flag(fi
, FI_NO_EXTENT
);
368 write_unlock(&fi
->ext_lock
);
372 static struct extent_node
*__attach_extent_node(struct f2fs_sb_info
*sbi
,
373 struct extent_tree
*et
, struct extent_info
*ei
,
374 struct rb_node
*parent
, struct rb_node
**p
)
376 struct extent_node
*en
;
378 en
= kmem_cache_alloc(extent_node_slab
, GFP_ATOMIC
);
383 INIT_LIST_HEAD(&en
->list
);
385 rb_link_node(&en
->rb_node
, parent
, p
);
386 rb_insert_color(&en
->rb_node
, &et
->root
);
388 atomic_inc(&sbi
->total_ext_node
);
392 static void __detach_extent_node(struct f2fs_sb_info
*sbi
,
393 struct extent_tree
*et
, struct extent_node
*en
)
395 rb_erase(&en
->rb_node
, &et
->root
);
397 atomic_dec(&sbi
->total_ext_node
);
400 static struct extent_node
*__lookup_extent_tree(struct extent_tree
*et
,
403 struct rb_node
*node
= et
->root
.rb_node
;
404 struct extent_node
*en
;
407 en
= rb_entry(node
, struct extent_node
, rb_node
);
409 if (fofs
< en
->ei
.fofs
)
410 node
= node
->rb_left
;
411 else if (fofs
>= en
->ei
.fofs
+ en
->ei
.len
)
412 node
= node
->rb_right
;
419 static struct extent_node
*__try_back_merge(struct f2fs_sb_info
*sbi
,
420 struct extent_tree
*et
, struct extent_node
*en
)
422 struct extent_node
*prev
;
423 struct rb_node
*node
;
425 node
= rb_prev(&en
->rb_node
);
429 prev
= rb_entry(node
, struct extent_node
, rb_node
);
430 if (__is_back_mergeable(&en
->ei
, &prev
->ei
)) {
431 en
->ei
.fofs
= prev
->ei
.fofs
;
432 en
->ei
.blk
= prev
->ei
.blk
;
433 en
->ei
.len
+= prev
->ei
.len
;
434 __detach_extent_node(sbi
, et
, prev
);
440 static struct extent_node
*__try_front_merge(struct f2fs_sb_info
*sbi
,
441 struct extent_tree
*et
, struct extent_node
*en
)
443 struct extent_node
*next
;
444 struct rb_node
*node
;
446 node
= rb_next(&en
->rb_node
);
450 next
= rb_entry(node
, struct extent_node
, rb_node
);
451 if (__is_front_mergeable(&en
->ei
, &next
->ei
)) {
452 en
->ei
.len
+= next
->ei
.len
;
453 __detach_extent_node(sbi
, et
, next
);
459 static struct extent_node
*__insert_extent_tree(struct f2fs_sb_info
*sbi
,
460 struct extent_tree
*et
, struct extent_info
*ei
,
461 struct extent_node
**den
)
463 struct rb_node
**p
= &et
->root
.rb_node
;
464 struct rb_node
*parent
= NULL
;
465 struct extent_node
*en
;
469 en
= rb_entry(parent
, struct extent_node
, rb_node
);
471 if (ei
->fofs
< en
->ei
.fofs
) {
472 if (__is_front_mergeable(ei
, &en
->ei
)) {
473 f2fs_bug_on(sbi
, !den
);
474 en
->ei
.fofs
= ei
->fofs
;
475 en
->ei
.blk
= ei
->blk
;
476 en
->ei
.len
+= ei
->len
;
477 *den
= __try_back_merge(sbi
, et
, en
);
481 } else if (ei
->fofs
>= en
->ei
.fofs
+ en
->ei
.len
) {
482 if (__is_back_mergeable(ei
, &en
->ei
)) {
483 f2fs_bug_on(sbi
, !den
);
484 en
->ei
.len
+= ei
->len
;
485 *den
= __try_front_merge(sbi
, et
, en
);
494 return __attach_extent_node(sbi
, et
, ei
, parent
, p
);
497 static unsigned int __free_extent_tree(struct f2fs_sb_info
*sbi
,
498 struct extent_tree
*et
, bool free_all
)
500 struct rb_node
*node
, *next
;
501 struct extent_node
*en
;
502 unsigned int count
= et
->count
;
504 node
= rb_first(&et
->root
);
506 next
= rb_next(node
);
507 en
= rb_entry(node
, struct extent_node
, rb_node
);
510 spin_lock(&sbi
->extent_lock
);
511 if (!list_empty(&en
->list
))
512 list_del_init(&en
->list
);
513 spin_unlock(&sbi
->extent_lock
);
516 if (free_all
|| list_empty(&en
->list
)) {
517 __detach_extent_node(sbi
, et
, en
);
518 kmem_cache_free(extent_node_slab
, en
);
523 return count
- et
->count
;
526 static bool f2fs_lookup_extent_tree(struct inode
*inode
, pgoff_t pgofs
,
527 struct extent_info
*ei
)
529 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
530 struct extent_tree
*et
;
531 struct extent_node
*en
;
533 if (is_inode_flag_set(F2FS_I(inode
), FI_NO_EXTENT
))
536 down_read(&sbi
->extent_tree_lock
);
537 et
= radix_tree_lookup(&sbi
->extent_tree_root
, inode
->i_ino
);
539 up_read(&sbi
->extent_tree_lock
);
542 atomic_inc(&et
->refcount
);
543 up_read(&sbi
->extent_tree_lock
);
545 read_lock(&et
->lock
);
546 en
= __lookup_extent_tree(et
, pgofs
);
549 spin_lock(&sbi
->extent_lock
);
550 if (!list_empty(&en
->list
))
551 list_move_tail(&en
->list
, &sbi
->extent_list
);
552 spin_unlock(&sbi
->extent_lock
);
553 stat_inc_read_hit(sbi
->sb
);
555 stat_inc_total_hit(sbi
->sb
);
556 read_unlock(&et
->lock
);
558 atomic_dec(&et
->refcount
);
559 return en
? true : false;
562 static void f2fs_update_extent_tree(struct inode
*inode
, pgoff_t fofs
,
565 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
566 nid_t ino
= inode
->i_ino
;
567 struct extent_tree
*et
;
568 struct extent_node
*en
= NULL
, *en1
= NULL
, *en2
= NULL
, *en3
= NULL
;
569 struct extent_node
*den
= NULL
;
570 struct extent_info ei
, dei
;
573 if (is_inode_flag_set(F2FS_I(inode
), FI_NO_EXTENT
))
576 down_write(&sbi
->extent_tree_lock
);
577 et
= radix_tree_lookup(&sbi
->extent_tree_root
, ino
);
579 et
= f2fs_kmem_cache_alloc(extent_tree_slab
, GFP_NOFS
);
580 f2fs_radix_tree_insert(&sbi
->extent_tree_root
, ino
, et
);
581 memset(et
, 0, sizeof(struct extent_tree
));
584 rwlock_init(&et
->lock
);
585 atomic_set(&et
->refcount
, 0);
587 sbi
->total_ext_tree
++;
589 atomic_inc(&et
->refcount
);
590 up_write(&sbi
->extent_tree_lock
);
592 write_lock(&et
->lock
);
594 /* 1. lookup and remove existing extent info in cache */
595 en
= __lookup_extent_tree(et
, fofs
);
600 __detach_extent_node(sbi
, et
, en
);
602 /* 2. if extent can be split more, split and insert the left part */
604 /* insert left part of split extent into cache */
605 if (fofs
- dei
.fofs
>= F2FS_MIN_EXTENT_LEN
) {
606 set_extent_info(&ei
, dei
.fofs
, dei
.blk
,
608 en1
= __insert_extent_tree(sbi
, et
, &ei
, NULL
);
611 /* insert right part of split extent into cache */
612 endofs
= dei
.fofs
+ dei
.len
- 1;
613 if (endofs
- fofs
>= F2FS_MIN_EXTENT_LEN
) {
614 set_extent_info(&ei
, fofs
+ 1,
615 fofs
- dei
.fofs
+ dei
.blk
, endofs
- fofs
);
616 en2
= __insert_extent_tree(sbi
, et
, &ei
, NULL
);
621 /* 3. update extent in extent cache */
623 set_extent_info(&ei
, fofs
, blkaddr
, 1);
624 en3
= __insert_extent_tree(sbi
, et
, &ei
, &den
);
627 /* 4. update in global extent list */
628 spin_lock(&sbi
->extent_lock
);
629 if (en
&& !list_empty(&en
->list
))
632 * en1 and en2 split from en, they will become more and more smaller
633 * fragments after splitting several times. So if the length is smaller
634 * than F2FS_MIN_EXTENT_LEN, we will not add them into extent tree.
637 list_add_tail(&en1
->list
, &sbi
->extent_list
);
639 list_add_tail(&en2
->list
, &sbi
->extent_list
);
641 if (list_empty(&en3
->list
))
642 list_add_tail(&en3
->list
, &sbi
->extent_list
);
644 list_move_tail(&en3
->list
, &sbi
->extent_list
);
646 if (den
&& !list_empty(&den
->list
))
647 list_del(&den
->list
);
648 spin_unlock(&sbi
->extent_lock
);
650 /* 5. release extent node */
652 kmem_cache_free(extent_node_slab
, en
);
654 kmem_cache_free(extent_node_slab
, den
);
656 write_unlock(&et
->lock
);
657 atomic_dec(&et
->refcount
);
660 void f2fs_shrink_extent_tree(struct f2fs_sb_info
*sbi
, int nr_shrink
)
662 struct extent_tree
*treevec
[EXT_TREE_VEC_SIZE
];
663 struct extent_node
*en
, *tmp
;
664 unsigned long ino
= F2FS_ROOT_INO(sbi
);
665 struct radix_tree_iter iter
;
669 if (available_free_memory(sbi
, EXTENT_CACHE
))
672 spin_lock(&sbi
->extent_lock
);
673 list_for_each_entry_safe(en
, tmp
, &sbi
->extent_list
, list
) {
676 list_del_init(&en
->list
);
678 spin_unlock(&sbi
->extent_lock
);
680 down_read(&sbi
->extent_tree_lock
);
681 while ((found
= radix_tree_gang_lookup(&sbi
->extent_tree_root
,
682 (void **)treevec
, ino
, EXT_TREE_VEC_SIZE
))) {
685 ino
= treevec
[found
- 1]->ino
+ 1;
686 for (i
= 0; i
< found
; i
++) {
687 struct extent_tree
*et
= treevec
[i
];
689 atomic_inc(&et
->refcount
);
690 write_lock(&et
->lock
);
691 __free_extent_tree(sbi
, et
, false);
692 write_unlock(&et
->lock
);
693 atomic_dec(&et
->refcount
);
696 up_read(&sbi
->extent_tree_lock
);
698 down_write(&sbi
->extent_tree_lock
);
699 radix_tree_for_each_slot(slot
, &sbi
->extent_tree_root
, &iter
,
700 F2FS_ROOT_INO(sbi
)) {
701 struct extent_tree
*et
= (struct extent_tree
*)*slot
;
703 if (!atomic_read(&et
->refcount
) && !et
->count
) {
704 radix_tree_delete(&sbi
->extent_tree_root
, et
->ino
);
705 kmem_cache_free(extent_tree_slab
, et
);
706 sbi
->total_ext_tree
--;
709 up_write(&sbi
->extent_tree_lock
);
712 void f2fs_destroy_extent_tree(struct inode
*inode
)
714 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
715 struct extent_tree
*et
;
717 down_read(&sbi
->extent_tree_lock
);
718 et
= radix_tree_lookup(&sbi
->extent_tree_root
, inode
->i_ino
);
720 up_read(&sbi
->extent_tree_lock
);
723 atomic_inc(&et
->refcount
);
724 up_read(&sbi
->extent_tree_lock
);
726 /* free all extent info belong to this extent tree */
727 write_lock(&et
->lock
);
728 __free_extent_tree(sbi
, et
, true);
729 write_unlock(&et
->lock
);
731 atomic_dec(&et
->refcount
);
733 /* try to find and delete extent tree entry in radix tree */
734 down_write(&sbi
->extent_tree_lock
);
735 et
= radix_tree_lookup(&sbi
->extent_tree_root
, inode
->i_ino
);
737 up_write(&sbi
->extent_tree_lock
);
740 f2fs_bug_on(sbi
, atomic_read(&et
->refcount
) || et
->count
);
741 radix_tree_delete(&sbi
->extent_tree_root
, inode
->i_ino
);
742 kmem_cache_free(extent_tree_slab
, et
);
743 sbi
->total_ext_tree
--;
744 up_write(&sbi
->extent_tree_lock
);
749 static bool f2fs_lookup_extent_cache(struct inode
*inode
, pgoff_t pgofs
,
750 struct extent_info
*ei
)
752 return lookup_extent_info(inode
, pgofs
, ei
);
755 void f2fs_update_extent_cache(struct dnode_of_data
*dn
)
757 struct f2fs_inode_info
*fi
= F2FS_I(dn
->inode
);
760 f2fs_bug_on(F2FS_I_SB(dn
->inode
), dn
->data_blkaddr
== NEW_ADDR
);
762 /* Update the page address in the parent node */
763 __set_data_blkaddr(dn
);
765 fofs
= start_bidx_of_node(ofs_of_node(dn
->node_page
), fi
) +
768 if (update_extent_info(dn
->inode
, fofs
, dn
->data_blkaddr
))
772 struct page
*find_data_page(struct inode
*inode
, pgoff_t index
, bool sync
)
774 struct address_space
*mapping
= inode
->i_mapping
;
775 struct dnode_of_data dn
;
778 struct f2fs_io_info fio
= {
780 .rw
= sync
? READ_SYNC
: READA
,
783 page
= find_get_page(mapping
, index
);
784 if (page
&& PageUptodate(page
))
786 f2fs_put_page(page
, 0);
788 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
789 err
= get_dnode_of_data(&dn
, index
, LOOKUP_NODE
);
794 if (dn
.data_blkaddr
== NULL_ADDR
)
795 return ERR_PTR(-ENOENT
);
797 /* By fallocate(), there is no cached page, but with NEW_ADDR */
798 if (unlikely(dn
.data_blkaddr
== NEW_ADDR
))
799 return ERR_PTR(-EINVAL
);
801 page
= grab_cache_page(mapping
, index
);
803 return ERR_PTR(-ENOMEM
);
805 if (PageUptodate(page
)) {
810 fio
.blk_addr
= dn
.data_blkaddr
;
811 err
= f2fs_submit_page_bio(F2FS_I_SB(inode
), page
, &fio
);
816 wait_on_page_locked(page
);
817 if (unlikely(!PageUptodate(page
))) {
818 f2fs_put_page(page
, 0);
819 return ERR_PTR(-EIO
);
826 * If it tries to access a hole, return an error.
827 * Because, the callers, functions in dir.c and GC, should be able to know
828 * whether this page exists or not.
830 struct page
*get_lock_data_page(struct inode
*inode
, pgoff_t index
)
832 struct address_space
*mapping
= inode
->i_mapping
;
833 struct dnode_of_data dn
;
836 struct f2fs_io_info fio
= {
841 page
= grab_cache_page(mapping
, index
);
843 return ERR_PTR(-ENOMEM
);
845 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
846 err
= get_dnode_of_data(&dn
, index
, LOOKUP_NODE
);
848 f2fs_put_page(page
, 1);
853 if (unlikely(dn
.data_blkaddr
== NULL_ADDR
)) {
854 f2fs_put_page(page
, 1);
855 return ERR_PTR(-ENOENT
);
858 if (PageUptodate(page
))
862 * A new dentry page is allocated but not able to be written, since its
863 * new inode page couldn't be allocated due to -ENOSPC.
864 * In such the case, its blkaddr can be remained as NEW_ADDR.
865 * see, f2fs_add_link -> get_new_data_page -> init_inode_metadata.
867 if (dn
.data_blkaddr
== NEW_ADDR
) {
868 zero_user_segment(page
, 0, PAGE_CACHE_SIZE
);
869 SetPageUptodate(page
);
873 fio
.blk_addr
= dn
.data_blkaddr
;
874 err
= f2fs_submit_page_bio(F2FS_I_SB(inode
), page
, &fio
);
879 if (unlikely(!PageUptodate(page
))) {
880 f2fs_put_page(page
, 1);
881 return ERR_PTR(-EIO
);
883 if (unlikely(page
->mapping
!= mapping
)) {
884 f2fs_put_page(page
, 1);
891 * Caller ensures that this data page is never allocated.
892 * A new zero-filled data page is allocated in the page cache.
894 * Also, caller should grab and release a rwsem by calling f2fs_lock_op() and
896 * Note that, ipage is set only by make_empty_dir.
898 struct page
*get_new_data_page(struct inode
*inode
,
899 struct page
*ipage
, pgoff_t index
, bool new_i_size
)
901 struct address_space
*mapping
= inode
->i_mapping
;
903 struct dnode_of_data dn
;
906 set_new_dnode(&dn
, inode
, ipage
, NULL
, 0);
907 err
= f2fs_reserve_block(&dn
, index
);
911 page
= grab_cache_page(mapping
, index
);
917 if (PageUptodate(page
))
920 if (dn
.data_blkaddr
== NEW_ADDR
) {
921 zero_user_segment(page
, 0, PAGE_CACHE_SIZE
);
922 SetPageUptodate(page
);
924 struct f2fs_io_info fio
= {
927 .blk_addr
= dn
.data_blkaddr
,
929 err
= f2fs_submit_page_bio(F2FS_I_SB(inode
), page
, &fio
);
934 if (unlikely(!PageUptodate(page
))) {
935 f2fs_put_page(page
, 1);
939 if (unlikely(page
->mapping
!= mapping
)) {
940 f2fs_put_page(page
, 1);
946 i_size_read(inode
) < ((index
+ 1) << PAGE_CACHE_SHIFT
)) {
947 i_size_write(inode
, ((index
+ 1) << PAGE_CACHE_SHIFT
));
948 /* Only the directory inode sets new_i_size */
949 set_inode_flag(F2FS_I(inode
), FI_UPDATE_DIR
);
958 static int __allocate_data_block(struct dnode_of_data
*dn
)
960 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dn
->inode
);
961 struct f2fs_inode_info
*fi
= F2FS_I(dn
->inode
);
962 struct f2fs_summary sum
;
964 int seg
= CURSEG_WARM_DATA
;
967 if (unlikely(is_inode_flag_set(F2FS_I(dn
->inode
), FI_NO_ALLOC
)))
969 if (unlikely(!inc_valid_block_count(sbi
, dn
->inode
, 1)))
972 get_node_info(sbi
, dn
->nid
, &ni
);
973 set_summary(&sum
, dn
->nid
, dn
->ofs_in_node
, ni
.version
);
975 if (dn
->ofs_in_node
== 0 && dn
->inode_page
== dn
->node_page
)
976 seg
= CURSEG_DIRECT_IO
;
978 allocate_data_block(sbi
, NULL
, NULL_ADDR
, &dn
->data_blkaddr
, &sum
, seg
);
980 /* direct IO doesn't use extent cache to maximize the performance */
981 __set_data_blkaddr(dn
);
984 fofs
= start_bidx_of_node(ofs_of_node(dn
->node_page
), fi
) +
986 if (i_size_read(dn
->inode
) < ((fofs
+ 1) << PAGE_CACHE_SHIFT
))
987 i_size_write(dn
->inode
, ((fofs
+ 1) << PAGE_CACHE_SHIFT
));
992 static void __allocate_data_blocks(struct inode
*inode
, loff_t offset
,
995 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
996 struct dnode_of_data dn
;
997 u64 start
= F2FS_BYTES_TO_BLK(offset
);
998 u64 len
= F2FS_BYTES_TO_BLK(count
);
1003 f2fs_balance_fs(sbi
);
1006 /* When reading holes, we need its node page */
1007 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
1008 if (get_dnode_of_data(&dn
, start
, ALLOC_NODE
))
1012 end_offset
= ADDRS_PER_PAGE(dn
.node_page
, F2FS_I(inode
));
1014 while (dn
.ofs_in_node
< end_offset
&& len
) {
1015 if (dn
.data_blkaddr
== NULL_ADDR
) {
1016 if (__allocate_data_block(&dn
))
1026 sync_inode_page(&dn
);
1028 f2fs_put_dnode(&dn
);
1029 f2fs_unlock_op(sbi
);
1035 sync_inode_page(&dn
);
1036 f2fs_put_dnode(&dn
);
1038 f2fs_unlock_op(sbi
);
1043 * get_data_block() now supported readahead/bmap/rw direct_IO with mapped bh.
1044 * If original data blocks are allocated, then give them to blockdev.
1046 * a. preallocate requested block addresses
1047 * b. do not use extent cache for better performance
1048 * c. give the block addresses to blockdev
1050 static int __get_data_block(struct inode
*inode
, sector_t iblock
,
1051 struct buffer_head
*bh_result
, int create
, bool fiemap
)
1053 unsigned int blkbits
= inode
->i_sb
->s_blocksize_bits
;
1054 unsigned maxblocks
= bh_result
->b_size
>> blkbits
;
1055 struct dnode_of_data dn
;
1056 int mode
= create
? ALLOC_NODE
: LOOKUP_NODE_RA
;
1057 pgoff_t pgofs
, end_offset
;
1058 int err
= 0, ofs
= 1;
1059 struct extent_info ei
;
1060 bool allocated
= false;
1062 /* Get the page offset from the block offset(iblock) */
1063 pgofs
= (pgoff_t
)(iblock
>> (PAGE_CACHE_SHIFT
- blkbits
));
1065 if (f2fs_lookup_extent_cache(inode
, pgofs
, &ei
)) {
1066 f2fs_map_bh(inode
->i_sb
, pgofs
, &ei
, bh_result
);
1071 f2fs_lock_op(F2FS_I_SB(inode
));
1073 /* When reading holes, we need its node page */
1074 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
1075 err
= get_dnode_of_data(&dn
, pgofs
, mode
);
1081 if (dn
.data_blkaddr
== NEW_ADDR
&& !fiemap
)
1084 if (dn
.data_blkaddr
!= NULL_ADDR
) {
1085 set_buffer_new(bh_result
);
1086 map_bh(bh_result
, inode
->i_sb
, dn
.data_blkaddr
);
1087 } else if (create
) {
1088 err
= __allocate_data_block(&dn
);
1092 set_buffer_new(bh_result
);
1093 map_bh(bh_result
, inode
->i_sb
, dn
.data_blkaddr
);
1098 end_offset
= ADDRS_PER_PAGE(dn
.node_page
, F2FS_I(inode
));
1099 bh_result
->b_size
= (((size_t)1) << blkbits
);
1104 if (dn
.ofs_in_node
>= end_offset
) {
1106 sync_inode_page(&dn
);
1108 f2fs_put_dnode(&dn
);
1110 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
1111 err
= get_dnode_of_data(&dn
, pgofs
, mode
);
1117 if (dn
.data_blkaddr
== NEW_ADDR
&& !fiemap
)
1120 end_offset
= ADDRS_PER_PAGE(dn
.node_page
, F2FS_I(inode
));
1123 if (maxblocks
> (bh_result
->b_size
>> blkbits
)) {
1124 block_t blkaddr
= datablock_addr(dn
.node_page
, dn
.ofs_in_node
);
1125 if (blkaddr
== NULL_ADDR
&& create
) {
1126 err
= __allocate_data_block(&dn
);
1130 blkaddr
= dn
.data_blkaddr
;
1132 /* Give more consecutive addresses for the readahead */
1133 if (blkaddr
== (bh_result
->b_blocknr
+ ofs
)) {
1137 bh_result
->b_size
+= (((size_t)1) << blkbits
);
1143 sync_inode_page(&dn
);
1145 f2fs_put_dnode(&dn
);
1148 f2fs_unlock_op(F2FS_I_SB(inode
));
1150 trace_f2fs_get_data_block(inode
, iblock
, bh_result
, err
);
1154 static int get_data_block(struct inode
*inode
, sector_t iblock
,
1155 struct buffer_head
*bh_result
, int create
)
1157 return __get_data_block(inode
, iblock
, bh_result
, create
, false);
1160 static int get_data_block_fiemap(struct inode
*inode
, sector_t iblock
,
1161 struct buffer_head
*bh_result
, int create
)
1163 return __get_data_block(inode
, iblock
, bh_result
, create
, true);
1166 int f2fs_fiemap(struct inode
*inode
, struct fiemap_extent_info
*fieinfo
,
1169 return generic_block_fiemap(inode
, fieinfo
,
1170 start
, len
, get_data_block_fiemap
);
1173 static int f2fs_read_data_page(struct file
*file
, struct page
*page
)
1175 struct inode
*inode
= page
->mapping
->host
;
1178 trace_f2fs_readpage(page
, DATA
);
1180 /* If the file has inline data, try to read it directly */
1181 if (f2fs_has_inline_data(inode
))
1182 ret
= f2fs_read_inline_data(inode
, page
);
1184 ret
= mpage_readpage(page
, get_data_block
);
1189 static int f2fs_read_data_pages(struct file
*file
,
1190 struct address_space
*mapping
,
1191 struct list_head
*pages
, unsigned nr_pages
)
1193 struct inode
*inode
= file
->f_mapping
->host
;
1195 /* If the file has inline data, skip readpages */
1196 if (f2fs_has_inline_data(inode
))
1199 return mpage_readpages(mapping
, pages
, nr_pages
, get_data_block
);
1202 int do_write_data_page(struct page
*page
, struct f2fs_io_info
*fio
)
1204 struct inode
*inode
= page
->mapping
->host
;
1205 struct dnode_of_data dn
;
1208 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
1209 err
= get_dnode_of_data(&dn
, page
->index
, LOOKUP_NODE
);
1213 fio
->blk_addr
= dn
.data_blkaddr
;
1215 /* This page is already truncated */
1216 if (fio
->blk_addr
== NULL_ADDR
)
1219 set_page_writeback(page
);
1222 * If current allocation needs SSR,
1223 * it had better in-place writes for updated data.
1225 if (unlikely(fio
->blk_addr
!= NEW_ADDR
&&
1226 !is_cold_data(page
) &&
1227 need_inplace_update(inode
))) {
1228 rewrite_data_page(page
, fio
);
1229 set_inode_flag(F2FS_I(inode
), FI_UPDATE_WRITE
);
1231 write_data_page(page
, &dn
, fio
);
1232 f2fs_update_extent_cache(&dn
);
1233 set_inode_flag(F2FS_I(inode
), FI_APPEND_WRITE
);
1236 f2fs_put_dnode(&dn
);
1240 static int f2fs_write_data_page(struct page
*page
,
1241 struct writeback_control
*wbc
)
1243 struct inode
*inode
= page
->mapping
->host
;
1244 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1245 loff_t i_size
= i_size_read(inode
);
1246 const pgoff_t end_index
= ((unsigned long long) i_size
)
1247 >> PAGE_CACHE_SHIFT
;
1248 unsigned offset
= 0;
1249 bool need_balance_fs
= false;
1251 struct f2fs_io_info fio
= {
1253 .rw
= (wbc
->sync_mode
== WB_SYNC_ALL
) ? WRITE_SYNC
: WRITE
,
1256 trace_f2fs_writepage(page
, DATA
);
1258 if (page
->index
< end_index
)
1262 * If the offset is out-of-range of file size,
1263 * this page does not have to be written to disk.
1265 offset
= i_size
& (PAGE_CACHE_SIZE
- 1);
1266 if ((page
->index
>= end_index
+ 1) || !offset
)
1269 zero_user_segment(page
, offset
, PAGE_CACHE_SIZE
);
1271 if (unlikely(is_sbi_flag_set(sbi
, SBI_POR_DOING
)))
1273 if (f2fs_is_drop_cache(inode
))
1275 if (f2fs_is_volatile_file(inode
) && !wbc
->for_reclaim
&&
1276 available_free_memory(sbi
, BASE_CHECK
))
1279 /* Dentry blocks are controlled by checkpoint */
1280 if (S_ISDIR(inode
->i_mode
)) {
1281 if (unlikely(f2fs_cp_error(sbi
)))
1283 err
= do_write_data_page(page
, &fio
);
1287 /* we should bypass data pages to proceed the kworkder jobs */
1288 if (unlikely(f2fs_cp_error(sbi
))) {
1293 if (!wbc
->for_reclaim
)
1294 need_balance_fs
= true;
1295 else if (has_not_enough_free_secs(sbi
, 0))
1300 if (f2fs_has_inline_data(inode
))
1301 err
= f2fs_write_inline_data(inode
, page
);
1303 err
= do_write_data_page(page
, &fio
);
1304 f2fs_unlock_op(sbi
);
1306 if (err
&& err
!= -ENOENT
)
1309 clear_cold_data(page
);
1311 inode_dec_dirty_pages(inode
);
1313 if (need_balance_fs
)
1314 f2fs_balance_fs(sbi
);
1315 if (wbc
->for_reclaim
)
1316 f2fs_submit_merged_bio(sbi
, DATA
, WRITE
);
1320 redirty_page_for_writepage(wbc
, page
);
1321 return AOP_WRITEPAGE_ACTIVATE
;
1324 static int __f2fs_writepage(struct page
*page
, struct writeback_control
*wbc
,
1327 struct address_space
*mapping
= data
;
1328 int ret
= mapping
->a_ops
->writepage(page
, wbc
);
1329 mapping_set_error(mapping
, ret
);
1333 static int f2fs_write_data_pages(struct address_space
*mapping
,
1334 struct writeback_control
*wbc
)
1336 struct inode
*inode
= mapping
->host
;
1337 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1338 bool locked
= false;
1342 trace_f2fs_writepages(mapping
->host
, wbc
, DATA
);
1344 /* deal with chardevs and other special file */
1345 if (!mapping
->a_ops
->writepage
)
1348 if (S_ISDIR(inode
->i_mode
) && wbc
->sync_mode
== WB_SYNC_NONE
&&
1349 get_dirty_pages(inode
) < nr_pages_to_skip(sbi
, DATA
) &&
1350 available_free_memory(sbi
, DIRTY_DENTS
))
1353 diff
= nr_pages_to_write(sbi
, DATA
, wbc
);
1355 if (!S_ISDIR(inode
->i_mode
)) {
1356 mutex_lock(&sbi
->writepages
);
1359 ret
= write_cache_pages(mapping
, wbc
, __f2fs_writepage
, mapping
);
1361 mutex_unlock(&sbi
->writepages
);
1363 f2fs_submit_merged_bio(sbi
, DATA
, WRITE
);
1365 remove_dirty_dir_inode(inode
);
1367 wbc
->nr_to_write
= max((long)0, wbc
->nr_to_write
- diff
);
1371 wbc
->pages_skipped
+= get_dirty_pages(inode
);
1375 static void f2fs_write_failed(struct address_space
*mapping
, loff_t to
)
1377 struct inode
*inode
= mapping
->host
;
1379 if (to
> inode
->i_size
) {
1380 truncate_pagecache(inode
, inode
->i_size
);
1381 truncate_blocks(inode
, inode
->i_size
, true);
1385 static int f2fs_write_begin(struct file
*file
, struct address_space
*mapping
,
1386 loff_t pos
, unsigned len
, unsigned flags
,
1387 struct page
**pagep
, void **fsdata
)
1389 struct inode
*inode
= mapping
->host
;
1390 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1391 struct page
*page
, *ipage
;
1392 pgoff_t index
= ((unsigned long long) pos
) >> PAGE_CACHE_SHIFT
;
1393 struct dnode_of_data dn
;
1396 trace_f2fs_write_begin(inode
, pos
, len
, flags
);
1398 f2fs_balance_fs(sbi
);
1401 * We should check this at this moment to avoid deadlock on inode page
1402 * and #0 page. The locking rule for inline_data conversion should be:
1403 * lock_page(page #0) -> lock_page(inode_page)
1406 err
= f2fs_convert_inline_inode(inode
);
1411 page
= grab_cache_page_write_begin(mapping
, index
, flags
);
1421 /* check inline_data */
1422 ipage
= get_node_page(sbi
, inode
->i_ino
);
1423 if (IS_ERR(ipage
)) {
1424 err
= PTR_ERR(ipage
);
1428 set_new_dnode(&dn
, inode
, ipage
, ipage
, 0);
1430 if (f2fs_has_inline_data(inode
)) {
1431 if (pos
+ len
<= MAX_INLINE_DATA
) {
1432 read_inline_data(page
, ipage
);
1433 set_inode_flag(F2FS_I(inode
), FI_DATA_EXIST
);
1434 sync_inode_page(&dn
);
1437 err
= f2fs_convert_inline_page(&dn
, page
);
1441 err
= f2fs_reserve_block(&dn
, index
);
1445 f2fs_put_dnode(&dn
);
1446 f2fs_unlock_op(sbi
);
1448 if ((len
== PAGE_CACHE_SIZE
) || PageUptodate(page
))
1451 f2fs_wait_on_page_writeback(page
, DATA
);
1453 if ((pos
& PAGE_CACHE_MASK
) >= i_size_read(inode
)) {
1454 unsigned start
= pos
& (PAGE_CACHE_SIZE
- 1);
1455 unsigned end
= start
+ len
;
1457 /* Reading beyond i_size is simple: memset to zero */
1458 zero_user_segments(page
, 0, start
, end
, PAGE_CACHE_SIZE
);
1462 if (dn
.data_blkaddr
== NEW_ADDR
) {
1463 zero_user_segment(page
, 0, PAGE_CACHE_SIZE
);
1465 struct f2fs_io_info fio
= {
1468 .blk_addr
= dn
.data_blkaddr
,
1470 err
= f2fs_submit_page_bio(sbi
, page
, &fio
);
1475 if (unlikely(!PageUptodate(page
))) {
1476 f2fs_put_page(page
, 1);
1480 if (unlikely(page
->mapping
!= mapping
)) {
1481 f2fs_put_page(page
, 1);
1486 SetPageUptodate(page
);
1487 clear_cold_data(page
);
1491 f2fs_put_dnode(&dn
);
1493 f2fs_unlock_op(sbi
);
1494 f2fs_put_page(page
, 1);
1496 f2fs_write_failed(mapping
, pos
+ len
);
1500 static int f2fs_write_end(struct file
*file
,
1501 struct address_space
*mapping
,
1502 loff_t pos
, unsigned len
, unsigned copied
,
1503 struct page
*page
, void *fsdata
)
1505 struct inode
*inode
= page
->mapping
->host
;
1507 trace_f2fs_write_end(inode
, pos
, len
, copied
);
1509 set_page_dirty(page
);
1511 if (pos
+ copied
> i_size_read(inode
)) {
1512 i_size_write(inode
, pos
+ copied
);
1513 mark_inode_dirty(inode
);
1514 update_inode_page(inode
);
1517 f2fs_put_page(page
, 1);
1521 static int check_direct_IO(struct inode
*inode
, int rw
,
1522 struct iov_iter
*iter
, loff_t offset
)
1524 unsigned blocksize_mask
= inode
->i_sb
->s_blocksize
- 1;
1529 if (offset
& blocksize_mask
)
1532 if (iov_iter_alignment(iter
) & blocksize_mask
)
1538 static ssize_t
f2fs_direct_IO(int rw
, struct kiocb
*iocb
,
1539 struct iov_iter
*iter
, loff_t offset
)
1541 struct file
*file
= iocb
->ki_filp
;
1542 struct address_space
*mapping
= file
->f_mapping
;
1543 struct inode
*inode
= mapping
->host
;
1544 size_t count
= iov_iter_count(iter
);
1547 /* we don't need to use inline_data strictly */
1548 if (f2fs_has_inline_data(inode
)) {
1549 err
= f2fs_convert_inline_inode(inode
);
1554 if (check_direct_IO(inode
, rw
, iter
, offset
))
1557 trace_f2fs_direct_IO_enter(inode
, offset
, count
, rw
);
1560 __allocate_data_blocks(inode
, offset
, count
);
1562 err
= blockdev_direct_IO(rw
, iocb
, inode
, iter
, offset
, get_data_block
);
1563 if (err
< 0 && (rw
& WRITE
))
1564 f2fs_write_failed(mapping
, offset
+ count
);
1566 trace_f2fs_direct_IO_exit(inode
, offset
, count
, rw
, err
);
1571 void f2fs_invalidate_page(struct page
*page
, unsigned int offset
,
1572 unsigned int length
)
1574 struct inode
*inode
= page
->mapping
->host
;
1575 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1577 if (inode
->i_ino
>= F2FS_ROOT_INO(sbi
) &&
1578 (offset
% PAGE_CACHE_SIZE
|| length
!= PAGE_CACHE_SIZE
))
1581 if (PageDirty(page
)) {
1582 if (inode
->i_ino
== F2FS_META_INO(sbi
))
1583 dec_page_count(sbi
, F2FS_DIRTY_META
);
1584 else if (inode
->i_ino
== F2FS_NODE_INO(sbi
))
1585 dec_page_count(sbi
, F2FS_DIRTY_NODES
);
1587 inode_dec_dirty_pages(inode
);
1589 ClearPagePrivate(page
);
1592 int f2fs_release_page(struct page
*page
, gfp_t wait
)
1594 /* If this is dirty page, keep PagePrivate */
1595 if (PageDirty(page
))
1598 ClearPagePrivate(page
);
1602 static int f2fs_set_data_page_dirty(struct page
*page
)
1604 struct address_space
*mapping
= page
->mapping
;
1605 struct inode
*inode
= mapping
->host
;
1607 trace_f2fs_set_page_dirty(page
, DATA
);
1609 SetPageUptodate(page
);
1611 if (f2fs_is_atomic_file(inode
)) {
1612 register_inmem_page(inode
, page
);
1616 mark_inode_dirty(inode
);
1618 if (!PageDirty(page
)) {
1619 __set_page_dirty_nobuffers(page
);
1620 update_dirty_page(inode
, page
);
1626 static sector_t
f2fs_bmap(struct address_space
*mapping
, sector_t block
)
1628 struct inode
*inode
= mapping
->host
;
1630 /* we don't need to use inline_data strictly */
1631 if (f2fs_has_inline_data(inode
)) {
1632 int err
= f2fs_convert_inline_inode(inode
);
1636 return generic_block_bmap(mapping
, block
, get_data_block
);
1639 void init_extent_cache_info(struct f2fs_sb_info
*sbi
)
1641 INIT_RADIX_TREE(&sbi
->extent_tree_root
, GFP_NOIO
);
1642 init_rwsem(&sbi
->extent_tree_lock
);
1643 INIT_LIST_HEAD(&sbi
->extent_list
);
1644 spin_lock_init(&sbi
->extent_lock
);
1645 sbi
->total_ext_tree
= 0;
1646 atomic_set(&sbi
->total_ext_node
, 0);
1649 int __init
create_extent_cache(void)
1651 extent_tree_slab
= f2fs_kmem_cache_create("f2fs_extent_tree",
1652 sizeof(struct extent_tree
));
1653 if (!extent_tree_slab
)
1655 extent_node_slab
= f2fs_kmem_cache_create("f2fs_extent_node",
1656 sizeof(struct extent_node
));
1657 if (!extent_node_slab
) {
1658 kmem_cache_destroy(extent_tree_slab
);
1664 void destroy_extent_cache(void)
1666 kmem_cache_destroy(extent_node_slab
);
1667 kmem_cache_destroy(extent_tree_slab
);
1670 const struct address_space_operations f2fs_dblock_aops
= {
1671 .readpage
= f2fs_read_data_page
,
1672 .readpages
= f2fs_read_data_pages
,
1673 .writepage
= f2fs_write_data_page
,
1674 .writepages
= f2fs_write_data_pages
,
1675 .write_begin
= f2fs_write_begin
,
1676 .write_end
= f2fs_write_end
,
1677 .set_page_dirty
= f2fs_set_data_page_dirty
,
1678 .invalidatepage
= f2fs_invalidate_page
,
1679 .releasepage
= f2fs_release_page
,
1680 .direct_IO
= f2fs_direct_IO
,