Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp363436pxa; Tue, 4 Aug 2020 07:27:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/XWAt0o9OZvDLL7g0UrFkX0zIfhS/whX7dFp2VHSfwh8qvkMPqEBVoBalbx4PBy9xycff X-Received: by 2002:a50:af45:: with SMTP id g63mr21710234edd.52.1596551226754; Tue, 04 Aug 2020 07:27:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596551226; cv=none; d=google.com; s=arc-20160816; b=vKiYcG/IFH38kXoXf9dZ47+NR1qdM75FOaBjsXmeFxXRVTozaWocVBwYTNrToiQvT/ VgooMEixTfdAoRscSB8XZEBfnLlnlalKYQ3fuxXFyL+qfO+HNe0RSZwr1FIKCLxotIxs eczKRUQq3MiIhYezcQ1JpktNoUO4jM95dAS0pTpJYQMMQ4gMOyIaUCb5Jzy+8/S5EC7v vXSXoOFbDUllG5f5Y4gE1sUTtIk4YHX+5VhX+004GeW7+lB1+ivOeXzy82hthlRcS0gw 8ry9p2PM64HGfVq4pXFYkh6Vhvu6nb7QALmqxZOr4ZZFNb6DIxI/RuxjkM6Js5XgfBJA trnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:dkim-signature; bh=M0Y1lAG8iL0zYPMKekhn33850obJOldf0sGyt7FqSpg=; b=kr5FVl6uzPgb6V0pp4p+Nw84VWHC8JLI+1Gsyzh8wFutLBFLdUud6V4LlQXUGMZSTp kU3vR8aGGb2Y8WIIoWvTmILazyr8AUNNmlXlBjnP8KBB93yQVyX/Ox0acOQPOnB/hdXV 9hvHDfJ2U9WmE2A0SrCobR/c66UqKezn7kC2n/aLNakJ9dEIoraQ4aF4+HXSnqTMZerD YH+3nATQ+0QKf0eW4kB2Yz0GD/LdCe89j0tv2pAQdMlnBmi+lKTK+4aiaTpq1mm4v1DB b9Dm2jazfRPXe9tbN6Bfgocu5nzsBN90fAAyWmftNVknrjxQY+AvRch7rwDmf02cxWEd ClLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=u8HK0zEA; 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 k22si12731538edo.603.2020.08.04.07.26.43; Tue, 04 Aug 2020 07:27:06 -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=u8HK0zEA; 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 S1729092AbgHDOZ6 (ORCPT + 99 others); Tue, 4 Aug 2020 10:25:58 -0400 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:49838 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729081AbgHDOZh (ORCPT ); Tue, 4 Aug 2020 10:25:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1596551137; x=1628087137; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=M0Y1lAG8iL0zYPMKekhn33850obJOldf0sGyt7FqSpg=; b=u8HK0zEAPnTFkSak5lLA1eew5SMReTqpUG07e/LKAVzS48Zema8YzznB VomnioodFS2cZRTUghCHB8Wg0CCgXRCfht/1Wq0CxCuhIrbSzOCOIEBS4 PHxoWgiYBaB0MfhktHpmtSO5ZRGEvPtYtE+47b94xALArl8yY79uaa/rt c=; IronPort-SDR: rK3aPDVphy3kNoWySGenlfhwvmuVp2scXMLeXguH4UG5X94oiRZ9x1IhB7K9i3wXW3ljCP/mVu zgT692SCMeRQ== X-IronPort-AV: E=Sophos;i="5.75,434,1589241600"; d="scan'208";a="45890399" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2c-397e131e.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 04 Aug 2020 14:25:28 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-397e131e.us-west-2.amazon.com (Postfix) with ESMTPS id 9CBE7A17E3; Tue, 4 Aug 2020 14:25:25 +0000 (UTC) Received: from EX13D31EUA001.ant.amazon.com (10.43.165.15) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 4 Aug 2020 14:25:24 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.161.203) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 4 Aug 2020 14:25:08 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v14 1/7] mm/damon: Account age of target regions Date: Tue, 4 Aug 2020 16:24:24 +0200 Message-ID: <20200804142430.15384-2-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200804142430.15384-1-sjpark@amazon.com> References: <20200804142430.15384-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.161.203] X-ClientProxiedBy: EX13D17UWC004.ant.amazon.com (10.43.162.195) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park DAMON can be used as a primitive for data access pattern aware memory management optimizations. However, users who want such optimizations 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 optimizations, 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.c | 20 +++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index ad771c39d1a9..ca5bd8de4aa4 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -31,12 +31,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.c b/mm/damon.c index 114ef319eeab..69090aa22207 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -107,6 +107,9 @@ static struct damon_region *damon_new_region(unsigned long start, region->nr_accesses = 0; INIT_LIST_HEAD(®ion->list); + region->age = 0; + region->last_nr_accesses = 0; + return region; } @@ -881,6 +884,7 @@ static void kdamond_reset_aggregated(struct damon_ctx *c) damon_write_rbuf(c, &r->nr_accesses, sizeof(r->nr_accesses)); trace_damon_aggregated(t, r, nr); + r->last_nr_accesses = r->nr_accesses; r->nr_accesses = 0; } } @@ -894,9 +898,11 @@ static void kdamond_reset_aggregated(struct damon_ctx *c) static void damon_merge_two_regions(struct damon_region *l, struct damon_region *r) { - l->nr_accesses = (l->nr_accesses * sz_damon_region(l) + - r->nr_accesses * sz_damon_region(r)) / - (sz_damon_region(l) + sz_damon_region(r)); + unsigned long sz_l = sz_damon_region(l), sz_r = sz_damon_region(r); + + 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); } @@ -916,6 +922,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) @@ -959,6 +970,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