Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2816675ybz; Mon, 27 Apr 2020 05:11:18 -0700 (PDT) X-Google-Smtp-Source: APiQypLgR9QU5hQ7xZQBivrokPiWoXp0q3xCiqWPsyGMMMySCmeKal1Jr3tOlM2+VE7saHOURThz X-Received: by 2002:a17:906:c839:: with SMTP id dd25mr18858849ejb.164.1587989478664; Mon, 27 Apr 2020 05:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587989478; cv=none; d=google.com; s=arc-20160816; b=RHnmto1LiAND5tVgsC/pcq7/Mk5iBn/Biv72DZLThMOLgR+5e3QzxthQb+HGLjj817 GTBdpBcaMMKowGwULEjoVJ6XuQLOR5k5oYlx9IFoCXtRrTXLeNR1fm2INMSyAWTPFvnX +wjwqjlX/Fq8xnzYwOfsXj5ihQL2VwuUHfSQQIusdWsEs1IqrL9W3Eu5vhHaNUna+TrL 3T26W23dOlsLRJl696pw/YwJnE/BKetjlnvk0daNP1tREGa8LHh41PvkTGMDx6ZRV0WO 7VLiqDjnnvM1vopMwS693SKHBMyBHmNCZ5sH26Hl3OsomMhAip72WpEnhj/hdKve2K7O LftQ== 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=7dTCzlsSd0rALJ8Pob5V+u9VFVvbxuYVhAL4qneveuY=; b=zUTHleR7yadjF3wepNZeGgsYYRQQdMnMcXjUkRJE1MWYEzGJYjtypWucBUvTjqWWLB JpxqLM/PELUXVjHMAxlqhuUYb/8TSeE1nqBJ6YmI6owRLrisbxaLJmkHEbgfn5olxK29 6TBR+mCButtntokPltJULJ9AXMT0T9rXnLazJtT3cOYY53fF2C0wSYe5CtTFMgLxQk1a RJqvNFYuatU8qAGJMTqKY0v6i+o4vfUPxB2MAoj6GD3f7R96IqtTDb6cxnSXuGLxBbvD irtN3CEUyCYv0y+gn1Jt//jqN9mkn2+gT7x/+kJlByHr5SAiN+FJWZa4u9ZUFOxFCcfm dVPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=kK+ix21O; 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 o13si8709497edz.352.2020.04.27.05.10.55; Mon, 27 Apr 2020 05:11:18 -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=kK+ix21O; 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 S1727012AbgD0MIn (ORCPT + 99 others); Mon, 27 Apr 2020 08:08:43 -0400 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:60186 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726504AbgD0MIn (ORCPT ); Mon, 27 Apr 2020 08:08:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1587989323; x=1619525323; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=7dTCzlsSd0rALJ8Pob5V+u9VFVvbxuYVhAL4qneveuY=; b=kK+ix21OhzT1XosoagvWdICzhL2vU7AdopGE8CLQUc4ah+UwisHTwFNk kpwllxiQLlXief+EmnoZFjBsEpi2PsZeVseM3aZwg3b3HwRi2VkQXB+WS 5pDF6b14r0k2lz5x2sFoObAhX5gI22RjHp/n+06PYb5S6ZwCSoji/SQPl w=; IronPort-SDR: F/njc9jfZQj5vj9gzYHPEeYFgn0aWjJcssd+CkJwIn+SSiDSa16dRRD6BAOCnZDb+FK+pVx5e/ zg5fZX+Xid/A== X-IronPort-AV: E=Sophos;i="5.73,324,1583193600"; d="scan'208";a="28868288" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-397e131e.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 27 Apr 2020 12:08:27 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-397e131e.us-west-2.amazon.com (Postfix) with ESMTPS id CD9A2A03C2; Mon, 27 Apr 2020 12:08:24 +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, 27 Apr 2020 12:08:24 +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, 27 Apr 2020 12:08:08 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v9 07/15] mm/damon: Implement callbacks Date: Mon, 27 Apr 2020 14:04:34 +0200 Message-ID: <20200427120442.24179-8-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200427120442.24179-1-sjpark@amazon.com> References: <20200427120442.24179-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.53] X-ClientProxiedBy: EX13D34UWC004.ant.amazon.com (10.43.162.155) 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 2ee93014628b..863b60e16a4a 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -834,6 +834,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); @@ -841,6 +843,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