History

mm: bdi: allow setting a maximum for the bdi dirty limit

Add "max_ratio" to /sys/class/bdi. This indicates the maximum percentage of the global dirty threshold allocated to this bdi. [mszeredi@suse.cz] - fix parsing in max_ratio_store(). - export bdi_set_max_ratio() to modules - limit bdi_dirty with bdi->max_ratio - document new sysfs attribute

Peter Zijlstra committed 18 years ago

Commit a42dde01 parent 189d3c46 files · +111 −13Browse files

Unified · Split

6 files
  1. Documentation/ABI/testing/sysfs-class-bdi +8 −1
  2. include/linux/backing-dev.h +2 −0
  3. include/linux/proportions.h +13 −0
  4. lib/proportions.c +32 −6
  5. mm/backing-dev.c +21 −0
  6. mm/page-writeback.c +35 −6
Documentation/ABI/testing/sysfs-class-bdi+8−1
@@ -49,4 +49,11 @@ min_ratio (read-write) · 48 unmodified lines
4949 Minimal percentage of global dirty threshold allocated to this
5050 bdi. If the value written to this file would make the the sum
5151 of all min_ratio values exceed 100, then EINVAL is returned.
52− The default is zero
52+ If min_ratio would become larger than the current max_ratio,
53+ then also EINVAL is returned. The default is zero
54+
55+max_ratio (read-write)
56+
57+ Maximal percentage of global dirty threshold allocated to this
58+ bdi. If max_ratio would become smaller than the current
59+ min_ratio, then EINVAL is returned. The default is 100
include/linux/backing-dev.h+2−0
@@ -52,6 +52,7 @@ struct backing_dev_info { · 51 unmodified lines
5252 int dirty_exceeded;
5353
5454 unsigned int min_ratio;
55+ unsigned int max_ratio, max_prop_frac;
5556
5657 struct device *dev;
5758 };
@@ -140,6 +141,7 @@ static inline unsigned long bdi_stat_error(struct backing_dev_info *bdi) · 82 unmodified lines
140141 }
141142
142143 int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio);
144+int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
143145
144146 /*
145147 * Flags in backing_dev_info::capability
include/linux/proportions.h+13−0
@@ -77,6 +77,19 @@ void prop_inc_percpu(struct prop_descriptor *pd, struct prop_local_percpu *pl) · 76 unmodified lines
7777 local_irq_restore(flags);
7878 }
7979
80+/*
81+ * Limit the time part in order to ensure there are some bits left for the
82+ * cycle counter and fraction multiply.
83+ */
84+#define PROP_MAX_SHIFT (3*BITS_PER_LONG/4)
85+
86+#define PROP_FRAC_SHIFT (BITS_PER_LONG - PROP_MAX_SHIFT - 1)
87+#define PROP_FRAC_BASE (1UL << PROP_FRAC_SHIFT)
88+
89+void __prop_inc_percpu_max(struct prop_descriptor *pd,
90+ struct prop_local_percpu *pl, long frac);
91+
92+
8093 /*
8194 * ----- SINGLE ------
8295 */
lib/proportions.c+32−6
@@ -73,12 +73,6 @@ · 72 unmodified lines
7373 #include <linux/proportions.h>
7474 #include <linux/rcupdate.h>
7575
76−/*
77− * Limit the time part in order to ensure there are some bits left for the
78− * cycle counter.
79− */
80−#define PROP_MAX_SHIFT (3*BITS_PER_LONG/4)
81−
8276 int prop_descriptor_init(struct prop_descriptor *pd, int shift)
8377 {
8478 int err;
@@ -267,6 +261,38 @@ void __prop_inc_percpu(struct prop_descriptor *pd, struct prop_local_percpu *pl) · 182 unmodified lines
267261 prop_put_global(pd, pg);
268262 }
269263
264+/*
265+ * identical to __prop_inc_percpu, except that it limits this pl's fraction to
266+ * @frac/PROP_FRAC_BASE by ignoring events when this limit has been exceeded.
267+ */
268+void __prop_inc_percpu_max(struct prop_descriptor *pd,
269+ struct prop_local_percpu *pl, long frac)
270+{
271+ struct prop_global *pg = prop_get_global(pd);
272+
273+ prop_norm_percpu(pg, pl);
274+
275+ if (unlikely(frac != PROP_FRAC_BASE)) {
276+ unsigned long period_2 = 1UL << (pg->shift - 1);
277+ unsigned long counter_mask = period_2 - 1;
278+ unsigned long global_count;
279+ long numerator, denominator;
280+
281+ numerator = percpu_counter_read_positive(&pl->events);
282+ global_count = percpu_counter_read(&pg->events);
283+ denominator = period_2 + (global_count & counter_mask);
284+
285+ if (numerator > ((denominator * frac) >> PROP_FRAC_SHIFT))
286+ goto out_put;
287+ }
288+
289+ percpu_counter_add(&pl->events, 1);
290+ percpu_counter_add(&pg->events, 1);
291+
292+out_put:
293+ prop_put_global(pd, pg);
294+}
295+
270296 /*
271297 * Obtain a fraction of this proportion
272298 *
mm/backing-dev.c+21−0
@@ -73,6 +73,24 @@ static ssize_t min_ratio_store(struct device *dev, · 72 unmodified lines
7373 }
7474 BDI_SHOW(min_ratio, bdi->min_ratio)
7575
76+static ssize_t max_ratio_store(struct device *dev,
77+ struct device_attribute *attr, const char *buf, size_t count)
78+{
79+ struct backing_dev_info *bdi = dev_get_drvdata(dev);
80+ char *end;
81+ unsigned int ratio;
82+ ssize_t ret = -EINVAL;
83+
84+ ratio = simple_strtoul(buf, &end, 10);
85+ if (*buf && (end[0] == '\0' || (end[0] == '\n' && end[1] == '\0'))) {
86+ ret = bdi_set_max_ratio(bdi, ratio);
87+ if (!ret)
88+ ret = count;
89+ }
90+ return ret;
91+}
92+BDI_SHOW(max_ratio, bdi->max_ratio)
93+
7694 #define __ATTR_RW(attr) __ATTR(attr, 0644, attr##_show, attr##_store)
7795
7896 static struct device_attribute bdi_dev_attrs[] = {
@@ -82,6 +100,7 @@ static struct device_attribute bdi_dev_attrs[] = { · 3 unmodified lines
82100 __ATTR_RO(dirty_kb),
83101 __ATTR_RO(bdi_dirty_kb),
84102 __ATTR_RW(min_ratio),
103+ __ATTR_RW(max_ratio),
85104 __ATTR_NULL,
86105 };
87106
@@ -147,6 +166,8 @@ int bdi_init(struct backing_dev_info *bdi) · 59 unmodified lines
147166 bdi->dev = NULL;
148167
149168 bdi->min_ratio = 0;
169+ bdi->max_ratio = 100;
170+ bdi->max_prop_frac = PROP_FRAC_BASE;
150171
151172 for (i = 0; i < NR_BDI_STAT_ITEMS; i++) {
152173 err = percpu_counter_init_irq(&bdi->bdi_stat[i], 0);
mm/page-writeback.c+35−6
@@ -164,7 +164,8 @@ int dirty_ratio_handler(struct ctl_table *table, int write, · 163 unmodified lines
164164 */
165165 static inline void __bdi_writeout_inc(struct backing_dev_info *bdi)
166166 {
167− __prop_inc_percpu(&vm_completions, &bdi->completions);
167+ __prop_inc_percpu_max(&vm_completions, &bdi->completions,
168+ bdi->max_prop_frac);
168169 }
169170
170171 static inline void task_dirty_inc(struct task_struct *tsk)
@@ -254,16 +255,42 @@ int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio) · 83 unmodified lines
254255 unsigned long flags;
255256
256257 spin_lock_irqsave(&bdi_lock, flags);
257− min_ratio -= bdi->min_ratio;
258− if (bdi_min_ratio + min_ratio < 100) {
259− bdi_min_ratio += min_ratio;
260− bdi->min_ratio += min_ratio;
261− } else
258+ if (min_ratio > bdi->max_ratio) {
262259 ret = -EINVAL;
260+ } else {
261+ min_ratio -= bdi->min_ratio;
262+ if (bdi_min_ratio + min_ratio < 100) {
263+ bdi_min_ratio += min_ratio;
264+ bdi->min_ratio += min_ratio;
265+ } else {
266+ ret = -EINVAL;
267+ }
268+ }
269+ spin_unlock_irqrestore(&bdi_lock, flags);
270+
271+ return ret;
272+}
273+
274+int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned max_ratio)
275+{
276+ unsigned long flags;
277+ int ret = 0;
278+
279+ if (max_ratio > 100)
280+ return -EINVAL;
281+
282+ spin_lock_irqsave(&bdi_lock, flags);
283+ if (bdi->min_ratio > max_ratio) {
284+ ret = -EINVAL;
285+ } else {
286+ bdi->max_ratio = max_ratio;
287+ bdi->max_prop_frac = (PROP_FRAC_BASE * max_ratio) / 100;
288+ }
263289 spin_unlock_irqrestore(&bdi_lock, flags);
264290
265291 return ret;
266292 }
293+EXPORT_SYMBOL(bdi_set_max_ratio);
267294
268295 /*
269296 * Work out the current dirty-memory clamping and background writeout
@@ -365,6 +392,8 @@ get_dirty_limits(long *pbackground, long *pdirty, long *pbdi_dirty, · 95 unmodified lines
365392 bdi_dirty *= numerator;
366393 do_div(bdi_dirty, denominator);
367394 bdi_dirty += (dirty * bdi->min_ratio) / 100;
395+ if (bdi_dirty > (dirty * bdi->max_ratio) / 100)
396+ bdi_dirty = dirty * bdi->max_ratio / 100;
368397
369398 *pbdi_dirty = bdi_dirty;
370399 clip_bdi_dirty_limit(bdi, dirty, pbdi_dirty);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t