summaryrefslogtreecommitdiff
path: root/mm/compaction.c
diff options
context:
space:
mode:
authorKefeng Wang <wangkefeng.wang@huawei.com>2024-02-08 10:25:08 +0800
committerAndrew Morton <akpm@linux-foundation.org>2024-02-23 17:48:31 -0800
commitf6f3f27597864d38bce5b4c346494970ecc19544 (patch)
treed39fc2ebc67485f4676dd111709e303a63d40435 /mm/compaction.c
parent55e78c933d747ed44b2b22879e6a55e5af34b9f7 (diff)
mm: compaction: early termination in compact_nodes()
No need to continue try compact memory if pending fatal signal, allow loop termination earlier in compact_nodes(). The existing fatal_signal_pending() check does make compact_zone() break out of the while loop, but it still enters the next zone/next nid, and some unnecessary functions(eg, lru_add_drain) are called. There was no observable benefit from the new test, it is just found from code inspection when refactoring compact_node(). Link: https://lkml.kernel.org/r/20240208022508.1771534-1-wangkefeng.wang@huawei.com Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/compaction.c')
-rw-r--r--mm/compaction.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/mm/compaction.c b/mm/compaction.c
index f146478b01bc..52ff6b9344c7 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -2808,7 +2808,7 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
* reaching score targets due to various back-off conditions, such as,
* contention on per-node or per-zone locks.
*/
-static void compact_node(pg_data_t *pgdat, bool proactive)
+static int compact_node(pg_data_t *pgdat, bool proactive)
{
int zoneid;
struct zone *zone;
@@ -2826,6 +2826,9 @@ static void compact_node(pg_data_t *pgdat, bool proactive)
if (!populated_zone(zone))
continue;
+ if (fatal_signal_pending(current))
+ return -EINTR;
+
cc.zone = zone;
compact_zone(&cc, NULL);
@@ -2837,18 +2840,25 @@ static void compact_node(pg_data_t *pgdat, bool proactive)
cc.total_free_scanned);
}
}
+
+ return 0;
}
/* Compact all zones of all nodes in the system */
-static void compact_nodes(void)
+static int compact_nodes(void)
{
- int nid;
+ int ret, nid;
/* Flush pending updates to the LRU lists */
lru_add_drain_all();
- for_each_online_node(nid)
- compact_node(NODE_DATA(nid), false);
+ for_each_online_node(nid) {
+ ret = compact_node(NODE_DATA(nid), false);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
}
static int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
@@ -2894,9 +2904,9 @@ static int sysctl_compaction_handler(struct ctl_table *table, int write,
return -EINVAL;
if (write)
- compact_nodes();
+ ret = compact_nodes();
- return 0;
+ return ret;
}
#if defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)