From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.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 08DDD19FA92 for ; Mon, 27 Jan 2025 21:47:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738014429; cv=none; b=MzWZhFj8OK/nSoGrlQwswClbIkllc0sWY0XuEgiHzO0d89h0vsqk/DERqmw1wg86Fdia8BT/S7qPHi5KunMx8sN9EyedDR/cw5qqSqSwv7GVugOG005BbhR0w/xQ3kZafFfVWCOg/D7OcbPEJszJgrQIDJPgn+3LgXYfeMmLqcY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738014429; c=relaxed/simple; bh=BBHleDM9C9FJNfBv2twc+mQiQO4HySLcMezDTfT+25Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ql83OWG+g74NJUUk95zDDrjPUNwOf0ym1AVHlfMtVq5++kSxyJ/tPfQqa/r07h3DzUZckMfb1LAZnOhqOi5ldhwjepay3KZMJ1E6BViHjsgLycemBjLTlxhm909n4ot2jQqNohjRLPsLPmW+8pVJ3DdAw6MzP7ufxbWkrpvOyDU= 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=aBSE2KXz; arc=none smtp.client-ip=209.85.218.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="aBSE2KXz" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-aaf901a0ef9so387177666b.0 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=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=7UVb+GoBBSHoiZedLFy6B8b5YfCszIM+0jeoCG22gAA=; b=aBSE2KXzem3BqbUQExHbYEVGanC1d8Mr88peUgfREjfrTvC345Xnpw9ZhDsV5t5mlV 3M6qUp99rUdPcM2e8vXF6diC53lb79MYNCRfgCBWON/BHeaMG1LijSgdoZvuBFKCfWyy ob8qZh/W4BjM0jm8EfuCgvH3QyTJDDs0SW/IBSKEsnZHLGe32YPhgtN4+SNCcWKxzmSW vpCG4wHnrPsQbbmf+3HtnU6LBq57qm1VfflpdVDgNpPHiD8s0MsNfcWPUhsxY5/rf9+V KP6LMTlzp7Bp/CLQbinmQKiejPwV17D+BhqU1YZ2hbvGVqTGjrftAj8nRy8hqN8qGuUq S5lQ== 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=BueLMqHJuP6QbyshCS1kpdjzBD0A0YPC6P7WMBQJMISxh6x/gTYJEJujiQAJGQZkEo kn4nc3TBFyjwTXoUc/G7UKi/BcWlD2xeg2sGZx+PtEqM+szmnEO0Vf1vEloEc6fjMhoC bXT+qqiZiLAjQgoSnv25LxcwhxQa9gC/LhZu5HLQUsKIB1lWhYO9SKfOnxx9Pan5Db04 j8IXwnWTZSzBdHUWhswoO7IdvIxb0cnBxldUuEJZvxAM36tx17gMEqiAK48ZAfxhEwlX BEGQnd02878A+ixFiO2QwkcbyqUQDIh0Xy63ue9JVsJifrSB5rK2/qRVOg7AijV5EqPq EG4w== X-Forwarded-Encrypted: i=1; AJvYcCXT7Q7Cdbt1ikgJ/0cyv6+bZ220PnfGTDzloHwVbtIBudtO4UX6NNoPZwXKINcD0igOj0VG0nrZdYQUz1U=@vger.kernel.org X-Gm-Message-State: AOJu0YxdqrLWswLO0qGjBo87iQiUar8QtWig0haiIO+82zOkSxmm7Y+g FJfkm7wituDChPxZFKDuIYUknA4IJ9IK6b30Z+7ea/cc4pH52etGA2znJ+uKbndiBpYCPzcFPGT XpnIsSM7Djp6RBckatg== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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 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, -- 2.48.1.262.g85cc9f2d1e-goog