fs-writeback.c (082439004b31adc146e96e5f1c574dd2b57dcd93) | fs-writeback.c (455b2864686d3591b3b2f39eb46290c95f76471f) |
---|---|
1/* 2 * fs/fs-writeback.c 3 * 4 * Copyright (C) 2002, Linus Torvalds. 5 * 6 * Contains all the functions related to writing back and waiting 7 * upon dirty inodes against superblocks, and writing back dirty 8 * pages against inodes. ie: data writeback. Writeout of the --- 12 unchanged lines hidden (view full) --- 21#include <linux/fs.h> 22#include <linux/mm.h> 23#include <linux/kthread.h> 24#include <linux/freezer.h> 25#include <linux/writeback.h> 26#include <linux/blkdev.h> 27#include <linux/backing-dev.h> 28#include <linux/buffer_head.h> | 1/* 2 * fs/fs-writeback.c 3 * 4 * Copyright (C) 2002, Linus Torvalds. 5 * 6 * Contains all the functions related to writing back and waiting 7 * upon dirty inodes against superblocks, and writing back dirty 8 * pages against inodes. ie: data writeback. Writeout of the --- 12 unchanged lines hidden (view full) --- 21#include <linux/fs.h> 22#include <linux/mm.h> 23#include <linux/kthread.h> 24#include <linux/freezer.h> 25#include <linux/writeback.h> 26#include <linux/blkdev.h> 27#include <linux/backing-dev.h> 28#include <linux/buffer_head.h> |
29#include <linux/tracepoint.h> |
|
29#include "internal.h" 30 | 30#include "internal.h" 31 |
31#define inode_to_bdi(inode) ((inode)->i_mapping->backing_dev_info) 32 | |
33/* | 32/* |
34 * We don't actually have pdflush, but this one is exported though /proc... 35 */ 36int nr_pdflush_threads; 37 38/* | |
39 * Passed into wb_writeback(), essentially a subset of writeback_control 40 */ 41struct wb_writeback_work { 42 long nr_pages; 43 struct super_block *sb; 44 enum writeback_sync_modes sync_mode; 45 unsigned int for_kupdate:1; 46 unsigned int range_cyclic:1; 47 unsigned int for_background:1; 48 49 struct list_head list; /* pending work list */ 50 struct completion *done; /* set if the caller waits */ 51}; 52 | 33 * Passed into wb_writeback(), essentially a subset of writeback_control 34 */ 35struct wb_writeback_work { 36 long nr_pages; 37 struct super_block *sb; 38 enum writeback_sync_modes sync_mode; 39 unsigned int for_kupdate:1; 40 unsigned int range_cyclic:1; 41 unsigned int for_background:1; 42 43 struct list_head list; /* pending work list */ 44 struct completion *done; /* set if the caller waits */ 45}; 46 |
47/* 48 * Include the creation of the trace points after defining the 49 * wb_writeback_work structure so that the definition remains local to this 50 * file. 51 */ 52#define CREATE_TRACE_POINTS 53#include <trace/events/writeback.h> 54 55#define inode_to_bdi(inode) ((inode)->i_mapping->backing_dev_info) 56 57/* 58 * We don't actually have pdflush, but this one is exported though /proc... 59 */ 60int nr_pdflush_threads; 61 |
|
53/** 54 * writeback_in_progress - determine whether there is writeback in progress 55 * @bdi: the device's backing_dev_info structure. 56 * 57 * Determine whether there is writeback waiting to be handled against a 58 * backing device. 59 */ 60int writeback_in_progress(struct backing_dev_info *bdi) 61{ 62 return !list_empty(&bdi->work_list); 63} 64 65static void bdi_queue_work(struct backing_dev_info *bdi, 66 struct wb_writeback_work *work) 67{ | 62/** 63 * writeback_in_progress - determine whether there is writeback in progress 64 * @bdi: the device's backing_dev_info structure. 65 * 66 * Determine whether there is writeback waiting to be handled against a 67 * backing device. 68 */ 69int writeback_in_progress(struct backing_dev_info *bdi) 70{ 71 return !list_empty(&bdi->work_list); 72} 73 74static void bdi_queue_work(struct backing_dev_info *bdi, 75 struct wb_writeback_work *work) 76{ |
77 trace_writeback_queue(bdi, work); 78 |
|
68 spin_lock(&bdi->wb_lock); 69 list_add_tail(&work->list, &bdi->work_list); 70 spin_unlock(&bdi->wb_lock); 71 72 /* 73 * If the default thread isn't there, make sure we add it. When 74 * it gets created and wakes up, we'll run this work. 75 */ 76 if (unlikely(!bdi->wb.task)) { | 79 spin_lock(&bdi->wb_lock); 80 list_add_tail(&work->list, &bdi->work_list); 81 spin_unlock(&bdi->wb_lock); 82 83 /* 84 * If the default thread isn't there, make sure we add it. When 85 * it gets created and wakes up, we'll run this work. 86 */ 87 if (unlikely(!bdi->wb.task)) { |
88 trace_writeback_nothread(bdi, work); |
|
77 wake_up_process(default_backing_dev_info.wb.task); 78 } else { 79 struct bdi_writeback *wb = &bdi->wb; 80 81 if (wb->task) 82 wake_up_process(wb->task); 83 } 84} --- 5 unchanged lines hidden (view full) --- 90 struct wb_writeback_work *work; 91 92 /* 93 * This is WB_SYNC_NONE writeback, so if allocation fails just 94 * wakeup the thread for old dirty data writeback 95 */ 96 work = kzalloc(sizeof(*work), GFP_ATOMIC); 97 if (!work) { | 89 wake_up_process(default_backing_dev_info.wb.task); 90 } else { 91 struct bdi_writeback *wb = &bdi->wb; 92 93 if (wb->task) 94 wake_up_process(wb->task); 95 } 96} --- 5 unchanged lines hidden (view full) --- 102 struct wb_writeback_work *work; 103 104 /* 105 * This is WB_SYNC_NONE writeback, so if allocation fails just 106 * wakeup the thread for old dirty data writeback 107 */ 108 work = kzalloc(sizeof(*work), GFP_ATOMIC); 109 if (!work) { |
98 if (bdi->wb.task) | 110 if (bdi->wb.task) { 111 trace_writeback_nowork(bdi); |
99 wake_up_process(bdi->wb.task); | 112 wake_up_process(bdi->wb.task); |
113 } |
|
100 return; 101 } 102 103 work->sync_mode = WB_SYNC_NONE; 104 work->nr_pages = nr_pages; 105 work->range_cyclic = range_cyclic; 106 work->for_background = for_background; 107 --- 638 unchanged lines hidden (view full) --- 746 while ((work = get_next_work_item(bdi, wb)) != NULL) { 747 /* 748 * Override sync mode, in case we must wait for completion 749 * because this thread is exiting now. 750 */ 751 if (force_wait) 752 work->sync_mode = WB_SYNC_ALL; 753 | 114 return; 115 } 116 117 work->sync_mode = WB_SYNC_NONE; 118 work->nr_pages = nr_pages; 119 work->range_cyclic = range_cyclic; 120 work->for_background = for_background; 121 --- 638 unchanged lines hidden (view full) --- 760 while ((work = get_next_work_item(bdi, wb)) != NULL) { 761 /* 762 * Override sync mode, in case we must wait for completion 763 * because this thread is exiting now. 764 */ 765 if (force_wait) 766 work->sync_mode = WB_SYNC_ALL; 767 |
768 trace_writeback_exec(bdi, work); 769 |
|
754 wrote += wb_writeback(wb, work); 755 756 /* 757 * Notify the caller of completion if this is a synchronous 758 * work item, otherwise just free it. 759 */ 760 if (work->done) 761 complete(work->done); --- 38 unchanged lines hidden (view full) --- 800 801 /* 802 * Clear pending bit and wakeup anybody waiting to tear us down 803 */ 804 clear_bit(BDI_pending, &bdi->state); 805 smp_mb__after_clear_bit(); 806 wake_up_bit(&bdi->state, BDI_pending); 807 | 770 wrote += wb_writeback(wb, work); 771 772 /* 773 * Notify the caller of completion if this is a synchronous 774 * work item, otherwise just free it. 775 */ 776 if (work->done) 777 complete(work->done); --- 38 unchanged lines hidden (view full) --- 816 817 /* 818 * Clear pending bit and wakeup anybody waiting to tear us down 819 */ 820 clear_bit(BDI_pending, &bdi->state); 821 smp_mb__after_clear_bit(); 822 wake_up_bit(&bdi->state, BDI_pending); 823 |
824 trace_writeback_thread_start(bdi); 825 |
|
808 while (!kthread_should_stop()) { 809 pages_written = wb_do_writeback(wb, 0); 810 | 826 while (!kthread_should_stop()) { 827 pages_written = wb_do_writeback(wb, 0); 828 |
829 trace_writeback_pages_written(pages_written); 830 |
|
811 if (pages_written) 812 last_active = jiffies; 813 else if (wait_jiffies != -1UL) { 814 unsigned long max_idle; 815 816 /* 817 * Longest period of inactivity that we tolerate. If we 818 * see dirty data again later, the task will get --- 21 unchanged lines hidden (view full) --- 840 wb->task = NULL; 841 842 /* 843 * Flush any work that raced with us exiting. No new work 844 * will be added, since this bdi isn't discoverable anymore. 845 */ 846 if (!list_empty(&bdi->work_list)) 847 wb_do_writeback(wb, 1); | 831 if (pages_written) 832 last_active = jiffies; 833 else if (wait_jiffies != -1UL) { 834 unsigned long max_idle; 835 836 /* 837 * Longest period of inactivity that we tolerate. If we 838 * see dirty data again later, the task will get --- 21 unchanged lines hidden (view full) --- 860 wb->task = NULL; 861 862 /* 863 * Flush any work that raced with us exiting. No new work 864 * will be added, since this bdi isn't discoverable anymore. 865 */ 866 if (!list_empty(&bdi->work_list)) 867 wb_do_writeback(wb, 1); |
868 869 trace_writeback_thread_stop(bdi); |
|
848 return 0; 849} 850 851 852/* 853 * Start writeback of `nr_pages' pages. If `nr_pages' is zero, write back 854 * the whole world. 855 */ --- 339 unchanged lines hidden --- | 870 return 0; 871} 872 873 874/* 875 * Start writeback of `nr_pages' pages. If `nr_pages' is zero, write back 876 * the whole world. 877 */ --- 339 unchanged lines hidden --- |