From patchwork Thu Feb 8 01:36:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13549216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 749E9C4828D for ; Thu, 8 Feb 2024 01:36:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07F5B6B0078; Wed, 7 Feb 2024 20:36:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 008266B007E; Wed, 7 Feb 2024 20:36:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DEBC06B0080; Wed, 7 Feb 2024 20:36:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C78876B0078 for ; Wed, 7 Feb 2024 20:36:16 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 69DAB1C1258 for ; Thu, 8 Feb 2024 01:36:16 +0000 (UTC) X-FDA: 81766921152.21.1E285D6 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf04.hostedemail.com (Postfix) with ESMTP id 6BA414000D for ; Thu, 8 Feb 2024 01:36:13 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707356174; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=hxF2avw1HAjYEofmThJzwl/rc10OF3cXC0FxT4uWahA=; b=FFMy0xsWxScZgLwZYbvWM9nbPuX15ykQYe7aCNcdO/t9CL0ovD0S35G1D65nmQX8FVaqLF qExS1llQAseZy1gQmfrQS6UJUM1hWzMWHihcj+aMOwFEayG7gpFafEK7bbGK9WiMmbGhbp ui2Uvuj2z7OGH9lA6Re4+Y5rRASa26s= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707356174; a=rsa-sha256; cv=none; b=D5bXn0dDoq0fTEXYTv5JkC9qeYBWbQZTS+tcFDtFEGRUIGRSqPKkwqsgeH1y8FBzsJDRhj qtorgbTPgHXYQPqVxZgDiaQhdB8FsrkbhjWBIyeqmt2z6ATWJB2oye/I+1elCAxiXLbPXx wb2OtjWFxDkidKv8iR5AiVGuy9+njQk= Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TVffD0ypwz29lLk; Thu, 8 Feb 2024 09:34:12 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 47E00180061; Thu, 8 Feb 2024 09:36:09 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 8 Feb 2024 09:36:08 +0800 From: Kefeng Wang To: Andrew Morton , CC: Kefeng Wang Subject: [PATCH v2] mm: compaction: refactor compact_node() Date: Thu, 8 Feb 2024 09:36:07 +0800 Message-ID: <20240208013607.1731817-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 6BA414000D X-Stat-Signature: isx8gsmwhpdkctpaa1srq8k7d9s647q5 X-Rspam-User: X-HE-Tag: 1707356173-868961 X-HE-Meta: U2FsdGVkX1+ftulD4olBjElpjkyUkVTK7Wgoivs+9tcUlWlDuH4OWR9JJh6nkiyJ0aJpjJj87K3k0gut6jFfrFjjkrFnBTuNJDFeEB2cBQrqOejpQcgjezDLHnDCbVxfuDc0LETAhMUkuEF9rOB3XCJJWwSaKUJd2prXRjpHQtlJmCNFPQwNrChrL2EIBgo/TP2JYmSmPSrsMZVElydoSP9U7xFssC3CXZnjwtzrsP7YGWltYoSBKjhfrzczYSPe/biRT2pSoFG6nlMJYJuUOEWdRLeLfyuwruWPJSVay+mw2jS5rhspZWP7EM+npgOXogIf5ji48pj6Py7g4eUxMnWDi35N+nz3YjMDF1fYAq4lCoeXBQORbdosWPaMOGE42zu/ZBRsQTdVNwV5ML+LcmwyRNXdV3a1ByI91DKt/sHSkC5/RxAn6gHe6LUECoC8+snDjgICiqVhQU9jgj39hnCtTu0kKnkZuH2z1Qo49THMNOr0aXowIqGmEhKrD05RcNaQuuJJ+StXXuJh4TlCMfYLSWVSfcXXh7ZEitbEjGy7syMOaHkB43BtdDG8luHnkgxTuxnhugXEuX7D5JmIUs7wim198he0wFcx23zCQ4i3NzKXRenYK65DqmuwesnwsXexzU5p2AlPGOvrlfixzT3k7aaATWoqsI3r69643IXE0uGrc0bKINWUoaPz1GUnshZqZiFgaR9Lj/YB7xqIHQqgZFWhYbMRhbRl8vxUq9Oz7nNSnahvyOj6JLIj+rIn6o0kulmy6EBSIzoDUUchV+7o584AAyQ59YdCD8J1YMEJQoXrrRaVW5btCUDZLu2s1pu+ZWG108LwKlhwzf71wpILot3/gmzs0sw2rjFEiUEu1XxmL6ZzA/0k+BCfNHYZWFQbz4XWHP+P+9c5+M+zEmRlDC5NidLD0fNfSuSEh6t3REmkE712Ds2OuJSJCE0/aWK1nfAumqtnwRyrR6p Ool9PHBf pdRRSdM/JIf3NfLaOCo3kk+Eri4TM8uo0jWX2+M/ZPjf8ByajudDm3nIcsOmlqEQjSemk+PeOLJfYfJLZhTcIdVcQw41U5wieCLWWpUSKssQ0PpA/auON6Qi/zuGuFn7SRFdTfruu5h4DTTyVbrN7agGRgLypv6mEohiR6MAdDlU/P+8gg64p7B1Vxd2H6usmAWRp X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Refactor compact_node() to handle both proactive and synchronous compact memory, which cleanups code a bit. Signed-off-by: Kefeng Wang Reviewed-by: Baolin Wang --- v2: - drop proactive_compact_node() and add comments for compact_node() suggested by Andrew mm/compaction.c | 65 ++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 44 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index e63a4ee7e029..de882ecb61c5 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2885,25 +2885,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 - * reaches within proactive compaction thresholds (as determined by the - * proactiveness tunable). + * compact_node() - compact all zones within a node + * @pgdat: The node page data + * @proactive: Whether the compaction is proactive * - * 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. + * For proactive compaction, compact till each zone's fragmentation score + * reaches within proactive compaction thresholds (as determined by the + * 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; struct zone *zone; struct compact_control cc = { .order = -1, - .mode = MIGRATE_SYNC_LIGHT, + .mode = proactive ? MIGRATE_SYNC_LIGHT : MIGRATE_SYNC, .ignore_skip_hint = true, .whole_zone = true, .gfp_mask = GFP_KERNEL, - .proactive_compaction = true, + .proactive_compaction = proactive, }; for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) { @@ -2915,41 +2917,16 @@ static void proactive_compact_node(pg_data_t *pgdat) compact_zone(&cc, NULL); - count_compact_events(KCOMPACTD_MIGRATE_SCANNED, - cc.total_migrate_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); + if (proactive) { + count_compact_events(KCOMPACTD_MIGRATE_SCANNED, + cc.total_migrate_scanned); + count_compact_events(KCOMPACTD_FREE_SCANNED, + cc.total_free_scanned); + } } } -/* Compact all nodes in the system */ +/* Compact all zones of all nodes in the system */ static void compact_nodes(void) { int nid; @@ -2958,7 +2935,7 @@ static void compact_nodes(void) lru_add_drain_all(); 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, @@ -3020,7 +2997,7 @@ static ssize_t compact_store(struct device *dev, /* Flush pending updates to the LRU lists */ lru_add_drain_all(); - compact_node(nid); + compact_node(NODE_DATA(nid), false); } return count; @@ -3229,7 +3206,7 @@ static int kcompactd(void *p) unsigned int prev_score, score; prev_score = fragmentation_score_node(pgdat); - proactive_compact_node(pgdat); + compact_node(pgdat, true); score = fragmentation_score_node(pgdat); /* * Defer proactive compaction if the fragmentation