From patchwork Fri Sep 1 15:51:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13372168 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 902CBCA0FE9 for ; Fri, 1 Sep 2023 07:52:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12E118D0022; Fri, 1 Sep 2023 03:52:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DDC38D0002; Fri, 1 Sep 2023 03:52:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBF8B8D0022; Fri, 1 Sep 2023 03:52:17 -0400 (EDT) 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 DE0E48D0002 for ; Fri, 1 Sep 2023 03:52:17 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B2424120170 for ; Fri, 1 Sep 2023 07:52:17 +0000 (UTC) X-FDA: 81187260714.18.9FB9D82 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf06.hostedemail.com (Postfix) with ESMTP id 40CF4180018 for ; Fri, 1 Sep 2023 07:52:14 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=none; spf=none (imf06.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693554736; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mN73l8G61ghV59udGjlIFAJtpqlW1LFDFmlIeaJRrjo=; b=yvKXfpuZytvz4V2I8VgPB+x9JQ8jV6sI1Cbpt1W79WLgVWLqEzPHZteloRyUVPf4Ja2f30 J9Uaq/LKkmBXF7Sd6EpfmwYPNLX1/zt/zvhHRs3uQ3FUN0vlGzOg2x+E4RRuGmUl/lLbkI cqLi1TPY6yTKthHle4kROTSyAiIvHL8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=none; spf=none (imf06.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693554736; a=rsa-sha256; cv=none; b=CwmNV+C53QGx3KVVSs7By69ghLtM3UH61l4g97sGKv4JpSjzIEGWdnlkzXlschAEsq8lQB Bw5BcQd5+DkzmxL7KTt9y2GOl0Orj5XLdybNpwm7M/T3o1a9RRlzeStrNv0vK2YE4BxX99 tiedCyIFnPEbsFU7WcPf6GchXKnhS00= Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4RcVc123jZz4f3m7b for ; Fri, 1 Sep 2023 15:52:01 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgDnw6YfmPFk1Z5cCA--.13825S8; Fri, 01 Sep 2023 15:52:02 +0800 (CST) From: Kemeng Shi To: akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, mgorman@techsingularity.net, david@redhat.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/6] mm/compaction: factor out code to test if we should run compaction for target order Date: Fri, 1 Sep 2023 23:51:41 +0800 Message-Id: <20230901155141.249860-7-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230901155141.249860-1-shikemeng@huaweicloud.com> References: <20230901155141.249860-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDnw6YfmPFk1Z5cCA--.13825S8 X-Coremail-Antispam: 1UD129KBjvJXoWxGr1xGry3Jr4xKF17ZrW5Wrg_yoWrAryUpF y8Wry3t395XF17GFWxtF48XF15Xw4xJF1UtwsFq3s7Aw1aya1vv3Wkta4UZFWUX343JF4j qF4FgF1DKanrAaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAv FVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3w A2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE 3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr2 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUIL05UUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 40CF4180018 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: doxtosxfacb16czwt1gthbrk4yt6j1s3 X-HE-Tag: 1693554734-824723 X-HE-Meta: U2FsdGVkX1+rK5t/WS1yPRGhNlyJNpSSa4iRdY1GBSDok52dSxP+MTXHAhYqf9Cv3q3GWRjBU6GiH04R+9W1hkwSo+TqfwlG+mz4LNuk7OKcjazz3yRm96CadSfhFR8rjzkbkePkRxQpsNA2PjYV2WDBEgrWrTHYIBkrs+/d7oKl2RUy6egJmcIxekoL3BrzTCVfsmq6lbwJSHeKeCi+M876U7EuYa71wJb+zPJybHaa43UqI4f2jlYsteORGMbga12W5FSrNlieUoWn7dkL7VKqdOKMfbLjSqI35pWMu4sgQdlfXp88C6Hr1/For0nSg48LgQnTxDMNeR6XAFlno+0XRrkvWHwGemhaBbo7kp3C29LPlhqT6BQWKxulRLnbC98dhq5KVWVGox9c+O85IVhyAO9CxHW0OXdU6JxCYXD4QaFqTUOkh0okUxcQ7ZjtacVd2JCe5kW6e6CgWqoxsPAVmnN01XSqUg8X/x+qI4E9rDtMNL+t0+sPI8keYjI3dUrQvyQFbl1GfWxCxUNi9g0mDV/CxpR7WnZ3sq+9kaXm55pfr84zoAg3MXHlQtV273ATp95kAdtF8Dn2R5cMyxVZbjQh9a3oYiWyweP+iGx8m/HBI0rubCxQmrsbcpUnSMe4fhaE7pRChGKi0fB4yF2pAQ5i8g6e92byjpZ9cgRbkfsa/44rudowpF5VsYcuqMy2KxNtFidE4t79sR9nLWUvfI2NV+mlFsxXsdI3D2jQDNYPgRWWZEjLAxUYapRVij/y9t8p7rJLJm73lNrpT2jfGu6C5T6DzY+qgSc0Gox8i5LqTj21In/HtO2NFnf4A5gHHZyZRmWvU4FFfQ4BS0st+gatnloeXJsAGR34jELaXlhdxj6NC168Qh55ZRAsSHQ/cU9Q+k3LqSQIvL54KhkV1wSHkfmG5qfNc/CQ4b89QHARuvuPKMilacuMJ9ZOHx7zN4ovfZzgYJ4jXIi U8RzSa9M WIEL0gVAMHVhN0F8o1SZR88YOrLUOBdt3jL1PxhceKKMtXdSuO7W2yxIdO4zcKbZHgPsl2QPwYieOuFZViJjDvf642TV2X5jbUum+hJaE7pN0OAHghki0khszETtaTV1EVmgyG6cd5xNREYiFaRmIe/8/NvEZsFifzJcUxY8jPv+j+BpUkivjzkdhesQxoW+pvet/ncbOiPXJfjYG7DkeOBLExzT7CT0VdhY0Eqwbfio4NhcZ9IKs0K6FDC0A+1XPuI6qGnA1eJjhO9v5jwJBcAOnrsdYRYkdrLYgZm/vmn6l7MB3hkpxR7QlxAFNFJoR8w99lREqTardSRCkHb6gtOdGTxPvA2aH9gZiUN6ecQMXShI= 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: We always do zone_watermark_ok check and compaction_suitable check together to test if compaction for target order should be ran. Factor these code out to remove repeat code. Signed-off-by: Kemeng Shi Reviewed-by: Baolin Wang --- mm/compaction.c | 66 +++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index ff3426a0d9c5..1940e8693638 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2378,6 +2378,30 @@ bool compaction_zonelist_suitable(struct alloc_context *ac, int order, return false; } +/* + * Should we do compaction for target allocation order. + * Return COMPACT_SUCCESS if allocation for target order can be already + * satisfied + * Return COMPACT_SKIPPED if compaction for target order is likely to fail + * Return COMPACT_CONTINUE if compaction for target order should be ran + */ +static enum compact_result +compaction_suit_allocation_order(struct zone *zone, unsigned int order, + int highest_zoneidx, unsigned int alloc_flags) +{ + unsigned long watermark; + + watermark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK); + if (zone_watermark_ok(zone, order, watermark, highest_zoneidx, + alloc_flags)) + return COMPACT_SUCCESS; + + if (!compaction_suitable(zone, order, highest_zoneidx)) + return COMPACT_SKIPPED; + + return COMPACT_CONTINUE; +} + static enum compact_result compact_zone(struct compact_control *cc, struct capture_control *capc) { @@ -2403,19 +2427,11 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) cc->migratetype = gfp_migratetype(cc->gfp_mask); if (!is_via_compact_memory(cc->order)) { - unsigned long watermark; - - /* Allocation can already succeed, nothing to do */ - watermark = wmark_pages(cc->zone, - cc->alloc_flags & ALLOC_WMARK_MASK); - if (zone_watermark_ok(cc->zone, cc->order, watermark, - cc->highest_zoneidx, cc->alloc_flags)) - return COMPACT_SUCCESS; - - /* Compaction is likely to fail */ - if (!compaction_suitable(cc->zone, cc->order, - cc->highest_zoneidx)) - return COMPACT_SKIPPED; + ret = compaction_suit_allocation_order(cc->zone, cc->order, + cc->highest_zoneidx, + cc->alloc_flags); + if (ret != COMPACT_CONTINUE) + return ret; } /* @@ -2914,6 +2930,7 @@ static bool kcompactd_node_suitable(pg_data_t *pgdat) int zoneid; struct zone *zone; enum zone_type highest_zoneidx = pgdat->kcompactd_highest_zoneidx; + enum compact_result ret; for (zoneid = 0; zoneid <= highest_zoneidx; zoneid++) { zone = &pgdat->node_zones[zoneid]; @@ -2921,14 +2938,10 @@ static bool kcompactd_node_suitable(pg_data_t *pgdat) if (!populated_zone(zone)) continue; - /* Allocation can already succeed, check other zones */ - if (zone_watermark_ok(zone, pgdat->kcompactd_max_order, - min_wmark_pages(zone), - highest_zoneidx, 0)) - continue; - - if (compaction_suitable(zone, pgdat->kcompactd_max_order, - highest_zoneidx)) + ret = compaction_suit_allocation_order(zone, + pgdat->kcompactd_max_order, + highest_zoneidx, ALLOC_WMARK_MIN); + if (ret == COMPACT_CONTINUE) return true; } @@ -2951,6 +2964,8 @@ static void kcompactd_do_work(pg_data_t *pgdat) .ignore_skip_hint = false, .gfp_mask = GFP_KERNEL, }; + enum compact_result ret; + trace_mm_compaction_kcompactd_wake(pgdat->node_id, cc.order, cc.highest_zoneidx); count_compact_event(KCOMPACTD_WAKE); @@ -2965,12 +2980,9 @@ static void kcompactd_do_work(pg_data_t *pgdat) if (compaction_deferred(zone, cc.order)) continue; - /* Allocation can already succeed, nothing to do */ - if (zone_watermark_ok(zone, cc.order, - min_wmark_pages(zone), zoneid, 0)) - continue; - - if (!compaction_suitable(zone, cc.order, zoneid)) + ret = compaction_suit_allocation_order(zone, + cc.order, zoneid, ALLOC_WMARK_MIN); + if (ret != COMPACT_CONTINUE) continue; if (kthread_should_stop())