From patchwork Sat Aug 26 15:36:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13366515 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 45E17C83F01 for ; Sat, 26 Aug 2023 07:36:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0CD0440150; Sat, 26 Aug 2023 03:36:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBDBC44014C; Sat, 26 Aug 2023 03:36:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5DC6440150; Sat, 26 Aug 2023 03:36:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id AA0A944014C for ; Sat, 26 Aug 2023 03:36:45 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 66E1B1C8CD8 for ; Sat, 26 Aug 2023 07:36:45 +0000 (UTC) X-FDA: 81165448770.03.8662FDC Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf26.hostedemail.com (Postfix) with ESMTP id 0105014000E for ; Sat, 26 Aug 2023 07:36:42 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=none (imf26.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693035403; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AjXZUiTH42XzAW/K/LgNIkF4R91T1F6yHcSixziYi1o=; b=XRe+Mef/4CtqnnnaAAjRpf7pVp/Lg+E/ZjoHeMu+HOvpnESFgq6rku9/OLiBsP+Y7Rlnhe IlbaF3/43Ty5LOE8KeeLtCYx3ZyoVcoNIxAOEL679dH7I8yTUu0RUtmSF6gDRxghA5gmkG rscnQ18ZL/2nJbQfyZEa7fcsHVDp+aM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=none (imf26.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693035403; a=rsa-sha256; cv=none; b=wACnid4O8hJN7o2bSFZSOzWrgkX/AlqoelemcfXOemSZpL+U7+JQujgsYDfU1/EAdBfKLN OVep7unO3hdAQW54ACZ8X7SfF99KFNMm6MXqDiuI41CRr0FcbutXmSSJFVJ9nnOwFt1cYF KkqtLY6HD33jRgH0rmWn7OOHumpRr5Y= Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4RXpXt74SVz4f3lDK for ; Sat, 26 Aug 2023 15:36:30 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP1 (Coremail) with SMTP id cCh0CgDHQi98q+lk6GgZBg--.2153S9; Sat, 26 Aug 2023 15:36:32 +0800 (CST) From: Kemeng Shi To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, mgorman@techsingularity.net, david@redhat.com, willy@infradead.org Cc: shikemeng@huaweicloud.com Subject: [PATCH v2 7/7] mm/compaction: factor out code to test if we should run compaction for target order Date: Sat, 26 Aug 2023 23:36:17 +0800 Message-Id: <20230826153617.4019189-8-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230826153617.4019189-1-shikemeng@huaweicloud.com> References: <20230826153617.4019189-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgDHQi98q+lk6GgZBg--.2153S9 X-Coremail-Antispam: 1UD129KBjvJXoWxJFW8Gr43KrWxCw1fKr47XFb_yoW5tF4fpF yxur13t395XF13GrWxta18JF45Xw4xGF1Utwsrt3s7Aw1ayayvv3Wkta4xAFWUXry3JF4j qFWFgF9rKanxAaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_JF0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0 rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6x IIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK 6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4 xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8 JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20V AGYxC7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRvJPtU UUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 0105014000E X-Rspam-User: X-Stat-Signature: 6r5p98g97k5xia1gybuawucqymtm3ykt X-Rspamd-Server: rspam01 X-HE-Tag: 1693035402-841183 X-HE-Meta: U2FsdGVkX1+tOvvG6AAaz6ah7FZNCgUvX8U1meSWaelwUPiHWCyI857CnlaDHGLza2L3Kdltp8ELAJDquDDdQqeOUBD0YSH94oS14Wg3/51szOqXPx/lWBdPL2Esicge5Hkfx7uFxZAG/dwtS39pYYMlgC0E7Q3p02UFzzRc2d8MtSWYcQOk0j5D/2xFIIcbduz3YrN5+LC9KA3PTjnqk/qmDEVJB83WtmtyXCNDTgIvwzoeLK67tn34Ds7FseVPzdS14NRJRiNFiaLlVc+Eq9w/v44fAV4dVpBkPOjlX2lWH/MxVeCSyMMBg8p9PaEahFU5NzNKhZtF1hxxgiPhA7MoHUiu1CZJEC1YNRJDQdQUjuo8QjVDrP08fyDdQL3hPlmWBMnxQxQNyNy2V1cweJsnxD/YtGWu/lAyk/hXTvkyiAhJE7zSdO0g54MQdYUXLGCtRz/oEAV6bUtJsUI8Gzf0bNAXmXN0Vhmb1+NHf6vzxAl63Zb0jex7VYVfHbIqoOUkXja9LqnZflEDuxRM1flBCATheGNNh+Sdt0Xar8qIOcpHfLFBb8nrTYlo1NT26vz2HWfLiq0jHzCi8cti7EBgkG8UoMcmVEdTHvgrr+9xDAJvWAQv9tKIB7ys1FxF5ps5Z+1zp9+Y5DNG5PJnCZzExQtvoXgX0rZq059AGjBLqvCgleN6VTamHtAmWP9ckyMiB8acO1rYb4s1395M3hFYegsOEYWYhN0BQfynTLnbS2cBB2BsUjgG2cv3KXPE1WcAyDicsWzrVic+KoGacw3ndWneZmg+md51gixXMoRkYRmQ9xKzlZUa8PuvJ87qxWjEqIwFvrJfHji9UD1X/1A5uw+Q+u2kNf6SLqT4xfWE8T817Th2jjeAq7gMUJU85UN6y52fybNocxlvHw9Ha5ynAOGpOzLxDrnJFPZK8dSaP9WvEN73D+hXzOdem0Y+CZFjA2RuZPZJCA67YLp kBljXpCy 2tzRD586Eb29qC8v3GeJEo8z3lgvVbpuoebbc5X0W8WcoMd0EMivlCz9F4/h0m7e5aGoYJ54OcssncBjsLM7Xdji6A0hK0bxX+Yn0V6rj5EtdqG/kaK3F9xc28txQWnPdSmUa9M72XkUpZ+7rGFy7P6E3/8ZAuZ1CrgYvgsjtY5YAf8tDYmT2KaFSSpypUSBlte5Ba/gBGiSPtAk7JNXLaCfA295GE1RiDvJ/m2JE8YYnYD/CMypXklCxxZqMdKLez+bfsoA9RGjtfCqsmsfzyWWyqkZY3caZN5rb 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 runned. Factor these code out to remove repeat code. Signed-off-by: Kemeng Shi Reviewed-by: Baolin Wang --- mm/compaction.c | 63 ++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 00b7bba6c72e..6f2b87b026b8 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2374,6 +2374,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 runned + */ +static inline 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) { @@ -2399,19 +2423,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; } /* @@ -2917,14 +2933,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)) + if (compaction_suit_allocation_order(zone, + pgdat->kcompactd_max_order, + highest_zoneidx, ALLOC_WMARK_MIN) == + COMPACT_CONTINUE) return true; } @@ -2961,12 +2973,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)) + if (compaction_suit_allocation_order(zone, + cc.order, zoneid, ALLOC_WMARK_MIN) != + COMPACT_CONTINUE) continue; if (kthread_should_stop())