From patchwork Thu Jan 19 01:38:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 45562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp87759wrn; Wed, 18 Jan 2023 17:58:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXtiD/P7yVp01OpcHtPk7Qo/p/9oVlaa0Dcw/TBCup9QjnnWyGHky019cooMhuFBh/XOKniY X-Received: by 2002:a17:90a:5587:b0:229:74a3:3017 with SMTP id c7-20020a17090a558700b0022974a33017mr9779188pji.27.1674093500936; Wed, 18 Jan 2023 17:58:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674093500; cv=none; d=google.com; s=arc-20160816; b=OTei7Quj4Q+OpXFp3SOyoih3GMZcuym1bqeqacGUrqt1SFo/M7FaIFySF/W9hjhRNZ G2Uhzst9atw3IfP9MrIPoHREzEBg1etW54EM1kJfT8DhhD0Am9ppL9Ziycm9TARkUKb8 TaC7w1scO7XSLz6Gu0uYrsxv1P6TmRyXFYS1lX0BFMhCLR9HIWqtSmjQQNMNfP6SLkkz YLlaeZaTERSsW1UXleyXrIY9eAVYAZYQcslwZrg1N1nvf6ziVAmdw6/UuOUORuQWsqrM sbEB2DYIL97u7oUJwsxM55ct5NNEPIm6AyBx0KEQmmv2lZ2iqBgLPHrXrk7kBRd2VsJU iMkA== 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=Oy1cp+7yGyUimK41XJ4B2m90vIX7M8nbu9KoSvGzCqQ=; b=m2WxKhsgd4rlZZ1EfbvGX2aAFCxmh6lVxMafRz/9cuhU3em+3D2CTMHHj01ebW9ZsG XFeP41yYvAQqdk8fdwza5dfO3emZv8uIXbaWEd4/0MK2AwQdW70QWvV1v2AZfZ2QPuPd jbBfb7nJEZJORJ7hIcqUqFyFNoHT0Jg57KvH5iaSeSn8owPK1KDMy6gc6oc4WXDWKilI jFzc9G4cNFejkrlRaFkKvUl/OOUtiUJK6Atwk5NliQQazwGcuZEdOmSluC2HdtMPUex2 PF5oD8fClVeho//fh3Vve4dSo37Be5xwvibIT+CB6tITj9SH8P+4nycAmuYy7oUU41/0 sNLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CnXTVAit; 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 x11-20020a17090ab00b00b00229791d2daesi3490698pjq.12.2023.01.18.17.58.08; Wed, 18 Jan 2023 17:58:20 -0800 (PST) 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=CnXTVAit; 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 S229576AbjASBt1 (ORCPT + 99 others); Wed, 18 Jan 2023 20:49:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229983AbjASBpl (ORCPT ); Wed, 18 Jan 2023 20:45:41 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 823A06CCC3 for ; Wed, 18 Jan 2023 17:38:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CC56DB81FB1 for ; Thu, 19 Jan 2023 01:38:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26FDAC433EF; Thu, 19 Jan 2023 01:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674092318; bh=fkjQwp0vLjtzRNvd4VhBq2nF7CfFg6frjzTnDoBz50k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CnXTVAitPDgUvsOiX6vW9aROGzCslmoqZfT8CZ2eLQCt4U75qjK1GOtsmFX5Hh1mL GHkICAtA9fIez2uteqBjb+qkYlDqDgZoVFOyaA4k/GTtblnEyhvBhAtb4e4LVws6Qp DA9xynr2yHeQuGfMie535L77J68Rf4loZ8vsr36yvq7yvQL4QJvvOEOs1qtxUHHtBx eUoZBktQdw6BQ+9ajw8kIqoYs6Jgg2rVBMLS5qY0Iq/Jrrd97ra5R6/NBQbhXbH+Sh OBWxwozsw+MPupdH+wpqF7B5X13pWPDxxv1U/jyd8aViHxPxoVK+3G1FYOFKLnTa3g k+lZHNQuKqP+A== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mm/damon: update comments in damon.h for damon_attrs Date: Thu, 19 Jan 2023 01:38:29 +0000 Message-Id: <20230119013831.1911-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230119013831.1911-1-sj@kernel.org> References: <20230119013831.1911-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755414266438994381?= X-GMAIL-MSGID: =?utf-8?q?1755414266438994381?= Commit cbeaa77b0449 ("mm/damon/core: use a dedicated struct for monitoring attributes") moved monitoring intervals from damon_ctx to a new struct, damon_attrs, but a comment in the header file has not updated for the change. Update it. Fixes: cbeaa77b0449 ("mm/damon/core: use a dedicated struct for monitoring attributes") Signed-off-by: SeongJae Park --- include/linux/damon.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index dfb245bb3053..d5d4d19928e0 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -354,10 +354,10 @@ struct damon_ctx; * users should register the low level operations for their target address * space and usecase via the &damon_ctx.ops. Then, the monitoring thread * (&damon_ctx.kdamond) calls @init and @prepare_access_checks before starting - * the monitoring, @update after each &damon_ctx.ops_update_interval, and + * the monitoring, @update after each &damon_attrs.ops_update_interval, and * @check_accesses, @target_valid and @prepare_access_checks after each - * &damon_ctx.sample_interval. Finally, @reset_aggregated is called after each - * &damon_ctx.aggr_interval. + * &damon_attrs.sample_interval. Finally, @reset_aggregated is called after + * each &damon_attrs.aggr_interval. * * Each &struct damon_operations instance having valid @id can be registered * via damon_register_ops() and selected by damon_select_ops() later. From patchwork Thu Jan 19 01:38:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 45563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp87761wrn; Wed, 18 Jan 2023 17:58:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXsFE076Xsom2rKTW+F+weTw2QgY9MiSxN+RW5769iESraToXEr1cQEleXeYgKY0FluiDKqR X-Received: by 2002:a05:6a21:398b:b0:b6:a58c:d01 with SMTP id ad11-20020a056a21398b00b000b6a58c0d01mr10330428pzc.30.1674093501151; Wed, 18 Jan 2023 17:58:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674093501; cv=none; d=google.com; s=arc-20160816; b=pgfsOe51Zd8ReR6r98e300AiwLTohSvJz3aodKNMajtGgQKfNGBazjWfKAXTnFTYtc +4GEPGcUKpuL3+MnzIA5tC3gh3jL3tpboLGFP2d68uTAlQJqbkC2AN/ZXgBtAP+6C7uJ qqQVua2vtAQJ8jp6XyVr740f5dIoUIjLore9lpF6XJahc6F+KTQPpQdhcjMw+//Qud1R h5FZ5fMMshSL9SZnq0MxYOazjLqbecsImPO5KP2gDpwqbYRCkM3yfDrFOo52Xn25nGS3 zbqW3d7uB/psaKNvGYWs4TWk05gOBTfpnT9VWydkIiL6aSo63vwDY1d65cY3uYCcPTBE H6pA== 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=MnbWAeGIgkbFdIP5SaC2nqAaGdYVI4g3zgJAzihcluk=; b=GThMXOwJYkW02QEiFVyd+znE72N2HvtlugSfyYFb9fjhlZI4cAMWD0pZJI345Vi/Ir wPXpLubb8khuyye269p/7d5X0da13AInqYBYJ2ES4yhC3EAOX+TWZGjKfW0Frt8P3LD1 6X6Jdidtu1XPwIK4OJ3fULphqEo0aRCI4jMmYPQxUmB7iVJyyhp1tZ4CVmDN4KGMfiWx j+WbB7JQZqF/otMZ5yS8UO89ix+uIH0mSRLVXaUxpRlRmWxWqDS2isqS4gL7LKMX8LzN JbSSmH915LFtFV0kqPORdTKzVU7FcECOx51DCO/+q9PejQPAu9P4E19I4HX1jLVL2NvO HQDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="s/Sn7kF6"; 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 s76-20020a632c4f000000b004cd4083794bsi11612391pgs.294.2023.01.18.17.58.09; Wed, 18 Jan 2023 17:58:21 -0800 (PST) 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="s/Sn7kF6"; 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 S229916AbjASBtg (ORCPT + 99 others); Wed, 18 Jan 2023 20:49:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229967AbjASBpl (ORCPT ); Wed, 18 Jan 2023 20:45:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E22C6B997 for ; Wed, 18 Jan 2023 17:38:40 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BB7256176F for ; Thu, 19 Jan 2023 01:38:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF8F7C433F1; Thu, 19 Jan 2023 01:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674092319; bh=yP6UCgAzws1bfIuCPl7GC+6z1XlLpntmwCkcasuOLyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s/Sn7kF6Omqwq6ivaQphfNyZL1j/yVGYRmDcofn0KoeDu27nTBXyEXj08jraNePN+ Xn4BAUjzN+DK4KTjJBGSJcB8oka3uisg8HYE5hMkn9XrF/IRHDk/KKChGrB3enxxv6 4mqfuu2PfswrNY11OQriGo6l+SmFWK12o3UpoVnDU2Fp2ZxmpdceUme7do10dGrDnU +TqGgvf+I8K8kk21Zmqht6LtGFiwLRyKbVqV5J/B7v663j9EYoJk9DuuGUZnFwsZTq bQmbCIu49vdLv1YmI9j8umVn8Ym1RnWBYzFW9gzIpapvEb3oZMUwJ1HueZvAcuErDK gjORYVfVgvtqA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm/damon/core: update monitoring results for new monitoring attributes Date: Thu, 19 Jan 2023 01:38:30 +0000 Message-Id: <20230119013831.1911-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230119013831.1911-1-sj@kernel.org> References: <20230119013831.1911-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755414267103934485?= X-GMAIL-MSGID: =?utf-8?q?1755414267103934485?= region->nr_accesses is the number of sampling intervals in the last aggregation interval that access to the region has found, and region->age is the number of aggregation intervals that its access pattern has maintained. Hence, the real meaning of the two fields' values is depending on current sampling and aggregation intervals. This means the values need to be updated for every sampling and/or aggregation intervals updates. As DAMON core doesn't, it is a duty of in-kernel DAMON framework applications like DAMON sysfs interface, or the userspace users. Handling it in userspace or in-kernel DAMON application is complicated, inefficient, and repetitive compared to doing the update in DAMON core. Do the update in DAMON core. Signed-off-by: SeongJae Park --- mm/damon/core.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index 2db8c53491ca..d9ef62047bf5 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -465,6 +465,76 @@ void damon_destroy_ctx(struct damon_ctx *ctx) kfree(ctx); } +static unsigned int damon_age_for_new_attrs(unsigned int age, + struct damon_attrs *old_attrs, struct damon_attrs *new_attrs) +{ + return age * old_attrs->aggr_interval / new_attrs->aggr_interval; +} + +/* convert access ratio in bp (per 10,000) to nr_accesses */ +static unsigned int damon_accesses_bp_to_nr_accesses( + unsigned int accesses_bp, struct damon_attrs *attrs) +{ + unsigned int max_nr_accesses = + attrs->aggr_interval / attrs->sample_interval; + + return accesses_bp * max_nr_accesses / 10000; +} + +/* convert nr_accesses to access ratio in bp (per 10,000) */ +static unsigned int damon_nr_accesses_to_accesses_bp( + unsigned int nr_accesses, struct damon_attrs *attrs) +{ + unsigned int max_nr_accesses = + attrs->aggr_interval / attrs->sample_interval; + + return nr_accesses * 10000 / max_nr_accesses; +} + +static unsigned int damon_nr_accesses_for_new_attrs(unsigned int nr_accesses, + struct damon_attrs *old_attrs, struct damon_attrs *new_attrs) +{ + return damon_accesses_bp_to_nr_accesses( + damon_nr_accesses_to_accesses_bp( + nr_accesses, old_attrs), + new_attrs); +} + +static void damon_update_monitoring_result(struct damon_region *r, + struct damon_attrs *old_attrs, struct damon_attrs *new_attrs) +{ + r->nr_accesses = damon_nr_accesses_for_new_attrs(r->nr_accesses, + old_attrs, new_attrs); + r->age = damon_age_for_new_attrs(r->age, old_attrs, new_attrs); +} + +/* + * region->nr_accesses is the number of sampling intervals in the last + * aggregation interval that access to the region has found, and region->age is + * the number of aggregation intervals that its access pattern has maintained. + * For the reason, the real meaning of the two fields depend on current + * sampling interval and aggregation interval. This function updates + * ->nr_accesses and ->age of given damon_ctx's regions for new damon_attrs. + */ +static void damon_update_monitoring_results(struct damon_ctx *ctx, + struct damon_attrs *new_attrs) +{ + struct damon_attrs *old_attrs = &ctx->attrs; + struct damon_target *t; + struct damon_region *r; + + /* if any interval is zero, simply forgive conversion */ + if (!old_attrs->sample_interval || !old_attrs->aggr_interval || + !new_attrs->sample_interval || + !new_attrs->aggr_interval) + return; + + damon_for_each_target(t, ctx) + damon_for_each_region(r, t) + damon_update_monitoring_result( + r, old_attrs, new_attrs); +} + /** * damon_set_attrs() - Set attributes for the monitoring. * @ctx: monitoring context @@ -482,6 +552,7 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs) if (attrs->min_nr_regions > attrs->max_nr_regions) return -EINVAL; + damon_update_monitoring_results(ctx, attrs); ctx->attrs = *attrs; return 0; } From patchwork Thu Jan 19 01:38:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 45564 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp87778wrn; Wed, 18 Jan 2023 17:58:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXsHCAawHwWoWjgzXcExXMfgt73fIItdPt3Iuqez50Ky377qWljSuu9PBYIc234G4MK3SMZW X-Received: by 2002:a05:6a21:3381:b0:af:6cc0:5b3d with SMTP id yy1-20020a056a21338100b000af6cc05b3dmr13314704pzb.7.1674093504945; Wed, 18 Jan 2023 17:58:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674093504; cv=none; d=google.com; s=arc-20160816; b=l4gZAiB81RgYeRgNCNd+j7+qxEoLKZKQLc+RSBavUqWXJ3OlR6jl5qAtwM2BCE3Ll9 kCxt1amaQ4AqWqkjpNYgJxy6hNLuhKM2SLL6jtIwgqrT+eqsp4rRsMpw88CQu6E2XXF7 vr7nPlSD5vaZ/q0eCdT0HO/UfOrxRr5epVdH7JnGwvwqEbvcjhzF0NDXbNaiG/Ro/lU5 nEwK89Rskk60WpRdydOlfMCP/swLzYGjOCuyc20pA4BM+tYo5FIB9fchAQGjAQDMCBy4 1QaZs9EoLSHv1wcfl+ZMviFKVYIyE+KLVLCjXJHu0UUnhh2ROqcgKitA4CV3qZiQ2TeI uz7Q== 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=3fNupXQhsN5vsVTB6XW0C50NRNjjMAsS/7fTR58sXqA=; b=bmgpEKouJxWcx5Y3Lip6FcTcTvYwCHMgBGhcsTlRsxrirwnP1WMkNr8Zg52frPAb4i 9JDU8DE4R8BuMP4DVtIiVVBJIBGqU/Ee+X2uq3XwzP033MrJu+im7JXzK/2vqjH6k5to uuYAcQNhXJvBDjsjuiCtHgZrrrQm7HiviCXtdnt85VJaJa/RWv9/jdyn++cwIPxp6jMI Tksz77HFw/AJSkjUMKsVi924MyjS8HhxuulbL1iRXiJZKC3wLv5titr92HcKjxV31cLB OfmuKL+917UFiQjRe9crzqov1Yd4Lt/hVKUUeNcZNWKP/GpCbiko3T9o6UNH8rLo3Mr9 uEhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kg1+ilbz; 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 e7-20020a170903240700b00170f6f728d4si35879206plo.543.2023.01.18.17.58.12; Wed, 18 Jan 2023 17:58:24 -0800 (PST) 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=kg1+ilbz; 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 S230140AbjASBtm (ORCPT + 99 others); Wed, 18 Jan 2023 20:49:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbjASBpl (ORCPT ); Wed, 18 Jan 2023 20:45:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4E286CCC2 for ; Wed, 18 Jan 2023 17:38:40 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7480561781 for ; Thu, 19 Jan 2023 01:38:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 640F5C43396; Thu, 19 Jan 2023 01:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674092319; bh=4x0hnDy4BX61lB/pbgUpUZC1nSP8lE0d4hLy0MishdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kg1+ilbzWZybIQkILRS0j625AZhP7sNVWI2JBN+aHXZ2odIdbzI0kIXodhRrbj8ig ZMlQ4qeSzaSsYFpuRnzk1VeYWQRxyj3bxvcHY4BsmNvGwxGvezui3C/8oY8XHTfMr1 riwUIv17ty8xmzBgdHfrQcUrlhG/vmLian0Hf13hjJTOKFHuNoMjtcPWMyym5tVu2W Z2l+vaKdgROZU4t5MbhLxAXrs0ziF63YtDE1YtWY33j47VgUn7nJ579EToCzI5pPi+ ETtxqdK8+Gl28xqf7e28CIgB8kJEL99OCQ7yiOS28Z5gqgwE3vjfd2dFLeexDvyU9g HDsnVYKUsQkew== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , brendanhiggins@google.com, kunit-dev@googlegroups.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mm/damon/core-test: add a test for damon_update_monitoring_results() Date: Thu, 19 Jan 2023 01:38:31 +0000 Message-Id: <20230119013831.1911-4-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230119013831.1911-1-sj@kernel.org> References: <20230119013831.1911-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755414270878618656?= X-GMAIL-MSGID: =?utf-8?q?1755414270878618656?= Add a simple unit test for damon_update_monitoring_results() function. Signed-off-by: SeongJae Park --- mm/damon/core-test.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index 3db9b7368756..fae64d32b925 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -289,6 +289,35 @@ static void damon_test_set_regions(struct kunit *test) damon_destroy_target(t); } +static void damon_test_update_monitoring_result(struct kunit *test) +{ + struct damon_attrs old_attrs = { + .sample_interval = 10, .aggr_interval = 1000,}; + struct damon_attrs new_attrs; + struct damon_region *r = damon_new_region(3, 7); + + r->nr_accesses = 15; + r->age = 20; + + new_attrs = (struct damon_attrs){ + .sample_interval = 100, .aggr_interval = 10000,}; + damon_update_monitoring_result(r, &old_attrs, &new_attrs); + KUNIT_EXPECT_EQ(test, r->nr_accesses, 15); + KUNIT_EXPECT_EQ(test, r->age, 2); + + new_attrs = (struct damon_attrs){ + .sample_interval = 1, .aggr_interval = 1000}; + damon_update_monitoring_result(r, &old_attrs, &new_attrs); + KUNIT_EXPECT_EQ(test, r->nr_accesses, 150); + KUNIT_EXPECT_EQ(test, r->age, 2); + + new_attrs = (struct damon_attrs){ + .sample_interval = 1, .aggr_interval = 100}; + damon_update_monitoring_result(r, &old_attrs, &new_attrs); + KUNIT_EXPECT_EQ(test, r->nr_accesses, 150); + KUNIT_EXPECT_EQ(test, r->age, 20); +} + static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_target), KUNIT_CASE(damon_test_regions), @@ -299,6 +328,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_split_regions_of), KUNIT_CASE(damon_test_ops_registration), KUNIT_CASE(damon_test_set_regions), + KUNIT_CASE(damon_test_update_monitoring_result), {}, };