Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp284426ybg; Wed, 3 Jun 2020 00:19:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMrz0Bes5jHSO1ADe/v18H0y9g7WwVco5FEBC+bJpsv6AwjJgOkiek+AsVgTBF0lCdt6Rr X-Received: by 2002:a17:906:af48:: with SMTP id ly8mr12556118ejb.28.1591168787894; Wed, 03 Jun 2020 00:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591168787; cv=none; d=google.com; s=arc-20160816; b=08QquKC7uCMlPzPuLnlyl2VknJc8F+XOfeRfm4VvxX5u76XGq9/yMLoLbh1Hb/lRDN auei7TARe+5P6GBt6123J2DRIXy1Yt0HKwJLGpwUAG4RvyHVyp/fngF7IoyZfzOIiNXP fRWdTRKU5RxIrSdbHUfxj4j4jan3ppKrQA5BYFumcqxOkjXrid6YVy/2/2pZNJcZkVaU HSZMyqb6HbFbBwOpNSoJ5u9Ofuux6e9DMEnleZd1CKCb9ogRY1k95iHmDghdLHRbTCex MAS97zWEOE4biFXIW5VRObsoZZaSxYYnxhxGv2pAkbfnDXfcqxwBvwkiQ5u1s0WEc2/i dmUw== 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=/kfAd1XjpVq3L6on7njk4xOmlv6uR7G/4ENC2AijgCU=; b=IG86StmjE0MoxyK4I9IXKAWgnjyDQFk3bEdNBVcFO2ixfrlxyNGFRwHlJ+64k7vXvq pvfLWcVZ2TYpbB0HqxwZpxGXdgMJl1TsqOa0rL9OHQvlJEOzAYgx6F65DrvsoWTO8ptK 5+dEAGQLZa+o5UZPbyqt8tv/qMY0HPADRdiLL/4sCD9RS1XW+CCcUybeFnd9rTfhHJ2M FDlyB1AT1sRpg9NNwp+K/AywM7xWaHkDnkvcnEDCKxn4cqnJNSw3kh6ZP18mFnqDTQn9 fiy/26DH49etf7xLbiIo/1lsvEJ0gh+ApVs4AZl89L3hApcFQD5esH5B4Bi5yRSpFYGb YuVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=RdQiG7Vd; 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 v5si650048eji.39.2020.06.03.00.19.16; Wed, 03 Jun 2020 00:19:47 -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=RdQiG7Vd; 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 S1726123AbgFCHOZ (ORCPT + 99 others); Wed, 3 Jun 2020 03:14:25 -0400 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:29301 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbgFCHOZ (ORCPT ); Wed, 3 Jun 2020 03:14:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591168464; x=1622704464; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=/kfAd1XjpVq3L6on7njk4xOmlv6uR7G/4ENC2AijgCU=; b=RdQiG7Vdl8D5xvsi4n96Yh1ugUgMFNQ/puFth7mfc9IOGOA8JNstucit Udhkw21D8PAjMZmI0ZShS91T5SBYlXs/Ox89R78yvKw9brW8bWvqKwl+/ m7rpIkHNAI36Y4GIUDdnIAATPgzUN7e1f/tD7nLvx4qg7Mf4oSI6BtLJZ k=; IronPort-SDR: LhSGDLBJ5HRtVy36/p0AM84Q0ZyaoUHX9GeokDN4aqmODKjlWYoEc4DZSi3kurv3yCs3RClP3u 0+OXVumWR8oQ== X-IronPort-AV: E=Sophos;i="5.73,467,1583193600"; d="scan'208";a="34199761" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 03 Jun 2020 07:14:24 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1e-c7c08562.us-east-1.amazon.com (Postfix) with ESMTPS id CE219243DF4; Wed, 3 Jun 2020 07:14:21 +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; Wed, 3 Jun 2020 07:14:21 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.160.26) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 3 Jun 2020 07:14:06 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 2/8] mm/damon: Account age of target regions Date: Wed, 3 Jun 2020 09:11:32 +0200 Message-ID: <20200603071138.8152-3-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200603071138.8152-1-sjpark@amazon.com> References: <20200603071138.8152-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.26] X-ClientProxiedBy: EX13D10UWB003.ant.amazon.com (10.43.161.106) 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 | 29 +++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index c4796a10cb1a..6a8ff2c63c2a 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -24,6 +24,13 @@ * @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 { unsigned long vm_start; @@ -31,6 +38,9 @@ struct damon_region { 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 2c44e0860672..6e9cc3330589 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -86,6 +86,9 @@ static struct damon_region *damon_new_region(struct damon_ctx *ctx, region->nr_accesses = 0; INIT_LIST_HEAD(®ion->list); + region->age = 0; + region->last_nr_accesses = 0; + return region; } @@ -659,6 +662,7 @@ static void kdamond_reset_aggregated(struct damon_ctx *c) sizeof(r->nr_accesses)); trace_damon_aggregated(t->pid, nr, r->vm_start, r->vm_end, r->nr_accesses); + r->last_nr_accesses = r->nr_accesses; r->nr_accesses = 0; } } @@ -672,9 +676,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->vm_end = r->vm_end; damon_destroy_region(r); } @@ -692,12 +698,16 @@ 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 (!prev || prev->vm_end != r->vm_start || - diff_of(prev->nr_accesses, r->nr_accesses) > thres) { + if (diff_of(r->nr_accesses, r->last_nr_accesses) > thres) + r->age = 0; + else + r->age++; + + if (prev && prev->vm_end == r->vm_start && + diff_of(prev->nr_accesses, r->nr_accesses) <= thres) + damon_merge_two_regions(prev, r); + else prev = r; - continue; - } - damon_merge_two_regions(prev, r); } } @@ -733,6 +743,9 @@ static void damon_split_region_at(struct damon_ctx *ctx, new = damon_new_region(ctx, r->vm_start + sz_r, r->vm_end); r->vm_end = new->vm_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