From nobody Sun Jul 26 01:50:16 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED5FF54723 for ; Fri, 10 Jul 2026 04:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783656956; cv=none; b=Cft3ueQ8iG4HK6q8fMhbL9pAATXnMEgnCFl+qUOhSoj9m4dM70XNLXcgyoYcOJL3CM6PzNHqhPBhUn/+ImkOmsojJctvXZycmpfgdW4uKNq6fqh6cWrgV98GOcW/Xr8Jf3X0LcxLqTfq2X5qfI5wMhMtg9U75j87bE2os0DtDGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783656956; c=relaxed/simple; bh=StEnbOo+zEHodg6CrOnCLMQne7D1onrJ0AjE/PZLws8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Bt1CThG2DIILsZ/mPJ9rrTt6pelJS31xSCEiwT6CpBYAxosWULOhKlNyfBT0HVEaIoaDA6mhP1K1aaxljwfsXvCGwP/YFIZNPtt8RIIjuMkrPaxi8k0zGO7Nuf+ScRVeLOXR+qLvDKCM7KiRYe4Nqgv6jl+wP81qWoonBc+zZVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 045c12ee7c1611f1aa26b74ffac11d73-20260710 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM, HR_SJ_PHRASE HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT, HR_TO_NO_NAME IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED, SA_EXISTED, SN_UNTRUSTED SN_UNFAMILIAR, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS, CIE_GOOD CIE_GOOD_SPF, GTI_FG_BS, GTI_RG_INFO, GTI_C_BU, AMN_GOOD ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:fd994086-c493-4c72-b1db-2b690073c017,IP:10, URL:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:35 X-CID-INFO: VERSION:1.3.12,REQID:fd994086-c493-4c72-b1db-2b690073c017,IP:10,UR L:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:35 X-CID-META: VersionHash:e7bac3a,CLOUDID:d75f8329d6be75e53ff2f0d667151fff,BulkI D:260710121545M08Y2OKM,BulkQuantity:0,Recheck:0,SF:17|19|66|78|102|127|865 |898,TC:nil,Content:0|15|50,EDM:5,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS: nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,AR C:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 045c12ee7c1611f1aa26b74ffac11d73-20260710 X-User: husong@kylinos.cn Received: from ctao-book.. [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 154396007; Fri, 10 Jul 2026 12:15:42 +0800 From: Song Hu To: sj@kernel.org Cc: akpm@linux-foundation.org, shu17az@gmail.com, jiayuan.chen@shopee.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Song Hu Subject: [PATCH] mm/damon/tests/core-kunit: test damon_nr_accesses_mvsum() Date: Fri, 10 Jul 2026 12:15:30 +0800 Message-ID: <20260710041530.557455-1-husong@kylinos.cn> X-Mailer: git-send-email 2.43.0 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_nr_accesses_mvsum() wraps damon_mvsum() with the monitoring intervals of the context to compute the pseudo moving sum of a region's access frequency, with a special case for when the whole aggregation window remains. damon_mvsum() itself is already covered by damon_test_mvsum(), but the wrapper is not. Add a table-driven KUnit test that exercises the full-window-remaining boundary (with both reset and not-yet-reset nr_accesses), partially elapsed windows, and the no-window-remaining case. Signed-off-by: Song Hu --- mm/damon/tests/core-kunit.h | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index 0124f83b39b8..8c030282a638 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -683,6 +683,54 @@ static void damon_test_mvsum(struct kunit *test) } } =20 +/* + * Test damon_nr_accesses_mvsum(), which wraps damon_mvsum() with the moni= toring + * intervals of the context. With a sample interval of 1 and an aggregati= on + * interval of 10, an aggregation window is 10 sample intervals long. Eac= h row + * below specifies the passed sample intervals, the next aggregation time = in + * sample intervals, the current and last nr_accesses of a region, and the + * expected return value. + */ +static void damon_test_nr_accesses_mvsum(struct kunit *test) +{ + unsigned long input_expects[] =3D { + /* passed, next_aggr, nr_accesses, last_nr_accesses, expect */ + 0, 10, 5, 3, 3, /* bp=3D10000: unreset nr_accesses ignored */ + 0, 10, 0, 7, 7, /* bp=3D10000: reset nr_accesses */ + 5, 10, 3, 10, 8, /* bp=3D5000: half window left */ + 8, 10, 3, 10, 5, /* bp=3D2000: 20% window left */ + 10, 10, 42, 49, 42, /* bp=3D0: no window left */ + }; + struct damon_ctx *c =3D damon_new_ctx(); + struct damon_region *r; + int i; + + if (!c) + kunit_skip(test, "ctx alloc fail"); + + r =3D damon_new_region(0, 4096); + if (!r) { + damon_destroy_ctx(c); + kunit_skip(test, "region alloc fail"); + } + + c->attrs.sample_interval =3D 1; + c->attrs.aggr_interval =3D 10; + + for (i =3D 0; i < ARRAY_SIZE(input_expects); i +=3D 5) { + c->passed_sample_intervals =3D input_expects[i]; + c->next_aggregation_sis =3D input_expects[i + 1]; + r->nr_accesses =3D input_expects[i + 2]; + r->last_nr_accesses =3D input_expects[i + 3]; + + KUNIT_EXPECT_EQ(test, (unsigned int)input_expects[i + 4], + damon_nr_accesses_mvsum(r, c)); + } + + damon_free_region(r); + damon_destroy_ctx(c); +} + static void damos_test_new_filter(struct kunit *test) { struct damos_filter *filter; @@ -1576,6 +1624,7 @@ static struct kunit_case damon_test_cases[] =3D { KUNIT_CASE(damon_test_update_monitoring_result), KUNIT_CASE(damon_test_set_attrs), KUNIT_CASE(damon_test_mvsum), + KUNIT_CASE(damon_test_nr_accesses_mvsum), KUNIT_CASE(damos_test_new_filter), KUNIT_CASE(damos_test_commit_quota_goal), KUNIT_CASE(damos_test_commit_quota_goals), --=20 2.43.0