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: 127883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp712365vqg; Fri, 28 Jul 2023 15:00:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHETZcgIZ8WIKUSDpN0vKc7WpbKb1B/QC9rGx6dBXdk83yDERDywbzYsCK++Umd7SLfA3jk X-Received: by 2002:a17:906:538f:b0:988:71c8:9f3a with SMTP id g15-20020a170906538f00b0098871c89f3amr753234ejo.16.1690581611029; Fri, 28 Jul 2023 15:00:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690581611; cv=none; d=google.com; s=arc-20160816; b=fqCsBysPIoXarKte1Jgq4VW43IJVckk4pCjtAwkZKTWigZOivUs8/awi6lEB1eNHbf em7tdgxt/Y1Ke5uJ0OvVop2hAWuRAnKG0GLNP8PA8u7zLilqnks2xG/JsRXA2iAp1cF5 OV7Nsd0uzvBFFk0haFa1kYnX2pjOK0PzQM47PO48htDBVAaOMjvCrcXcQSRKx6KVh0ba SbKdg9mi2lR1AfV1GY3VV6jYHG2/uTPpyvmHVSR879Qx5L32XNQGq9LVsHgmI90L/prR vVpreS+ZR/JSGt3ZT+Gj0bqKO1j0nYJATGP98CMvR0qlP+0IKNfQi07A0OGriIQVZ4nc nQQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fVYuQJLiZl8uIc53LWCcyTnroAUK9bg2u4FsZ4TNlFE=; fh=d/e0e8gtUnIan/NSjMuu66p3SVPUMATwe3K/TPr/ppM=; b=ZyYgkCDJPbQyK2YHB0KMkJ8lF/DPw2/Ef3ywpLycKd5zGZIgZOrYmGTczpOdxYb22c PbXgVr7+AFqDUJfvVQYsVMRs7xwwaW0OvN7ZQgoGj11Sl3Obcx5atIhj3xJNKuLBwlkh DHwfqoLFqPaFeoCP5BFcRTCNJnmCxxDDs/cdZBnxyWP0SV7gbXesR9uHlmAuCQ7zsWsJ pfxz+otCjTNaw5Hj938E3TFVd1QXCYe4jsmARmKq0nMvqwJaLHdUIsHdl3dx3N7If6lv bUFjSx+vjSpvK958Ue3yfkz4GIuDaTpel1wXQxI/7aJOUi9VlCtOF9YcccNG8lmoh6Th cjCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uHaALqes; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id op12-20020a170906bcec00b00988c81e980dsi845142ejb.1039.2023.07.28.14.59.47; Fri, 28 Jul 2023 15:00:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uHaALqes; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234779AbjG1UfE (ORCPT + 99 others); Fri, 28 Jul 2023 16:35:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233017AbjG1Uey (ORCPT ); Fri, 28 Jul 2023 16:34:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D040B44B1; Fri, 28 Jul 2023 13:34:51 -0700 (PDT) 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 25D0A621DE; 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772700729094589863 X-GMAIL-MSGID: 1772703303690786488 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), {}, };