Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp886416ybt; Tue, 7 Jul 2020 02:42:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkUS1GmyIjbP+qMl55Xc9ISdE6L+YrjE0RlVIDk3+rucnAWdsr/1zhJSFqzMQW6Lc9AMAy X-Received: by 2002:a17:906:fa9a:: with SMTP id lt26mr37154115ejb.502.1594114951641; Tue, 07 Jul 2020 02:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594114951; cv=none; d=google.com; s=arc-20160816; b=zo7g7HUBn3SVYEvxbu3HC+h6iVjYLhtkj6gPghdK+totdGuy65uNV45D7j/pBIk6JS aWkPRSvUxGgqUAgwunMKM92a3I009H+1J5uoz6+mfXbsMc9cZVw0D58PFJQvaZgypfh9 AWl6AJIzGBtV+zkqyxbqzi3RIl5xp3HH+L1MI/w3npM4S+9iUveokFUgKfKts6N/O25X EYBl1PcNQndrHFmA8nAim4q78qWMfqafTy7LISBXP74MIKbXGwfgqt+/G4WZYD7+caX7 4AKc1MhR18RlBGLKfenJgoJ5anwfm3I+iqFWvIV3Hypg/f4fAXvkyo/3WJmb1ZYGZ+Sx fAUQ== 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=mIgUox7uwj8thtKs2JbmsZgOp7Zig/++PODoaiDRC+A=; b=Jj0vzCLczVDnTEPjJj4+t0n52z4Ipm4M98zXuLqUeOohuNcfCplzen2zSYPVpWG1JM tOoNd0Z2h/gOiVlmkKluvRwwc/9Zm7uWvSYqYNfQJrOUXx04rfSxj+Qhnz3Zwy/b1rfo 2b2lCBwy6+pO5V6uZyT4lpFkVF2lSQqKli2HI0UdUKEpUTyX4krNTa9Ma8bzeYRvhSI1 ArkmW/Wc4V/dScuti8EErjicDgY+SdYZdjPCKE4A0+Go5Cn57tdAcDRgN/3AreygFld6 V50lHcLlKPWtEyKzYa3g+kS1rDsOjtuMTgZ8ehtfvM7uFgpzBq9bi9FMes0uIORkamms supQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=WaOOs7pZ; 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 o5si15528868ejm.227.2020.07.07.02.42.08; Tue, 07 Jul 2020 02:42:31 -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=WaOOs7pZ; 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 S1728189AbgGGJjl (ORCPT + 99 others); Tue, 7 Jul 2020 05:39:41 -0400 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:9286 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726757AbgGGJjl (ORCPT ); Tue, 7 Jul 2020 05:39:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1594114781; x=1625650781; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=mIgUox7uwj8thtKs2JbmsZgOp7Zig/++PODoaiDRC+A=; b=WaOOs7pZzEcNHx9sR+03zYKzqjoEkXmVSsGYgb7NApYf1OUWRviA46Yj 3AsR/GqPF9hz7I8uOEOAkzaqx9MH4tEUgvoYn0PAKU8FAGdKaSb5Uvvm9 ngPpF7jLu7W6AeotQdUvuzPvibea1jhG8HMMWU/Ig3dLCd5nORukiHwd3 Y=; IronPort-SDR: wZZk2i/Mvl91gpY124d1UCPVvkmTlU048tRtQyIuDVhcLsFRmlOl8/EY7lBQPo0jOZIBC/CfLZ X1Yds6/SNZ3A== X-IronPort-AV: E=Sophos;i="5.75,323,1589241600"; d="scan'208";a="41867180" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-17c49630.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 07 Jul 2020 09:39:39 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-17c49630.us-east-1.amazon.com (Postfix) with ESMTPS id A861CA1DEA; Tue, 7 Jul 2020 09:39:27 +0000 (UTC) Received: from EX13D31EUA004.ant.amazon.com (10.43.165.161) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 7 Jul 2020 09:39:26 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.161.203) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 7 Jul 2020 09:39:10 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v13 2/8] mm/damon: Account age of target regions Date: Tue, 7 Jul 2020 11:37:59 +0200 Message-ID: <20200707093805.4775-3-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200707093805.4775-1-sjpark@amazon.com> References: <20200707093805.4775-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.161.203] X-ClientProxiedBy: EX13D36UWA002.ant.amazon.com (10.43.160.24) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 b0e7e31a22b3..e94dab4edab6 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 0f906126d21f..f46844540b37 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; } @@ -815,6 +818,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; } } @@ -828,9 +832,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); } @@ -850,6 +856,11 @@ static void damon_merge_regions_of(struct damon_task *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) @@ -893,6 +904,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