From patchwork Fri Jul 28 20:34:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13332650 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B0C8C001E0 for ; Fri, 28 Jul 2023 20:34:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFD626B0071; Fri, 28 Jul 2023 16:34:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E85A18D0006; Fri, 28 Jul 2023 16:34:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD7AE6B0075; Fri, 28 Jul 2023 16:34:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B9A2C6B0071 for ; Fri, 28 Jul 2023 16:34:53 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 91302803D9 for ; Fri, 28 Jul 2023 20:34:53 +0000 (UTC) X-FDA: 81062174466.18.5798223 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id CE74B40028 for ; Fri, 28 Jul 2023 20:34:51 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uHaALqes; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690576491; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fVYuQJLiZl8uIc53LWCcyTnroAUK9bg2u4FsZ4TNlFE=; b=ZHZmBNsIWhCZk/gvGxm1bJgk8P21RIAi4qvMKmpNwD5lWqp3m1aEUir5fU26J8YB9RnDJ7 qb7epZIUKr+1l3ngBN6YymW6zMb6Gm3PkRbuT0dWxzKJLL1W3JLR7R8hryjTAyY82mfUZn IIEHCzfTt1CGGJpZH15xTaesFQiuj0E= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uHaALqes; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690576491; a=rsa-sha256; cv=none; b=T3L4E8ihzJcpUNDGc7qvhfv2WDhHgmkT6XjmExSiHRABiGvKKER3dWwWGkJnHITTujBaPa mVBqoZU3Xznw/JBRRHW4W961E34IAdetLbEv0gsQLGqTL+FtySJi3w+NpwjyurIUwLnKy7 627TbEdaK2Ea9HvjVhDY2Zk6mjj6Kug= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2626C621FF; Fri, 28 Jul 2023 20:34:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05B8FC433C7; Fri, 28 Jul 2023 20:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690576490; bh=aTd7ZuoN2dqMb+Dc3vZmzHmkBbEHdDRR0W76w/Wxm9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uHaALqesayPQAQaMFyoatkS0d9yBuH4VODT9oIuLMtnuAYobLsCePrdVnBbcsbqqI VBDvvxTRr6nqxiWs+zGazfRlogNLiP45rDy2vrRvGL7e6Uj5UlZciuqGHUfpgqoMv3 0f6p2eJ4s3HUw0+aMGyXSDYfCSJ3HijPVajgOTVCY3bH4bKqTAumxSG5m8NKPOd7Di QE599sbBuX1GKUKHgOO2OWsG1PfEFk/S1J56QLMkx8qe4Zf0hIjqRfVgQ+ZKPqiIxQ WyWIfDqCEzRje4Caw7wlBeubHSlwUsIfL+O3Oaobp4qZeBM2YikOnI3sLb/ipF0D04 f22X8tBKLD/Sw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Brendan Higgins , damon@lists.linux.dev, linux-mm@kvack.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 02/13] mm/damon/sysfs-schemes: support address range type DAMOS filter Date: Fri, 28 Jul 2023 20:34:34 +0000 Message-Id: <20230728203444.70703-4-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230728203444.70703-1-sj@kernel.org> References: <20230728203444.70703-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: CE74B40028 X-Stat-Signature: 9iuemrtn7wg7yiq7z1rio3enehnkpbyr X-Rspam-User: X-HE-Tag: 1690576491-790149 X-HE-Meta: U2FsdGVkX1/HGALVnVyh8IZg0nhJiP24JoZ4R0lZlGDKiry4OdRDYt5Llb2aC+oVrhl2+YDcyQHP/km4i/Mv6d5LyYYoBgZNyroOmQ5GQpB75Z6DAl/v78c0EvInSwdi9IM+a0UqnQCZjfLCfQ21IBcYcDb7+6BncVge7mFVqPaOtaOMkz1WyvcqS1rk9bZ00Q/csfb+C3MZPgb7RwWh/Hfaq9MIH4E9AzvkZGk0gtJFMMVTr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Kin+sq19F+s+sNWE8jA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Date: Sat, 22 Jul 2023 19:45:58 +0000 Subject: [RFC PATCH 03/13] mm/damon/core-test: add a unit test for __damos_filter_out() Implement a kunit test for the core of address range DAMOS filter handling, namely __damos_filter_out(). The test especially focus on regions that overlap with given filter's target address range. Signed-off-by: SeongJae Park --- mm/damon/core-test.h | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index bb07721909e1..44e925bbb094 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -341,6 +341,66 @@ static void damon_test_set_attrs(struct kunit *test) KUNIT_EXPECT_EQ(test, damon_set_attrs(c, &invalid_attrs), -EINVAL); } +static void damos_test_filter_out(struct kunit *test) +{ + struct damon_target *t; + struct damon_region *r, *r2; + struct damos_filter *f; + + f = damos_new_filter(DAMOS_FILTER_TYPE_ADDR, true); + f->addr_range = (struct damon_addr_range){ + .start = DAMON_MIN_REGION * 2, .end = DAMON_MIN_REGION * 6}; + + t = damon_new_target(); + r = damon_new_region(DAMON_MIN_REGION * 3, DAMON_MIN_REGION * 5); + damon_add_region(r, t); + + /* region in the range */ + KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); + + /* region before the range */ + r->ar.start = DAMON_MIN_REGION * 1; + r->ar.end = DAMON_MIN_REGION * 2; + KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); + + /* region after the range */ + r->ar.start = DAMON_MIN_REGION * 6; + r->ar.end = DAMON_MIN_REGION * 8; + KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); + + /* region started before the range */ + r->ar.start = DAMON_MIN_REGION * 1; + r->ar.end = DAMON_MIN_REGION * 4; + KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + /* filter should have split the region */ + KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 1); + KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 2); + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2); + r2 = damon_next_region(r); + KUNIT_EXPECT_EQ(test, r2->ar.start, DAMON_MIN_REGION * 2); + KUNIT_EXPECT_EQ(test, r2->ar.end, DAMON_MIN_REGION * 4); + damon_destroy_region(r2, t); + + /* region started in the range */ + r->ar.start = DAMON_MIN_REGION * 2; + r->ar.end = DAMON_MIN_REGION * 8; + KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f)); + /* filter should have split the region */ + KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 2); + KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 6); + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2); + r2 = damon_next_region(r); + KUNIT_EXPECT_EQ(test, r2->ar.start, DAMON_MIN_REGION * 6); + KUNIT_EXPECT_EQ(test, r2->ar.end, DAMON_MIN_REGION * 8); + damon_destroy_region(r2, t); + + damon_free_target(t); + damos_free_filter(f); +} + static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_target), KUNIT_CASE(damon_test_regions), @@ -353,6 +413,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_set_regions), KUNIT_CASE(damon_test_update_monitoring_result), KUNIT_CASE(damon_test_set_attrs), + KUNIT_CASE(damos_test_filter_out), {}, };