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: 13107282 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 228FDC38159 for ; Thu, 19 Jan 2023 01:38:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8722B6B0073; Wed, 18 Jan 2023 20:38:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8234D6B0074; Wed, 18 Jan 2023 20:38:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5681A6B0075; Wed, 18 Jan 2023 20:38:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 402716B0073 for ; Wed, 18 Jan 2023 20:38:42 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 068F2AAD7B for ; Thu, 19 Jan 2023 01:38:42 +0000 (UTC) X-FDA: 80369839284.11.7D0E232 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 7F51E1A0009 for ; Thu, 19 Jan 2023 01:38:40 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="s/Sn7kF6"; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674092320; 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=MnbWAeGIgkbFdIP5SaC2nqAaGdYVI4g3zgJAzihcluk=; b=YG7CQl9ePtGkGnOL5pEK/xyzQ14n9MlinBY92EEfgKuSg5vdwRQnSutvo7lThGu2Qysnuc 9P2ixKOPWj+XoMbg3q7TZw9P78b2ruy4BfbunPFSqFqr8c/FlydxCjawl73UUqLH4kg8BI ghh/lXd5B/Pe2YdVe0IrCb89nRR8qak= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="s/Sn7kF6"; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674092320; a=rsa-sha256; cv=none; b=8egz0PhCRFQZDv0STuci8Qwtkbm4hVew07/GKk9Gh1UBw3XkwreC0EMy0GxNNNxaS0rplV nBz/vb4WHBiLoowaVpQDhTJ7ztyQmtHxoCkZbAaga3mHlp6qaST9OW3WqinG8wZtou65BU zWpb3Gedy8GnHaR8vV8mHajtJVFF2HY= 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 BAEBB61745; 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7F51E1A0009 X-Rspam-User: X-Stat-Signature: 63tkatxit8gqb9t4i3wxcybpkrzpbc7j X-HE-Tag: 1674092320-115300 X-HE-Meta: U2FsdGVkX1/VZpsy8nrhA9T/eXPK3iqXijABhNIRmD3vmYPzvxG5gCNYxsBehlduCreaZLmbTbaJoR8le0qHB+OuNvnUor7DSNheH0XZp0zDm/L9CVEuXPFrBaBc1CaMTJg9OZY4zww/hT4/y+63R75RGe3y+jayjwhJaCsdl4OdqRiSLtKchdJJRG/Zv0PhnZLl7KMpjyI7/R13iW2CTZM2o11gkaOfyGJfwDiiY4sn4Q1NH9BsEtangbfzhKjU9AZ/9VplU7Vm/FrpdB1FaCUkKvjvVZb7BrMZK8Ihm2css8pxnI9yA6NQF4tCxkuJuZrQDY/FbBdCd6z1l/3BKzr73X+UJwsWpFQvqjJj3BpkgA1/suG5Bluo+e/rhSV0cw7Zj6m/6cIsnYCRCGTaZ/GT2extQIVaPyhQY+4VqIM+0eESivCAc8CoQRxjuc0JeJR2dtq5VRC4m4XuCTmlZVWcm10GiJx23cjUMkNJrrDPV+yKdU4qi0oAYFsXx2nleDIwJ0fJh/nF6te7fLsNIxgOKY8ddwrIx8zLrsTYvrcr6cgZkfCr0JkO9fxzuZW5WyJUVRKfspTLsfPbSnuyeN006V+YC5mtMsEboHjLYx1XjGhoZTw7FvZpkfyMX8jC9ZgzOF0crgtPbV9cHcrX37hZNZ+jtOleHfBuWhhM2Uz3/mPItXpKWg1PYKVtjo3Q1SvsjwaT5jsAKbUDdBqLXgac52vqG5bdpf6ZXt7hx+WMZr0lwROCU8AWFAtiO+Zuhvhbh6C+ONoXd9dk3Of1FKHlNR2V8dKwrQzxeUh3UeFOT9ffcNy1q6c1yZORiSW5AIfg7FS8GnC2BPyryY2H+Yg51UXNVwL78zGbmsDweFF0fAdiKp0zPcbuq3Io3QUFf31F5LuAoHuoEDzONk1TbQWDQE5xO2/3g/esI0LrHsDwunFYpaIGVXdoMdcJ4bcz5N9GFg+D5mEE/TQqj6Z hk2JN1Ck f9AyqFeg43kkPMqaUrE0qcvG/DXnACUOr+AML+asuzHhzyKHAPAC4FYJYICM+qxT3Tp6n 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: 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; }