From patchwork Mon Jan 27 21:46:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBDxYJhcGnFhHNraQ==?= X-Patchwork-Id: 13951748 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 79A19C02188 for ; Mon, 27 Jan 2025 21:47:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 097F32801B2; Mon, 27 Jan 2025 16:47:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 045FB2801B0; Mon, 27 Jan 2025 16:47:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E500E2801B2; Mon, 27 Jan 2025 16:47:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C2E1A2801B0 for ; Mon, 27 Jan 2025 16:47:09 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7E349160727 for ; Mon, 27 Jan 2025 21:47:09 +0000 (UTC) X-FDA: 83054567778.04.59F206E Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf11.hostedemail.com (Postfix) with ESMTP id AE9A640019 for ; Mon, 27 Jan 2025 21:47:07 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=iBckJDMJ; spf=pass (imf11.hostedemail.com: domain of 32v6XZwoKCHslbkZohmrjhfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--mclapinski.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=32v6XZwoKCHslbkZohmrjhfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--mclapinski.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738014427; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7UVb+GoBBSHoiZedLFy6B8b5YfCszIM+0jeoCG22gAA=; b=5stBZHK+cJreBFRtSCznBihYOv9m1goZo+tWVvH/hGBntJIaUAfB/y6UgeKpDSYs/Hhrjg oHyBoAgEjBgFC2SMqA/pMBGGmH+yKSIBQ4cvfAg4xXYJt/7snZfUIYE7sCsPA7SYSrmNPj uvbAACbzhRE+CgTw1opbOk54QIPEToI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=iBckJDMJ; spf=pass (imf11.hostedemail.com: domain of 32v6XZwoKCHslbkZohmrjhfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--mclapinski.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=32v6XZwoKCHslbkZohmrjhfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--mclapinski.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738014427; a=rsa-sha256; cv=none; b=yES0D0ZEvFrC4TodYBK6CQJ2bdUk+3eNVIQXNUZqIhF35XtXFsfmKwoLm2xP4znzhrPgNT J9llsIaDRAN16hgY4VWsLNsTmNOKklWlvSaz4hJpd4wWvTQXWEaTMyM16PkL19l8MBW6H3 0NRc8o9PTgI2Y7L/K9FzcBF5snA1ppk= Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-ab6aa02e747so130571966b.2 for ; Mon, 27 Jan 2025 13:47:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738014426; x=1738619226; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7UVb+GoBBSHoiZedLFy6B8b5YfCszIM+0jeoCG22gAA=; b=iBckJDMJ02U7A+BVSz1hoqfIuKO75fccOvrRIYJwWJTnazqHCJShhWS8rJ6yjlylr4 tTUW1ej3WM6u0juOAyHfpVLjmhuU7Xd2dEiMzVL9ythj0LWE8wTMSIolAPPZ3A1mYiov pYdMmn6tD19C7nYHlwiIjlLCS9FkMhMnsHW6AFEBMFiILPwbNA/Uo9SJR5xOlM1WHHsC cl3v/Ss+t05BMuWoiF0Ubx+Zh1bvkHIcDFmpmxFGAGx5T0Ftb6zOE8CGzI/eg36R2YWo ZH4pinNFZcVdZ7wjcsaowXyqW2HFHHYSBtKmsYF3L5n0q1W41CQb63XeCleLofNRkONd MYuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738014426; x=1738619226; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7UVb+GoBBSHoiZedLFy6B8b5YfCszIM+0jeoCG22gAA=; b=Ak97qTsQ8l5VhIGwI6EZoXZ1hsdmHJqiOkmPG5widFmCFpQ4ZS7mKRCrtv880kvAk4 RT+WLUAj5TjuyruKL5l0m57020u/P/T9LUoB0cHwk5KUtImiI/AodLzhhNN2YbNgVUCB pTTEVySnHPW4AyyjDU+G0tH+uIZKJamfVQb34b+y7RG6FpxMfOEo/GqW3QT5x5DqEKLg KT2/uMR91I0EMOd/1LYdxQ/KeNfywccah4TJSQMVDISxKWQOBv7Tk3+jXi2MKfMYLADh Iw4ErD7SbArfsNaV+JAxDpzIHMdhZ4gX5u17jKIuRmlxxfvcVsVmgpgj9VOIPqOi7sJV CG0Q== X-Gm-Message-State: AOJu0YzMFmm+hIQnsypvWewP0kRMQnWb0O4bhI3x+7jgKT7DMUAfRUIF Q6HkIOrEALayvkqP4c5k6PrP1YY06giRjBMRh0UFp31cxhQ3R8j6AHJxzNzyKHCxGNfGhOuX60G hHSNy74pHER5/L/fHRA== X-Google-Smtp-Source: AGHT+IECc9KE6PE4hZ2lv2wDyvkCk2SPm4zj7FVDRyIlw43wk0T+qFIScoGSEgOBvO62QokHsGzieqtaukjywscp X-Received: from ejccm19.prod.google.com ([2002:a17:907:9393:b0:ab6:8e30:8be2]) (user=mclapinski job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:7e8c:b0:aa6:af4b:7c87 with SMTP id a640c23a62f3a-ab38b1ff093mr3382815566b.21.1738014426260; Mon, 27 Jan 2025 13:47:06 -0800 (PST) Date: Mon, 27 Jan 2025 22:46:27 +0100 In-Reply-To: <20250127214627.4021412-1-mclapinski@google.com> Mime-Version: 1.0 References: <20250127214627.4021412-1-mclapinski@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127214627.4021412-3-mclapinski@google.com> Subject: [PATCH v2 2/2] mm/compaction: make proactive compaction high watermark configurable via sysctl From: Michal Clapinski To: Andrew Morton , Vlastimil Babka , Pasha Tatashin Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Michal Clapinski X-Rspamd-Queue-Id: AE9A640019 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: tb4ggr68suimxieog3is1skhj8pqngsx X-HE-Tag: 1738014427-73409 X-HE-Meta: U2FsdGVkX1+MzgUVkDprLNsvb5sP5cKyqiJHnPqt0EfLLpxRae6Xz4gXrv7BdZZ10V8JXHzDzKybKcKczexvc3svv2Q+ow/A5Rxriaz3yPPQBITvDpSQHiM8EIdCrthfA7d6BWcFOVYGqcdajMBauYA6gAXltF7hwJNur/ZE5DqIJ2xvQ+7A625S5y3BuFDjDNkjX4/I+HTCHvTKJtYmYVPUjJ2E6GRE4JNFQ0yCumVV25O/9XgMHu9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Igp0B5yIpFXy08R1F25uAf5o0Qi46des4JJ0c5TjbAvq3Bp4mwBbxtx/QZyZzln3MO5pI8uCrNe3yFuO7C+uFQd/QLsM3bEtdpxHf67KkHra9u8z+Hh1jAyD5PgqNpZo0S8fi+sTI70MoH1ma4Gm0bIhZIkxZBuWyaOzuI6nLO5aEjdZ6nKtJEkCrEjTz+hQhmgI/5wY1mGlyfUC4pR4redNxMzixY4 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, the difference between the high and low watermarks for proactive compaction is hardcoded to 10. This hardcoded difference is too large for free page reporting to work well. Add a new sysctl, `compaction_proactiveness_leeway`, to control the difference between the high and low watermarks. Signed-off-by: Michal Clapinski Change-Id: I4fecd273e9ac55a3e75770ff18c53d5db6acf1ff --- Documentation/admin-guide/sysctl/vm.rst | 17 +++++++++++++++++ mm/compaction.c | 12 +++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst index f48eaa98d22d2..ec6343ee4248d 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -27,6 +27,7 @@ Currently, these files are in /proc/sys/vm: - admin_reserve_kbytes - compact_memory - compaction_proactiveness +- compaction_proactiveness_leeway - compact_unevictable_allowed - dirty_background_bytes - dirty_background_ratio @@ -133,6 +134,22 @@ proactive compaction is not being effective. Be careful when setting it to extreme values like 100, as that may cause excessive background compaction activity. +compaction_proactiveness_leeway +=============================== + +This tunable controls the difference between high and low watermarks for +proactive compaction. This tunable takes a value in the range [0, 100] with +a default value of 10. Higher values will result in proactive compaction +triggering less often but doing more work when it does trigger. + +Proactive compaction triggers when fragmentation score (lower is better) gets +larger than high watermark. Compaction stops when the score gets smaller or +equal to low watermark (or when no progress is being made). +The watermarks are calculated as follows: + +low_wmark = 100 - compaction_proactiveness; +high_wmark = low_wmark + compaction_proactiveness_leeway; + compact_unevictable_allowed =========================== diff --git a/mm/compaction.c b/mm/compaction.c index 29524242a16ef..fd546b797e544 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1921,6 +1921,7 @@ static int sysctl_compact_unevictable_allowed __read_mostly = CONFIG_COMPACT_UNE * background. It takes values in the range [0, 100]. */ static unsigned int __read_mostly sysctl_compaction_proactiveness = 20; +static unsigned int __read_mostly sysctl_compaction_proactiveness_leeway = 10; static int sysctl_extfrag_threshold = 500; static int __read_mostly sysctl_compact_memory; @@ -2254,7 +2255,7 @@ static unsigned int fragmentation_score_wmark(bool low) * close to 100 (maximum). */ wmark_low = 100U - sysctl_compaction_proactiveness; - return low ? wmark_low : min(wmark_low + 10, 100U); + return low ? wmark_low : min(wmark_low + sysctl_compaction_proactiveness_leeway, 100U); } static bool should_proactive_compact_node(pg_data_t *pgdat) @@ -3314,6 +3315,15 @@ static struct ctl_table vm_compaction[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE_HUNDRED, }, + { + .procname = "compaction_proactiveness_leeway", + .data = &sysctl_compaction_proactiveness_leeway, + .maxlen = sizeof(sysctl_compaction_proactiveness_leeway), + .mode = 0644, + .proc_handler = compaction_proactiveness_sysctl_handler, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE_HUNDRED, + }, { .procname = "extfrag_threshold", .data = &sysctl_extfrag_threshold,