gc.c (8c57a5e7b2820f349c95b8c8393fec1e0f4070d2) gc.c (70246286e94c335b5bea0cbc68a17a96dd620281)
1/*
2 * fs/f2fs/gc.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
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

--- 82 unchanged lines hidden (view full) ---

91}
92
93int start_gc_thread(struct f2fs_sb_info *sbi)
94{
95 struct f2fs_gc_kthread *gc_th;
96 dev_t dev = sbi->sb->s_bdev->bd_dev;
97 int err = 0;
98
1/*
2 * fs/f2fs/gc.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
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

--- 82 unchanged lines hidden (view full) ---

91}
92
93int start_gc_thread(struct f2fs_sb_info *sbi)
94{
95 struct f2fs_gc_kthread *gc_th;
96 dev_t dev = sbi->sb->s_bdev->bd_dev;
97 int err = 0;
98
99 gc_th = kmalloc(sizeof(struct f2fs_gc_kthread), GFP_KERNEL);
99 gc_th = f2fs_kmalloc(sizeof(struct f2fs_gc_kthread), GFP_KERNEL);
100 if (!gc_th) {
101 err = -ENOMEM;
102 goto out;
103 }
104
105 gc_th->min_sleep_time = DEF_GC_THREAD_MIN_SLEEP_TIME;
106 gc_th->max_sleep_time = DEF_GC_THREAD_MAX_SLEEP_TIME;
107 gc_th->no_gc_sleep_time = DEF_GC_THREAD_NOGC_SLEEP_TIME;

--- 352 unchanged lines hidden (view full) ---

460 }
461
462 get_node_info(sbi, nid, &ni);
463 if (ni.blk_addr != start_addr + off) {
464 f2fs_put_page(node_page, 1);
465 continue;
466 }
467
100 if (!gc_th) {
101 err = -ENOMEM;
102 goto out;
103 }
104
105 gc_th->min_sleep_time = DEF_GC_THREAD_MIN_SLEEP_TIME;
106 gc_th->max_sleep_time = DEF_GC_THREAD_MAX_SLEEP_TIME;
107 gc_th->no_gc_sleep_time = DEF_GC_THREAD_NOGC_SLEEP_TIME;

--- 352 unchanged lines hidden (view full) ---

460 }
461
462 get_node_info(sbi, nid, &ni);
463 if (ni.blk_addr != start_addr + off) {
464 f2fs_put_page(node_page, 1);
465 continue;
466 }
467
468 /* set page dirty and write it */
469 if (gc_type == FG_GC) {
470 f2fs_wait_on_page_writeback(node_page, NODE, true);
471 set_page_dirty(node_page);
472 } else {
473 if (!PageWriteback(node_page))
474 set_page_dirty(node_page);
475 }
476 f2fs_put_page(node_page, 1);
468 move_node_page(node_page, gc_type);
477 stat_inc_node_blk_count(sbi, 1, gc_type);
478 }
479
480 if (initial) {
481 initial = false;
482 goto next_step;
483 }
484}

--- 56 unchanged lines hidden (view full) ---

541 return true;
542}
543
544static void move_encrypted_block(struct inode *inode, block_t bidx)
545{
546 struct f2fs_io_info fio = {
547 .sbi = F2FS_I_SB(inode),
548 .type = DATA,
469 stat_inc_node_blk_count(sbi, 1, gc_type);
470 }
471
472 if (initial) {
473 initial = false;
474 goto next_step;
475 }
476}

--- 56 unchanged lines hidden (view full) ---

533 return true;
534}
535
536static void move_encrypted_block(struct inode *inode, block_t bidx)
537{
538 struct f2fs_io_info fio = {
539 .sbi = F2FS_I_SB(inode),
540 .type = DATA,
549 .rw = READ_SYNC,
541 .op = REQ_OP_READ,
542 .op_flags = READ_SYNC,
550 .encrypted_page = NULL,
551 };
552 struct dnode_of_data dn;
553 struct f2fs_summary sum;
554 struct node_info ni;
555 struct page *page;
556 block_t newaddr;
557 int err;

--- 57 unchanged lines hidden (view full) ---

615 if (clear_page_dirty_for_io(fio.encrypted_page))
616 dec_page_count(fio.sbi, F2FS_DIRTY_META);
617
618 set_page_writeback(fio.encrypted_page);
619
620 /* allocate block address */
621 f2fs_wait_on_page_writeback(dn.node_page, NODE, true);
622
543 .encrypted_page = NULL,
544 };
545 struct dnode_of_data dn;
546 struct f2fs_summary sum;
547 struct node_info ni;
548 struct page *page;
549 block_t newaddr;
550 int err;

--- 57 unchanged lines hidden (view full) ---

