Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp599889ybh; Tue, 10 Mar 2020 04:55:49 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvR81NRm3mGaLRymzpdj5xdR/In8POUZm1bCvRtYHppXs3fvAuymfAfOvGG+HSXh+VYZpBV X-Received: by 2002:a9d:6205:: with SMTP id g5mr17359570otj.153.1583841349332; Tue, 10 Mar 2020 04:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583841349; cv=none; d=google.com; s=arc-20160816; b=QhZhqfMpwXWtf9CooAAvIyRuv8T87F4s2y6nsqjnXULXoj2J2f+cHVbAeZ65oACmXH 23LzZY066IuxeLR6JqlKObis5HU5V13hKvPosPMWKD5E86kU1pX0ZkXIVokmT2ddLhvj wGe3tZlmpxTSc3lz9T+6HJH+laLIqpfcr+rjwp4HlrdHHF/ssPOEB5Dd3ZH2V7Kfj2Ga Ec9ArMBuKV0igYHIfCkMWsop3QxNhwaNSHsNO1Qvoein/TAL+eo1S8iw1+wzvOlJkHEA Fc+TR3LgSzmL4rbdDZuArgU3zybr1miacH7Zxfyv0ehF+C8dAjGxj6MJPsO9dhQ/5K78 bVFg== 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=cEO6B2zoUX3o5zZBIn4kHVPe4ZydoyJnq/OuRSRvQzE=; b=R6L6c3nZR1/aQBkTzNDCQYR4XD/0o+PWbRb+hYZImPbtHPql0/gsznrmR7ulDQkui8 bIVPzWP/ETcyotnS1x7Y1D1I+PtvzvAe4U8oCQog70WR4B/cKgvkXlevPYJAPe4gMIZj XwbJYdB31z7qKpVQBgBYrsk9bKszahAU/v4+UlAnzixlZ6aXkCe77jZ9O6ru/DKmobUQ NKB3cDUmgZyxOMCIydcdHFtNaUFEx0tpueSiKFE6zCwl0mK/sWo0AdNX691g0tLUs2ou TVf6x2Cj1RpgkTKzl8kkjWX1yHFT9/NxHFblZd5PmeN79pshDfb+KcF0+nsZLjluKZIo ZySg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=GRH1ja5P; 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 i6si7240608oth.182.2020.03.10.04.55.37; Tue, 10 Mar 2020 04:55:49 -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=GRH1ja5P; 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 S1726475AbgCJLyF (ORCPT + 99 others); Tue, 10 Mar 2020 07:54:05 -0400 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:37380 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726205AbgCJLyE (ORCPT ); Tue, 10 Mar 2020 07:54:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583841245; x=1615377245; h=from:to:cc:subject:date:message-id:in-reply-to: mime-version; bh=cEO6B2zoUX3o5zZBIn4kHVPe4ZydoyJnq/OuRSRvQzE=; b=GRH1ja5Pfjl4OECSNmhW4J2Vi7DHIvBkH3B0FDNgJWUM440jnRNndgy2 7KdZJYOg3w3hmOxcWT5/0TssXYIHrszaE1Ll8AWSotpRNYOtL85Z/xzM3 bqqJabwU56IqUlOrcyMhjKN02vwV2kXTCkkmaWpFu6valPX9RKNPM0RQr Q=; IronPort-SDR: C8b11fHP0Abw2gjRpvgZA1QYpBVNPK8JVIYF8HfkLJo1vNbmbmzh/j4Ri4m/Djt0Pmetjt9l38 Dz6SolDhTthg== X-IronPort-AV: E=Sophos;i="5.70,536,1574121600"; d="scan'208";a="21950836" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-98acfc19.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 10 Mar 2020 11:54:02 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-98acfc19.us-east-1.amazon.com (Postfix) with ESMTPS id 6DA28A186F; Tue, 10 Mar 2020 11:53:51 +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.1236.3; Tue, 10 Mar 2020 11:53:51 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.67) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 10 Mar 2020 11:53:39 +0000 From: SeongJae Park To: Jonathan Cameron CC: SeongJae Park , , "SeongJae Park" , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: Re: [PATCH v6 03/14] mm/damon: Adaptively adjust regions Date: Tue, 10 Mar 2020 12:53:24 +0100 Message-ID: <20200310115324.23715-1-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200310085747.000018ad@Huawei.com> (raw) MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.67] X-ClientProxiedBy: EX13D27UWB004.ant.amazon.com (10.43.161.101) 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, 10 Mar 2020 08:57:47 +0000 Jonathan Cameron wrote: > On Mon, 24 Feb 2020 13:30:36 +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 > > Really minor comments inline. Very helpful comments for me. You are indeed making this much better! Will apply whole your comments below in the next spin. > > > --- > > mm/damon.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++--- > > 1 file changed, 144 insertions(+), 7 deletions(-) > > > > diff --git a/mm/damon.c b/mm/damon.c > > index 6bdeb84d89af..1c8bb71bbce9 100644 > > --- a/mm/damon.c > > +++ b/mm/damon.c [...] > > +/* > > + * Merge adjacent regions having similar access frequencies > > + * > > + * t task that merge operation will make change > > + * thres merge regions having '->nr_accesses' diff smaller than this > > + */ > > +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) > > + goto next; > > + if (diff_of(prev->nr_accesses, r->nr_accesses) > thres) > > + goto next; > > if (!prev || prev->vm_end != r->vm_start || > diff_of(prev->nr_accesses, r->nr_accesses) > thres) { > prev = r; > continue; > } > > Seems more logical to my head. Maybe it's just me though. A goto inside a > loop isn't pretty to my mind. Yes, your version seems much prettier to me, either :) > > > + damon_merge_two_regions(prev, r); > > + continue; > > +next: > > + prev = r; > > + } > > +} > > + [...] > > @@ -590,21 +711,29 @@ static int kdamond_fn(void *data) > > struct damon_task *t; > > struct damon_region *r, *next; > > struct mm_struct *mm; > > + unsigned long 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); > > + if (r->nr_accesses > max_nr_accesses) > > + max_nr_accesses = r->nr_accesses; > > max_nr_accesses = max(r->nr_accesses, max_nr_accesses) Good point! Thanks, SeongJae Park [...]