From patchwork Sat Sep 9 03:37:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13377947 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 708E3EEB584 for ; Sat, 9 Sep 2023 03:37:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B0F46B0102; Fri, 8 Sep 2023 23:37:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 160976B0103; Fri, 8 Sep 2023 23:37:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1C1A6B0104; Fri, 8 Sep 2023 23:37:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DE5526B0102 for ; Fri, 8 Sep 2023 23:37:30 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C580116027F for ; Sat, 9 Sep 2023 03:37:30 +0000 (UTC) X-FDA: 81215649060.21.F3F2B1B Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf22.hostedemail.com (Postfix) with ESMTP id 002BEC0002 for ; Sat, 9 Sep 2023 03:37:28 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Ip76wGuy; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 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=1694230649; 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=SaXC8O4arGdhiJ1dzbeNeChkubxREk2+pcfb1cTA5D8=; b=QoDl9VkqbmJoczrWfynTxhc56RW1CM4XkokAhjN2k8EGcx9X0z25BPxRF8eeNQcmEPHKwI sTkPXJWGA4dbgO8DBG96wUW6E+snr5KKMRxN5aPOdB5KsMok9JfzY7YENu9HyHfCSzxget nvo+tAuwSBAf2K8pZQv/Xypv3BDwzVU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Ip76wGuy; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694230649; a=rsa-sha256; cv=none; b=2YQjYGGPa/aQmm4HootUQES/JJYwavyGMokEvgzrR8Eg6JKQFGNFA3KQVzHT/A5/uU/d+V pSzIuLGT678/h1ALk93r9Iih0mf0bar4GKMxNeU1v2fVKjuhr6dKN4TYHLPUvhw5KeV/Pu i8y8vPyZ3sbdVcl0bZCFJgydGteo6nQ= 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 ams.source.kernel.org (Postfix) with ESMTPS id 97FB0B82334; Sat, 9 Sep 2023 03:37:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3A86C4339A; Sat, 9 Sep 2023 03:37:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694230647; bh=mrmW1/+KNJqZoPin01nmYe0xzn8mqXbGYK0Xoycksvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ip76wGuy1kQclDid3O3Hr+H5aEqWsLxQ9VqlQGBqDbPNn4DIjYmx7dNVCCEDUXl6+ qSKTUGWoIiZ6CkGeDuD/wIu6qJzbPCAJdOpDMLb415uyHG6hCONMG0hJdxH0B/A2Tv zcBSITAi15CoDEkGyEkmGRB3Cr8zNVJHoTSnrjcWnmZH8pkLudRjKX5RInhXJj6EVd pydN8L02IK71T4nYiVFOGkkpWvbkqTwjrjVpXQ9vDASI17I89KJ90cOoWuM1vkrLtC mOVkysAoFWjhh2nZmHS0RF5ENIcMuJf2Vt70WNzYnDE0lMJKBSCtNUbzarm6e2VDzk 5klC4ikfyfMTQ== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 5/8] mm/damon/core: introduce nr_accesses_bp Date: Sat, 9 Sep 2023 03:37:08 +0000 Message-Id: <20230909033711.55794-6-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230909033711.55794-1-sj@kernel.org> References: <20230909033711.55794-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 002BEC0002 X-Stat-Signature: tcxzworeatygh1s1p5j7cexhthedk8ib X-Rspam-User: X-HE-Tag: 1694230648-347017 X-HE-Meta: U2FsdGVkX18r+CZsa6O12bOMJfnoZrW+AxIlQi8EYaHs9Ye2PAbwLIkdozlWZj0bmSMYazEGwC2Rh573da9r5co4lVdnje7KQUQINwJ3WnjSV8J9zEFjXfEOPzYet0vdTAdPHun5NeyqJAAbRLUxXtQ/Pew82WXp5HKuZgql/BBUI3wnd8LFs13ok+zfBp2J5+cB7YqhiR8aFa46VKJzKEzoVrjRngbWasY07yZvhB2AOZxif+lsiE1S5mKr+cXsZioKo05i1uyUHCcwsGQcM5I3j8dAw+CsKlEkzvzWbmJY0gWppnmeCkXO54J6l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bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add yet another representation of the access rate of each region, namely nr_accesses_bp. It is just same to the nr_accesses but represents the value in basis point (1 in 10,000), and updated at once in every aggregation interval. That is, moving_accesses_bp is just nr_accesses * 10000. This may seems useless at the moment. However, it will be useful for representing less than one nr_accesses value that will be needed to make moving sum-based nr_accesses. Signed-off-by: SeongJae Park --- include/linux/damon.h | 5 +++++ mm/damon/core-test.h | 5 +++++ mm/damon/core.c | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 487a545a11b4..15f24b23c9a0 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -40,6 +40,7 @@ struct damon_addr_range { * @ar: The address range of the region. * @sampling_addr: Address of the sample for the next access check. * @nr_accesses: Access frequency of this region. + * @nr_accesses_bp: @nr_accesses in basis point (0.01%). * @list: List head for siblings. * @age: Age of this region. * @@ -49,6 +50,9 @@ struct damon_addr_range { * not be done with direct access but with the helper function, * damon_update_region_access_rate(). * + * @nr_accesses_bp is another representation of @nr_accesses in basis point + * (1 in 10,000) that updated every aggregation interval. + * * @age is initially zero, increased for each aggregation interval, and reset * to zero again if the access frequency is significantly changed. If two * regions are merged into a new region, both @nr_accesses and @age of the new @@ -58,6 +62,7 @@ struct damon_region { struct damon_addr_range ar; unsigned long sampling_addr; unsigned int nr_accesses; + unsigned int nr_accesses_bp; struct list_head list; unsigned int age; diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index c539f0e8377e..79f1f12e0dd5 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -94,6 +94,7 @@ static void damon_test_aggregate(struct kunit *test) for (ir = 0; ir < 3; ir++) { r = damon_new_region(saddr[it][ir], eaddr[it][ir]); r->nr_accesses = accesses[it][ir]; + r->nr_accesses_bp = accesses[it][ir] * 10000; damon_add_region(r, t); } it++; @@ -147,9 +148,11 @@ static void damon_test_merge_two(struct kunit *test) t = damon_new_target(); r = damon_new_region(0, 100); r->nr_accesses = 10; + r->nr_accesses_bp = 100000; damon_add_region(r, t); r2 = damon_new_region(100, 300); r2->nr_accesses = 20; + r2->nr_accesses_bp = 200000; damon_add_region(r2, t); damon_merge_two_regions(t, r, r2); @@ -196,6 +199,7 @@ static void damon_test_merge_regions_of(struct kunit *test) for (i = 0; i < ARRAY_SIZE(sa); i++) { r = damon_new_region(sa[i], ea[i]); r->nr_accesses = nrs[i]; + r->nr_accesses_bp = nrs[i] * 10000; damon_add_region(r, t); } @@ -297,6 +301,7 @@ static void damon_test_update_monitoring_result(struct kunit *test) struct damon_region *r = damon_new_region(3, 7); r->nr_accesses = 15; + r->nr_accesses_bp = 150000; r->age = 20; new_attrs = (struct damon_attrs){ diff --git a/mm/damon/core.c b/mm/damon/core.c index 5bc0544b9f50..a97026489301 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -134,6 +134,7 @@ struct damon_region *damon_new_region(unsigned long start, unsigned long end) region->ar.start = start; region->ar.end = end; region->nr_accesses = 0; + region->nr_accesses_bp = 0; INIT_LIST_HEAD(®ion->list); region->age = 0; @@ -537,6 +538,7 @@ static void damon_update_monitoring_result(struct damon_region *r, { r->nr_accesses = damon_nr_accesses_for_new_attrs(r->nr_accesses, old_attrs, new_attrs); + r->nr_accesses_bp = r->nr_accesses * 10000; r->age = damon_age_for_new_attrs(r->age, old_attrs, new_attrs); } @@ -1148,6 +1150,7 @@ static void damon_merge_two_regions(struct damon_target *t, l->nr_accesses = (l->nr_accesses * sz_l + r->nr_accesses * sz_r) / (sz_l + sz_r); + l->nr_accesses_bp = l->nr_accesses * 10000; l->age = (l->age * sz_l + r->age * sz_r) / (sz_l + sz_r); l->ar.end = r->ar.end; @@ -1179,6 +1182,8 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres, else r->age++; + r->nr_accesses_bp = r->nr_accesses * 10000; + if (prev && prev->ar.end == r->ar.start && abs(prev->nr_accesses - r->nr_accesses) <= thres && damon_sz_region(prev) + damon_sz_region(r) <= sz_limit) @@ -1233,6 +1238,7 @@ static void damon_split_region_at(struct damon_target *t, new->age = r->age; new->last_nr_accesses = r->last_nr_accesses; + new->nr_accesses_bp = r->nr_accesses_bp; damon_insert_region(new, r, damon_next_region(r), t); }