From patchwork Wed Jan 31 13:16:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13539453 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 0076AC47DB3 for ; Wed, 31 Jan 2024 13:16:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5468A6B0080; Wed, 31 Jan 2024 08:16:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F2F16B0081; Wed, 31 Jan 2024 08:16:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E2926B0082; Wed, 31 Jan 2024 08:16:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2E88B6B0080 for ; Wed, 31 Jan 2024 08:16:51 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C03C5A2340 for ; Wed, 31 Jan 2024 13:16:50 +0000 (UTC) X-FDA: 81739656180.24.2B756BA Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf22.hostedemail.com (Postfix) with ESMTP id 7AB0FC001E for ; Wed, 31 Jan 2024 13:16:46 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=JZmxo1ii; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf22.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706707008; 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:references:dkim-signature; bh=R4BfaarR7H+2VERwphKn+Lf333CX+5PuQuJGhvUGjOc=; b=uxnGD4R8BpbGfJPSkmwR0ouyMHjBtQ6IzU/Dd4KyjehnQqZ/SI/Hfi/06Cmz9diGNjlM4B hIHyJIYB4rt2sY5592dU5jEexjvHSEAOomzHvJga38DCfL9pswyD6jilYIXCY4/9x2i9PZ 0c2ncqA44sRHgk9r73ICOHAS4lRuZKU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=JZmxo1ii; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf22.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706707008; a=rsa-sha256; cv=none; b=4WQqwpA2/ENGzH5R9qWWMW/MW3srXTzRNtV2JzKXdzCDdJkpvwamiGYHy/YwlDS4mCATix nXQmtZTsaIjYRKJedjM7QmwaguQKV+r27LaBKWIzF61or0gdqj0EMYSIulsPLTM91Pn9xl g9mkcyiYmmzARxTPAhE6qoLaawN1Vwk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1706707003; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=R4BfaarR7H+2VERwphKn+Lf333CX+5PuQuJGhvUGjOc=; b=JZmxo1ii5jxqtCbBIC4cv78oIDn8OzE79ujXrULStacHpRb/+4iVsEi9FQIDulahxlqz8qKHec96myzMbBFDazAtoAf4W7jPQxFzTzOtyQ9AZM2woD/zBBKdTI5ASQ/+PafRhcUBWWn3OYMJbUMoCeVr+2cs+9OceEoOKIuqTfo= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R711e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0W.jsM4d_1706707001; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W.jsM4d_1706707001) by smtp.aliyun-inc.com; Wed, 31 Jan 2024 21:16:42 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, vbabka@suse.cz, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm: compaction: update the cc->nr_migratepages when allocating or freeing the freepages Date: Wed, 31 Jan 2024 21:16:26 +0800 Message-Id: <994af744828efe3c060128445204a56ab41e3ebb.1706706820.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 7btsfcgqwiid8rkq11rwurk4n4krjq1u X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7AB0FC001E X-HE-Tag: 1706707006-936234 X-HE-Meta: U2FsdGVkX1+7Akk4R8jfQm4uBsGHq8pqBhyDJUy7AzxsYl6xa36LTbS7MXJEfHJsBW5JRIdZcIVbpCZZlXkvqE57p9BORwkxJhOw8lt2V/NPiO2+hXUqqH58TRO8lp+r3k3x5t3sYKGX+ymXP7qekX2cLHjMQOSRUaHQtYPJBEO1rELVBzZ7MzrSp2I0GDC2BPDFSj8usr+9T8/yZbhj/wKroe0HYbEHcCfdUPeIxA+v7mvDjPPoLg+0DTsaT1hDV2F16C06RZBXorVRsSM5M541VySOMAEJN9UroAE/UMK8ZA3UEZTiqAu/ijN5krUQ6Rko6r+ICys/fnMtCR+6ObzmRtiL9JJgmFCbJsKAxFJtuBTUTGEEMtCVzW4sDgIXkT3oPPn8kAVSjpsW+JeMSOXcpo28Ot14HG0qHgnt8PaCRz0b3XygKOU00FawalIqjtIIzCVotDE1uAatwNqhuhiOJgNsMJp7Cxs1KS3U11uADkJgG1uw4TZvI4ayEJJAcygaTJl9xZODdbkfZ/9qGjFmlcf5g+8nYS27vi/kPJBUhKea1LsxTWun+KLvzQzyDqIxoQXnikmaMj+ghjNNIXmBpFbVqQ1OKzDT9G66n4fe5lf2vWulZhmqiJkV8Ad4AJdXVXnYhqygSViRQYi9p82qMMVDBwbD0HhklZcytEaNxfrcBhabgZwparAfJ8Jo09HcRyrnb8E3Oq9od0s5JGC4mZ0bfzdNrjPNOsILOHosKxuLSNK0uyY1m0sJwJqMqKPU84C4h81YBsbm8ODI7n66OgmuesAfqmkcEb2fvehbf3mlP50jEFYVU18blwPt+sdnztQup7XGr1UO3fDcWPxR6ygfeAlGSkAT8KhMR3XzJI+6CAAmWRvkQqSti4aG2a4x30Dk8qa3APEBRpomldI2uUiSWor8y3rR0o0J2R2csvNIBZxpR9Blx/HqFCDMunu0lI5uo92pZ0z9VIw Y0J+eWQW Ij6syS4V+u2wKbsElFMs553Z5xhX2nlJomptW0BYEJ0gA/QZO+D2l/0jrWsnDCmu/nibzgPimIaonsOAF8ZECxm4B8LVHKDyXV9Zn2aouj+pLyQ4YbjiRX0A2tgXcejiNQ7RP2IiQnwr0nvaljtNVH0kbw8u974ZKWj0QTLuv8qTtixXzYiLwb4Szo6jMbfiSp6ForoFW//TI4eKUi0MQBXGWma5t302vy9C4tJ3VDfo4ocpKmIjoex6L3kbnTdvuQaN8j1zktfs4IMA= 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: Currently we will use 'cc->nr_freepages >= cc->nr_migratepages' comparison to ensure that enough freepages are isolated in isolate_freepages(), however it just decreases the cc->nr_freepages without updating cc->nr_migratepages in compaction_alloc(), which will waste more CPU cycles and cause too many freepages to be isolated. So we should also update the cc->nr_migratepages when allocating or freeing the freepages to avoid isolating excess freepages. And I can see fewer free pages are scanned and isolated when running thpcompact on my Arm64 server: k6.7 k6.7_patched Ops Compaction pages isolated 120692036.00 118160797.00 Ops Compaction migrate scanned 131210329.00 154093268.00 Ops Compaction free scanned 1090587971.00 1080632536.00 Ops Compact scan efficiency 12.03 14.26 Moreover, I did not see an obvious latency improvements, this is likely because isolating freepages is not the bottleneck in the thpcompact test case. k6.7 k6.7_patched Amean fault-both-1 1089.76 ( 0.00%) 1080.16 * 0.88%* Amean fault-both-3 1616.48 ( 0.00%) 1636.65 * -1.25%* Amean fault-both-5 2266.66 ( 0.00%) 2219.20 * 2.09%* Amean fault-both-7 2909.84 ( 0.00%) 2801.90 * 3.71%* Amean fault-both-12 4861.26 ( 0.00%) 4733.25 * 2.63%* Amean fault-both-18 7351.11 ( 0.00%) 6950.51 * 5.45%* Amean fault-both-24 9059.30 ( 0.00%) 9159.99 * -1.11%* Amean fault-both-30 10685.68 ( 0.00%) 11399.02 * -6.68%* Signed-off-by: Baolin Wang --- Changes from v1: - Rebased on the latest mm-unstable branch. --- mm/compaction.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 055687e6bd17..363c3e49fe80 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1882,6 +1882,7 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) if (order) prep_compound_page(&dst->page, order); cc->nr_freepages -= 1 << order; + cc->nr_migratepages -= 1 << order; return page_rmappable_folio(&dst->page); } @@ -1904,6 +1905,7 @@ static void compaction_free(struct folio *dst, unsigned long data) list_add(&dst->lru, &cc->freepages[order].pages); cc->freepages[order].nr_pages++; cc->nr_freepages += 1 << order; + cc->nr_migratepages += 1 << order; } /* possible outcome of isolate_migratepages */