diff options
Diffstat (limited to 'include/linux/backing-dev.h')
-rw-r--r-- | include/linux/backing-dev.h | 94 |
1 files changed, 93 insertions, 1 deletions
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index 7011d6255593..48a62baace58 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h | |||
@@ -8,6 +8,9 @@ | |||
8 | #ifndef _LINUX_BACKING_DEV_H | 8 | #ifndef _LINUX_BACKING_DEV_H |
9 | #define _LINUX_BACKING_DEV_H | 9 | #define _LINUX_BACKING_DEV_H |
10 | 10 | ||
11 | #include <linux/percpu_counter.h> | ||
12 | #include <linux/log2.h> | ||
13 | #include <linux/proportions.h> | ||
11 | #include <asm/atomic.h> | 14 | #include <asm/atomic.h> |
12 | 15 | ||
13 | struct page; | 16 | struct page; |
@@ -24,6 +27,14 @@ enum bdi_state { | |||
24 | 27 | ||
25 | typedef int (congested_fn)(void *, int); | 28 | typedef int (congested_fn)(void *, int); |
26 | 29 | ||
30 | enum bdi_stat_item { | ||
31 | BDI_RECLAIMABLE, | ||
32 | BDI_WRITEBACK, | ||
33 | NR_BDI_STAT_ITEMS | ||
34 | }; | ||
35 | |||
36 | #define BDI_STAT_BATCH (8*(1+ilog2(nr_cpu_ids))) | ||
37 | |||
27 | struct backing_dev_info { | 38 | struct backing_dev_info { |
28 | unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */ | 39 | unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */ |
29 | unsigned long state; /* Always use atomic bitops on this */ | 40 | unsigned long state; /* Always use atomic bitops on this */ |
@@ -32,8 +43,90 @@ struct backing_dev_info { | |||
32 | void *congested_data; /* Pointer to aux data for congested func */ | 43 | void *congested_data; /* Pointer to aux data for congested func */ |
33 | void (*unplug_io_fn)(struct backing_dev_info *, struct page *); | 44 | void (*unplug_io_fn)(struct backing_dev_info *, struct page *); |
34 | void *unplug_io_data; | 45 | void *unplug_io_data; |
46 | |||
47 | struct percpu_counter bdi_stat[NR_BDI_STAT_ITEMS]; | ||
48 | |||
49 | struct prop_local_percpu completions; | ||
50 | int dirty_exceeded; | ||
35 | }; | 51 | }; |
36 | 52 | ||
53 | int bdi_init(struct backing_dev_info *bdi); | ||
54 | void bdi_destroy(struct backing_dev_info *bdi); | ||
55 | |||
56 | static inline void __add_bdi_stat(struct backing_dev_info *bdi, | ||
57 | enum bdi_stat_item item, s64 amount) | ||
58 | { | ||
59 | __percpu_counter_add(&bdi->bdi_stat[item], amount, BDI_STAT_BATCH); | ||
60 | } | ||
61 | |||
62 | static inline void __inc_bdi_stat(struct backing_dev_info *bdi, | ||
63 | enum bdi_stat_item item) | ||
64 | { | ||
65 | __add_bdi_stat(bdi, item, 1); | ||
66 | } | ||
67 | |||
68 | static inline void inc_bdi_stat(struct backing_dev_info *bdi, | ||
69 | enum bdi_stat_item item) | ||
70 | { | ||
71 | unsigned long flags; | ||
72 | |||
73 | local_irq_save(flags); | ||
74 | __inc_bdi_stat(bdi, item); | ||
75 | local_irq_restore(flags); | ||
76 | } | ||
77 | |||
78 | static inline void __dec_bdi_stat(struct backing_dev_info *bdi, | ||
79 | enum bdi_stat_item item) | ||
80 | { | ||
81 | __add_bdi_stat(bdi, item, -1); | ||
82 | } | ||
83 | |||
84 | static inline void dec_bdi_stat(struct backing_dev_info *bdi, | ||
85 | enum bdi_stat_item item) | ||
86 | { | ||
87 | unsigned long flags; | ||
88 | |||
89 | local_irq_save(flags); | ||
90 | __dec_bdi_stat(bdi, item); | ||
91 | local_irq_restore(flags); | ||
92 | } | ||
93 | |||
94 | static inline s64 bdi_stat(struct backing_dev_info *bdi, | ||
95 | enum bdi_stat_item item) | ||
96 | { | ||
97 | return percpu_counter_read_positive(&bdi->bdi_stat[item]); | ||
98 | } | ||
99 | |||
100 | static inline s64 __bdi_stat_sum(struct backing_dev_info *bdi, | ||
101 | enum bdi_stat_item item) | ||
102 | { | ||
103 | return percpu_counter_sum_positive(&bdi->bdi_stat[item]); | ||
104 | } | ||
105 | |||
106 | static inline s64 bdi_stat_sum(struct backing_dev_info *bdi, | ||
107 | enum bdi_stat_item item) | ||
108 | { | ||
109 | s64 sum; | ||
110 | unsigned long flags; | ||
111 | |||
112 | local_irq_save(flags); | ||
113 | sum = __bdi_stat_sum(bdi, item); | ||
114 | local_irq_restore(flags); | ||
115 | |||
116 | return sum; | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | * maximal error of a stat counter. | ||
121 | */ | ||
122 | static inline unsigned long bdi_stat_error(struct backing_dev_info *bdi) | ||
123 | { | ||
124 | #ifdef CONFIG_SMP | ||
125 | return nr_cpu_ids * BDI_STAT_BATCH; | ||
126 | #else | ||
127 | return 1; | ||
128 | #endif | ||
129 | } | ||
37 | 130 | ||
38 | /* | 131 | /* |
39 | * Flags in backing_dev_info::capability | 132 | * Flags in backing_dev_info::capability |
@@ -93,7 +186,6 @@ static inline int bdi_rw_congested(struct backing_dev_info *bdi) | |||
93 | void clear_bdi_congested(struct backing_dev_info *bdi, int rw); | 186 | void clear_bdi_congested(struct backing_dev_info *bdi, int rw); |
94 | void set_bdi_congested(struct backing_dev_info *bdi, int rw); | 187 | void set_bdi_congested(struct backing_dev_info *bdi, int rw); |
95 | long congestion_wait(int rw, long timeout); | 188 | long congestion_wait(int rw, long timeout); |
96 | void congestion_end(int rw); | ||
97 | 189 | ||
98 | #define bdi_cap_writeback_dirty(bdi) \ | 190 | #define bdi_cap_writeback_dirty(bdi) \ |
99 | (!((bdi)->capabilities & BDI_CAP_NO_WRITEBACK)) | 191 | (!((bdi)->capabilities & BDI_CAP_NO_WRITEBACK)) |