compaction.c (748446bb6b5a9390b546af38ec899c868a9dbcf0) | compaction.c (76ab0f530e4a01d4dc20cdc1d5e87753c579dc18) |
---|---|
1/* 2 * linux/mm/compaction.c 3 * 4 * Memory compaction for the reduction of external fragmentation. Note that 5 * this heavily depends upon page migration to do all the real heavy 6 * lifting 7 * 8 * Copyright IBM Corp. 2007-2010 Mel Gorman <mel@csn.ul.ie> 9 */ 10#include <linux/swap.h> 11#include <linux/migrate.h> 12#include <linux/compaction.h> 13#include <linux/mm_inline.h> 14#include <linux/backing-dev.h> | 1/* 2 * linux/mm/compaction.c 3 * 4 * Memory compaction for the reduction of external fragmentation. Note that 5 * this heavily depends upon page migration to do all the real heavy 6 * lifting 7 * 8 * Copyright IBM Corp. 2007-2010 Mel Gorman <mel@csn.ul.ie> 9 */ 10#include <linux/swap.h> 11#include <linux/migrate.h> 12#include <linux/compaction.h> 13#include <linux/mm_inline.h> 14#include <linux/backing-dev.h> |
15#include <linux/sysctl.h> |
|
15#include "internal.h" 16 17/* 18 * compact_control is used to track pages being migrated and the free pages 19 * they are being migrated to during memory compaction. The free_pfn starts 20 * at the end of a zone and migrate_pfn begins at the start. Movable pages 21 * are moved to the end of a zone during a compaction run and the run 22 * completes when free_pfn <= migrate_pfn --- 363 unchanged lines hidden (view full) --- 386 } 387 388 /* Release free pages and check accounting */ 389 cc->nr_freepages -= release_freepages(&cc->freepages); 390 VM_BUG_ON(cc->nr_freepages != 0); 391 392 return ret; 393} | 16#include "internal.h" 17 18/* 19 * compact_control is used to track pages being migrated and the free pages 20 * they are being migrated to during memory compaction. The free_pfn starts 21 * at the end of a zone and migrate_pfn begins at the start. Movable pages 22 * are moved to the end of a zone during a compaction run and the run 23 * completes when free_pfn <= migrate_pfn --- 363 unchanged lines hidden (view full) --- 387 } 388 389 /* Release free pages and check accounting */ 390 cc->nr_freepages -= release_freepages(&cc->freepages); 391 VM_BUG_ON(cc->nr_freepages != 0); 392 393 return ret; 394} |
395 396/* Compact all zones within a node */ 397static int compact_node(int nid) 398{ 399 int zoneid; 400 pg_data_t *pgdat; 401 struct zone *zone; 402 403 if (nid < 0 || nid >= nr_node_ids || !node_online(nid)) 404 return -EINVAL; 405 pgdat = NODE_DATA(nid); 406 407 /* Flush pending updates to the LRU lists */ 408 lru_add_drain_all(); 409 410 for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) { 411 struct compact_control cc = { 412 .nr_freepages = 0, 413 .nr_migratepages = 0, 414 }; 415 416 zone = &pgdat->node_zones[zoneid]; 417 if (!populated_zone(zone)) 418 continue; 419 420 cc.zone = zone; 421 INIT_LIST_HEAD(&cc.freepages); 422 INIT_LIST_HEAD(&cc.migratepages); 423 424 compact_zone(zone, &cc); 425 426 VM_BUG_ON(!list_empty(&cc.freepages)); 427 VM_BUG_ON(!list_empty(&cc.migratepages)); 428 } 429 430 return 0; 431} 432 433/* Compact all nodes in the system */ 434static int compact_nodes(void) 435{ 436 int nid; 437 438 for_each_online_node(nid) 439 compact_node(nid); 440 441 return COMPACT_COMPLETE; 442} 443 444/* The written value is actually unused, all memory is compacted */ 445int sysctl_compact_memory; 446 447/* This is the entry point for compacting all nodes via /proc/sys/vm */ 448int sysctl_compaction_handler(struct ctl_table *table, int write, 449 void __user *buffer, size_t *length, loff_t *ppos) 450{ 451 if (write) 452 return compact_nodes(); 453 454 return 0; 455} |
|