Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp580469ybj; Tue, 5 May 2020 04:14:40 -0700 (PDT) X-Google-Smtp-Source: APiQypLuNU9j8wJvXlrotwD9jrZH2kljNT4QqWBeiEhgQja2ho7bCqAWiZaBjAJPd0ocLj/bCc7z X-Received: by 2002:a17:906:af6f:: with SMTP id os15mr2232009ejb.78.1588677280388; Tue, 05 May 2020 04:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588677280; cv=none; d=google.com; s=arc-20160816; b=JrK+wk6FRQs7v8b3gpWxa2n6CkbU6UNswwSy9giqHmGyYwwMCzcmTScUgOi7MIx0Jw ck83YA8DLfGT01jNsCB5UkLShQJNYFhoya6QpzW0lbxAwwK4dOMCoIIudCYjY5S1YUU1 eXLqmDjPJ5atwl79wK7vCbgrn/LZcTk7elnVeOZdptszTMczJX6Suc1tTbOZ0Gn9C1an Fg3cDPExV+Vq5VfnxQHEVJPX//CnfxrFh/ff715TTxOtE4kR9FU+SJg0qitHoz3u14Hg w3XSMYxp2LuDxrIK9Bfh6jxcuuqUbLPAAp5v8E0R7oV+nU3aYlVmcV+bgP2/qXadrNt4 wvmA== 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=EQbl7rOOjtYrE6L37e3OFBgSfvKsaVHWKp2n7JPyBSs=; b=Hx7W3j+c0xInoCKkm/SWgVAfE54rHKFt2IvJ0CRYzE3mWsBt+pAZltl3DjaFLG6jCe Oki46eeyKoIpYHQ6UTt/lCgTMM4zmK9HRSv1uPOhYLjGECFwBHzRekqQNCHN7YLbDdNs 5Ms+gKRV7n8611bO0FB/HNo9M2JKuSBG49XQ05f+CSV6L64fCUZf7ZdS6pdmZ3kMgPnV ndXrK5/f+7EyHxbQNuhRt+1Z9wit7+GZYQ3G0+7FzqGVi8GdCIFgE/iQHNDKXHVGwkSe TJE5IlL+fOUiA8GXs5+oKn+8Z00j0Vfi7JKWSRh/n2Qi0clYP3s9PeiNgQa4fIsCnx3u seig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=RK28XZcp; 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 s28si1087695eds.186.2020.05.05.04.14.17; Tue, 05 May 2020 04:14:40 -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=RK28XZcp; 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 S1728699AbgEELMS (ORCPT + 99 others); Tue, 5 May 2020 07:12:18 -0400 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:4445 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725766AbgEELMS (ORCPT ); Tue, 5 May 2020 07:12:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1588677138; x=1620213138; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=EQbl7rOOjtYrE6L37e3OFBgSfvKsaVHWKp2n7JPyBSs=; b=RK28XZcpYBoIwFmEDT8/1PfqX7I4YHRxXe5rPKbpUxV/4vqVz0T0Se8+ STBEMgjk1R07Neknc2uUpcd6VugtBLDe+YTVmzPQ2ktnoCTIvMm4+oDOk H5NXSygElLyn/nBoKtJMhe1q922mKEw/k0X5EdzPAE93fRXTtOq+Kw2Kd Q=; IronPort-SDR: ztgBPyEtq54iXtWKE3sDgkIQmxvwYOHZVa1JdnfPCWHfBI5hWDSP09xvfxRCKx53w9ARDfIsjk 6g2FfAGpbZRA== X-IronPort-AV: E=Sophos;i="5.73,354,1583193600"; d="scan'208";a="28673087" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 05 May 2020 11:12:14 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com (Postfix) with ESMTPS id 43D71A253D; Tue, 5 May 2020 11:12:12 +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; Tue, 5 May 2020 11:12:11 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.160.92) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 5 May 2020 11:11:55 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v10 08/16] mm/damon: Implement callbacks Date: Tue, 5 May 2020 13:08:07 +0200 Message-ID: <20200505110815.10532-9-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505110815.10532-1-sjpark@amazon.com> References: <20200505110815.10532-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.92] X-ClientProxiedBy: EX13D35UWB004.ant.amazon.com (10.43.161.230) 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 122a649c1321..89ac5b245945 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -844,6 +844,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); @@ -851,6 +853,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