From patchwork Mon Jan 27 21:50:20 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: 13951753 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 234BBC0218C for ; Mon, 27 Jan 2025 21:50:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5F1A2801B5; Mon, 27 Jan 2025 16:50:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E650280163; Mon, 27 Jan 2025 16:50:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AE5C2801B5; Mon, 27 Jan 2025 16:50:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 68038280163 for ; Mon, 27 Jan 2025 16:50:35 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DB815C03FD for ; Mon, 27 Jan 2025 21:50:34 +0000 (UTC) X-FDA: 83054576388.16.BFA4F39 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf21.hostedemail.com (Postfix) with ESMTP id 19A5C1C0002 for ; Mon, 27 Jan 2025 21:50:32 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="FNFpd1a/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3p_-XZwoKCEoyoxm1uz4wus00sxq.o0yxuz69-yyw7mow.03s@flex--mclapinski.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3p_-XZwoKCEoyoxm1uz4wus00sxq.o0yxuz69-yyw7mow.03s@flex--mclapinski.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738014633; a=rsa-sha256; cv=none; b=GLmkTRbtGKYritCDSR9alcm707YigomDGPknR8W7DzBnVuzpek7WeJPtHoRqZh3nbwYUGA GHKUN3h3lLwn54sWHggQuuo27EodXV3opHeKgp1Je8ishNgel8x5tm8Et/A9xLSJfJuMzi vvODnf7l3taEYGDkJEPmbv5L0zs4wI4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="FNFpd1a/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3p_-XZwoKCEoyoxm1uz4wus00sxq.o0yxuz69-yyw7mow.03s@flex--mclapinski.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3p_-XZwoKCEoyoxm1uz4wus00sxq.o0yxuz69-yyw7mow.03s@flex--mclapinski.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738014633; 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=L5Uvq/LtSk5V9Bp+Wn1p8p4zxiWha0dPng9zxfaQzuI=; b=a/A0AbqB1KPDMaFcnoBJhgdhmq2ynlwZu+5SifokaubnWPtkvrVlXi9f8XcUsXMqB/5d3/ skxu73vDKo7LLgDxUdANV18wp6R05TQiSIaiOsLpiFFvLpZz//rVkf6nwRarP7Kjcj/JXh rIoC5OIBEdNCMc+2PPa1vlKcyRajrI8= Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-5d3fe991854so5250159a12.0 for ; Mon, 27 Jan 2025 13:50:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738014632; x=1738619432; 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=L5Uvq/LtSk5V9Bp+Wn1p8p4zxiWha0dPng9zxfaQzuI=; b=FNFpd1a/dsLyDW4Uqn99/UeJLA5AzET+AnU20u+SH5U4RCbjamIKDIr9CszsZ9ag7x 3+Yx4HZJ3f/XMdRW870wYUyf9J3YIJBTB2j8U+iiZakHCPh9rt35oOOl42osgAAboO5s xGECkSFtqPKQsrJw/K3p5jSHW2mOnPGl6+o5FflqEtAHqxc9qFbYqZ5cWneTjJiPz9oN m70DijYoEqDOPiHt0xh82pcKxFLdlyB9bsqj4/bctIRfVcPA6IdfhbjnU8xbRuqK83cB X5wK/V98Q2gYRC9AKNbwCAR1by6j+oev4WMOBoLo8NBHnm7HxUMvxk+avgZeAzPHDMqG 0mkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738014632; x=1738619432; 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=L5Uvq/LtSk5V9Bp+Wn1p8p4zxiWha0dPng9zxfaQzuI=; b=LlpzipdSQvdUPQLnHNZJnaSVBSe9GyiLFe6TjV/1PymZEs0j29Z7HaxfytGSJtpeAW IlCoHKzo29crgTcLN6Qtldmw1IZzaPdYq/u0kWHYvPdpyZ85hlbQi3qPRo3c56RaWGQd ywzrijjkeNcliAu1dNNJH9pv+/VcBjk3zfswI+7k1E5bQavfoDUoYFRE7xkyJ9HFU9N+ s793g/YBpo+w6sP3jvvNPUkw59dPsk6KUQGy176mWJGvIk13rDs5DE+CDjcL8FC0W0Ew Cv6xtFm70JMNsUerEknHbsTo+uqkN1wq3F/6M45wNwjITc4ax3u2QemfYHP6A27ePIzG mOig== X-Gm-Message-State: AOJu0Yxyt86rlFjdkaRzdYFpNQuv2+9GFdiXAxQmZftxDMQ0NnM1wpOs uA9112+6tQSIuS6EAKO+Yfa+kfBxveGYfSMIP0jNRDqE3eX2lf9Kpv6gan1cqetJMbX/j1QNEJt edCGgcswA97UtVCxBFw== X-Google-Smtp-Source: AGHT+IF5MyGmzo6X6+ce58m37kliBMO5fYfLSX6/URh968H5U46tULENGEI65EXk+Tg837YFHhk3WYFX9gbmAolq X-Received: from edben21.prod.google.com ([2002:a05:6402:5295:b0:5d1:21a6:f033]) (user=mclapinski job=prod-delivery.src-stubby-dispatcher) by 2002:a50:cd02:0:b0:5db:ff5f:333 with SMTP id 4fb4d7f45d1cf-5dbff5f039cmr15071154a12.24.1738014631863; Mon, 27 Jan 2025 13:50:31 -0800 (PST) Date: Mon, 27 Jan 2025 22:50:20 +0100 In-Reply-To: <20250127215020.4023545-1-mclapinski@google.com> Mime-Version: 1.0 References: <20250127215020.4023545-1-mclapinski@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127215020.4023545-3-mclapinski@google.com> Subject: [PATCH v3 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-Server: rspam04 X-Rspamd-Queue-Id: 19A5C1C0002 X-Stat-Signature: w9npxqcxadjei54smwb4gxgdbawgb3ud X-Rspam-User: X-HE-Tag: 1738014632-623170 X-HE-Meta: U2FsdGVkX18UKLH23E8w3fCQLK7gl0t4F5eh8nIqSC8leaI1mXNxw8TzY9Elz1NtTtgaxEa4h+4QQTmkNODQK/a/TO1I0FwcFgeYns67rJbmEVSxbsB7T84tAYvXrl9ugLKWEa9DSvzuMmNUhkKkwV8qVU2UihZ9mP3cIMzVaC4u5gv14MG9w8cTSGfEssE1NzY4KCBvCvlQ19xpw2ltPl+K5IZ5XgHJs3kpV/+VusjbTEAb35K4moDhBeigZ+T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4ssk5Avyq4+GQaSL3KmqjhhxG1j3/LQVlmtTDg4JB6mGKL8ovsOyuHd90bd7VQen1HgkLNrZA12rxujF/SuQdJ1urfLh7T2fqBx4RUl1b2BOK4iOLCXekvVSRByGRPSEfnxJNop2K56XU6bodI1EaH0I57KXHE7ju0gdBG8ojJrnN9EIPCg5+AOQzG73k/Q9lBkHXHbxLwpy6D986WcyFp6BqvTl5oqAkmsrsidN3O 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 --- 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,