Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1281851ybg; Tue, 2 Jun 2020 06:10:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUe6yDWtcxQyqpPFjGAJ0UL55kUR1nosjl3+IkIGxG6Dz0Se1zkwnw+wl+MObw95q7AqVx X-Received: by 2002:a50:d715:: with SMTP id t21mr25727546edi.194.1591103411552; Tue, 02 Jun 2020 06:10:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591103411; cv=none; d=google.com; s=arc-20160816; b=NJEAmtzFb1dhKsSMtSMkDy6DOpNxuf4LDTNGo7xXuMGLxyxegU2V9dbWtTLc8qlB64 MsulJOecBql8C3+mVDBFoByJOr1E3ISptGIuubEEGhQAZM/QzTR9K62zFM5T3hk3FApm WeQcQfB1c/JkGWGr7uEFMnj6SlRwKEd5QnVLwno67EaT2lz88YJqrFPuVas05mq0WCq6 azSRC0rF3FyTy/qjPzN6epibDZRJrMGR1Quz4Jgv5xwcH1ARkVTClikyRIkyXpzwPbMp 2ae15iZ6N1005MDIyoFhvMl0AMs6ZHu7exeTkUY+YDFk6phGHz3mrkVP9V/n4AXN7uR2 FUHw== 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=yXcscIx9TszwKz07XL6u8QTZrOQmEAxwAfn/hK3gC7Q=; b=lehgps5arKOspOLMWYeRpPgjFlBZRfRtDsiEOJeTvb/JFbZU9dj8dSbIAL2MazC7Cc Fkt6br78FMX8G4rY/pBQvxbKUWFImMngOYOmjhG369ol7RV2oQQhEpJ64znZi1CNhINA ksjYEvmtNQjGj+mQTN6cIYL/8TRto1jZY3P4I6sIIJT9XiSaAL52pAyi5QKuAWpwx/Cp 3WUMSrGOXXw1G0xz5RqBiiP+T2AjDBKLCfqBKI5o1zFn5UEEDSBZhYsRSscn0yEjVJVA RhU5piNPg/lWPMmP87jbdTgTTUAQOt2EkloVzBKJZIRtv5UrJ7o+1igIKU99UpRjDGCv s+Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=QbBe2b8D; 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 q24si123580eds.133.2020.06.02.06.09.48; Tue, 02 Jun 2020 06:10:11 -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=QbBe2b8D; 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 S1728574AbgFBNHP (ORCPT + 99 others); Tue, 2 Jun 2020 09:07:15 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:64000 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728514AbgFBNHI (ORCPT ); Tue, 2 Jun 2020 09:07:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591103227; x=1622639227; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=yXcscIx9TszwKz07XL6u8QTZrOQmEAxwAfn/hK3gC7Q=; b=QbBe2b8DUrb8rqOWWqimmXkRgO51MFymAKTPWrM0t3QgGf4gVE8QWZdT z8TPIj9jHci7Jb33rEQfAhSDa7+lBVO3f0vo/OB+JmDJ/AdEHh01ya7wY srrYXTUPJstFuY5dppplAv1ff9D6d+PZCSJ3HSnJuajBc/8aMmxouCEOD E=; IronPort-SDR: nC8b8AKKge52pMvpsUJykAc+9zQDcLWR3+//e6ireo+hA5Mc/Wly7o4xepmNyM7G5T4aVjWAny RgoBNPGBedtA== X-IronPort-AV: E=Sophos;i="5.73,464,1583193600"; d="scan'208";a="49176524" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-c300ac87.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 02 Jun 2020 13:06:59 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-c300ac87.us-west-2.amazon.com (Postfix) with ESMTPS id 5A27FA2019; Tue, 2 Jun 2020 13:06:57 +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, 2 Jun 2020 13:06:56 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.161.175) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 2 Jun 2020 13:06:41 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 06/15] mm/damon: Implement callbacks Date: Tue, 2 Jun 2020 15:01:16 +0200 Message-ID: <20200602130125.20467-7-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200602130125.20467-1-sjpark@amazon.com> References: <20200602130125.20467-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.161.175] X-ClientProxiedBy: EX13D29UWC002.ant.amazon.com (10.43.162.254) 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 de5ed38ac05c..42ce9df47f8b 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -850,6 +850,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); @@ -857,6 +859,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