From nobody Mon Feb 9 19:26:50 2026 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7159B1DA4E for ; Mon, 27 Jan 2025 21:50:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738014635; cv=none; b=PB6RlD9J35WrU5Ue/dMD8p18bJ36U4QbhOrrW+zxqlM8IEaN3qSRzzTzYYGC464OkFNnq4k1vGILLWbUjLPgxfBGRhHN+nMC5m/mlQc+RcL+bXVqvMvaBlvEmwU+Dq1uEv0MMsOFm+cwLZ/j4YanrhqM0ucAZX0eysgza/JG0o0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738014635; c=relaxed/simple; bh=UF0Upb5N5woSmcxTtqUmfF99OaGwuyc9MkFN7YGmogc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=py4tl30PAm/Ndm8qCqH52a1rX75Dx8LGqD8MBJTv7OF0TizZHIGDCSFMqb/YfdcsilB/X1zdOwyFVep6Aw2KwLR/XmgJjYBA5+7htfjmQ+SpriQJEdW+wVCPTeLORck2g+U61y63eCwAR/n6Eisx1e5+uZcmKzPcGrRbWnqq/bI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mclapinski.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wZV78wxx; arc=none smtp.client-ip=209.85.208.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mclapinski.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wZV78wxx" Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-5d3cb2e6c42so5633458a12.3 for ; Mon, 27 Jan 2025 13:50:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738014632; x=1738619432; darn=vger.kernel.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=wZV78wxxZE0SzXE/r8f94c+fgDziAvav7Zfad4e6DUFZeER6I3wd/Q4NIyUpqhqki6 ZNZv92l2Ldd4I8cX/7hiAn6Jq9v8sg4EFpnPvPQg41EoQE1K+wNMHljs+gknF/9TwQGf h1/fsXv49je8o2BX573fyTwLiko8JhsRbXizFqn9brqB4L9SUzLdF7pY5DUdWz325t0O 8eyYQnuYire/YfEhOeESj47/MFrKF54QXYOpb2nk05D358f4tVNKrVCmXOZmnjITPOJa Yzg+fwuvT9qPTOo+I/tZItplZ2njUT5YTCyk2YnjhCHRK2YO7Euo8FYZTnq5P38u12eG 2e0w== 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=sS/DLCUc2V+cB00DnaCM9VW+jSZK+I/eP5tBj/HN8vruYmhSH/2o+diS0t98OhvLSQ 0yH9IhUQ4Tf4IuM/aeWnKOlzQv3Bjw0Jkbx9GslkLtfllrPj7fuOT2/fR2hkP1ttxwas cgagk7b2weTxH/7A6puuJ3ueFxR9ZbudOaZyiktr9IZGECgsGpDWfKyYBz+v8/m58pJN YrkoSya6GEwye/8BQ/E940vtICdjG5K2r7/FQBcvATCdboi9J/iHPda7ZphXN3+7DJOF FtSwHqmHJ9FDNzgUyHyETL0tYlgmTEZzgb1YrDm4Cpr2yixDoomeqhf+jije/+59v3ji kS5g== X-Forwarded-Encrypted: i=1; AJvYcCXekh1aDkMHjaT1NvP5yBH5YtSj0op7zQBIPJlQ72hd5PmBkZBvRed5zgc38Pm/MrdGhdfpGVbAe2q20Tc=@vger.kernel.org X-Gm-Message-State: AOJu0YzNgbnn9sdDLpVtFlnnc5FwxjfsLoo1w7vGngbKvZ+8K2SLc49R 1sfJkQkmMZi3brttYBR2X50HHTZAPlTXVvoY/h2BDYGH8k16Rl5BtQYwOCf7wjKjf9bdlJx5ZqV cjyJ0G0nfaVyoHI16EQ== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. =20 +compaction_proactiveness_leeway +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D + +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) g= ets +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 =3D 100 - compaction_proactiveness; +high_wmark =3D low_wmark + compaction_proactiveness_leeway; + compact_unevictable_allowed =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =20 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 =3D CONFIG_COMPACT_UNE * background. It takes values in the range [0, 100]. */ static unsigned int __read_mostly sysctl_compaction_proactiveness =3D 20; +static unsigned int __read_mostly sysctl_compaction_proactiveness_leeway = =3D 10; static int sysctl_extfrag_threshold =3D 500; static int __read_mostly sysctl_compact_memory; =20 @@ -2254,7 +2255,7 @@ static unsigned int fragmentation_score_wmark(bool lo= w) * close to 100 (maximum). */ wmark_low =3D 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); } =20 static bool should_proactive_compact_node(pg_data_t *pgdat) @@ -3314,6 +3315,15 @@ static struct ctl_table vm_compaction[] =3D { .extra1 =3D SYSCTL_ZERO, .extra2 =3D SYSCTL_ONE_HUNDRED, }, + { + .procname =3D "compaction_proactiveness_leeway", + .data =3D &sysctl_compaction_proactiveness_leeway, + .maxlen =3D sizeof(sysctl_compaction_proactiveness_leeway), + .mode =3D 0644, + .proc_handler =3D compaction_proactiveness_sysctl_handler, + .extra1 =3D SYSCTL_ZERO, + .extra2 =3D SYSCTL_ONE_HUNDRED, + }, { .procname =3D "extfrag_threshold", .data =3D &sysctl_extfrag_threshold, --=20 2.48.1.262.g85cc9f2d1e-goog