608 if (clear_page_dirty_for_io(fio.encrypted_page))
609 dec_page_count(fio.sbi, F2FS_DIRTY_META);
610
611 set_page_writeback(fio.encrypted_page);
612
613 /* allocate block address */
614 f2fs_wait_on_page_writeback(dn.node_page, NODE, true);
615
623 fio.rw = WRITE_SYNC;
616 fio.op = REQ_OP_WRITE;
617 fio.op_flags = WRITE_SYNC;
624 fio.new_blkaddr = newaddr;
625 f2fs_submit_page_mbio(&fio);
626
627 f2fs_update_data_blkaddr(&dn, newaddr);
628 set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE);
629 if (page->index == 0)
630 set_inode_flag(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN);
631put_page_out:

--- 20 unchanged lines hidden (view full) ---

652 if (PageWriteback(page))
653 goto out;
654 set_page_dirty(page);
655 set_cold_data(page);
656 } else {
657 struct f2fs_io_info fio = {
658 .sbi = F2FS_I_SB(inode),
659 .type = DATA,
618 fio.new_blkaddr = newaddr;
619 f2fs_submit_page_mbio(&fio);
620
621 f2fs_update_data_blkaddr(&dn, newaddr);
622 set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE);
623 if (page->index == 0)
624 set_inode_flag(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN);
625put_page_out:

--- 20 unchanged lines hidden (view full) ---

646 if (PageWriteback(page))
647 goto out;
648 set_page_dirty(page);
649 set_cold_data(page);
650 } else {
651 struct f2fs_io_info fio = {
652 .sbi = F2FS_I_SB(inode),
653 .type = DATA,
660 .rw = WRITE_SYNC,
654 .op = REQ_OP_WRITE,
655 .op_flags = WRITE_SYNC,
661 .page = page,
662 .encrypted_page = NULL,
663 };
664 set_page_dirty(page);
665 f2fs_wait_on_page_writeback(page, DATA, true);
666 if (clear_page_dirty_for_io(page))
667 inode_dec_dirty_pages(inode);
668 set_cold_data(page);

--- 64 unchanged lines hidden (view full) ---

733 if (f2fs_encrypted_inode(inode) &&
734 S_ISREG(inode->i_mode)) {
735 add_gc_inode(gc_list, inode);
736 continue;
737 }
738
739 start_bidx = start_bidx_of_node(nofs, inode);
740 data_page = get_read_data_page(inode,
656 .page = page,
657 .encrypted_page = NULL,
658 };
659 set_page_dirty(page);
660 f2fs_wait_on_page_writeback(page, DATA, true);
661 if (clear_page_dirty_for_io(page))
662 inode_dec_dirty_pages(inode);
663 set_cold_data(page);

--- 64 unchanged lines hidden (view full) ---

728 if (f2fs_encrypted_inode(inode) &&
729 S_ISREG(inode->i_mode)) {
730 add_gc_inode(gc_list, inode);
731 continue;
732 }
733
734 start_bidx = start_bidx_of_node(nofs, inode);
735 data_page = get_read_data_page(inode,
741 start_bidx + ofs_in_node, READA, true);
736 start_bidx + ofs_in_node, REQ_RAHEAD,
737 true);
742 if (IS_ERR(data_page)) {
743 iput(inode);
744 continue;
745 }
746
747 f2fs_put_page(data_page, 0);
748 add_gc_inode(gc_list, inode);
749 continue;

--- 79 unchanged lines hidden (view full) ---

829 gc_data_segment(sbi, sum->entries, gc_list, segno,
830 gc_type);
831
832 stat_inc_seg_count(sbi, type, gc_type);
833
834 f2fs_put_page(sum_page, 0);
835 }
836
738 if (IS_ERR(data_page)) {
739 iput(inode);
740 continue;
741 }
742
743 f2fs_put_page(data_page, 0);
744 add_gc_inode(gc_list, inode);
745 continue;

--- 79 unchanged lines hidden (view full) ---

825 gc_data_segment(sbi, sum->entries, gc_list, segno,
826 gc_type);
827
828 stat_inc_seg_count(sbi, type, gc_type);
829
830 f2fs_put_page(sum_page, 0);
831 }
832
837 if (gc_type == FG_GC) {
838 if (type == SUM_TYPE_NODE) {
839 struct writeback_control wbc = {
840 .sync_mode = WB_SYNC_ALL,
841 .nr_to_write = LONG_MAX,
842 .for_reclaim = 0,
843 };
844 sync_node_pages(sbi, 0, &wbc);
845 } else {
846 f2fs_submit_merged_bio(sbi, DATA, WRITE);
847 }
848 }
833 if (gc_type == FG_GC)
834 f2fs_submit_merged_bio(sbi,
835 (type == SUM_TYPE_NODE) ? NODE : DATA, WRITE);
849
850 blk_finish_plug(&plug);
851
852 if (gc_type == FG_GC) {
853 while (start_segno < end_segno)
854 if (get_valid_blocks(sbi, start_segno++, 1) == 0)
855 seg_freed++;
856 }

--- 75 unchanged lines hidden ---
836
837 blk_finish_plug(&plug);
838
839 if (gc_type == FG_GC) {
840 while (start_segno < end_segno)
841 if (get_valid_blocks(sbi, start_segno++, 1) == 0)
842 seg_freed++;
843 }

--- 75 unchanged lines hidden ---