From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f195.google.com (mail-yw1-f195.google.com [209.85.128.195]) (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 E6AC9379EF7 for ; Sat, 16 May 2026 21:04:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778965448; cv=none; b=s5gcYoiYfW6tKTiCZaT4Z7Hwfz84Iei2Pu1vF+0XSrEG7al/Z6OfaTGbTO9bYWCkqxUUIx1WceeCM4RIhwgn2iy8ILXBCq70w4S8xZ93uBl1LwMg/wxA/3wwXkXAT/ZlW0W3GaR8SKzMhiOf+Qibjy8e/Wt99u7Y098dfWoHosk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778965448; c=relaxed/simple; bh=KzYiajAK+nfFBai/4/fm3cADm7PKM27ScIiqlEri7s0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Erx1tDCWcpe+hzjHROapuDiW2EwGSKRzkSHkdL1KoJwHjr+BxJYW0QxVYXtP5q8dBgG3aPHjoOnEpC1iq5/xPY8ESjd9LKubVkZuTvxE1LLYKIjJnAs5e1aQZFKJBcxUkcMr5yp4a7Ox2DJvXuFuDwpH13vIJK5D3vxmR512Vtk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cQ8okIvf; arc=none smtp.client-ip=209.85.128.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cQ8okIvf" Received: by mail-yw1-f195.google.com with SMTP id 00721157ae682-7bd6f65c781so4949297b3.1 for ; Sat, 16 May 2026 14:04:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778965446; x=1779570246; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N+8d6F/ecIm4OU9cM2uGG4hmEo0TfbVFCv/yoQTzhTg=; b=cQ8okIvfH13f8sDCMwES9mmpGCysjeW46WPqlL8XwL1XYMnP2oosCjfzWMwcpQjLFn FlgTSyNZP1WrpMs68EtkODnkGFP2/IashtYQE+Sm8SoJwvhn5S2rINwFFdZTxbPeqxxP af6dvMOtZ+ALDs+a0xY+R129kwLr6dnsKPkLCKLkX3/JaCZ/ya0/Q28ovrZN+cCvBOL5 zqJEQk8lLQ+KCT40azUJNX0r3gbTLjXY6ZLUPF7k5mRq4RaeFaLI1o43TDaGAoUcNIiO TQimB8wNEDDNCRw4L1inWIhP4L9PuByxQyzbSg/3RdW237GGJfKBjykT2dNJgCLD2sHw N7OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778965446; x=1779570246; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=N+8d6F/ecIm4OU9cM2uGG4hmEo0TfbVFCv/yoQTzhTg=; b=GhsJc/Xc6WEM0pA1/O4JEhls3tgW+58HO+k07mzSpIuhGFuW2D51bng9uvkjGCuuTT rsadthBlnEhW5sSz8GjE8ASaB+9uKQHsbmJpfaj4E2jIq2jGFxPjdhcf0ggAAHd8ApcF leh5rVHOb3vh3rGuuSoK52HUd9DrivPFzhXv5gsGTb/6dfvUYF9B8WhXOcmy5rOX4nDr ZyZrSkkpUIh9pAhKjnkamGCp3Vl4JJYJwFdfPAdbvFySFJoyrKvu0MNlCpG9NMq6GNyh UMh2fdPZFoh5LCd01Zstq39/GD57oG043JlzUsskguuntC1jKQxZMNYhIkdCPee2kelu OW7Q== X-Forwarded-Encrypted: i=1; AFNElJ8YzOTRSc+1a/5GBqyBKnp4qQvaZw6vxvd9qpIbZIu2Uvm4PJ03S6Y7dNma5De7LqbxcPD/jU35/qp5fZA=@vger.kernel.org X-Gm-Message-State: AOJu0Yzk0ya/zamm0h3IQNelm9hqJOib1Dol0OSaxX+B/pghhI0dwwvY If8jSG0W7GWzy7wlMymdvM83aJc9Zy94fR1gn3ECtQLgPPe7xrXIJaM= X-Gm-Gg: Acq92OEWq77EhZ9yaFZL+0PdLw6V+4AihwOzTqIeXMzyYvYgl80b+og0jhPQWbZWUuh bohb8wENzY3HiulIta5BgehAL1Krrh30Ai8On8SS86mh2DysY1lNZfwlUDng5ORKkvJ0SJlafVw 2sDva8QncmZQcMl0YRHrVlChI0dgxdUSiDUhcEZ/Z/buV7cv7+l2CnJJs3/1LN5bL98er0EX7Ca 0ZUjb/Nz7Lb1lBO/3u2McFpZqVCnAdNqoZOsj0kgKQwioY4vDLYy0tQKjmHyc8iuLoTIRcxLff1 H3wVnyc5dkkfpxsllTNZiO2ZUWcwdSmYvZ6KGbbJJUMuas0Xp2fYacoW6kngy3bhpxV6owBz3Vf 6NJJRG/YmrpsDLYlttMMSgofmykp938FPK2/j4QZ56uZ0HncNCbxO5MSi442F806yqAxN0fvKx5 N3WQ4bWtU+8ETxO4r7Bx9rBms5doc6oDficDBhltgqVx7pdRXz1iIimAaXkWy4fGzELcfHFaxrL cJpyL6tiHDZ X-Received: by 2002:a05:690c:e28d:10b0:7bd:9a25:f39f with SMTP id 00721157ae682-7c7e5d8e253mr91991277b3.4.1778965446076; Sat, 16 May 2026 14:04:06 -0700 (PDT) Received: from localhost (23-116-43-216.lightspeed.sntcca.sbcglobal.net. [23.116.43.216]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7c7f4ee8726sm48887337b3.27.2026.05.16.14.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 May 2026 14:04:05 -0700 (PDT) From: Ravi Jonnalagadda To: sj@kernel.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: akpm@linux-foundation.org, corbet@lwn.net, bijan311@gmail.com, ajayjoshi@micron.com, honggyu.kim@sk.com, yunjeong.mun@sk.com, ravis.opensrc@gmail.com Subject: [RFC PATCH 2/5] mm/damon/core: cap effective quota size to total monitored memory Date: Sat, 16 May 2026 14:03:54 -0700 Message-ID: <20260516210357.2247-3-ravis.opensrc@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260516210357.2247-1-ravis.opensrc@gmail.com> References: <20260516210357.2247-1-ravis.opensrc@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The DAMOS quota goal tuner can compute an effective size (esz) larger than the total monitored memory because it integrates over cumulative deltas without bounding by the actual workload size. Once esz exceeds total monitored memory, the per-tick "remaining quota" arithmetic stops being meaningful: any scheme can apply to the entire monitored space and "remaining" stays positive indefinitely. Cap esz to the total size of all currently monitored regions as a final bound after all other quota calculations. Add damon_ctx_total_monitored_sz() helper that sums region sizes across all targets. The helper runs only inside damos_set_effective_quota(), which is called at most once per quota reset_interval (default 1s) per scheme, not per kdamond tick. Walk cost is O(nr_regions) at that frequency and is dominated by the enclosing tuner work. This bound is tuner-shape and goal-metric agnostic: it constrains the quota controller to physically realisable values regardless of which tuner or goal metric drives it. Signed-off-by: Ravi Jonnalagadda --- mm/damon/core.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index 9975f3d9ebfe9..fd1db234ca304 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2614,6 +2614,19 @@ static void damos_goal_tune_esz_bp_temporal(struct damon_ctx *c, quota->esz_bp = ULONG_MAX; } +/* Sum of all monitored region sizes across all targets in @ctx. */ +static unsigned long damon_ctx_total_monitored_sz(struct damon_ctx *ctx) +{ + struct damon_target *t; + struct damon_region *r; + unsigned long total = 0; + + damon_for_each_target(t, ctx) + damon_for_each_region(r, t) + total += damon_sz_region(r); + return total; +} + /* * Called only if quota->ms, or quota->sz are set, or quota->goals is not empty */ @@ -2621,6 +2634,7 @@ static void damos_set_effective_quota(struct damon_ctx *ctx, struct damos *s) { struct damos_quota *quota = &s->quota; unsigned long throughput; + unsigned long total_sz; unsigned long esz = ULONG_MAX; if (!quota->ms && list_empty("a->goals)) { @@ -2649,6 +2663,11 @@ static void damos_set_effective_quota(struct damon_ctx *ctx, struct damos *s) if (quota->sz && quota->sz < esz) esz = quota->sz; + /* Safety cap: never migrate more than total monitored memory */ + total_sz = damon_ctx_total_monitored_sz(ctx); + if (total_sz && esz > total_sz) + esz = total_sz; + quota->esz = esz; } -- 2.43.0