diff options
author | Johannes Weiner <hannes@cmpxchg.org> | 2014-01-29 17:05:39 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-29 19:22:39 -0500 |
commit | a804552b9a15c931cfc2a92a2e0aed1add8b580a (patch) | |
tree | 33a820daefed39d2e8163a0298e78076ab7d0647 /mm | |
parent | 8582cb96b0bfd6891766d8c30d759bf21aad3b4d (diff) |
mm/page-writeback.c: fix dirty_balance_reserve subtraction from dirtyable memory
Tejun reported stuttering and latency spikes on a system where random
tasks would enter direct reclaim and get stuck on dirty pages. Around
50% of memory was occupied by tmpfs backed by an SSD, and another disk
(rotating) was reading and writing at max speed to shrink a partition.
: The problem was pretty ridiculous. It's a 8gig machine w/ one ssd and 10k
: rpm harddrive and I could reliably reproduce constant stuttering every
: several seconds for as long as buffered IO was going on on the hard drive
: either with tmpfs occupying somewhere above 4gig or a test program which
: allocates about the same amount of anon memory. Although swap usage was
: zero, turning off swap also made the problem go away too.
:
: The trigger conditions seem quite plausible - high anon memory usage w/
: heavy buffered IO and swap configured - and it's highly likely that this
: is happening in the wild too. (this can happen with copying large files
: to usb sticks too, right?)
This patch (of 2):
The dirty_balance_reserve is an approximation of the fraction of free
pages that the page allocator does not make available for page cache
allocations. As a result, it has to be taken into account when
calculating the amount of "dirtyable memory", the baseline to which
dirty_background_ratio and dirty_ratio are applied.
However, currently the reserve is subtracted from the sum of free and
reclaimable pages, which is non-sensical and leads to erroneous results
when the system is dominated by unreclaimable pages and the
dirty_balance_reserve is bigger than free+reclaimable. In that case, at
least the already allocated cache should be considered dirtyable.
Fix the calculation by subtracting the reserve from the amount of free
pages, then adding the reclaimable pages on top.
[akpm@linux-foundation.org: fix CONFIG_HIGHMEM build]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reported-by: Tejun Heo <tj@kernel.org>
Tested-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/page-writeback.c | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 63807583d8e8..61119b8a11e6 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c | |||
@@ -191,6 +191,25 @@ static unsigned long writeout_period_time = 0; | |||
191 | * global dirtyable memory first. | 191 | * global dirtyable memory first. |
192 | */ | 192 | */ |
193 | 193 | ||
194 | /** | ||
195 | * zone_dirtyable_memory - number of dirtyable pages in a zone | ||
196 | * @zone: the zone | ||
197 | * | ||
198 | * Returns the zone's number of pages potentially available for dirty | ||
199 | * page cache. This is the base value for the per-zone dirty limits. | ||
200 | */ | ||
201 | static unsigned long zone_dirtyable_memory(struct zone *zone) | ||
202 | { | ||
203 | unsigned long nr_pages; | ||
204 | |||
205 | nr_pages = zone_page_state(zone, NR_FREE_PAGES); | ||
206 | nr_pages -= min(nr_pages, zone->dirty_balance_reserve); | ||
207 | |||
208 | nr_pages += zone_reclaimable_pages(zone); | ||
209 | |||
210 | return nr_pages; | ||
211 | } | ||
212 | |||
194 | static unsigned long highmem_dirtyable_memory(unsigned long total) | 213 | static unsigned long highmem_dirtyable_memory(unsigned long total) |
195 | { | 214 | { |
196 | #ifdef CONFIG_HIGHMEM | 215 | #ifdef CONFIG_HIGHMEM |
@@ -198,11 +217,9 @@ static unsigned long highmem_dirtyable_memory(unsigned long total) | |||
198 | unsigned long x = 0; | 217 | unsigned long x = 0; |
199 | 218 | ||
200 | for_each_node_state(node, N_HIGH_MEMORY) { | 219 | for_each_node_state(node, N_HIGH_MEMORY) { |
201 | struct zone *z = | 220 | struct zone *z = &NODE_DATA(node)->node_zones[ZONE_HIGHMEM]; |
202 | &NODE_DATA(node)->node_zones[ZONE_HIGHMEM]; | ||
203 | 221 | ||
204 | x += zone_page_state(z, NR_FREE_PAGES) + | 222 | x += zone_dirtyable_memory(z); |
205 | zone_reclaimable_pages(z) - z->dirty_balance_reserve; | ||
206 | } | 223 | } |
207 | /* | 224 | /* |
208 | * Unreclaimable memory (kernel memory or anonymous memory | 225 | * Unreclaimable memory (kernel memory or anonymous memory |
@@ -238,9 +255,11 @@ static unsigned long global_dirtyable_memory(void) | |||
238 | { | 255 | { |
239 | unsigned long x; | 256 | unsigned long x; |
240 | 257 | ||
241 | x = global_page_state(NR_FREE_PAGES) + global_reclaimable_pages(); | 258 | x = global_page_state(NR_FREE_PAGES); |
242 | x -= min(x, dirty_balance_reserve); | 259 | x -= min(x, dirty_balance_reserve); |
243 | 260 | ||
261 | x += global_reclaimable_pages(); | ||
262 | |||
244 | if (!vm_highmem_is_dirtyable) | 263 | if (!vm_highmem_is_dirtyable) |
245 | x -= highmem_dirtyable_memory(x); | 264 | x -= highmem_dirtyable_memory(x); |
246 | 265 | ||
@@ -289,32 +308,6 @@ void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty) | |||
289 | } | 308 | } |
290 | 309 | ||
291 | /** | 310 | /** |
292 | * zone_dirtyable_memory - number of dirtyable pages in a zone | ||
293 | * @zone: the zone | ||
294 | * | ||
295 | * Returns the zone's number of pages potentially available for dirty | ||
296 | * page cache. This is the base value for the per-zone dirty limits. | ||
297 | */ | ||
298 | static unsigned long zone_dirtyable_memory(struct zone *zone) | ||
299 | { | ||
300 | /* | ||
301 | * The effective global number of dirtyable pages may exclude | ||
302 | * highmem as a big-picture measure to keep the ratio between | ||
303 | * dirty memory and lowmem reasonable. | ||
304 | * | ||
305 | * But this function is purely about the individual zone and a | ||
306 | * highmem zone can hold its share of dirty pages, so we don't | ||
307 | * care about vm_highmem_is_dirtyable here. | ||
308 | */ | ||
309 | unsigned long nr_pages = zone_page_state(zone, NR_FREE_PAGES) + | ||
310 | zone_reclaimable_pages(zone); | ||
311 | |||
312 | /* don't allow this to underflow */ | ||
313 | nr_pages -= min(nr_pages, zone->dirty_balance_reserve); | ||
314 | return nr_pages; | ||
315 | } | ||
316 | |||
317 | /** | ||
318 | * zone_dirty_limit - maximum number of dirty pages allowed in a zone | 311 | * zone_dirty_limit - maximum number of dirty pages allowed in a zone |
319 | * @zone: the zone | 312 | * @zone: the zone |
320 | * | 313 | * |