aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorAndrea Arcangeli <aarcange@redhat.com>2011-01-13 18:47:11 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-13 20:32:46 -0500
commit5a03b051ed87e72b959f32a86054e1142ac4cf55 (patch)
tree31f0e8efb86d48b0292f8a7ea4bd9cf7c930a0ab /mm
parent878aee7d6b5504e01b9caffce080e792b6b8d090 (diff)
thp: use compaction in kswapd for GFP_ATOMIC order > 0
This takes advantage of memory compaction to properly generate pages of order > 0 if regular page reclaim fails and priority level becomes more severe and we don't reach the proper watermarks. Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> 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/compaction.c31
-rw-r--r--mm/vmscan.c30
2 files changed, 46 insertions, 15 deletions
diff --git a/mm/compaction.c b/mm/compaction.c
index da25b5a2e476..60d52a7298d5 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -42,6 +42,8 @@ struct compact_control {
42 unsigned int order; /* order a direct compactor needs */ 42 unsigned int order; /* order a direct compactor needs */
43 int migratetype; /* MOVABLE, RECLAIMABLE etc */ 43 int migratetype; /* MOVABLE, RECLAIMABLE etc */
44 struct zone *zone; 44 struct zone *zone;
45
46 int compact_mode;
45}; 47};
46 48
47static unsigned long release_freepages(struct list_head *freelist) 49static unsigned long release_freepages(struct list_head *freelist)
@@ -382,10 +384,10 @@ static void update_nr_listpages(struct compact_control *cc)
382} 384}
383 385
384static int compact_finished(struct zone *zone, 386static int compact_finished(struct zone *zone,
385 struct compact_control *cc) 387 struct compact_control *cc)
386{ 388{
387 unsigned int order; 389 unsigned int order;
388 unsigned long watermark = low_wmark_pages(zone) + (1 << cc->order); 390 unsigned long watermark;
389 391
390 if (fatal_signal_pending(current)) 392 if (fatal_signal_pending(current))
391 return COMPACT_PARTIAL; 393 return COMPACT_PARTIAL;
@@ -395,12 +397,27 @@ static int compact_finished(struct zone *zone,
395 return COMPACT_COMPLETE; 397 return COMPACT_COMPLETE;
396 398
397 /* Compaction run is not finished if the watermark is not met */ 399 /* Compaction run is not finished if the watermark is not met */
400 if (cc->compact_mode != COMPACT_MODE_KSWAPD)
401 watermark = low_wmark_pages(zone);
402 else
403 watermark = high_wmark_pages(zone);
404 watermark += (1 << cc->order);
405
398 if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0)) 406 if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0))
399 return COMPACT_CONTINUE; 407 return COMPACT_CONTINUE;
400 408
401 if (cc->order == -1) 409 if (cc->order == -1)
402 return COMPACT_CONTINUE; 410 return COMPACT_CONTINUE;
403 411
412 /*
413 * Generating only one page of the right order is not enough
414 * for kswapd, we must continue until we're above the high
415 * watermark as a pool for high order GFP_ATOMIC allocations
416 * too.
417 */
418 if (cc->compact_mode == COMPACT_MODE_KSWAPD)
419 return COMPACT_CONTINUE;
420
404 /* Direct compactor: Is a suitable page free? */ 421 /* Direct compactor: Is a suitable page free? */
405 for (order = cc->order; order < MAX_ORDER; order++) { 422 for (order = cc->order; order < MAX_ORDER; order++) {
406 /* Job done if page is free of the right migratetype */ 423 /* Job done if page is free of the right migratetype */
@@ -514,8 +531,9 @@ static int compact_zone(struct zone *zone, struct compact_control *cc)
514} 531}
515 532
516unsigned long compact_zone_order(struct zone *zone, 533unsigned long compact_zone_order(struct zone *zone,
517 int order, gfp_t gfp_mask, 534 int order, gfp_t gfp_mask,
518 bool sync) 535 bool sync,
536 int compact_mode)
519{ 537{
520 struct compact_control cc = { 538 struct compact_control cc = {
521 .nr_freepages = 0, 539 .nr_freepages = 0,
@@ -524,6 +542,7 @@ unsigned long compact_zone_order(struct zone *zone,
524 .migratetype = allocflags_to_migratetype(gfp_mask), 542 .migratetype = allocflags_to_migratetype(gfp_mask),
525 .zone = zone, 543 .zone = zone,
526 .sync = sync, 544 .sync = sync,
545 .compact_mode = compact_mode,
527 }; 546 };
528 INIT_LIST_HEAD(&cc.freepages); 547 INIT_LIST_HEAD(&cc.freepages);
529 INIT_LIST_HEAD(&cc.migratepages); 548 INIT_LIST_HEAD(&cc.migratepages);
@@ -569,7 +588,8 @@ unsigned long try_to_compact_pages(struct zonelist *zonelist,
569 nodemask) { 588 nodemask) {
570 int status; 589 int status;
571 590
572 status = compact_zone_order(zone, order, gfp_mask, sync); 591 status = compact_zone_order(zone, order, gfp_mask, sync,
592 COMPACT_MODE_DIRECT_RECLAIM);
573 rc = max(status, rc); 593 rc = max(status, rc);
574 594
575 /* If a normal allocation would succeed, stop compacting */ 595 /* If a normal allocation would succeed, stop compacting */
@@ -600,6 +620,7 @@ static int compact_node(int nid)
600 .nr_freepages = 0, 620 .nr_freepages = 0,
601 .nr_migratepages = 0, 621 .nr_migratepages = 0,
602 .order = -1, 622 .order = -1,
623 .compact_mode = COMPACT_MODE_DIRECT_RECLAIM,
603 }; 624 };
604 625
605 zone = &pgdat->node_zones[zoneid]; 626 zone = &pgdat->node_zones[zoneid];
diff --git a/mm/vmscan.c b/mm/vmscan.c
index cfdef0bcc7ab..f5b762ae23a2 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -41,6 +41,7 @@
41#include <linux/memcontrol.h> 41#include <linux/memcontrol.h>
42#include <linux/delayacct.h> 42#include <linux/delayacct.h>
43#include <linux/sysctl.h> 43#include <linux/sysctl.h>
44#include <linux/compaction.h>
44 45
45#include <asm/tlbflush.h> 46#include <asm/tlbflush.h>
46#include <asm/div64.h> 47#include <asm/div64.h>
@@ -2382,6 +2383,7 @@ loop_again:
2382 * cause too much scanning of the lower zones. 2383 * cause too much scanning of the lower zones.
2383 */ 2384 */
2384 for (i = 0; i <= end_zone; i++) { 2385 for (i = 0; i <= end_zone; i++) {
2386 int compaction;
2385 struct zone *zone = pgdat->node_zones + i; 2387 struct zone *zone = pgdat->node_zones + i;
2386 int nr_slab; 2388 int nr_slab;
2387 2389
@@ -2411,9 +2413,26 @@ loop_again:
2411 lru_pages); 2413 lru_pages);
2412 sc.nr_reclaimed += reclaim_state->reclaimed_slab; 2414 sc.nr_reclaimed += reclaim_state->reclaimed_slab;
2413 total_scanned += sc.nr_scanned; 2415 total_scanned += sc.nr_scanned;
2416
2417 compaction = 0;
2418 if (order &&
2419 zone_watermark_ok(zone, 0,
2420 high_wmark_pages(zone),
2421 end_zone, 0) &&
2422 !zone_watermark_ok(zone, order,
2423 high_wmark_pages(zone),
2424 end_zone, 0)) {
2425 compact_zone_order(zone,
2426 order,
2427 sc.gfp_mask, false,
2428 COMPACT_MODE_KSWAPD);
2429 compaction = 1;
2430 }
2431
2414 if (zone->all_unreclaimable) 2432 if (zone->all_unreclaimable)
2415 continue; 2433 continue;
2416 if (nr_slab == 0 && !zone_reclaimable(zone)) 2434 if (!compaction && nr_slab == 0 &&
2435 !zone_reclaimable(zone))
2417 zone->all_unreclaimable = 1; 2436 zone->all_unreclaimable = 1;
2418 /* 2437 /*
2419 * If we've done a decent amount of scanning and 2438 * If we've done a decent amount of scanning and
@@ -2424,15 +2443,6 @@ loop_again:
2424 total_scanned > sc.nr_reclaimed + sc.nr_reclaimed / 2) 2443 total_scanned > sc.nr_reclaimed + sc.nr_reclaimed / 2)
2425 sc.may_writepage = 1; 2444 sc.may_writepage = 1;
2426 2445
2427 /*
2428 * Compact the zone for higher orders to reduce
2429 * latencies for higher-order allocations that
2430 * would ordinarily call try_to_compact_pages()
2431 */
2432 if (sc.order > PAGE_ALLOC_COSTLY_ORDER)
2433 compact_zone_order(zone, sc.order, sc.gfp_mask,
2434 false);
2435
2436 if (!zone_watermark_ok_safe(zone, order, 2446 if (!zone_watermark_ok_safe(zone, order,
2437 high_wmark_pages(zone), end_zone, 0)) { 2447 high_wmark_pages(zone), end_zone, 0)) {
2438 all_zones_ok = 0; 2448 all_zones_ok = 0;