From nobody Thu Sep 24 20:36:59 2026 Received: from mail-wr2-f12.google.com (mail-wr2-f12.google.com [74.125.225.76]) (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 5D3201A9B24 for ; Mon, 21 Sep 2026 00:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.76 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789950654; cv=none; b=qGzfy8OESkEG7QFIoS0zlgbJEaODnUsnCjEF27tOGGZX6Ju/RAEytndZPjqmnyj97CBRvtRqaZk1YdK42PQ5Q0pXRiFcqP97r0Ea+C1z3FKO5M/PFntPKnavWn0BMD1P09EQCDwBpr/NFV/OYC1aDbUI2aUgT87GfqChXLVbwyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789950654; c=relaxed/simple; bh=QQSAd2CYAnQxdw/DgFc6joStjKQYfZmSz3ZExj0RHZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jFtz8gW16FlCdSYzF2AwTEq4aQBJXE7QSi+9ty5N3Vcl3S8mVKpUfLFlORvMmH95vFCfj2aqXH/ieZdw2DS/kq1FP03xxE0dQ58yo2ylh9waj220iX0SHHcS31mqgimrjza0ucS5oyoKNOD2CoDGfnvHNeqxLoe6yhJudxtrvhs= 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=PyBNMXus; arc=none smtp.client-ip=74.125.225.76 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="PyBNMXus" Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-482f633ece3so1855105f8f.3 for ; Sun, 20 Sep 2026 17:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789950651; x=1790555451; 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:content-type; bh=8p2uHDJTRX2GGhCC6kgbhWuhGhbxvLj9khVv1KzE7G0=; b=PyBNMXusrf9v64NzGSK8NnmM3Xh1Vt8o4jWusKUYnnOTd2jwTd7ScvTfaklE37jGMG 0X7wvoDWcTMe3iiVa6LOWRLNyshRuGFuacRlB4M67RoxTIP95AWkx5cwxVvUQrhfEfng 69howN4n5cPor6tKck+JNVayGim9qY6SAb4je7RbbGN18khyobwDT+SxIkWzbV0LiWCL CZ4zMlJMuAGGh6s5dPMsIwkAn0IWAPBhexnWOxdVCKFt5YGmEv3zodkzzsVbRYieZ6TZ TE5v3KRCoY2uUWLBIqg/r7Aw2m7C+EP0+Hr/y0VM8uPnwuX9uWBMyBITV8pTyE6hg0k3 nOXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789950651; x=1790555451; 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:content-type; bh=8p2uHDJTRX2GGhCC6kgbhWuhGhbxvLj9khVv1KzE7G0=; b=0djpROvmmX1vFh3Ksz8pA9xvChAKsxf4ioXwVx5K1n+APrOz072IsrAegYBXyYSJfJ T4+Rf6haWPQeisbSrUVz2wGbJ4t9OZRrQNYBINMXkgo8JJj+Z2TjvjraXnkIkRlrip98 N/ey52MUHqSo/S/htSeB1SWnjrmQmh9a58ECq4hoTkWT0fHLsP8AM1IauW0TzZ19pS4x mKF3TiE7RopS5Ux50YkS9FdCXeQ3AcpypVRwNrtJbWP9BY+4WKfSfKp6PWSao0mfOcd3 /HQiwld75Ay+D42G0dSgh7UlNsmO6y4tap82Hu3S+lyLie2e+Dhf4/FlttDSh7FgAmtk H88g== X-Forwarded-Encrypted: i=1; AKwUvBxibtIyTwJZ3oMKIBfYYgIiQaRHFA3vMXpDr0aNlri0tDonNknHnf4cj4RP9dRTj8pbHyLFNRF0po6mLnY=@vger.kernel.org X-Gm-Message-State: AFuF++l4NvDPfQ07+RPFG76dgSJCIA3IupMr1uaRP71nijRUtuBpPDD3 /QH59fMEWxFArYgs8UGJ+ABF3u4YoodpqO8RJR7LY3A7Wy3zMdOpOSoc X-Gm-Gg: AYBFou2o6XOB7ZdCQHHPg3iyjVRPh11rxEFZbJG8SEOzgvnWtpmvBsCh2P9tRCJuR9t GlgtXYwmaTG5SXDGV+WY4Fk/Sc2iCOO8pYzJ6meaqbuY8tBTbqNGRIeWHbGitPKqdu4eaPB6MGW g5eGerfm1yJzItxzYXMT1Xn2KVylDWt+OIiAqvLFqdcyduxjF32dogvAPXTDzNIY2A7X0YW2jJB JSjcuM3OKPrqbiqpGPMBPzAdYxCQ9BpJxpCpn29P4TMz/fM++Q6Q6TNCQ9EeE5snAKRYUSsUkib APxmJVmfUyXhAMzjWYTMlX5AYT7V/nElxlmfh9UxZwVmJ2OD5fBhZEgApmyYVzeJSYEfkRHRXie Ym18FlwifZU6GQszLw0tlCM04Re7pDfaxCt/Amynku8Y6VCLtO5VRwFkcJBPH3GR+mbAwoBsv0W jgXT6p5Gq70675+ufHm6TovII/i2BX9V6GlZZqNqmhSYtqli0++QP6DUqUKnBQd6P3VfYoc9Cp/ eWUD0E6yWLXOALc+3wGTQ3EN/JGK6MgUME0KiFa84D+m4hYs2iSsPbS6dzL+1fdZr3qij33gnPi mY1R7hmjMH3RXXo+M0/qJlWtSZJ+n5HUVdSX9EHjecidtz7ohvyt8Opf7CJzrLuOaiD2mqOxrHd ckQ== X-Received: by 2002:a05:6000:186a:b0:486:e949:532c with SMTP id ffacd0b85a97d-4871e367f08mr12791266f8f.43.1789950651450; Sun, 20 Sep 2026 17:30:51 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a02-3100-a012-6c01-e0c2-ccc1-7acc-3570.310.pool.telefonica.de. [2a02:3100:a012:6c01:e0c2:ccc1:7acc:3570]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48724583fffsm17515695f8f.23.2026.09.20.17.30.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 20 Sep 2026 17:30:51 -0700 (PDT) From: Karl Mehltretter To: SJ Park Cc: Karl Mehltretter , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm/damon/core: preserve the caller's quota in damon_new_scheme() Date: Mon, 21 Sep 2026 02:30:46 +0200 Message-Id: <20260921003047.12041-2-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260921003047.12041-1-kmehltretter@gmail.com> References: <20260921003047.12041-1-kmehltretter@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: quoted-printable Content-Type: text/plain; charset="utf-8" damon_new_scheme() calls damos_quota_init() on the caller's quota before copying it to the new scheme. This clears the caller's effective quota, feedback input and charging state as a side effect. damon_commit_ctx() first copies the running context into a temporary context for validating the proposed parameters. When damon_commit_schemes() creates the temporary schemes, it passes the quota of each running scheme to damon_new_scheme(). The quota pointer therefore refers to the running scheme, and damos_quota_init() clears that scheme's state before it is copied to the temporary scheme. Even an update rejected with -EINVAL loses the running quota state. For a size quota, this discards the bytes already charged and allows the scheme to use a fresh quota before the reset interval has elapsed. For a goal-driven quota, the consist tuner loses its accumulated input and restarts from its minimum input. A time quota loses its throughput estimate and falls back to the initial estimate. The constructor side effect was introduced by commit 70e0c1d1bf94 ("mm/damon/core: factor out 'damos_quota' private fileds initialization"). Commit 60bd24f272d0 ("mm/damon/sysfs: test commit input against realistic destination"), merged in v6.19, exposed it when validating sysfs updates against a copy of the running context. Commit b90408ef1163 ("mm/damon/core: safely validate src on damon_commit_ctx()") later moved that validation into the core API. Sashiko reported the same side effect [1] on the RFC of the core API change. Copy the quota to the new scheme first, then initialize that copy. Make damos_quota_init() return void, since its return value is no longer needed. Fixes: 70e0c1d1bf94 ("mm/damon/core: factor out 'damos_quota' private filed= s initialization") Cc: # 6.19.x Link: https://lore.kernel.org/damon/20260702212143.0CB6D1F00A3D@smtp.kernel= .org/ [1] Assisted-by: LLM Signed-off-by: Karl Mehltretter --- mm/damon/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 2258b72da7a78..e655863d33d9c 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -734,7 +734,7 @@ static bool damos_quota_goals_empty(struct damos_quota = *q) } =20 /* initialize fields of @quota that normally API users wouldn't set */ -static struct damos_quota *damos_quota_init(struct damos_quota *quota) +static void damos_quota_init(struct damos_quota *quota) { quota->esz =3D 0; quota->total_charged_sz =3D 0; @@ -744,7 +744,6 @@ static struct damos_quota *damos_quota_init(struct damo= s_quota *quota) quota->charge_target_from =3D NULL; quota->charge_addr_from =3D 0; quota->esz_bp =3D 0; - return quota; } =20 struct damos *damon_new_scheme(struct damos_access_pattern *pattern, @@ -776,7 +775,8 @@ struct damos *damon_new_scheme(struct damos_access_patt= ern *pattern, scheme->last_applied =3D NULL; INIT_LIST_HEAD(&scheme->list); =20 - scheme->quota =3D *(damos_quota_init(quota)); + scheme->quota =3D *quota; + damos_quota_init(&scheme->quota); /* quota.goals should be separately set by caller */ INIT_LIST_HEAD(&scheme->quota.goals); =20 --=20 2.53.0 From nobody Thu Sep 24 20:36:59 2026 Received: from mail-wr2-f12.google.com (mail-wr2-f12.google.com [74.125.225.76]) (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 D2DD8287518 for ; Mon, 21 Sep 2026 00:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.76 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789950657; cv=none; b=nKb9p32xvp/xzo1YnMToz69OjYqWSGLOrotwOP4L1EsXU/gAzOY5DkyefUyzHbXLwVT3hV2NKavUVfImsNkEGktA0WakViV+E8VQlACOyD6QaM8eH1v9QxiLtTm7mMH2Qee0QhLtysZNfTuYwXsckbhHTrtemsT2SM49HO8fy2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789950657; c=relaxed/simple; bh=m3sULRI5UFp0Vrtz1PVlSriadvaJcu4eq0E21z1jQLs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jH11VY93iDVfq7cdXBpsPQoRgZgOzusPftk8LwSF4BGRtfKqb7b57DGz37on8BpVjI5T4r4Q35+/8hHX/vD1kZB/O8IIkDmR321vvWN5wqvv3/UD47bnTQgK6vBmImhpnXbCC0EEIGSyLS6XDJV/GFMHCL6pggAI6QMQCujPqYA= 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=omrBLpRH; arc=none smtp.client-ip=74.125.225.76 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="omrBLpRH" Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-4843378fb37so1075690f8f.3 for ; Sun, 20 Sep 2026 17:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789950654; x=1790555454; 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:content-type; bh=6dpGtqMcJeHhOEzV/bkAAFY9Zr0/SXcgfjA47TvgATw=; b=omrBLpRHt2690wyr2OO9+Z3PTwZPmVY8m6MuJjqGcRgPUeGxqfFY+iVg7kjVJtNDlu gIVNLgEp/4KRYEGtwZjtpzCy9MD53GHg5uFXBcMnveY5GbhRGgP4PbV1+YqQOFairPhz BDTV7jeAAsufz5hlNx6ozpueJULP17osggQlPcCAT6BOYtzcAuD5hiEDak8awcjN8jmH YdlgDso9EYNnJlQga4SYHZFbstI+ijxCTQbLZx39W1gvevM4rLc6tlX4jkF8J4cKmnmr b3Ku9ZEfeREAgF42LhcJL7haRDSMV9FlZCarL0g2Fzaj+HKbqq2CGrDffxij/L7qsPBf i3HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789950654; x=1790555454; 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:content-type; bh=6dpGtqMcJeHhOEzV/bkAAFY9Zr0/SXcgfjA47TvgATw=; b=X70ecQZUrKEjrzj8RSvm+LyQATk9psGvtlutwZTTEl0pnE4oacnDSezAqEjMriabSZ YfOxJctV/yZyr2S6c9G814g+yHT0mK++/ka74noIWkom6bVh+SNS4sAqQWkpPewxxJnX AnRKwV8d8YrHDb3FrvIPPRZRGRm+EA4xL+Uv0sdwvHDfHrSSsd3PtF6LkyrYSBQB6EaS OSRA0alNlRntcND5XczxYFSZ9Z6dhfMqtUnewZyAL/ZODc2nRhqVh4K1SmlV7+gBTB5U dB1Jm/qWtnziDQASKy+P5q3Xcbe6NTVndWUKhQ6gWeUpmZM7YGnJa7ifK3TCHNNJQtoN xWeg== X-Forwarded-Encrypted: i=1; AKwUvByBklmc9mhqKIraVEEKoN9NqDuYNQ4ztEjCpOtDpI6r+P8vOuoqR/0BT6eLYW0b5WXNjGfAze5dHapQWMQ=@vger.kernel.org X-Gm-Message-State: AFuF++m97aEZyD+Od9D4hATfaT8NspAOSnMoyIQ4cN+S3KDqlILB3z7u N2m0rAgldiVWxSdGCOWhZMDaFsuL43CiCkgBNUcRUTgnxfXQqwIrIFH0 X-Gm-Gg: AYBFou3+3DvBhFg0b2UibfErwMCxjF+I+GTCXMI3fX2/NE/uEvyY8GwSM4EQwRfy7Bl Css7LwDOYxPMXSCQ90ZKBZ4xivUqAvCWJmp8zCDFvlQ6DJqYQlra3LlfjpcFXjcIhFkxJsRGS0m x2/eEDzyRgDNFP4OouDJgZmH/WsHKscyyvxFIjHr6yX7vWgKYAYEZMSerY3mmBDdhVJjgUTlp2u gUyfiBN7wcXLOJHb7mqUqio8xGqXVsmzXPCRE/JN5MDWHY3U0+0HpC187WE9X41Ed/aFpHqaSNY UzJyZjMcxR/s+dDA5EHd8v/kZbt5g4PIxw6KqC7UMFpLoL72W4YxaZMIiECY5ub/sPa7C0j46pS BF2Uj4jp8U31A3GRpfK+pcuTww2FH7dhNbC/0ttApWZlKj5uG1fsouBwXE/Em1R9Uex81CLT1hU MAXCsgpHdRACsmOGNqAAUS9FuLME5T6oQeUQh6CEexx0kupvXszmCG0iKohXAko4gkJ+9S1ITGS LaX4Braoz7tu4xacKkOoGFB+xyTWBtXHmh85N5GEMBqrrtCiFSLKxG+JXCRDfodBeuxP5lRGSD+ +gznojth3gKewp2IxC6/Jh1G8ksLIgZgsmmn25ZPUgkoXaKpNGB+fDKbFAF6y/062Udeu28pFSm TPg== X-Received: by 2002:a05:6000:610:b0:487:afe:c154 with SMTP id ffacd0b85a97d-4871e36bf11mr15086090f8f.40.1789950653979; Sun, 20 Sep 2026 17:30:53 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a02-3100-a012-6c01-e0c2-ccc1-7acc-3570.310.pool.telefonica.de. [2a02:3100:a012:6c01:e0c2:ccc1:7acc:3570]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48724583fffsm17515695f8f.23.2026.09.20.17.30.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 20 Sep 2026 17:30:52 -0700 (PDT) From: Karl Mehltretter To: SJ Park Cc: Karl Mehltretter , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm/damon/tests/core-kunit: test preservation of caller quota state Date: Mon, 21 Sep 2026 02:30:47 +0200 Message-Id: <20260921003047.12041-3-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260921003047.12041-1-kmehltretter@gmail.com> References: <20260921003047.12041-1-kmehltretter@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: quoted-printable Content-Type: text/plain; charset="utf-8" Check that damon_new_scheme() initializes the new scheme's quota without changing the caller's quota. Cover all eight fields initialized by damos_quota_init(). Also check that damon_commit_ctx() preserves those fields in the destination scheme for both accepted and rejected parameter updates. Use an invalid min_region_sz for the rejected update and confirm that returning -EINVAL leaves the running quota state unchanged. Without the preceding fix, all eight fields are cleared in the constructor test and in both context update cases. Assisted-by: LLM Signed-off-by: Karl Mehltretter Reviewed-by: SJ Park --- Please feel free to take the fix on its own. I can also fold the context-update checks into damon_test_commit_ctx() if that would fit better. mm/damon/tests/core-kunit.h | 107 ++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index 5ff0436c58441..811fd668e2482 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -812,6 +812,48 @@ static void damos_test_new_filter(struct kunit *test) damos_destroy_filter(filter); } =20 +static void damos_test_new_scheme_keeps_src_quota(struct kunit *test) +{ + struct damos_access_pattern pattern =3D {}; + struct damon_target target =3D {}; + struct damos_quota quota =3D { + .sz =3D SZ_64K, + .esz =3D 123, + .esz_bp =3D 456, + .total_charged_sz =3D 789, + .total_charged_ns =3D 1011, + .charged_sz =3D 12, + .charged_from =3D 13, + .charge_target_from =3D &target, + .charge_addr_from =3D 14, + }; + struct damos_watermarks wmarks =3D {}; + struct damos *s; + + s =3D damon_new_scheme(&pattern, DAMOS_STAT, 0, "a, &wmarks, + NUMA_NO_NODE); + if (!s) + kunit_skip(test, "scheme alloc fail"); + KUNIT_EXPECT_EQ(test, s->quota.sz, (unsigned long)SZ_64K); + KUNIT_EXPECT_EQ(test, s->quota.esz, 0ul); + KUNIT_EXPECT_EQ(test, s->quota.esz_bp, 0ul); + KUNIT_EXPECT_EQ(test, s->quota.total_charged_sz, 0ul); + KUNIT_EXPECT_EQ(test, s->quota.total_charged_ns, 0ul); + KUNIT_EXPECT_EQ(test, s->quota.charged_sz, 0ul); + KUNIT_EXPECT_EQ(test, s->quota.charged_from, 0ul); + KUNIT_EXPECT_PTR_EQ(test, s->quota.charge_target_from, NULL); + KUNIT_EXPECT_EQ(test, s->quota.charge_addr_from, 0ul); + KUNIT_EXPECT_EQ(test, quota.esz, 123ul); + KUNIT_EXPECT_EQ(test, quota.esz_bp, 456ul); + KUNIT_EXPECT_EQ(test, quota.total_charged_sz, 789ul); + KUNIT_EXPECT_EQ(test, quota.total_charged_ns, 1011ul); + KUNIT_EXPECT_EQ(test, quota.charged_sz, 12ul); + KUNIT_EXPECT_EQ(test, quota.charged_from, 13ul); + KUNIT_EXPECT_PTR_EQ(test, quota.charge_target_from, &target); + KUNIT_EXPECT_EQ(test, quota.charge_addr_from, 14ul); + damon_destroy_scheme(s); +} + static void damos_test_commit_quota_goal_for(struct kunit *test, struct damos_quota_goal *dst, struct damos_quota_goal *src) @@ -1572,6 +1614,69 @@ static void damon_test_commit_ctx(struct kunit *test) damon_destroy_ctx(dst); } =20 +static void damon_test_commit_ctx_keeps_quota_for(struct kunit *test, + unsigned long min_region_sz, int expected_err) +{ + struct damos_access_pattern pattern =3D {}; + struct damos_quota quota =3D {.sz =3D SZ_64K}; + struct damos_watermarks wmarks =3D {}; + struct damon_ctx *src, *dst; + struct damon_target *target; + struct damos *s; + + dst =3D damon_new_ctx(); + if (!dst) + kunit_skip(test, "dst alloc fail"); + target =3D damon_new_target(); + if (!target) { + damon_destroy_ctx(dst); + kunit_skip(test, "target alloc fail"); + } + damon_add_target(dst, target); + s =3D damon_new_scheme(&pattern, DAMOS_STAT, 0, "a, &wmarks, + NUMA_NO_NODE); + if (!s) { + damon_destroy_ctx(dst); + kunit_skip(test, "scheme alloc fail"); + } + damon_add_scheme(dst, s); + + /* Copy the parameters before populating dst's runtime quota state. */ + src =3D damon_new_test_ctx(dst); + if (!src) { + damon_destroy_ctx(dst); + kunit_skip(test, "src alloc fail"); + } + src->min_region_sz =3D min_region_sz; + s->quota.esz =3D 123; + s->quota.esz_bp =3D 456; + s->quota.total_charged_sz =3D 789; + s->quota.total_charged_ns =3D 1011; + s->quota.charged_sz =3D 12; + s->quota.charged_from =3D 13; + s->quota.charge_target_from =3D target; + s->quota.charge_addr_from =3D 14; + + KUNIT_EXPECT_EQ(test, damon_commit_ctx(dst, src), expected_err); + KUNIT_EXPECT_EQ(test, s->quota.esz, 123ul); + KUNIT_EXPECT_EQ(test, s->quota.esz_bp, 456ul); + KUNIT_EXPECT_EQ(test, s->quota.total_charged_sz, 789ul); + KUNIT_EXPECT_EQ(test, s->quota.total_charged_ns, 1011ul); + KUNIT_EXPECT_EQ(test, s->quota.charged_sz, 12ul); + KUNIT_EXPECT_EQ(test, s->quota.charged_from, 13ul); + KUNIT_EXPECT_PTR_EQ(test, s->quota.charge_target_from, target); + KUNIT_EXPECT_EQ(test, s->quota.charge_addr_from, 14ul); + damon_destroy_ctx(src); + damon_destroy_ctx(dst); +} + +static void damon_test_commit_ctx_keeps_quota(struct kunit *test) +{ + /* Only power of two min_region_sz is allowed. */ + damon_test_commit_ctx_keeps_quota_for(test, 4096, 0); + damon_test_commit_ctx_keeps_quota_for(test, 4095, -EINVAL); +} + static void damon_test_valid_probe_params(struct kunit *test) { struct damon_ctx *ctx; @@ -1946,6 +2051,7 @@ static struct kunit_case damon_test_cases[] =3D { KUNIT_CASE(damon_test_mvsum), KUNIT_CASE(damon_test_nr_accesses_mvsum), KUNIT_CASE(damos_test_new_filter), + KUNIT_CASE(damos_test_new_scheme_keeps_src_quota), KUNIT_CASE(damos_test_commit_quota_goal), KUNIT_CASE(damos_test_commit_quota_goals), KUNIT_CASE(damos_test_commit_quota), @@ -1957,6 +2063,7 @@ static struct kunit_case damon_test_cases[] =3D { KUNIT_CASE(damon_test_commit_filter), KUNIT_CASE(damon_test_commit_probes), KUNIT_CASE(damon_test_commit_ctx), + KUNIT_CASE(damon_test_commit_ctx_keeps_quota), KUNIT_CASE(damon_test_valid_probe_params), KUNIT_CASE(damos_test_filter_out), KUNIT_CASE(damon_test_feed_loop_next_input), --=20 2.53.0