Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp368623ybb; Wed, 1 Apr 2020 01:25:18 -0700 (PDT) X-Google-Smtp-Source: ADFU+vspV99EJatek/qxmVWNDrI3kacyOjxVBdJE+BWN8gFaHnIQZil5lxURLi16gJKxDuJhDke+ X-Received: by 2002:a4a:e047:: with SMTP id v7mr15868569oos.49.1585729517930; Wed, 01 Apr 2020 01:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585729517; cv=none; d=google.com; s=arc-20160816; b=k67S9VaawREJbnRa61zbU6rmss5EymQD+ejJxykhegjBa5BMCV/A+wTTDwWGJkFMZQ oqSQZcizURnacJfKHwChLh1mVli8E3+9+Cv/qlOWjzN/kadV6NvychHjlbF9vQBxzg/k 54R5klXxPbuKQBRejYyGiZ2qXdPjaCXkjgaJO/7lb09umaQ9c4x1QbgotwzG58uFu4Fr Gw145zGQt9mN7lKFHKyNwp2Xc2aL9/6JniNMywmBK3EWMyocra2Wn1vptEaYsVwha5vo Wkfs1rdrEhSkRciO6THOIeOXU8df558FyghA9wFjYwnVDb3Rt4CSV35NmmCf++9+Vd3M g+PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:dkim-signature; bh=aq3bWriBLQql0BndeSu53xWecGPtWYNKWQvYWVyRjRU=; b=FXtEXOx8E2Aggc2nh6RELHR7l4JNIrvnRBQGDRY1oG3GJxhUHJ6rEkbW3LXqb98iGZ TlgjMi5n7AZf83Qn3mEWyEQ0bRFIpYrS2y6LEjYltzzQm6HpFfruFNBzjQgjaLmajGVO /LFalfZyVNMWuXTZpAaqFkFv05Af0dSjQOpES7Mry9sy8K1pdmHOZ3sSh9SmlKptrlfF vWu+uWjQknfVHIdGysyxNNRrVDVzqANCXrLQey+o4AN9ssojOukg8LWEj6kVSo47mQ82 d4tx8fOFyQLcJhbdXNCJtiqkr643s9C/dIDU6V91D4VEz8372nVBgKISaJxZSS0s+KiT Ri6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ClFLhGm7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id y4si519969ooh.53.2020.04.01.01.25.05; Wed, 01 Apr 2020 01:25:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ClFLhGm7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1731630AbgDAIXg (ORCPT + 99 others); Wed, 1 Apr 2020 04:23:36 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:35257 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730574AbgDAIXg (ORCPT ); Wed, 1 Apr 2020 04:23:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1585729416; x=1617265416; h=from:to:cc:subject:date:message-id:in-reply-to: mime-version; bh=aq3bWriBLQql0BndeSu53xWecGPtWYNKWQvYWVyRjRU=; b=ClFLhGm7G2oaGe91kr03It5oY9EldQ08Pt3sQ3PidOFFdc83cyma2Jm3 g6aFp8TDRCMo8xgbgSuzkp6Ct+f1Y1wjL/ovBEJkS7fss1dPATYHFyMPL vxEDIHNzNgY/5dKS6a9CVMkWTA0CBYGlRGEFqXuYth5j8uqeoLCH1EkcS w=; IronPort-SDR: 4SflCQgY22B5d62QR6UUROTKgfTsuxQh+AubpVF14xOq2OhLG1NA7fyz/7CIZ3/txiP3ZkocMf ym0kMjbqBpvQ== X-IronPort-AV: E=Sophos;i="5.72,331,1580774400"; d="scan'208";a="36012011" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-807d4a99.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 01 Apr 2020 08:23:33 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-807d4a99.us-east-1.amazon.com (Postfix) with ESMTPS id 0B274A333B; Wed, 1 Apr 2020 08:23:22 +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, 1 Apr 2020 08:23:22 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.160.8) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 1 Apr 2020 08:23:08 +0000 From: SeongJae Park To: Jonathan Cameron CC: SeongJae Park , , "SeongJae Park" , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: Re: [PATCH v7 05/15] mm/damon: Adaptively adjust regions Date: Wed, 1 Apr 2020 10:22:53 +0200 Message-ID: <20200401082253.21405-1-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331170855.0000024f@Huawei.com> (raw) MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.8] X-ClientProxiedBy: EX13D29UWC002.ant.amazon.com (10.43.162.254) 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 On Tue, 31 Mar 2020 17:08:55 +0100 Jonathan Cameron wrote: > On Wed, 18 Mar 2020 12:27:12 +0100 > SeongJae Park wrote: > > > From: SeongJae Park > > > > At the beginning of the monitoring, DAMON constructs the initial regions > > by evenly splitting the memory mapped address space of the process into > > the user-specified minimal number of regions. In this initial state, > > the assumption of the regions (pages in same region have similar access > > frequencies) is normally not kept and thus the monitoring quality could > > be low. To keep the assumption as much as possible, DAMON adaptively > > merges and splits each region. > > > > For each ``aggregation interval``, it compares the access frequencies of > > adjacent regions and merges those if the frequency difference is small. > > Then, after it reports and clears the aggregated access frequency of > > each region, it splits each region into two regions if the total number > > of regions is smaller than the half of the user-specified maximum number > > of regions. > > > > In this way, DAMON provides its best-effort quality and minimal overhead > > while keeping the bounds users set for their trade-off. > > > > Signed-off-by: SeongJae Park > > A few more edge cases in here, and a suggestion that might be more costly > but lead to simpler code. Thank you for finding those! > > Jonathan > > > --- > > include/linux/damon.h | 6 +- > > mm/damon.c | 148 ++++++++++++++++++++++++++++++++++++++++-- > > 2 files changed, 145 insertions(+), 9 deletions(-) > > [...] > > diff --git a/mm/damon.c b/mm/damon.c > > index 018016793555..23c0de3b502e 100644 > > --- a/mm/damon.c > > +++ b/mm/damon.c [...] > > + > > +/* > > + * Split a region into two small regions > > + * > > + * r the region to be split > > + * sz_r size of the first sub-region that will be made > > + */ > > +static void damon_split_region_at(struct damon_ctx *ctx, > > + struct damon_region *r, unsigned long sz_r) > > +{ > > + struct damon_region *new; > > + > > + new = damon_new_region(ctx, r->vm_start + sz_r, r->vm_end); > > + r->vm_end = new->vm_start; > > We may well have a sampling address that is in the wrong region. > It should have little effect on the stats as will fix on next sample > but in my view still worth cleaning up. Good catch! I will fix this in next spin. > > > + > > + damon_insert_region(new, r, damon_next_region(r)); > > +} > > + [...] > > @@ -571,21 +689,29 @@ static int kdamond_fn(void *data) > > struct damon_task *t; > > struct damon_region *r, *next; > > struct mm_struct *mm; > > + unsigned int max_nr_accesses; > > > > pr_info("kdamond (%d) starts\n", ctx->kdamond->pid); > > kdamond_init_regions(ctx); > > while (!kdamond_need_stop(ctx)) { > > + max_nr_accesses = 0; > > damon_for_each_task(ctx, t) { > > mm = damon_get_mm(t); > > if (!mm) > > continue; > > - damon_for_each_region(r, t) > > + damon_for_each_region(r, t) { > > kdamond_check_access(ctx, mm, r); > > + max_nr_accesses = max(r->nr_accesses, > > + max_nr_accesses); > > + } > > mmput(mm); > > } > > > > - if (kdamond_aggregate_interval_passed(ctx)) > > + if (kdamond_aggregate_interval_passed(ctx)) { > > + kdamond_merge_regions(ctx, max_nr_accesses / 10); > > kdamond_reset_aggregated(ctx); > > + kdamond_split_regions(ctx); > > + } > > I wonder if it would be simpler to split the sampling address setup and > mkold from the access check. We would have to walk regions twice, > but not have to bother separately dealing with updating some regions > if they are modified in the above block. > > Also, the above has some overhead, so will bias that first sample each > time the block above runs. If we do the mkold afterwards it will make > much less difference. Agreed, it will make code much more simple and easy to read. However, I'm not sure how much of the overhead will be biased because 'aggregate interval' is usually larger than 'sampling interval'. Anyway, Will change so in the next spin! Thanks, SeongJae Park [...]