From patchwork Wed Feb 7 09:58:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13548273 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 CEAFFC4828F for ; Wed, 7 Feb 2024 09:58:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CCCB6B0071; Wed, 7 Feb 2024 04:58:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 07D586B0072; Wed, 7 Feb 2024 04:58:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EADDB6B0074; Wed, 7 Feb 2024 04:58:54 -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 DAC936B0071 for ; Wed, 7 Feb 2024 04:58:54 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 784441C1693 for ; Wed, 7 Feb 2024 09:58:54 +0000 (UTC) X-FDA: 81764558988.10.9EDD46F Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf03.hostedemail.com (Postfix) with ESMTP id 29C5A20010 for ; Wed, 7 Feb 2024 09:58:50 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.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=1707299932; 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=2qRlToEUTkDJj+ivnNlMpke9L+rkDMnsDKtd1jzOuTQ=; b=rzcSzCmMMDbT0+hae7lZqdLuSbBbO6+pmRSMEAobt2r1eZ4+yIwJWRBgYMZ8wOHKLYjo2p nT3mR28IvN+1H+B9B1Be+vuXv9CNfcxS6gTBkZ2FZB3MjLZFFFQTNgOAl7w75JHhggK/+0 5Q87cdsEo6BQ8hbFFkeJFAvkGWztD94= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.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=1707299932; a=rsa-sha256; cv=none; b=afIS29IR28tABWGQGmuDEgR8x6W9Rx9hjPpLs/2gd3tnm2RMmub961bol5RGdjTWGpYv1z hwrql3yZZ15wyCh46UXM4aT/qRCivy4PIAsV3QkYrNE996LZcqLdmLfHvi04bBwNQscaWF qayHCsriPWz9NMlyf4eH/TqLiORgwlQ= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TVFsb3ZbTz1xnN6; Wed, 7 Feb 2024 17:57:39 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 035B914025A; Wed, 7 Feb 2024 17:58:47 +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; Wed, 7 Feb 2024 17:58:46 +0800 From: Kefeng Wang To: Andrew Morton CC: , Kefeng Wang Subject: [PATCH] mm: compaction: refactor compact_node() Date: Wed, 7 Feb 2024 17:58:41 +0800 Message-ID: <20240207095841.1648144-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: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Queue-Id: 29C5A20010 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ja3f17wr7sti7k1b9jy4za147c46xcoe X-HE-Tag: 1707299930-433589 X-HE-Meta: U2FsdGVkX1/kLuc5hUMpu1Lio3URmdwN5esn8JT9owoPQkCvT5EhhbY6TtAxBywCV3kvogm29z74R49OjlDoJCTdgneQydJY+cjzf/g0sfIYfKHZAZ1BTcjPHDdbxXO+wtHsH7KbUEgIsI/40cE7scIC1ufM6uBQQZBJ8NtvmgNvryiZS6CkJOCGYGVIvJDVD0DBHMsHZhr9b/MwBZvkoW8JuAcxhgWf/kJWL/GtC78MbJfSDFZ059jTzUg2C3jTC2D7PuLXUPLU6FNxsfpVEDaNR9y3PJ5t3U+VT6OE7p2t5ns3DV7f5mxjQuU2FQyBbZdqaoP0KaC4WgQCRrDLh+hkWNnNW5tnBkE4HAaKeSIE/7a11QcSzMR8iaj55iWrEhwZh5StXSvMKrc/+k0/d28JlDTQVnkrwPQeTRad4eWQaCOpMkmPNWBoUktimzk1mII63sfymYPI+S6nLa0ipilvRfa6VwL/EuHWv76Rq8Iqa9DzxpwSmWbfltjtf5stIsH6BHKKhVQsM5FmZu32n6q/Xq0CWqDX9HM7cIRwrpIhsEJ5u409BPnkrTs+EjAP/z2ILARyPhzmXx7YfnfF3RYqzlbvBiIpXqtPu/tGazbJUepw0VOF3J/OaeutIHZGlgT/K6EuSywwV5rPkqNPud61HbB/Xb7+o4hgw8O5lIn3aI89dQOjXR0nGd9XnoItl+S2cvBgHTy6iCLFqfar0dTAFykDReuFaT7GcvZdG4NL1+Vabf9tPmKrOnfhBf5AEGRivkd5fwGrsw5ZHY/Wk4+rQ9dM7vq4gztZcHUbph/Ew920nPY6VHsw8vfv2Xnfn1XrTiKpX3BJPq19zqQLQe/bBvT5wqjFpdGk8UsQut4hTa1DttKjH2Zg88SMJFe2YWWJUh8eeK3LUZ5v+nuTxrmVDjhSl00IwjR3nVqWn8SR4t62pBnlztHDkyiI9nWWtW1iGcHVnKyv537uvYM e7lmKD+b /CjpnsaOhvv2FNkEpHj07kWTIvAfb0bQlEf2VcEIrRNndycR4kuhchLerOVqeqyHHnEaIjc8pbnL1gW7gx1r91CanCRJFKq/7+M4HwRc5UYzzFXNU5AvPzJZMaubPNR1vUKYhhQaWsgxUzeAd9mcqExzNQpFFYf4WKCdZnxGxR1H706UaO4Dd8XSn5sDFwMbKEufo 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 --- mm/compaction.c | 66 +++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index e63a4ee7e029..f2d886a88ee1 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2884,26 +2884,17 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, return rc; } -/* - * Compact all zones within a node 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 +2906,30 @@ 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); + if (proactive) { + 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) +/* + * Compact all zones within a node 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) { - 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_node(pgdat, true); } -/* Compact all nodes in the system */ +/* Compact all zones of all nodes in the system */ static void compact_nodes(void) { int nid; @@ -2958,7 +2938,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 +3000,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;