Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp252231pxu; Tue, 6 Oct 2020 05:43:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyunJ9Bjxg1M5Y/rxLvybVUMcV2c07k3CfxbCBAk+iwcw+vaHqBX/h/EUMQwmIASASa2P/b X-Received: by 2002:aa7:c714:: with SMTP id i20mr5503466edq.136.1601988189789; Tue, 06 Oct 2020 05:43:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601988189; cv=none; d=google.com; s=arc-20160816; b=dUNBiJoJ+U4ftY2P4avgT8QwOjocD5r0ZnjfULNf4posRjsBaSjKFS87goFNcTaE/m baQX1K6aPNtVgS5ecIeDHGTJnYoEJvdmU7kQUyYVxqO654pnx8Hf4930aM/oawO4sVow jlyVqJfhkgxuSNPuAvLFCqdn1h2xDvwiRevCmGIzU5mBIIeBUimXjun6DZmKEXlImFch 9o3ScV77rN8wl5Wfh6I8K2YLwrGIvvK2DE9ATR/c0pYk3g9iBY3haFhGFBoudkVFFdU0 Sz81IFTcuA/G027YekTzob2kXKYLeCsjwDhmauiMcV0EAbsQ6BdxcBbpsgpVS8fvEP0E OyPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uW2wVCE0fdVcJc5KeJb9HPd/tw2Lj3G+kCxi3x3dF+c=; b=YuGlMynt9U3K3IANtteNikJ5E07O+jm2JvjlUE4AwOY7LSv7MxD0rPDc1AMZpeCOOE CTgfOEJNuY8ZkPeOWzfHdooeZVfAOV3cH8eWUmQxoMWMHLWSt0W31q/Pv2HNz04Pxq/c hsrjgxxZICdkQqS1Ulc1HwCHVOux8eFoL+ZgzUHnNvSGz/awEPkUoOdKVSCPaAnrBlUj 4DO03EnOMN4Mjl42lp/gLaMOD6QZdmoQEpoheuif1k3m9IBW7bE0f59J2l93jLGBJSLY 0SExTXpWDI3uEUH2Co3jJq1ERyEwkMGVqzvqeVKl+b/69Tgqy0ls9GcmZjOXMWkF9RwA o/dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=AtN0oKyO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q13si2023166eju.462.2020.10.06.05.42.44; Tue, 06 Oct 2020 05:43:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=AtN0oKyO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726613AbgJFMlK (ORCPT + 99 others); Tue, 6 Oct 2020 08:41:10 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:47739 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726439AbgJFMlI (ORCPT ); Tue, 6 Oct 2020 08:41:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1601988067; x=1633524067; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=uW2wVCE0fdVcJc5KeJb9HPd/tw2Lj3G+kCxi3x3dF+c=; b=AtN0oKyOj2QMTQcBpo3BEa4tR/Cg8lpVCXEDTTp4/mi/jTb8AiiJIZev g7FTczEA/6nWUampM9/QR5gcdRfWEjeOeKtrBDsf+0tPT59u96YLriEtP sxXX0Di8tPwnCz54qzntJAF+/bx7QW43nQHWcT+HVhwK5XVJdbOGsTEqd s=; X-IronPort-AV: E=Sophos;i="5.77,343,1596499200"; d="scan'208";a="80729222" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-c300ac87.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 06 Oct 2020 12:41:02 +0000 Received: from EX13D31EUA004.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-c300ac87.us-west-2.amazon.com (Postfix) with ESMTPS id 7EC9DA241F; Tue, 6 Oct 2020 12:40:50 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.237) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 6 Oct 2020 12:40:32 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v15 1/8] mm/damon/core: Account age of target regions Date: Tue, 6 Oct 2020 14:39:24 +0200 Message-ID: <20201006123931.5847-2-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006123931.5847-1-sjpark@amazon.com> References: <20201006123931.5847-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.161.237] X-ClientProxiedBy: EX13D18UWA002.ant.amazon.com (10.43.160.199) To EX13D31EUA004.ant.amazon.com (10.43.165.161) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park DAMON can be used for data access pattern aware memory management optimizations. For that, users should run DAMON, read the monitoring results, analyze it, plan a new memory management scheme, and apply the new scheme by themselves. It would not be too hard, but still require some level of effort. For complicated cases, this effort is inevitable. That said, in many cases, users would simply want to apply an actions to a memory region of a specific size having a specific access frequency for a specific time. For example, "page out a memory region larger than 100 MiB but having a low access frequency more than 10 minutes", or "Use THP for a memory region larger than 2 MiB having a high access frequency for more than 2 seconds". For such optimizations, users will need to first account the age of each region themselves. To reduce such efforts, this commit implements a simple age account of each region in DAMON. For each aggregation step, DAMON compares the access frequency with that from last aggregation and reset the age of the region if the change is significant. Else, the age is incremented. Also, in case of the merge of regions, the region size-weighted average of the ages is set as the age of merged new region. Signed-off-by: SeongJae Park --- include/linux/damon.h | 10 ++++++++++ mm/damon/core.c | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index d675ea908a02..696f25e25d95 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -28,12 +28,22 @@ struct damon_addr_range { * @sampling_addr: Address of the sample for the next access check. * @nr_accesses: Access frequency of this region. * @list: List head for siblings. + * @age: Age of this region. + * @last_nr_accesses: Internal value for age calculation. + * + * @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 + * region are set as region size-weighted average of those of the two regions. */ struct damon_region { struct damon_addr_range ar; unsigned long sampling_addr; unsigned int nr_accesses; struct list_head list; + + unsigned int age; + unsigned int last_nr_accesses; }; /** diff --git a/mm/damon/core.c b/mm/damon/core.c index 7c547e1022af..cf3a83509bfc 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -51,6 +51,9 @@ struct damon_region *damon_new_region(unsigned long start, unsigned long end) region->nr_accesses = 0; INIT_LIST_HEAD(®ion->list); + region->age = 0; + region->last_nr_accesses = 0; + return region; } @@ -443,6 +446,7 @@ static void kdamond_reset_aggregated(struct damon_ctx *c) damon_for_each_region(r, t) { trace_damon_aggregated(t, r, damon_nr_regions(t)); + r->last_nr_accesses = r->nr_accesses; r->nr_accesses = 0; } } @@ -460,6 +464,7 @@ static void damon_merge_two_regions(struct damon_region *l, l->nr_accesses = (l->nr_accesses * sz_l + r->nr_accesses * sz_r) / (sz_l + sz_r); + l->age = (l->age * sz_l + r->age * sz_r) / (sz_l + sz_r); l->ar.end = r->ar.end; damon_destroy_region(r); } @@ -479,6 +484,11 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres, struct damon_region *r, *prev = NULL, *next; damon_for_each_region_safe(r, next, t) { + if (diff_of(r->nr_accesses, r->last_nr_accesses) > thres) + r->age = 0; + else + r->age++; + if (prev && prev->ar.end == r->ar.start && diff_of(prev->nr_accesses, r->nr_accesses) <= thres && sz_damon_region(prev) + sz_damon_region(r) <= sz_limit) @@ -522,6 +532,9 @@ static void damon_split_region_at(struct damon_ctx *ctx, new = damon_new_region(r->ar.start + sz_r, r->ar.end); r->ar.end = new->ar.start; + new->age = r->age; + new->last_nr_accesses = r->last_nr_accesses; + damon_insert_region(new, r, damon_next_region(r)); } -- 2.17.1