Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2595517ybk; Mon, 18 May 2020 03:10:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxymDYjUpcCwNdHE5C2wYX14+dO0RsddYiza1J5IrzqLq9JkPFCzFeJKQk+hnEsRIjBXgUw X-Received: by 2002:a17:907:420e:: with SMTP id oh22mr14245337ejb.320.1589796616495; Mon, 18 May 2020 03:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589796616; cv=none; d=google.com; s=arc-20160816; b=Q/adwcV1UWPRKjsiNYDWd3tz2vTyUiLlBiFov5n1TU3Dmvm0uikMY+TCMLYlvg00E4 5t9/ZggvuiVlZtC7Gf6XeCfk5ZiTQ9HCXCTY0FH5pVaktAvDzmWmQUhc20Me1cKJORg/ u59wDvJ3rS0YTjRHQQ+qEFI3Y4ODjlMYkeu/r3EJFnDkv0aQ6j6lEobZ4vv2gzS7I+p/ TfixibQnxUKIAdxRYhf+0/gD86N6UY9j3fdCxxggAMxzEVgU5K9/TM2M8MRWjmd9k7Rs ELemLWYsmKDxzRttAzc5rWUl2jMuP7edNX83GRDJfqX2urO119gbsbBQhTr6wvRsh0cq DXEQ== 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=5eUUH3KSzXPS1Zv1Jyq7nrLXWic8IpcbJpzSCJto0dg=; b=SWzCZlU8J/0wqIorhSLMZVj/zV0+hxnQzmPB1u1WzF/JS3KzWbQxSqd09OIWJlw3XV S9m/TMj+TdXczoyaI2cL8qw0DD1W5ORbSLbmTjhF2sfqjaLYEDgA9UfOw8wP6s7XP/4V gMzwbwqtV1Ydn8wBdxlK5ty8Q18JkJA31J2fJI4TpidF7Hz8zaeKlMkkRNAibjlKwGis A3/t2qbZ8KsU0iGMxSWGlR3ewHtkom9luxTBDmijmf+ltF5ag68ahXDRz+PerzHw95XY u6r5+pw5ZjmtTmhVYBN8iVIRJT65mkik7yNTVOcZnEjJwUr44Ebpdx+nH/SBuVUZ34g9 OiaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=IkG273PP; 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 r13si6353369edc.201.2020.05.18.03.09.53; Mon, 18 May 2020 03:10:16 -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=IkG273PP; 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 S1726399AbgERKIQ (ORCPT + 99 others); Mon, 18 May 2020 06:08:16 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:27888 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbgERKIP (ORCPT ); Mon, 18 May 2020 06:08:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1589796495; x=1621332495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=5eUUH3KSzXPS1Zv1Jyq7nrLXWic8IpcbJpzSCJto0dg=; b=IkG273PPQ/L7u8pNWnMe336GL+deQ2g6qy+ul3HnSZX1Y0ZiAvxgGET/ 8121yikgyq2mnJWKWsOPSL6fGRCv80cTNY2W+okyaDrsCfFzGRZI8/0yV 1uREaQFprmh9Y3f1wVly1uJXE5ZoGjxyoDnk9sHVd9vpKpxyp4BZuXzzO 4=; IronPort-SDR: /z+M2zXz80vZxZfTWk2X7x8rwHYuD2KLFg2/BM+8tTVxa34bH5V6NzDTtdRBX3g3LLJVHvSmgV zE7gmDm2yuiQ== X-IronPort-AV: E=Sophos;i="5.73,406,1583193600"; d="scan'208";a="45461777" Received: from sea32-co-svc-lb4-vlan2.sea.corp.amazon.com (HELO email-inbound-relay-1a-af6a10df.us-east-1.amazon.com) ([10.47.23.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 18 May 2020 10:08:11 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1a-af6a10df.us-east-1.amazon.com (Postfix) with ESMTPS id 7F6A1A2072; Mon, 18 May 2020 10:07:58 +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; Mon, 18 May 2020 10:07:57 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.160.90) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 18 May 2020 10:07:42 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v12 08/16] mm/damon: Implement callbacks Date: Mon, 18 May 2020 12:00:10 +0200 Message-ID: <20200518100018.2293-9-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200518100018.2293-1-sjpark@amazon.com> References: <20200518100018.2293-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.90] X-ClientProxiedBy: EX13D04UWA003.ant.amazon.com (10.43.160.212) 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 This commit implements callbacks for DAMON. Using this, DAMON users can install their callbacks for each step of the access monitoring so that they can do something interesting with the monitored access patterns online. For example, callbacks can report the monitored patterns to users or do some access pattern based memory management such as proactive reclamations or access pattern based THP promotions/demotions decision makings. Signed-off-by: SeongJae Park --- include/linux/damon.h | 4 ++++ mm/damon.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 62b9f90ed87b..264569b21502 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -55,6 +55,10 @@ struct damon_ctx { struct mutex kdamond_lock; struct list_head tasks_list; /* 'damon_task' objects */ + + /* callbacks */ + void (*sample_cb)(struct damon_ctx *context); + void (*aggregate_cb)(struct damon_ctx *context); }; int damon_set_pids(struct damon_ctx *ctx, int *pids, ssize_t nr_pids); diff --git a/mm/damon.c b/mm/damon.c index 38a8a68b7beb..498160b5e086 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -851,6 +851,8 @@ static int kdamond_fn(void *data) kdamond_init_regions(ctx); while (!kdamond_need_stop(ctx)) { kdamond_prepare_access_checks(ctx); + if (ctx->sample_cb) + ctx->sample_cb(ctx); usleep_range(ctx->sample_interval, ctx->sample_interval + 1); @@ -858,6 +860,8 @@ static int kdamond_fn(void *data) if (kdamond_aggregate_interval_passed(ctx)) { kdamond_merge_regions(ctx, max_nr_accesses / 10); + if (ctx->aggregate_cb) + ctx->aggregate_cb(ctx); kdamond_reset_aggregated(ctx); kdamond_split_regions(ctx); } -- 2.17.1