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/bio.h>
14 #include <linux/blkdev.h>
15 #include <linux/prefetch.h>
16 #include <linux/kthread.h>
17 #include <linux/vmalloc.h>
18 #include <linux/swap.h>
23 #include <trace/events/f2fs.h>
25 #define __reverse_ffz(x) __reverse_ffs(~(x))
27 static struct kmem_cache *discard_entry_slab;
28 static struct kmem_cache *sit_entry_set_slab;
29 static struct kmem_cache *inmem_entry_slab;
32 * __reverse_ffs is copied from include/asm-generic/bitops/__ffs.h since
33 * MSB and LSB are reversed in a byte by f2fs_set_bit.
35 static inline unsigned long __reverse_ffs(unsigned long word)
39 #if BITS_PER_LONG == 64
40 if ((word & 0xffffffff) == 0) {
45 if ((word & 0xffff) == 0) {
49 if ((word & 0xff) == 0) {
53 if ((word & 0xf0) == 0)
57 if ((word & 0xc) == 0)
61 if ((word & 0x2) == 0)
67 * __find_rev_next(_zero)_bit is copied from lib/find_next_bit.c because
68 * f2fs_set_bit makes MSB and LSB reversed in a byte.
71 * f2fs_set_bit(0, bitmap) => 0000 0001
72 * f2fs_set_bit(7, bitmap) => 1000 0000
74 static unsigned long __find_rev_next_bit(const unsigned long *addr,
75 unsigned long size, unsigned long offset)
77 const unsigned long *p = addr + BIT_WORD(offset);
78 unsigned long result = offset & ~(BITS_PER_LONG - 1);
80 unsigned long mask, submask;
81 unsigned long quot, rest;
87 offset %= BITS_PER_LONG;
92 quot = (offset >> 3) << 3;
95 submask = (unsigned char)(0xff << rest) >> rest;
99 if (size < BITS_PER_LONG)
104 size -= BITS_PER_LONG;
105 result += BITS_PER_LONG;
107 while (size & ~(BITS_PER_LONG-1)) {
111 result += BITS_PER_LONG;
112 size -= BITS_PER_LONG;
118 tmp &= (~0UL >> (BITS_PER_LONG - size));
119 if (tmp == 0UL) /* Are any bits set? */
120 return result + size; /* Nope. */
122 return result + __reverse_ffs(tmp);
125 static unsigned long __find_rev_next_zero_bit(const unsigned long *addr,
126 unsigned long size, unsigned long offset)
128 const unsigned long *p = addr + BIT_WORD(offset);
129 unsigned long result = offset & ~(BITS_PER_LONG - 1);
131 unsigned long mask, submask;
132 unsigned long quot, rest;
138 offset %= BITS_PER_LONG;
143 quot = (offset >> 3) << 3;
145 mask = ~(~0UL << quot);
146 submask = (unsigned char)~((unsigned char)(0xff << rest) >> rest);
150 if (size < BITS_PER_LONG)
155 size -= BITS_PER_LONG;
156 result += BITS_PER_LONG;
158 while (size & ~(BITS_PER_LONG - 1)) {
162 result += BITS_PER_LONG;
163 size -= BITS_PER_LONG;
171 if (tmp == ~0UL) /* Are any bits zero? */
172 return result + size; /* Nope. */
174 return result + __reverse_ffz(tmp);
177 void register_inmem_page(struct inode *inode, struct page *page)
179 struct f2fs_inode_info *fi = F2FS_I(inode);
180 struct inmem_pages *new;
183 new = f2fs_kmem_cache_alloc(inmem_entry_slab, GFP_NOFS);
185 /* add atomic page indices to the list */
187 INIT_LIST_HEAD(&new->list);
189 /* increase reference count with clean state */
190 mutex_lock(&fi->inmem_lock);
191 err = radix_tree_insert(&fi->inmem_root, page->index, new);
192 if (err == -EEXIST) {
193 mutex_unlock(&fi->inmem_lock);
194 kmem_cache_free(inmem_entry_slab, new);
197 mutex_unlock(&fi->inmem_lock);
198 kmem_cache_free(inmem_entry_slab, new);
202 list_add_tail(&new->list, &fi->inmem_pages);
203 mutex_unlock(&fi->inmem_lock);
206 void invalidate_inmem_page(struct inode *inode, struct page *page)
208 struct f2fs_inode_info *fi = F2FS_I(inode);
209 struct inmem_pages *cur;
211 mutex_lock(&fi->inmem_lock);
212 cur = radix_tree_lookup(&fi->inmem_root, page->index);
214 radix_tree_delete(&fi->inmem_root, cur->page->index);
215 f2fs_put_page(cur->page, 0);
216 list_del(&cur->list);
217 kmem_cache_free(inmem_entry_slab, cur);
219 mutex_unlock(&fi->inmem_lock);
222 void commit_inmem_pages(struct inode *inode, bool abort)
224 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
225 struct f2fs_inode_info *fi = F2FS_I(inode);
226 struct inmem_pages *cur, *tmp;
227 bool submit_bio = false;
228 struct f2fs_io_info fio = {
233 f2fs_balance_fs(sbi);
236 mutex_lock(&fi->inmem_lock);
237 list_for_each_entry_safe(cur, tmp, &fi->inmem_pages, list) {
238 lock_page(cur->page);
239 if (!abort && cur->page->mapping == inode->i_mapping) {
240 f2fs_wait_on_page_writeback(cur->page, DATA);
241 if (clear_page_dirty_for_io(cur->page))
242 inode_dec_dirty_pages(inode);
243 do_write_data_page(cur->page, &fio);
246 radix_tree_delete(&fi->inmem_root, cur->page->index);
247 f2fs_put_page(cur->page, 1);
248 list_del(&cur->list);
249 kmem_cache_free(inmem_entry_slab, cur);
252 f2fs_submit_merged_bio(sbi, DATA, WRITE);
253 mutex_unlock(&fi->inmem_lock);
255 filemap_fdatawait_range(inode->i_mapping, 0, LLONG_MAX);
260 * This function balances dirty node and dentry pages.
261 * In addition, it controls garbage collection.
263 void f2fs_balance_fs(struct f2fs_sb_info *sbi)
266 * We should do GC or end up with checkpoint, if there are so many dirty
267 * dir/node pages without enough free segments.
269 if (has_not_enough_free_secs(sbi, 0)) {
270 mutex_lock(&sbi->gc_mutex);
275 void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi)
277 /* check the # of cached NAT entries and prefree segments */
278 if (try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK) ||
279 excess_prefree_segs(sbi))
280 f2fs_sync_fs(sbi->sb, true);
283 static int issue_flush_thread(void *data)
285 struct f2fs_sb_info *sbi = data;
286 struct flush_cmd_control *fcc = SM_I(sbi)->cmd_control_info;
287 wait_queue_head_t *q = &fcc->flush_wait_queue;
289 if (kthread_should_stop())
292 if (!llist_empty(&fcc->issue_list)) {
293 struct bio *bio = bio_alloc(GFP_NOIO, 0);
294 struct flush_cmd *cmd, *next;
297 fcc->dispatch_list = llist_del_all(&fcc->issue_list);
298 fcc->dispatch_list = llist_reverse_order(fcc->dispatch_list);
300 bio->bi_bdev = sbi->sb->s_bdev;
301 ret = submit_bio_wait(WRITE_FLUSH, bio);
303 llist_for_each_entry_safe(cmd, next,
304 fcc->dispatch_list, llnode) {
306 complete(&cmd->wait);
309 fcc->dispatch_list = NULL;
312 wait_event_interruptible(*q,
313 kthread_should_stop() || !llist_empty(&fcc->issue_list));
317 int f2fs_issue_flush(struct f2fs_sb_info *sbi)
319 struct flush_cmd_control *fcc = SM_I(sbi)->cmd_control_info;
320 struct flush_cmd cmd;
322 trace_f2fs_issue_flush(sbi->sb, test_opt(sbi, NOBARRIER),
323 test_opt(sbi, FLUSH_MERGE));
325 if (test_opt(sbi, NOBARRIER))
328 if (!test_opt(sbi, FLUSH_MERGE))
329 return blkdev_issue_flush(sbi->sb->s_bdev, GFP_KERNEL, NULL);
331 init_completion(&cmd.wait);
333 llist_add(&cmd.llnode, &fcc->issue_list);
335 if (!fcc->dispatch_list)
336 wake_up(&fcc->flush_wait_queue);
338 wait_for_completion(&cmd.wait);
343 int create_flush_cmd_control(struct f2fs_sb_info *sbi)
345 dev_t dev = sbi->sb->s_bdev->bd_dev;
346 struct flush_cmd_control *fcc;
349 fcc = kzalloc(sizeof(struct flush_cmd_control), GFP_KERNEL);
352 init_waitqueue_head(&fcc->flush_wait_queue);
353 init_llist_head(&fcc->issue_list);
354 SM_I(sbi)->cmd_control_info = fcc;
355 fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi,
356 "f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev));
357 if (IS_ERR(fcc->f2fs_issue_flush)) {
358 err = PTR_ERR(fcc->f2fs_issue_flush);
360 SM_I(sbi)->cmd_control_info = NULL;
367 void destroy_flush_cmd_control(struct f2fs_sb_info *sbi)
369 struct flush_cmd_control *fcc = SM_I(sbi)->cmd_control_info;
371 if (fcc && fcc->f2fs_issue_flush)
372 kthread_stop(fcc->f2fs_issue_flush);
374 SM_I(sbi)->cmd_control_info = NULL;
377 static void __locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,
378 enum dirty_type dirty_type)
380 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
382 /* need not be added */
383 if (IS_CURSEG(sbi, segno))
386 if (!test_and_set_bit(segno, dirty_i->dirty_segmap[dirty_type]))
387 dirty_i->nr_dirty[dirty_type]++;
389 if (dirty_type == DIRTY) {
390 struct seg_entry *sentry = get_seg_entry(sbi, segno);
391 enum dirty_type t = sentry->type;
393 if (unlikely(t >= DIRTY)) {
397 if (!test_and_set_bit(segno, dirty_i->dirty_segmap[t]))
398 dirty_i->nr_dirty[t]++;
402 static void __remove_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,
403 enum dirty_type dirty_type)
405 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
407 if (test_and_clear_bit(segno, dirty_i->dirty_segmap[dirty_type]))
408 dirty_i->nr_dirty[dirty_type]--;
410 if (dirty_type == DIRTY) {
411 struct seg_entry *sentry = get_seg_entry(sbi, segno);
412 enum dirty_type t = sentry->type;
414 if (test_and_clear_bit(segno, dirty_i->dirty_segmap[t]))
415 dirty_i->nr_dirty[t]--;
417 if (get_valid_blocks(sbi, segno, sbi->segs_per_sec) == 0)
418 clear_bit(GET_SECNO(sbi, segno),
419 dirty_i->victim_secmap);
424 * Should not occur error such as -ENOMEM.
425 * Adding dirty entry into seglist is not critical operation.
426 * If a given segment is one of current working segments, it won't be added.
428 static void locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno)
430 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
431 unsigned short valid_blocks;
433 if (segno == NULL_SEGNO || IS_CURSEG(sbi, segno))
436 mutex_lock(&dirty_i->seglist_lock);
438 valid_blocks = get_valid_blocks(sbi, segno, 0);
440 if (valid_blocks == 0) {
441 __locate_dirty_segment(sbi, segno, PRE);
442 __remove_dirty_segment(sbi, segno, DIRTY);
443 } else if (valid_blocks < sbi->blocks_per_seg) {
444 __locate_dirty_segment(sbi, segno, DIRTY);
446 /* Recovery routine with SSR needs this */
447 __remove_dirty_segment(sbi, segno, DIRTY);
450 mutex_unlock(&dirty_i->seglist_lock);
453 static int f2fs_issue_discard(struct f2fs_sb_info *sbi,
454 block_t blkstart, block_t blklen)
456 sector_t start = SECTOR_FROM_BLOCK(blkstart);
457 sector_t len = SECTOR_FROM_BLOCK(blklen);
458 trace_f2fs_issue_discard(sbi->sb, blkstart, blklen);
459 return blkdev_issue_discard(sbi->sb->s_bdev, start, len, GFP_NOFS, 0);
462 void discard_next_dnode(struct f2fs_sb_info *sbi, block_t blkaddr)
464 if (f2fs_issue_discard(sbi, blkaddr, 1)) {
465 struct page *page = grab_meta_page(sbi, blkaddr);
466 /* zero-filled page */
467 set_page_dirty(page);
468 f2fs_put_page(page, 1);
472 static void add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc)
474 struct list_head *head = &SM_I(sbi)->discard_list;
475 struct discard_entry *new;
476 int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
477 int max_blocks = sbi->blocks_per_seg;
478 struct seg_entry *se = get_seg_entry(sbi, cpc->trim_start);
479 unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
480 unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
481 unsigned long dmap[entries];
482 unsigned int start = 0, end = -1;
483 bool force = (cpc->reason == CP_DISCARD);
486 if (!force && !test_opt(sbi, DISCARD))
489 if (force && !se->valid_blocks) {
490 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
492 * if this segment is registered in the prefree list, then
493 * we should skip adding a discard candidate, and let the
494 * checkpoint do that later.
496 mutex_lock(&dirty_i->seglist_lock);
497 if (test_bit(cpc->trim_start, dirty_i->dirty_segmap[PRE])) {
498 mutex_unlock(&dirty_i->seglist_lock);
499 cpc->trimmed += sbi->blocks_per_seg;
502 mutex_unlock(&dirty_i->seglist_lock);
504 new = f2fs_kmem_cache_alloc(discard_entry_slab, GFP_NOFS);
505 INIT_LIST_HEAD(&new->list);
506 new->blkaddr = START_BLOCK(sbi, cpc->trim_start);
507 new->len = sbi->blocks_per_seg;
508 list_add_tail(&new->list, head);
509 SM_I(sbi)->nr_discards += sbi->blocks_per_seg;
510 cpc->trimmed += sbi->blocks_per_seg;
514 /* zero block will be discarded through the prefree list */
515 if (!se->valid_blocks || se->valid_blocks == max_blocks)
518 /* SIT_VBLOCK_MAP_SIZE should be multiple of sizeof(unsigned long) */
519 for (i = 0; i < entries; i++)
520 dmap[i] = ~(cur_map[i] | ckpt_map[i]);
522 while (force || SM_I(sbi)->nr_discards <= SM_I(sbi)->max_discards) {
523 start = __find_rev_next_bit(dmap, max_blocks, end + 1);
524 if (start >= max_blocks)
527 end = __find_rev_next_zero_bit(dmap, max_blocks, start + 1);
529 if (end - start < cpc->trim_minlen)
532 new = f2fs_kmem_cache_alloc(discard_entry_slab, GFP_NOFS);
533 INIT_LIST_HEAD(&new->list);
534 new->blkaddr = START_BLOCK(sbi, cpc->trim_start) + start;
535 new->len = end - start;
536 cpc->trimmed += end - start;
538 list_add_tail(&new->list, head);
539 SM_I(sbi)->nr_discards += end - start;
543 void release_discard_addrs(struct f2fs_sb_info *sbi)
545 struct list_head *head = &(SM_I(sbi)->discard_list);
546 struct discard_entry *entry, *this;
549 list_for_each_entry_safe(entry, this, head, list) {
550 list_del(&entry->list);
551 kmem_cache_free(discard_entry_slab, entry);
556 * Should call clear_prefree_segments after checkpoint is done.
558 static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)
560 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
563 mutex_lock(&dirty_i->seglist_lock);
564 for_each_set_bit(segno, dirty_i->dirty_segmap[PRE], MAIN_SEGS(sbi))
565 __set_test_and_free(sbi, segno);
566 mutex_unlock(&dirty_i->seglist_lock);
569 void clear_prefree_segments(struct f2fs_sb_info *sbi)
571 struct list_head *head = &(SM_I(sbi)->discard_list);
572 struct discard_entry *entry, *this;
573 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
574 unsigned long *prefree_map = dirty_i->dirty_segmap[PRE];
575 unsigned int start = 0, end = -1;
577 mutex_lock(&dirty_i->seglist_lock);
581 start = find_next_bit(prefree_map, MAIN_SEGS(sbi), end + 1);
582 if (start >= MAIN_SEGS(sbi))
584 end = find_next_zero_bit(prefree_map, MAIN_SEGS(sbi),
587 for (i = start; i < end; i++)
588 clear_bit(i, prefree_map);
590 dirty_i->nr_dirty[PRE] -= end - start;
592 if (!test_opt(sbi, DISCARD))
595 f2fs_issue_discard(sbi, START_BLOCK(sbi, start),
596 (end - start) << sbi->log_blocks_per_seg);
598 mutex_unlock(&dirty_i->seglist_lock);
600 /* send small discards */
601 list_for_each_entry_safe(entry, this, head, list) {
602 f2fs_issue_discard(sbi, entry->blkaddr, entry->len);
603 list_del(&entry->list);
604 SM_I(sbi)->nr_discards -= entry->len;
605 kmem_cache_free(discard_entry_slab, entry);
609 static bool __mark_sit_entry_dirty(struct f2fs_sb_info *sbi, unsigned int segno)
611 struct sit_info *sit_i = SIT_I(sbi);
613 if (!__test_and_set_bit(segno, sit_i->dirty_sentries_bitmap)) {
614 sit_i->dirty_sentries++;
621 static void __set_sit_entry_type(struct f2fs_sb_info *sbi, int type,
622 unsigned int segno, int modified)
624 struct seg_entry *se = get_seg_entry(sbi, segno);
627 __mark_sit_entry_dirty(sbi, segno);
630 static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
632 struct seg_entry *se;
633 unsigned int segno, offset;
634 long int new_vblocks;
636 segno = GET_SEGNO(sbi, blkaddr);
638 se = get_seg_entry(sbi, segno);
639 new_vblocks = se->valid_blocks + del;
640 offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr);
642 f2fs_bug_on(sbi, (new_vblocks >> (sizeof(unsigned short) << 3) ||
643 (new_vblocks > sbi->blocks_per_seg)));
645 se->valid_blocks = new_vblocks;
646 se->mtime = get_mtime(sbi);
647 SIT_I(sbi)->max_mtime = se->mtime;
649 /* Update valid block bitmap */
651 if (f2fs_test_and_set_bit(offset, se->cur_valid_map))
654 if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map))
657 if (!f2fs_test_bit(offset, se->ckpt_valid_map))
658 se->ckpt_valid_blocks += del;
660 __mark_sit_entry_dirty(sbi, segno);
662 /* update total number of valid blocks to be written in ckpt area */
663 SIT_I(sbi)->written_valid_blocks += del;
665 if (sbi->segs_per_sec > 1)
666 get_sec_entry(sbi, segno)->valid_blocks += del;
669 void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new)
671 update_sit_entry(sbi, new, 1);
672 if (GET_SEGNO(sbi, old) != NULL_SEGNO)
673 update_sit_entry(sbi, old, -1);
675 locate_dirty_segment(sbi, GET_SEGNO(sbi, old));
676 locate_dirty_segment(sbi, GET_SEGNO(sbi, new));
679 void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr)
681 unsigned int segno = GET_SEGNO(sbi, addr);
682 struct sit_info *sit_i = SIT_I(sbi);
684 f2fs_bug_on(sbi, addr == NULL_ADDR);
685 if (addr == NEW_ADDR)
688 /* add it into sit main buffer */
689 mutex_lock(&sit_i->sentry_lock);
691 update_sit_entry(sbi, addr, -1);
693 /* add it into dirty seglist */
694 locate_dirty_segment(sbi, segno);
696 mutex_unlock(&sit_i->sentry_lock);
700 * This function should be resided under the curseg_mutex lock
702 static void __add_sum_entry(struct f2fs_sb_info *sbi, int type,
703 struct f2fs_summary *sum)
705 struct curseg_info *curseg = CURSEG_I(sbi, type);
706 void *addr = curseg->sum_blk;
707 addr += curseg->next_blkoff * sizeof(struct f2fs_summary);
708 memcpy(addr, sum, sizeof(struct f2fs_summary));
712 * Calculate the number of current summary pages for writing
714 int npages_for_summary_flush(struct f2fs_sb_info *sbi)
716 int valid_sum_count = 0;
719 for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) {
720 if (sbi->ckpt->alloc_type[i] == SSR)
721 valid_sum_count += sbi->blocks_per_seg;
723 valid_sum_count += curseg_blkoff(sbi, i);
726 sum_in_page = (PAGE_CACHE_SIZE - 2 * SUM_JOURNAL_SIZE -
727 SUM_FOOTER_SIZE) / SUMMARY_SIZE;
728 if (valid_sum_count <= sum_in_page)
730 else if ((valid_sum_count - sum_in_page) <=
731 (PAGE_CACHE_SIZE - SUM_FOOTER_SIZE) / SUMMARY_SIZE)
737 * Caller should put this summary page
739 struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno)
741 return get_meta_page(sbi, GET_SUM_BLOCK(sbi, segno));
744 static void write_sum_page(struct f2fs_sb_info *sbi,
745 struct f2fs_summary_block *sum_blk, block_t blk_addr)
747 struct page *page = grab_meta_page(sbi, blk_addr);
748 void *kaddr = page_address(page);
749 memcpy(kaddr, sum_blk, PAGE_CACHE_SIZE);
750 set_page_dirty(page);
751 f2fs_put_page(page, 1);
754 static int is_next_segment_free(struct f2fs_sb_info *sbi, int type)
756 struct curseg_info *curseg = CURSEG_I(sbi, type);
757 unsigned int segno = curseg->segno + 1;
758 struct free_segmap_info *free_i = FREE_I(sbi);
760 if (segno < MAIN_SEGS(sbi) && segno % sbi->segs_per_sec)
761 return !test_bit(segno, free_i->free_segmap);
766 * Find a new segment from the free segments bitmap to right order
767 * This function should be returned with success, otherwise BUG
769 static void get_new_segment(struct f2fs_sb_info *sbi,
770 unsigned int *newseg, bool new_sec, int dir)
772 struct free_segmap_info *free_i = FREE_I(sbi);
773 unsigned int segno, secno, zoneno;
774 unsigned int total_zones = MAIN_SECS(sbi) / sbi->secs_per_zone;
775 unsigned int hint = *newseg / sbi->segs_per_sec;
776 unsigned int old_zoneno = GET_ZONENO_FROM_SEGNO(sbi, *newseg);
777 unsigned int left_start = hint;
782 write_lock(&free_i->segmap_lock);
784 if (!new_sec && ((*newseg + 1) % sbi->segs_per_sec)) {
785 segno = find_next_zero_bit(free_i->free_segmap,
786 MAIN_SEGS(sbi), *newseg + 1);
787 if (segno - *newseg < sbi->segs_per_sec -
788 (*newseg % sbi->segs_per_sec))
792 secno = find_next_zero_bit(free_i->free_secmap, MAIN_SECS(sbi), hint);
793 if (secno >= MAIN_SECS(sbi)) {
794 if (dir == ALLOC_RIGHT) {
795 secno = find_next_zero_bit(free_i->free_secmap,
797 f2fs_bug_on(sbi, secno >= MAIN_SECS(sbi));
800 left_start = hint - 1;
806 while (test_bit(left_start, free_i->free_secmap)) {
807 if (left_start > 0) {
811 left_start = find_next_zero_bit(free_i->free_secmap,
813 f2fs_bug_on(sbi, left_start >= MAIN_SECS(sbi));
819 segno = secno * sbi->segs_per_sec;
820 zoneno = secno / sbi->secs_per_zone;
822 /* give up on finding another zone */
825 if (sbi->secs_per_zone == 1)
827 if (zoneno == old_zoneno)
829 if (dir == ALLOC_LEFT) {
830 if (!go_left && zoneno + 1 >= total_zones)
832 if (go_left && zoneno == 0)
835 for (i = 0; i < NR_CURSEG_TYPE; i++)
836 if (CURSEG_I(sbi, i)->zone == zoneno)
839 if (i < NR_CURSEG_TYPE) {
840 /* zone is in user, try another */
842 hint = zoneno * sbi->secs_per_zone - 1;
843 else if (zoneno + 1 >= total_zones)
846 hint = (zoneno + 1) * sbi->secs_per_zone;
848 goto find_other_zone;
851 /* set it as dirty segment in free segmap */
852 f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap));
853 __set_inuse(sbi, segno);
855 write_unlock(&free_i->segmap_lock);
858 static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified)
860 struct curseg_info *curseg = CURSEG_I(sbi, type);
861 struct summary_footer *sum_footer;
863 curseg->segno = curseg->next_segno;
864 curseg->zone = GET_ZONENO_FROM_SEGNO(sbi, curseg->segno);
865 curseg->next_blkoff = 0;
866 curseg->next_segno = NULL_SEGNO;
868 sum_footer = &(curseg->sum_blk->footer);
869 memset(sum_footer, 0, sizeof(struct summary_footer));
870 if (IS_DATASEG(type))
871 SET_SUM_TYPE(sum_footer, SUM_TYPE_DATA);
872 if (IS_NODESEG(type))
873 SET_SUM_TYPE(sum_footer, SUM_TYPE_NODE);
874 __set_sit_entry_type(sbi, type, curseg->segno, modified);
878 * Allocate a current working segment.
879 * This function always allocates a free segment in LFS manner.
881 static void new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
883 struct curseg_info *curseg = CURSEG_I(sbi, type);
884 unsigned int segno = curseg->segno;
885 int dir = ALLOC_LEFT;
887 write_sum_page(sbi, curseg->sum_blk,
888 GET_SUM_BLOCK(sbi, segno));
889 if (type == CURSEG_WARM_DATA || type == CURSEG_COLD_DATA)
892 if (test_opt(sbi, NOHEAP))
895 get_new_segment(sbi, &segno, new_sec, dir);
896 curseg->next_segno = segno;
897 reset_curseg(sbi, type, 1);
898 curseg->alloc_type = LFS;
901 static void __next_free_blkoff(struct f2fs_sb_info *sbi,
902 struct curseg_info *seg, block_t start)
904 struct seg_entry *se = get_seg_entry(sbi, seg->segno);
905 int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
906 unsigned long target_map[entries];
907 unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
908 unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
911 for (i = 0; i < entries; i++)
912 target_map[i] = ckpt_map[i] | cur_map[i];
914 pos = __find_rev_next_zero_bit(target_map, sbi->blocks_per_seg, start);
916 seg->next_blkoff = pos;
920 * If a segment is written by LFS manner, next block offset is just obtained
921 * by increasing the current block offset. However, if a segment is written by
922 * SSR manner, next block offset obtained by calling __next_free_blkoff
924 static void __refresh_next_blkoff(struct f2fs_sb_info *sbi,
925 struct curseg_info *seg)
927 if (seg->alloc_type == SSR)
928 __next_free_blkoff(sbi, seg, seg->next_blkoff + 1);
934 * This function always allocates a used segment(from dirty seglist) by SSR
935 * manner, so it should recover the existing segment information of valid blocks
937 static void change_curseg(struct f2fs_sb_info *sbi, int type, bool reuse)
939 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
940 struct curseg_info *curseg = CURSEG_I(sbi, type);
941 unsigned int new_segno = curseg->next_segno;
942 struct f2fs_summary_block *sum_node;
943 struct page *sum_page;
945 write_sum_page(sbi, curseg->sum_blk,
946 GET_SUM_BLOCK(sbi, curseg->segno));
947 __set_test_and_inuse(sbi, new_segno);
949 mutex_lock(&dirty_i->seglist_lock);
950 __remove_dirty_segment(sbi, new_segno, PRE);
951 __remove_dirty_segment(sbi, new_segno, DIRTY);
952 mutex_unlock(&dirty_i->seglist_lock);
954 reset_curseg(sbi, type, 1);
955 curseg->alloc_type = SSR;
956 __next_free_blkoff(sbi, curseg, 0);
959 sum_page = get_sum_page(sbi, new_segno);
960 sum_node = (struct f2fs_summary_block *)page_address(sum_page);
961 memcpy(curseg->sum_blk, sum_node, SUM_ENTRY_SIZE);
962 f2fs_put_page(sum_page, 1);
966 static int get_ssr_segment(struct f2fs_sb_info *sbi, int type)
968 struct curseg_info *curseg = CURSEG_I(sbi, type);
969 const struct victim_selection *v_ops = DIRTY_I(sbi)->v_ops;
971 if (IS_NODESEG(type) || !has_not_enough_free_secs(sbi, 0))
972 return v_ops->get_victim(sbi,
973 &(curseg)->next_segno, BG_GC, type, SSR);
975 /* For data segments, let's do SSR more intensively */
976 for (; type >= CURSEG_HOT_DATA; type--)
977 if (v_ops->get_victim(sbi, &(curseg)->next_segno,
984 * flush out current segment and replace it with new segment
985 * This function should be returned with success, otherwise BUG
987 static void allocate_segment_by_default(struct f2fs_sb_info *sbi,
988 int type, bool force)
990 struct curseg_info *curseg = CURSEG_I(sbi, type);
993 new_curseg(sbi, type, true);
994 else if (type == CURSEG_WARM_NODE)
995 new_curseg(sbi, type, false);
996 else if (curseg->alloc_type == LFS && is_next_segment_free(sbi, type))
997 new_curseg(sbi, type, false);
998 else if (need_SSR(sbi) && get_ssr_segment(sbi, type))
999 change_curseg(sbi, type, true);
1001 new_curseg(sbi, type, false);
1003 stat_inc_seg_type(sbi, curseg);
1006 void allocate_new_segments(struct f2fs_sb_info *sbi)
1008 struct curseg_info *curseg;
1009 unsigned int old_curseg;
1012 for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) {
1013 curseg = CURSEG_I(sbi, i);
1014 old_curseg = curseg->segno;
1015 SIT_I(sbi)->s_ops->allocate_segment(sbi, i, true);
1016 locate_dirty_segment(sbi, old_curseg);
1020 static const struct segment_allocation default_salloc_ops = {
1021 .allocate_segment = allocate_segment_by_default,
1024 int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
1026 __u64 start = range->start >> sbi->log_blocksize;
1027 __u64 end = start + (range->len >> sbi->log_blocksize) - 1;
1028 unsigned int start_segno, end_segno;
1029 struct cp_control cpc;
1031 if (range->minlen > SEGMENT_SIZE(sbi) || start >= MAX_BLKADDR(sbi) ||
1032 range->len < sbi->blocksize)
1036 if (end <= MAIN_BLKADDR(sbi))
1039 /* start/end segment number in main_area */
1040 start_segno = (start <= MAIN_BLKADDR(sbi)) ? 0 : GET_SEGNO(sbi, start);
1041 end_segno = (end >= MAX_BLKADDR(sbi)) ? MAIN_SEGS(sbi) - 1 :
1042 GET_SEGNO(sbi, end);
1043 cpc.reason = CP_DISCARD;
1044 cpc.trim_start = start_segno;
1045 cpc.trim_end = end_segno;
1046 cpc.trim_minlen = range->minlen >> sbi->log_blocksize;
1048 /* do checkpoint to issue discard commands safely */
1049 mutex_lock(&sbi->gc_mutex);
1050 write_checkpoint(sbi, &cpc);
1051 mutex_unlock(&sbi->gc_mutex);
1053 range->len = cpc.trimmed << sbi->log_blocksize;
1057 static bool __has_curseg_space(struct f2fs_sb_info *sbi, int type)
1059 struct curseg_info *curseg = CURSEG_I(sbi, type);
1060 if (curseg->next_blkoff < sbi->blocks_per_seg)
1065 static int __get_segment_type_2(struct page *page, enum page_type p_type)
1068 return CURSEG_HOT_DATA;
1070 return CURSEG_HOT_NODE;
1073 static int __get_segment_type_4(struct page *page, enum page_type p_type)
1075 if (p_type == DATA) {
1076 struct inode *inode = page->mapping->host;
1078 if (S_ISDIR(inode->i_mode))
1079 return CURSEG_HOT_DATA;
1081 return CURSEG_COLD_DATA;
1083 if (IS_DNODE(page) && !is_cold_node(page))
1084 return CURSEG_HOT_NODE;
1086 return CURSEG_COLD_NODE;
1090 static int __get_segment_type_6(struct page *page, enum page_type p_type)
1092 if (p_type == DATA) {
1093 struct inode *inode = page->mapping->host;
1095 if (S_ISDIR(inode->i_mode))
1096 return CURSEG_HOT_DATA;
1097 else if (is_cold_data(page) || file_is_cold(inode))
1098 return CURSEG_COLD_DATA;
1100 return CURSEG_WARM_DATA;
1103 return is_cold_node(page) ? CURSEG_WARM_NODE :
1106 return CURSEG_COLD_NODE;
1110 static int __get_segment_type(struct page *page, enum page_type p_type)
1112 switch (F2FS_P_SB(page)->active_logs) {
1114 return __get_segment_type_2(page, p_type);
1116 return __get_segment_type_4(page, p_type);
1118 /* NR_CURSEG_TYPE(6) logs by default */
1119 f2fs_bug_on(F2FS_P_SB(page),
1120 F2FS_P_SB(page)->active_logs != NR_CURSEG_TYPE);
1121 return __get_segment_type_6(page, p_type);
1124 void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
1125 block_t old_blkaddr, block_t *new_blkaddr,
1126 struct f2fs_summary *sum, int type)
1128 struct sit_info *sit_i = SIT_I(sbi);
1129 struct curseg_info *curseg;
1131 curseg = CURSEG_I(sbi, type);
1133 mutex_lock(&curseg->curseg_mutex);
1135 *new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
1138 * __add_sum_entry should be resided under the curseg_mutex
1139 * because, this function updates a summary entry in the
1140 * current summary block.
1142 __add_sum_entry(sbi, type, sum);
1144 mutex_lock(&sit_i->sentry_lock);
1145 __refresh_next_blkoff(sbi, curseg);
1147 stat_inc_block_count(sbi, curseg);
1149 if (!__has_curseg_space(sbi, type))
1150 sit_i->s_ops->allocate_segment(sbi, type, false);
1152 * SIT information should be updated before segment allocation,
1153 * since SSR needs latest valid block information.
1155 refresh_sit_entry(sbi, old_blkaddr, *new_blkaddr);
1157 mutex_unlock(&sit_i->sentry_lock);
1159 if (page && IS_NODESEG(type))
1160 fill_node_footer_blkaddr(page, NEXT_FREE_BLKADDR(sbi, curseg));
1162 mutex_unlock(&curseg->curseg_mutex);
1165 static void do_write_page(struct f2fs_sb_info *sbi, struct page *page,
1166 block_t old_blkaddr, block_t *new_blkaddr,
1167 struct f2fs_summary *sum, struct f2fs_io_info *fio)
1169 int type = __get_segment_type(page, fio->type);
1171 allocate_data_block(sbi, page, old_blkaddr, new_blkaddr, sum, type);
1173 /* writeout dirty page into bdev */
1174 f2fs_submit_page_mbio(sbi, page, *new_blkaddr, fio);
1177 void write_meta_page(struct f2fs_sb_info *sbi, struct page *page)
1179 struct f2fs_io_info fio = {
1181 .rw = WRITE_SYNC | REQ_META | REQ_PRIO
1184 set_page_writeback(page);
1185 f2fs_submit_page_mbio(sbi, page, page->index, &fio);
1188 void write_node_page(struct f2fs_sb_info *sbi, struct page *page,
1189 struct f2fs_io_info *fio,
1190 unsigned int nid, block_t old_blkaddr, block_t *new_blkaddr)
1192 struct f2fs_summary sum;
1193 set_summary(&sum, nid, 0, 0);
1194 do_write_page(sbi, page, old_blkaddr, new_blkaddr, &sum, fio);
1197 void write_data_page(struct page *page, struct dnode_of_data *dn,
1198 block_t *new_blkaddr, struct f2fs_io_info *fio)
1200 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
1201 struct f2fs_summary sum;
1202 struct node_info ni;
1204 f2fs_bug_on(sbi, dn->data_blkaddr == NULL_ADDR);
1205 get_node_info(sbi, dn->nid, &ni);
1206 set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
1208 do_write_page(sbi, page, dn->data_blkaddr, new_blkaddr, &sum, fio);
1211 void rewrite_data_page(struct page *page, block_t old_blkaddr,
1212 struct f2fs_io_info *fio)
1214 f2fs_submit_page_mbio(F2FS_P_SB(page), page, old_blkaddr, fio);
1217 void recover_data_page(struct f2fs_sb_info *sbi,
1218 struct page *page, struct f2fs_summary *sum,
1219 block_t old_blkaddr, block_t new_blkaddr)
1221 struct sit_info *sit_i = SIT_I(sbi);
1222 struct curseg_info *curseg;
1223 unsigned int segno, old_cursegno;
1224 struct seg_entry *se;
1227 segno = GET_SEGNO(sbi, new_blkaddr);
1228 se = get_seg_entry(sbi, segno);
1231 if (se->valid_blocks == 0 && !IS_CURSEG(sbi, segno)) {
1232 if (old_blkaddr == NULL_ADDR)
1233 type = CURSEG_COLD_DATA;
1235 type = CURSEG_WARM_DATA;
1237 curseg = CURSEG_I(sbi, type);
1239 mutex_lock(&curseg->curseg_mutex);
1240 mutex_lock(&sit_i->sentry_lock);
1242 old_cursegno = curseg->segno;
1244 /* change the current segment */
1245 if (segno != curseg->segno) {
1246 curseg->next_segno = segno;
1247 change_curseg(sbi, type, true);
1250 curseg->next_blkoff = GET_BLKOFF_FROM_SEG0(sbi, new_blkaddr);
1251 __add_sum_entry(sbi, type, sum);
1253 refresh_sit_entry(sbi, old_blkaddr, new_blkaddr);
1254 locate_dirty_segment(sbi, old_cursegno);
1256 mutex_unlock(&sit_i->sentry_lock);
1257 mutex_unlock(&curseg->curseg_mutex);
1260 static inline bool is_merged_page(struct f2fs_sb_info *sbi,
1261 struct page *page, enum page_type type)
1263 enum page_type btype = PAGE_TYPE_OF_BIO(type);
1264 struct f2fs_bio_info *io = &sbi->write_io[btype];
1265 struct bio_vec *bvec;
1268 down_read(&io->io_rwsem);
1272 bio_for_each_segment_all(bvec, io->bio, i) {
1273 if (page == bvec->bv_page) {
1274 up_read(&io->io_rwsem);
1280 up_read(&io->io_rwsem);
1284 void f2fs_wait_on_page_writeback(struct page *page,
1285 enum page_type type)
1287 if (PageWriteback(page)) {
1288 struct f2fs_sb_info *sbi = F2FS_P_SB(page);
1290 if (is_merged_page(sbi, page, type))
1291 f2fs_submit_merged_bio(sbi, type, WRITE);
1292 wait_on_page_writeback(page);
1296 static int read_compacted_summaries(struct f2fs_sb_info *sbi)
1298 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1299 struct curseg_info *seg_i;
1300 unsigned char *kaddr;
1305 start = start_sum_block(sbi);
1307 page = get_meta_page(sbi, start++);
1308 kaddr = (unsigned char *)page_address(page);
1310 /* Step 1: restore nat cache */
1311 seg_i = CURSEG_I(sbi, CURSEG_HOT_DATA);
1312 memcpy(&seg_i->sum_blk->n_nats, kaddr, SUM_JOURNAL_SIZE);
1314 /* Step 2: restore sit cache */
1315 seg_i = CURSEG_I(sbi, CURSEG_COLD_DATA);
1316 memcpy(&seg_i->sum_blk->n_sits, kaddr + SUM_JOURNAL_SIZE,
1318 offset = 2 * SUM_JOURNAL_SIZE;
1320 /* Step 3: restore summary entries */
1321 for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) {
1322 unsigned short blk_off;
1325 seg_i = CURSEG_I(sbi, i);
1326 segno = le32_to_cpu(ckpt->cur_data_segno[i]);
1327 blk_off = le16_to_cpu(ckpt->cur_data_blkoff[i]);
1328 seg_i->next_segno = segno;
1329 reset_curseg(sbi, i, 0);
1330 seg_i->alloc_type = ckpt->alloc_type[i];
1331 seg_i->next_blkoff = blk_off;
1333 if (seg_i->alloc_type == SSR)
1334 blk_off = sbi->blocks_per_seg;
1336 for (j = 0; j < blk_off; j++) {
1337 struct f2fs_summary *s;
1338 s = (struct f2fs_summary *)(kaddr + offset);
1339 seg_i->sum_blk->entries[j] = *s;
1340 offset += SUMMARY_SIZE;
1341 if (offset + SUMMARY_SIZE <= PAGE_CACHE_SIZE -
1345 f2fs_put_page(page, 1);
1348 page = get_meta_page(sbi, start++);
1349 kaddr = (unsigned char *)page_address(page);
1353 f2fs_put_page(page, 1);
1357 static int read_normal_summaries(struct f2fs_sb_info *sbi, int type)
1359 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1360 struct f2fs_summary_block *sum;
1361 struct curseg_info *curseg;
1363 unsigned short blk_off;
1364 unsigned int segno = 0;
1365 block_t blk_addr = 0;
1367 /* get segment number and block addr */
1368 if (IS_DATASEG(type)) {
1369 segno = le32_to_cpu(ckpt->cur_data_segno[type]);
1370 blk_off = le16_to_cpu(ckpt->cur_data_blkoff[type -
1372 if (is_set_ckpt_flags(ckpt, CP_UMOUNT_FLAG))
1373 blk_addr = sum_blk_addr(sbi, NR_CURSEG_TYPE, type);
1375 blk_addr = sum_blk_addr(sbi, NR_CURSEG_DATA_TYPE, type);
1377 segno = le32_to_cpu(ckpt->cur_node_segno[type -
1379 blk_off = le16_to_cpu(ckpt->cur_node_blkoff[type -
1381 if (is_set_ckpt_flags(ckpt, CP_UMOUNT_FLAG))
1382 blk_addr = sum_blk_addr(sbi, NR_CURSEG_NODE_TYPE,
1383 type - CURSEG_HOT_NODE);
1385 blk_addr = GET_SUM_BLOCK(sbi, segno);
1388 new = get_meta_page(sbi, blk_addr);
1389 sum = (struct f2fs_summary_block *)page_address(new);
1391 if (IS_NODESEG(type)) {
1392 if (is_set_ckpt_flags(ckpt, CP_UMOUNT_FLAG)) {
1393 struct f2fs_summary *ns = &sum->entries[0];
1395 for (i = 0; i < sbi->blocks_per_seg; i++, ns++) {
1397 ns->ofs_in_node = 0;
1402 err = restore_node_summary(sbi, segno, sum);
1404 f2fs_put_page(new, 1);
1410 /* set uncompleted segment to curseg */
1411 curseg = CURSEG_I(sbi, type);
1412 mutex_lock(&curseg->curseg_mutex);
1413 memcpy(curseg->sum_blk, sum, PAGE_CACHE_SIZE);
1414 curseg->next_segno = segno;
1415 reset_curseg(sbi, type, 0);
1416 curseg->alloc_type = ckpt->alloc_type[type];
1417 curseg->next_blkoff = blk_off;
1418 mutex_unlock(&curseg->curseg_mutex);
1419 f2fs_put_page(new, 1);
1423 static int restore_curseg_summaries(struct f2fs_sb_info *sbi)
1425 int type = CURSEG_HOT_DATA;
1428 if (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_COMPACT_SUM_FLAG)) {
1429 /* restore for compacted data summary */
1430 if (read_compacted_summaries(sbi))
1432 type = CURSEG_HOT_NODE;
1435 for (; type <= CURSEG_COLD_NODE; type++) {
1436 err = read_normal_summaries(sbi, type);
1444 static void write_compacted_summaries(struct f2fs_sb_info *sbi, block_t blkaddr)
1447 unsigned char *kaddr;
1448 struct f2fs_summary *summary;
1449 struct curseg_info *seg_i;
1450 int written_size = 0;
1453 page = grab_meta_page(sbi, blkaddr++);
1454 kaddr = (unsigned char *)page_address(page);
1456 /* Step 1: write nat cache */
1457 seg_i = CURSEG_I(sbi, CURSEG_HOT_DATA);
1458 memcpy(kaddr, &seg_i->sum_blk->n_nats, SUM_JOURNAL_SIZE);
1459 written_size += SUM_JOURNAL_SIZE;
1461 /* Step 2: write sit cache */
1462 seg_i = CURSEG_I(sbi, CURSEG_COLD_DATA);
1463 memcpy(kaddr + written_size, &seg_i->sum_blk->n_sits,
1465 written_size += SUM_JOURNAL_SIZE;
1467 /* Step 3: write summary entries */
1468 for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) {
1469 unsigned short blkoff;
1470 seg_i = CURSEG_I(sbi, i);
1471 if (sbi->ckpt->alloc_type[i] == SSR)
1472 blkoff = sbi->blocks_per_seg;
1474 blkoff = curseg_blkoff(sbi, i);
1476 for (j = 0; j < blkoff; j++) {
1478 page = grab_meta_page(sbi, blkaddr++);
1479 kaddr = (unsigned char *)page_address(page);
1482 summary = (struct f2fs_summary *)(kaddr + written_size);
1483 *summary = seg_i->sum_blk->entries[j];
1484 written_size += SUMMARY_SIZE;
1486 if (written_size + SUMMARY_SIZE <= PAGE_CACHE_SIZE -
1490 set_page_dirty(page);
1491 f2fs_put_page(page, 1);
1496 set_page_dirty(page);
1497 f2fs_put_page(page, 1);
1501 static void write_normal_summaries(struct f2fs_sb_info *sbi,
1502 block_t blkaddr, int type)
1505 if (IS_DATASEG(type))
1506 end = type + NR_CURSEG_DATA_TYPE;
1508 end = type + NR_CURSEG_NODE_TYPE;
1510 for (i = type; i < end; i++) {
1511 struct curseg_info *sum = CURSEG_I(sbi, i);
1512 mutex_lock(&sum->curseg_mutex);
1513 write_sum_page(sbi, sum->sum_blk, blkaddr + (i - type));
1514 mutex_unlock(&sum->curseg_mutex);
1518 void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk)
1520 if (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_COMPACT_SUM_FLAG))
1521 write_compacted_summaries(sbi, start_blk);
1523 write_normal_summaries(sbi, start_blk, CURSEG_HOT_DATA);
1526 void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk)
1528 if (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG))
1529 write_normal_summaries(sbi, start_blk, CURSEG_HOT_NODE);
1532 int lookup_journal_in_cursum(struct f2fs_summary_block *sum, int type,
1533 unsigned int val, int alloc)
1537 if (type == NAT_JOURNAL) {
1538 for (i = 0; i < nats_in_cursum(sum); i++) {
1539 if (le32_to_cpu(nid_in_journal(sum, i)) == val)
1542 if (alloc && nats_in_cursum(sum) < NAT_JOURNAL_ENTRIES)
1543 return update_nats_in_cursum(sum, 1);
1544 } else if (type == SIT_JOURNAL) {
1545 for (i = 0; i < sits_in_cursum(sum); i++)
1546 if (le32_to_cpu(segno_in_journal(sum, i)) == val)
1548 if (alloc && sits_in_cursum(sum) < SIT_JOURNAL_ENTRIES)
1549 return update_sits_in_cursum(sum, 1);
1554 static struct page *get_current_sit_page(struct f2fs_sb_info *sbi,
1557 return get_meta_page(sbi, current_sit_addr(sbi, segno));
1560 static struct page *get_next_sit_page(struct f2fs_sb_info *sbi,
1563 struct sit_info *sit_i = SIT_I(sbi);
1564 struct page *src_page, *dst_page;
1565 pgoff_t src_off, dst_off;
1566 void *src_addr, *dst_addr;
1568 src_off = current_sit_addr(sbi, start);
1569 dst_off = next_sit_addr(sbi, src_off);
1571 /* get current sit block page without lock */
1572 src_page = get_meta_page(sbi, src_off);
1573 dst_page = grab_meta_page(sbi, dst_off);
1574 f2fs_bug_on(sbi, PageDirty(src_page));
1576 src_addr = page_address(src_page);
1577 dst_addr = page_address(dst_page);
1578 memcpy(dst_addr, src_addr, PAGE_CACHE_SIZE);
1580 set_page_dirty(dst_page);
1581 f2fs_put_page(src_page, 1);
1583 set_to_next_sit(sit_i, start);
1588 static struct sit_entry_set *grab_sit_entry_set(void)
1590 struct sit_entry_set *ses =
1591 f2fs_kmem_cache_alloc(sit_entry_set_slab, GFP_ATOMIC);
1594 INIT_LIST_HEAD(&ses->set_list);
1598 static void release_sit_entry_set(struct sit_entry_set *ses)
1600 list_del(&ses->set_list);
1601 kmem_cache_free(sit_entry_set_slab, ses);
1604 static void adjust_sit_entry_set(struct sit_entry_set *ses,
1605 struct list_head *head)
1607 struct sit_entry_set *next = ses;
1609 if (list_is_last(&ses->set_list, head))
1612 list_for_each_entry_continue(next, head, set_list)
1613 if (ses->entry_cnt <= next->entry_cnt)
1616 list_move_tail(&ses->set_list, &next->set_list);
1619 static void add_sit_entry(unsigned int segno, struct list_head *head)
1621 struct sit_entry_set *ses;
1622 unsigned int start_segno = START_SEGNO(segno);
1624 list_for_each_entry(ses, head, set_list) {
1625 if (ses->start_segno == start_segno) {
1627 adjust_sit_entry_set(ses, head);
1632 ses = grab_sit_entry_set();
1634 ses->start_segno = start_segno;
1636 list_add(&ses->set_list, head);
1639 static void add_sits_in_set(struct f2fs_sb_info *sbi)
1641 struct f2fs_sm_info *sm_info = SM_I(sbi);
1642 struct list_head *set_list = &sm_info->sit_entry_set;
1643 unsigned long *bitmap = SIT_I(sbi)->dirty_sentries_bitmap;
1646 for_each_set_bit(segno, bitmap, MAIN_SEGS(sbi))
1647 add_sit_entry(segno, set_list);
1650 static void remove_sits_in_journal(struct f2fs_sb_info *sbi)
1652 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
1653 struct f2fs_summary_block *sum = curseg->sum_blk;
1656 for (i = sits_in_cursum(sum) - 1; i >= 0; i--) {
1660 segno = le32_to_cpu(segno_in_journal(sum, i));
1661 dirtied = __mark_sit_entry_dirty(sbi, segno);
1664 add_sit_entry(segno, &SM_I(sbi)->sit_entry_set);
1666 update_sits_in_cursum(sum, -sits_in_cursum(sum));
1670 * CP calls this function, which flushes SIT entries including sit_journal,
1671 * and moves prefree segs to free segs.
1673 void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1675 struct sit_info *sit_i = SIT_I(sbi);
1676 unsigned long *bitmap = sit_i->dirty_sentries_bitmap;
1677 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
1678 struct f2fs_summary_block *sum = curseg->sum_blk;
1679 struct sit_entry_set *ses, *tmp;
1680 struct list_head *head = &SM_I(sbi)->sit_entry_set;
1681 bool to_journal = true;
1682 struct seg_entry *se;
1684 mutex_lock(&curseg->curseg_mutex);
1685 mutex_lock(&sit_i->sentry_lock);
1688 * add and account sit entries of dirty bitmap in sit entry
1691 add_sits_in_set(sbi);
1694 * if there are no enough space in journal to store dirty sit
1695 * entries, remove all entries from journal and add and account
1696 * them in sit entry set.
1698 if (!__has_cursum_space(sum, sit_i->dirty_sentries, SIT_JOURNAL))
1699 remove_sits_in_journal(sbi);
1701 if (!sit_i->dirty_sentries)
1705 * there are two steps to flush sit entries:
1706 * #1, flush sit entries to journal in current cold data summary block.
1707 * #2, flush sit entries to sit page.
1709 list_for_each_entry_safe(ses, tmp, head, set_list) {
1710 struct page *page = NULL;
1711 struct f2fs_sit_block *raw_sit = NULL;
1712 unsigned int start_segno = ses->start_segno;
1713 unsigned int end = min(start_segno + SIT_ENTRY_PER_BLOCK,
1714 (unsigned long)MAIN_SEGS(sbi));
1715 unsigned int segno = start_segno;
1718 !__has_cursum_space(sum, ses->entry_cnt, SIT_JOURNAL))
1722 page = get_next_sit_page(sbi, start_segno);
1723 raw_sit = page_address(page);
1726 /* flush dirty sit entries in region of current sit set */
1727 for_each_set_bit_from(segno, bitmap, end) {
1728 int offset, sit_offset;
1730 se = get_seg_entry(sbi, segno);
1732 /* add discard candidates */
1733 if (SM_I(sbi)->nr_discards < SM_I(sbi)->max_discards) {
1734 cpc->trim_start = segno;
1735 add_discard_addrs(sbi, cpc);
1739 offset = lookup_journal_in_cursum(sum,
1740 SIT_JOURNAL, segno, 1);
1741 f2fs_bug_on(sbi, offset < 0);
1742 segno_in_journal(sum, offset) =
1744 seg_info_to_raw_sit(se,
1745 &sit_in_journal(sum, offset));
1747 sit_offset = SIT_ENTRY_OFFSET(sit_i, segno);
1748 seg_info_to_raw_sit(se,
1749 &raw_sit->entries[sit_offset]);
1752 __clear_bit(segno, bitmap);
1753 sit_i->dirty_sentries--;
1758 f2fs_put_page(page, 1);
1760 f2fs_bug_on(sbi, ses->entry_cnt);
1761 release_sit_entry_set(ses);
1764 f2fs_bug_on(sbi, !list_empty(head));
1765 f2fs_bug_on(sbi, sit_i->dirty_sentries);
1767 if (cpc->reason == CP_DISCARD) {
1768 for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++)
1769 add_discard_addrs(sbi, cpc);
1771 mutex_unlock(&sit_i->sentry_lock);
1772 mutex_unlock(&curseg->curseg_mutex);
1774 set_prefree_as_free_segments(sbi);
1777 static int build_sit_info(struct f2fs_sb_info *sbi)
1779 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
1780 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1781 struct sit_info *sit_i;
1782 unsigned int sit_segs, start;
1783 char *src_bitmap, *dst_bitmap;
1784 unsigned int bitmap_size;
1786 /* allocate memory for SIT information */
1787 sit_i = kzalloc(sizeof(struct sit_info), GFP_KERNEL);
1791 SM_I(sbi)->sit_info = sit_i;
1793 sit_i->sentries = vzalloc(MAIN_SEGS(sbi) * sizeof(struct seg_entry));
1794 if (!sit_i->sentries)
1797 bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi));
1798 sit_i->dirty_sentries_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
1799 if (!sit_i->dirty_sentries_bitmap)
1802 for (start = 0; start < MAIN_SEGS(sbi); start++) {
1803 sit_i->sentries[start].cur_valid_map
1804 = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
1805 sit_i->sentries[start].ckpt_valid_map
1806 = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
1807 if (!sit_i->sentries[start].cur_valid_map
1808 || !sit_i->sentries[start].ckpt_valid_map)
1812 if (sbi->segs_per_sec > 1) {
1813 sit_i->sec_entries = vzalloc(MAIN_SECS(sbi) *
1814 sizeof(struct sec_entry));
1815 if (!sit_i->sec_entries)
1819 /* get information related with SIT */
1820 sit_segs = le32_to_cpu(raw_super->segment_count_sit) >> 1;
1822 /* setup SIT bitmap from ckeckpoint pack */
1823 bitmap_size = __bitmap_size(sbi, SIT_BITMAP);
1824 src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP);
1826 dst_bitmap = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL);
1830 /* init SIT information */
1831 sit_i->s_ops = &default_salloc_ops;
1833 sit_i->sit_base_addr = le32_to_cpu(raw_super->sit_blkaddr);
1834 sit_i->sit_blocks = sit_segs << sbi->log_blocks_per_seg;
1835 sit_i->written_valid_blocks = le64_to_cpu(ckpt->valid_block_count);
1836 sit_i->sit_bitmap = dst_bitmap;
1837 sit_i->bitmap_size = bitmap_size;
1838 sit_i->dirty_sentries = 0;
1839 sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK;
1840 sit_i->elapsed_time = le64_to_cpu(sbi->ckpt->elapsed_time);
1841 sit_i->mounted_time = CURRENT_TIME_SEC.tv_sec;
1842 mutex_init(&sit_i->sentry_lock);
1846 static int build_free_segmap(struct f2fs_sb_info *sbi)
1848 struct free_segmap_info *free_i;
1849 unsigned int bitmap_size, sec_bitmap_size;
1851 /* allocate memory for free segmap information */
1852 free_i = kzalloc(sizeof(struct free_segmap_info), GFP_KERNEL);
1856 SM_I(sbi)->free_info = free_i;
1858 bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi));
1859 free_i->free_segmap = kmalloc(bitmap_size, GFP_KERNEL);
1860 if (!free_i->free_segmap)
1863 sec_bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi));
1864 free_i->free_secmap = kmalloc(sec_bitmap_size, GFP_KERNEL);
1865 if (!free_i->free_secmap)
1868 /* set all segments as dirty temporarily */
1869 memset(free_i->free_segmap, 0xff, bitmap_size);
1870 memset(free_i->free_secmap, 0xff, sec_bitmap_size);
1872 /* init free segmap information */
1873 free_i->start_segno = GET_SEGNO_FROM_SEG0(sbi, MAIN_BLKADDR(sbi));
1874 free_i->free_segments = 0;
1875 free_i->free_sections = 0;
1876 rwlock_init(&free_i->segmap_lock);
1880 static int build_curseg(struct f2fs_sb_info *sbi)
1882 struct curseg_info *array;
1885 array = kcalloc(NR_CURSEG_TYPE, sizeof(*array), GFP_KERNEL);
1889 SM_I(sbi)->curseg_array = array;
1891 for (i = 0; i < NR_CURSEG_TYPE; i++) {
1892 mutex_init(&array[i].curseg_mutex);
1893 array[i].sum_blk = kzalloc(PAGE_CACHE_SIZE, GFP_KERNEL);
1894 if (!array[i].sum_blk)
1896 array[i].segno = NULL_SEGNO;
1897 array[i].next_blkoff = 0;
1899 return restore_curseg_summaries(sbi);
1902 static void build_sit_entries(struct f2fs_sb_info *sbi)
1904 struct sit_info *sit_i = SIT_I(sbi);
1905 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
1906 struct f2fs_summary_block *sum = curseg->sum_blk;
1907 int sit_blk_cnt = SIT_BLK_CNT(sbi);
1908 unsigned int i, start, end;
1909 unsigned int readed, start_blk = 0;
1910 int nrpages = MAX_BIO_BLOCKS(sbi);
1913 readed = ra_meta_pages(sbi, start_blk, nrpages, META_SIT);
1915 start = start_blk * sit_i->sents_per_block;
1916 end = (start_blk + readed) * sit_i->sents_per_block;
1918 for (; start < end && start < MAIN_SEGS(sbi); start++) {
1919 struct seg_entry *se = &sit_i->sentries[start];
1920 struct f2fs_sit_block *sit_blk;
1921 struct f2fs_sit_entry sit;
1924 mutex_lock(&curseg->curseg_mutex);
1925 for (i = 0; i < sits_in_cursum(sum); i++) {
1926 if (le32_to_cpu(segno_in_journal(sum, i))
1928 sit = sit_in_journal(sum, i);
1929 mutex_unlock(&curseg->curseg_mutex);
1933 mutex_unlock(&curseg->curseg_mutex);
1935 page = get_current_sit_page(sbi, start);
1936 sit_blk = (struct f2fs_sit_block *)page_address(page);
1937 sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, start)];
1938 f2fs_put_page(page, 1);
1940 check_block_count(sbi, start, &sit);
1941 seg_info_from_raw_sit(se, &sit);
1942 if (sbi->segs_per_sec > 1) {
1943 struct sec_entry *e = get_sec_entry(sbi, start);
1944 e->valid_blocks += se->valid_blocks;
1947 start_blk += readed;
1948 } while (start_blk < sit_blk_cnt);
1951 static void init_free_segmap(struct f2fs_sb_info *sbi)
1956 for (start = 0; start < MAIN_SEGS(sbi); start++) {
1957 struct seg_entry *sentry = get_seg_entry(sbi, start);
1958 if (!sentry->valid_blocks)
1959 __set_free(sbi, start);
1962 /* set use the current segments */
1963 for (type = CURSEG_HOT_DATA; type <= CURSEG_COLD_NODE; type++) {
1964 struct curseg_info *curseg_t = CURSEG_I(sbi, type);
1965 __set_test_and_inuse(sbi, curseg_t->segno);
1969 static void init_dirty_segmap(struct f2fs_sb_info *sbi)
1971 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
1972 struct free_segmap_info *free_i = FREE_I(sbi);
1973 unsigned int segno = 0, offset = 0;
1974 unsigned short valid_blocks;
1977 /* find dirty segment based on free segmap */
1978 segno = find_next_inuse(free_i, MAIN_SEGS(sbi), offset);
1979 if (segno >= MAIN_SEGS(sbi))
1982 valid_blocks = get_valid_blocks(sbi, segno, 0);
1983 if (valid_blocks == sbi->blocks_per_seg || !valid_blocks)
1985 if (valid_blocks > sbi->blocks_per_seg) {
1986 f2fs_bug_on(sbi, 1);
1989 mutex_lock(&dirty_i->seglist_lock);
1990 __locate_dirty_segment(sbi, segno, DIRTY);
1991 mutex_unlock(&dirty_i->seglist_lock);
1995 static int init_victim_secmap(struct f2fs_sb_info *sbi)
1997 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
1998 unsigned int bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi));
2000 dirty_i->victim_secmap = kzalloc(bitmap_size, GFP_KERNEL);
2001 if (!dirty_i->victim_secmap)
2006 static int build_dirty_segmap(struct f2fs_sb_info *sbi)
2008 struct dirty_seglist_info *dirty_i;
2009 unsigned int bitmap_size, i;
2011 /* allocate memory for dirty segments list information */
2012 dirty_i = kzalloc(sizeof(struct dirty_seglist_info), GFP_KERNEL);
2016 SM_I(sbi)->dirty_info = dirty_i;
2017 mutex_init(&dirty_i->seglist_lock);
2019 bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi));
2021 for (i = 0; i < NR_DIRTY_TYPE; i++) {
2022 dirty_i->dirty_segmap[i] = kzalloc(bitmap_size, GFP_KERNEL);
2023 if (!dirty_i->dirty_segmap[i])
2027 init_dirty_segmap(sbi);
2028 return init_victim_secmap(sbi);
2032 * Update min, max modified time for cost-benefit GC algorithm
2034 static void init_min_max_mtime(struct f2fs_sb_info *sbi)
2036 struct sit_info *sit_i = SIT_I(sbi);
2039 mutex_lock(&sit_i->sentry_lock);
2041 sit_i->min_mtime = LLONG_MAX;
2043 for (segno = 0; segno < MAIN_SEGS(sbi); segno += sbi->segs_per_sec) {
2045 unsigned long long mtime = 0;
2047 for (i = 0; i < sbi->segs_per_sec; i++)
2048 mtime += get_seg_entry(sbi, segno + i)->mtime;
2050 mtime = div_u64(mtime, sbi->segs_per_sec);
2052 if (sit_i->min_mtime > mtime)
2053 sit_i->min_mtime = mtime;
2055 sit_i->max_mtime = get_mtime(sbi);
2056 mutex_unlock(&sit_i->sentry_lock);
2059 int build_segment_manager(struct f2fs_sb_info *sbi)
2061 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
2062 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
2063 struct f2fs_sm_info *sm_info;
2066 sm_info = kzalloc(sizeof(struct f2fs_sm_info), GFP_KERNEL);
2071 sbi->sm_info = sm_info;
2072 sm_info->seg0_blkaddr = le32_to_cpu(raw_super->segment0_blkaddr);
2073 sm_info->main_blkaddr = le32_to_cpu(raw_super->main_blkaddr);
2074 sm_info->segment_count = le32_to_cpu(raw_super->segment_count);
2075 sm_info->reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
2076 sm_info->ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
2077 sm_info->main_segments = le32_to_cpu(raw_super->segment_count_main);
2078 sm_info->ssa_blkaddr = le32_to_cpu(raw_super->ssa_blkaddr);
2079 sm_info->rec_prefree_segments = sm_info->main_segments *
2080 DEF_RECLAIM_PREFREE_SEGMENTS / 100;
2081 sm_info->ipu_policy = 1 << F2FS_IPU_FSYNC;
2082 sm_info->min_ipu_util = DEF_MIN_IPU_UTIL;
2083 sm_info->min_fsync_blocks = DEF_MIN_FSYNC_BLOCKS;
2085 INIT_LIST_HEAD(&sm_info->discard_list);
2086 sm_info->nr_discards = 0;
2087 sm_info->max_discards = 0;
2089 INIT_LIST_HEAD(&sm_info->sit_entry_set);
2091 if (test_opt(sbi, FLUSH_MERGE) && !f2fs_readonly(sbi->sb)) {
2092 err = create_flush_cmd_control(sbi);
2097 err = build_sit_info(sbi);
2100 err = build_free_segmap(sbi);
2103 err = build_curseg(sbi);
2107 /* reinit free segmap based on SIT */
2108 build_sit_entries(sbi);
2110 init_free_segmap(sbi);
2111 err = build_dirty_segmap(sbi);
2115 init_min_max_mtime(sbi);
2119 static void discard_dirty_segmap(struct f2fs_sb_info *sbi,
2120 enum dirty_type dirty_type)
2122 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
2124 mutex_lock(&dirty_i->seglist_lock);
2125 kfree(dirty_i->dirty_segmap[dirty_type]);
2126 dirty_i->nr_dirty[dirty_type] = 0;
2127 mutex_unlock(&dirty_i->seglist_lock);
2130 static void destroy_victim_secmap(struct f2fs_sb_info *sbi)
2132 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
2133 kfree(dirty_i->victim_secmap);
2136 static void destroy_dirty_segmap(struct f2fs_sb_info *sbi)
2138 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
2144 /* discard pre-free/dirty segments list */
2145 for (i = 0; i < NR_DIRTY_TYPE; i++)
2146 discard_dirty_segmap(sbi, i);
2148 destroy_victim_secmap(sbi);
2149 SM_I(sbi)->dirty_info = NULL;
2153 static void destroy_curseg(struct f2fs_sb_info *sbi)
2155 struct curseg_info *array = SM_I(sbi)->curseg_array;
2160 SM_I(sbi)->curseg_array = NULL;
2161 for (i = 0; i < NR_CURSEG_TYPE; i++)
2162 kfree(array[i].sum_blk);
2166 static void destroy_free_segmap(struct f2fs_sb_info *sbi)
2168 struct free_segmap_info *free_i = SM_I(sbi)->free_info;
2171 SM_I(sbi)->free_info = NULL;
2172 kfree(free_i->free_segmap);
2173 kfree(free_i->free_secmap);
2177 static void destroy_sit_info(struct f2fs_sb_info *sbi)
2179 struct sit_info *sit_i = SIT_I(sbi);
2185 if (sit_i->sentries) {
2186 for (start = 0; start < MAIN_SEGS(sbi); start++) {
2187 kfree(sit_i->sentries[start].cur_valid_map);
2188 kfree(sit_i->sentries[start].ckpt_valid_map);
2191 vfree(sit_i->sentries);
2192 vfree(sit_i->sec_entries);
2193 kfree(sit_i->dirty_sentries_bitmap);
2195 SM_I(sbi)->sit_info = NULL;
2196 kfree(sit_i->sit_bitmap);
2200 void destroy_segment_manager(struct f2fs_sb_info *sbi)
2202 struct f2fs_sm_info *sm_info = SM_I(sbi);
2206 destroy_flush_cmd_control(sbi);
2207 destroy_dirty_segmap(sbi);
2208 destroy_curseg(sbi);
2209 destroy_free_segmap(sbi);
2210 destroy_sit_info(sbi);
2211 sbi->sm_info = NULL;
2215 int __init create_segment_manager_caches(void)
2217 discard_entry_slab = f2fs_kmem_cache_create("discard_entry",
2218 sizeof(struct discard_entry));
2219 if (!discard_entry_slab)
2222 sit_entry_set_slab = f2fs_kmem_cache_create("sit_entry_set",
2223 sizeof(struct nat_entry_set));
2224 if (!sit_entry_set_slab)
2225 goto destory_discard_entry;
2227 inmem_entry_slab = f2fs_kmem_cache_create("inmem_page_entry",
2228 sizeof(struct inmem_pages));
2229 if (!inmem_entry_slab)
2230 goto destroy_sit_entry_set;
2233 destroy_sit_entry_set:
2234 kmem_cache_destroy(sit_entry_set_slab);
2235 destory_discard_entry:
2236 kmem_cache_destroy(discard_entry_slab);
2241 void destroy_segment_manager_caches(void)
2243 kmem_cache_destroy(sit_entry_set_slab);
2244 kmem_cache_destroy(discard_entry_slab);
2245 kmem_cache_destroy(inmem_entry_slab);