Commit 3e40b3f4 authored by Kefeng Wang's avatar Kefeng Wang Committed by Andrew Morton

mm: compaction: refactor compact_node()

Refactor compact_node() to handle both proactive and synchronous compact
memory, which cleanups code a bit.

Link: https://lkml.kernel.org/r/20240208013607.1731817-1-wangkefeng.wang@huawei.comSigned-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: default avatarBaolin Wang <baolin.wang@linux.alibaba.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent b9ad003a
...@@ -2796,25 +2796,27 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, ...@@ -2796,25 +2796,27 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
} }
/* /*
* Compact all zones within a node till each zone's fragmentation score * compact_node() - compact all zones within a node
* reaches within proactive compaction thresholds (as determined by the * @pgdat: The node page data
* proactiveness tunable). * @proactive: Whether the compaction is proactive
* *
* It is possible that the function returns before reaching score targets * For proactive compaction, compact till each zone's fragmentation score
* due to various back-off conditions, such as, contention on per-node or * reaches within proactive compaction thresholds (as determined by the
* per-zone locks. * proactiveness tunable), it is possible that the function returns before
* reaching score targets due to various back-off conditions, such as,
* contention on per-node or per-zone locks.
*/ */
static void proactive_compact_node(pg_data_t *pgdat) static void compact_node(pg_data_t *pgdat, bool proactive)
{ {
int zoneid; int zoneid;
struct zone *zone; struct zone *zone;
struct compact_control cc = { struct compact_control cc = {
.order = -1, .order = -1,
.mode = MIGRATE_SYNC_LIGHT, .mode = proactive ? MIGRATE_SYNC_LIGHT : MIGRATE_SYNC,
.ignore_skip_hint = true, .ignore_skip_hint = true,
.whole_zone = true, .whole_zone = true,
.gfp_mask = GFP_KERNEL, .gfp_mask = GFP_KERNEL,
.proactive_compaction = true, .proactive_compaction = proactive,
}; };
for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) { for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) {
...@@ -2826,41 +2828,16 @@ static void proactive_compact_node(pg_data_t *pgdat) ...@@ -2826,41 +2828,16 @@ static void proactive_compact_node(pg_data_t *pgdat)
compact_zone(&cc, NULL); compact_zone(&cc, NULL);
count_compact_events(KCOMPACTD_MIGRATE_SCANNED, if (proactive) {
cc.total_migrate_scanned); count_compact_events(KCOMPACTD_MIGRATE_SCANNED,
count_compact_events(KCOMPACTD_FREE_SCANNED, cc.total_migrate_scanned);
cc.total_free_scanned); count_compact_events(KCOMPACTD_FREE_SCANNED,
} cc.total_free_scanned);
} }
/* Compact all zones within a node */
static void compact_node(int nid)
{
pg_data_t *pgdat = NODE_DATA(nid);
int zoneid;
struct zone *zone;
struct compact_control cc = {
.order = -1,
.mode = MIGRATE_SYNC,
.ignore_skip_hint = true,
.whole_zone = true,
.gfp_mask = GFP_KERNEL,
};
for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) {
zone = &pgdat->node_zones[zoneid];
if (!populated_zone(zone))
continue;
cc.zone = zone;
compact_zone(&cc, NULL);
} }
} }
/* Compact all nodes in the system */ /* Compact all zones of all nodes in the system */
static void compact_nodes(void) static void compact_nodes(void)
{ {
int nid; int nid;
...@@ -2869,7 +2846,7 @@ static void compact_nodes(void) ...@@ -2869,7 +2846,7 @@ static void compact_nodes(void)
lru_add_drain_all(); lru_add_drain_all();
for_each_online_node(nid) for_each_online_node(nid)
compact_node(nid); compact_node(NODE_DATA(nid), false);
} }
static int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write, static int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
...@@ -2931,7 +2908,7 @@ static ssize_t compact_store(struct device *dev, ...@@ -2931,7 +2908,7 @@ static ssize_t compact_store(struct device *dev,
/* Flush pending updates to the LRU lists */ /* Flush pending updates to the LRU lists */
lru_add_drain_all(); lru_add_drain_all();
compact_node(nid); compact_node(NODE_DATA(nid), false);
} }
return count; return count;
...@@ -3140,7 +3117,7 @@ static int kcompactd(void *p) ...@@ -3140,7 +3117,7 @@ static int kcompactd(void *p)
unsigned int prev_score, score; unsigned int prev_score, score;
prev_score = fragmentation_score_node(pgdat); prev_score = fragmentation_score_node(pgdat);
proactive_compact_node(pgdat); compact_node(pgdat, true);
score = fragmentation_score_node(pgdat); score = fragmentation_score_node(pgdat);
/* /*
* Defer proactive compaction if the fragmentation * Defer proactive compaction if the fragmentation
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment