Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4311398ybg; Mon, 8 Jun 2020 04:49:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztyFE5vNl4/7ltq0Fuuyn/0HjfuztdiiVXlGbrjtAVgU7yiiG1vBaCEyz+GTJMsfxbJBzM X-Received: by 2002:a17:906:1c8e:: with SMTP id g14mr20366075ejh.136.1591616940975; Mon, 08 Jun 2020 04:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591616940; cv=none; d=google.com; s=arc-20160816; b=aWYOQ+Ypr9TP4E3QM0uTCRX6i6uRKzsMntMtfIss5TDdsNWGPcmgLTktIzAjcLwWTw eRYVAmhJvk3WCuGs5UkUTDje5IC2kVi6azErEjqlD7suoNfQtWt42EoBnrhp0KqSQgMf rGGFx9+kZ2N/05A2KhYu4a4CFdqjRxxPKBvksfg+aVvmyRIB9C42RRkkHpDpcRuufAuv wo7v9qmDI53b/cjWxK42KyCxweWy/BeW5J5FDqPvjEeXTA0sdWn+6a9q/4HId9q/MTEr yZj2TGCO0EbdytzfY1ct0UBjFJPreM8AJkhfaUxHZg+pIx3pQ4G9Hn8gNpV9A12eDV5e JwZg== 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=aVHHNN4NPFIzJZZNoh2kDXXea3hT/G5gOQv7gUeYrN8=; b=lo6jGhOuiDbJFLRf/qmwSdqrvWh1rjgWqNw2M9zHYImY7drgMb6TG3W2LgTgY0ijvF IxnjXxY6rR59+4C0ijo99dVyxj5snUt4qTkWpSObz0/X5eBXeqows0W5XBdrYy4Bfecb kzCnio2nv9MXIgcwVAmGvm/v6tPj/qxBKTP1kmky2kgYT1b9Wv8A4LlzeDTqGFMNykkw TAw1QPxrIO4PHI4+1yMxP8854eNx8S1Glg5TU/DOv1FyNje478JNh6Q8LFRCs6mTAybM 4f0HE9L7Vpakh6g75+cyp2P6pHwNHNljsKKmc8dbnfthL3gBdg0r52nNEiXOm45pNeaF ymmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=MjpiG5xb; 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 b19si9065362edx.506.2020.06.08.04.48.37; Mon, 08 Jun 2020 04:49:00 -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=MjpiG5xb; 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 S1729629AbgFHLqw (ORCPT + 99 others); Mon, 8 Jun 2020 07:46:52 -0400 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:38845 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729535AbgFHLpy (ORCPT ); Mon, 8 Jun 2020 07:45:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591616753; x=1623152753; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=aVHHNN4NPFIzJZZNoh2kDXXea3hT/G5gOQv7gUeYrN8=; b=MjpiG5xbwlTbPUZ5eXO709G8BaueTF1+SODaaI6zi4Ec0a9p770idssw Zzh8EBU1KAs9ko84hf/TM+J9k8bMzg+LWY3oBpX9DMvPYB7tDnOV9L4Nn gdU6BkWcPk33lq58BCHpl3BT7uDtVRoOZUC/pQIGTQnb84a87iY0DiFSZ o=; IronPort-SDR: JE8c6Pt2m9JHbAlTTitN4BlFQHaqpl3qg8jrXNlYNs5eVPXX49l3hrh4Hc7B7dcVwVHRRb8vYG odDO/1/I6c6Q== X-IronPort-AV: E=Sophos;i="5.73,487,1583193600"; d="scan'208";a="36355588" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1a-af6a10df.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 08 Jun 2020 11:45:52 +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 6BDD0A2186; Mon, 8 Jun 2020 11:45:40 +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, 8 Jun 2020 11:45:34 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.53) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 8 Jun 2020 11:45:17 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 06/14] mm/damon: Implement callbacks Date: Mon, 8 Jun 2020 13:40:39 +0200 Message-ID: <20200608114047.26589-7-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200608114047.26589-1-sjpark@amazon.com> References: <20200608114047.26589-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.53] X-ClientProxiedBy: EX13D46UWB004.ant.amazon.com (10.43.161.204) 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 Reviewed-by: Leonard Foerster --- include/linux/damon.h | 13 +++++++++++++ mm/damon.c | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 5afcb2bb7f77..12536d9d2f74 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -80,6 +80,15 @@ struct damon_task { * @kdamond_lock. Accesses to other fields must be protected by themselves. * * @tasks_list: Head of monitoring target tasks (&damon_task) list. + * + * @sample_cb: Called for each sampling interval. + * @aggregate_cb: Called for each aggregation interval. + * + * @sample_cb and @aggregate_cb are called from @kdamond for each of the + * sampling intervals and aggregation intervals, respectively. Therefore, + * users can safely access to the monitoring results via @tasks_list without + * additional protection of @kdamond_lock. For the reason, users are + * recommended to use these callback for the accesses to the results. */ struct damon_ctx { unsigned long sample_interval; @@ -96,6 +105,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 778f4d87042d..1978ec4114bf 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -880,6 +880,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); @@ -887,6 +889,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