aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/backing-dev.h
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2007-10-17 02:25:47 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 11:42:45 -0400
commitb2e8fb6efa209c82203c79b491b5bc952d44aa57 (patch)
treee4c82e3f2c70a188ced7126435bf153f5f6c4a1c /include/linux/backing-dev.h
parente0bf68ddec4f4f90e5871404be4f1854c17f3120 (diff)
mm: scalable bdi statistics counters
Provide scalable per backing_dev_info statistics counters. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/backing-dev.h')
-rw-r--r--include/linux/backing-dev.h85
1 files changed, 82 insertions, 3 deletions
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index 8f56634f537a..f7677ff80cc5 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -8,6 +8,8 @@
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>
11#include <asm/atomic.h> 13#include <asm/atomic.h>
12 14
13struct page; 15struct page;
@@ -24,6 +26,12 @@ enum bdi_state {
24 26
25typedef int (congested_fn)(void *, int); 27typedef int (congested_fn)(void *, int);
26 28
29enum bdi_stat_item {
30 NR_BDI_STAT_ITEMS
31};
32
33#define BDI_STAT_BATCH (8*(1+ilog2(nr_cpu_ids)))
34
27struct backing_dev_info { 35struct backing_dev_info {
28 unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */ 36 unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */
29 unsigned long state; /* Always use atomic bitops on this */ 37 unsigned long state; /* Always use atomic bitops on this */
@@ -32,15 +40,86 @@ struct backing_dev_info {
32 void *congested_data; /* Pointer to aux data for congested func */ 40 void *congested_data; /* Pointer to aux data for congested func */
33 void (*unplug_io_fn)(struct backing_dev_info *, struct page *); 41 void (*unplug_io_fn)(struct backing_dev_info *, struct page *);
34 void *unplug_io_data; 42 void *unplug_io_data;
43
44 struct percpu_counter bdi_stat[NR_BDI_STAT_ITEMS];
35}; 45};
36 46
37static inline int bdi_init(struct backing_dev_info *bdi) 47int bdi_init(struct backing_dev_info *bdi);
48void bdi_destroy(struct backing_dev_info *bdi);
49
50static inline void __add_bdi_stat(struct backing_dev_info *bdi,
51 enum bdi_stat_item item, s64 amount)
38{ 52{
39 return 0; 53 __percpu_counter_add(&bdi->bdi_stat[item], amount, BDI_STAT_BATCH);
40} 54}
41 55
42static inline void bdi_destroy(struct backing_dev_info *bdi) 56static inline void __inc_bdi_stat(struct backing_dev_info *bdi,
57 enum bdi_stat_item item)
43{ 58{
59 __add_bdi_stat(bdi, item, 1);
60}
61
62static inline void inc_bdi_stat(struct backing_dev_info *bdi,
63 enum bdi_stat_item item)
64{
65 unsigned long flags;
66
67 local_irq_save(flags);
68 __inc_bdi_stat(bdi, item);
69 local_irq_restore(flags);
70}
71
72static inline void __dec_bdi_stat(struct backing_dev_info *bdi,
73 enum bdi_stat_item item)
74{
75 __add_bdi_stat(bdi, item, -1);
76}
77
78static inline void dec_bdi_stat(struct backing_dev_info *bdi,
79 enum bdi_stat_item item)
80{
81 unsigned long flags;
82
83 local_irq_save(flags);
84 __dec_bdi_stat(bdi, item);
85 local_irq_restore(flags);
86}
87
88static inline s64 bdi_stat(struct backing_dev_info *bdi,
89 enum bdi_stat_item item)
90{
91 return percpu_counter_read_positive(&bdi->bdi_stat[item]);
92}
93
94static inline s64 __bdi_stat_sum(struct backing_dev_info *bdi,
95 enum bdi_stat_item item)
96{
97 return percpu_counter_sum_positive(&bdi->bdi_stat[item]);
98}
99
100static inline s64 bdi_stat_sum(struct backing_dev_info *bdi,
101 enum bdi_stat_item item)
102{
103 s64 sum;
104 unsigned long flags;
105
106 local_irq_save(flags);
107 sum = __bdi_stat_sum(bdi, item);
108 local_irq_restore(flags);
109
110 return sum;
111}
112
113/*
114 * maximal error of a stat counter.
115 */
116static inline unsigned long bdi_stat_error(struct backing_dev_info *bdi)
117{
118#ifdef CONFIG_SMP
119 return nr_cpu_ids * BDI_STAT_BATCH;
120#else
121 return 1;
122#endif
44} 123}
45 124
46/* 125/*