Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp459782ybh; Tue, 10 Mar 2020 02:03:14 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu9miM8aSnPJqWCGzLdQWUJjbWovFhEVPvKC+nmOOX4/WjOhDx3P/KaY+EAxqIHSc1fqzil X-Received: by 2002:a9d:4d02:: with SMTP id n2mr6532385otf.107.1583830994162; Tue, 10 Mar 2020 02:03:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583830994; cv=none; d=google.com; s=arc-20160816; b=ULsBm3VIKk+dOTjPG/CMq3/A/8bee7+bjCgw76hJsHDyYyaKF5ZCmvuvHD88icP4UI spN/Y43OJQfT2lxaJXmx83iMBdo30G85VuED3uJDRRgCQokBwAdDv0wcAGhVbUL+wHhg shnplS1k77CWbtJaXGZ6vNSP3jUcWraBF0zdKXhP/RXkrOc/h3/825pcVyJQDtB6WpgV yVqiK+HRGZ52I29BoLADAATFULqpa5g1VqminVxVui5T8nhvaLI50sEi4JYTsqQ5+KSE OtOcCZ2JHH0i+rNNELO/BWGxZ3ZB8iCp6xGAsZVTsjJYG1ys0hfnwL0ciP9+tvToRNoC i2zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=Rh+J1h/fYYQujnIx1yUOL/S+q8y9LieaD1119gGaWx4=; b=gM8XSYZqWwczYtUF2jrd9oIH6J3OHtIbZldyj19Ykg1thZwHJ8Y8PkLdBi9GucUX6c 5gbyMYop7pXytB5PGSUGItt9ocyRyuttdV80A+QNxZr1YT9sb9yFwC4bUemFzEbpGk+K HN4xvEIaX3drbayi5aq1AVY//6mcLUg1grigY/PRtYLkzJusuhyd3L+wECmcNaQCN5/3 8kdeN1sAfakqL+9KzQaRZpKpj74TwEj29jRMRqZYJwYPGmyz2T6MarDSPvGFLykXmeot sX4JHzszXTU9lWcNon7dSLU7fwuU1uOlOGbb2JCO0QovYVjlZ7agKqaupBjiNELFUg7R iqEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e16si3518345ote.190.2020.03.10.02.02.59; Tue, 10 Mar 2020 02:03:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbgCJJB4 (ORCPT + 99 others); Tue, 10 Mar 2020 05:01:56 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:2536 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726389AbgCJJBz (ORCPT ); Tue, 10 Mar 2020 05:01:55 -0400 Received: from LHREML713-CAH.china.huawei.com (unknown [172.18.7.106]) by Forcepoint Email with ESMTP id 7C36B3821EE36C01EB43; Tue, 10 Mar 2020 09:01:54 +0000 (GMT) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by LHREML713-CAH.china.huawei.com (10.201.108.36) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 10 Mar 2020 09:01:54 +0000 Received: from localhost (10.202.226.57) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 10 Mar 2020 09:01:53 +0000 Date: Tue, 10 Mar 2020 09:01:52 +0000 From: Jonathan Cameron To: SeongJae Park CC: , SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v6 07/14] mm/damon: Implement kernel space API Message-ID: <20200310090152.00002c6e@Huawei.com> In-Reply-To: <20200224123047.32506-8-sjpark@amazon.com> References: <20200224123047.32506-1-sjpark@amazon.com> <20200224123047.32506-8-sjpark@amazon.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.57] X-ClientProxiedBy: lhreml715-chm.china.huawei.com (10.201.108.66) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 24 Feb 2020 13:30:40 +0100 SeongJae Park wrote: > From: SeongJae Park > > This commit implements the DAMON api for the kernel. Other kernel code > can use DAMON by calling damon_start() and damon_stop() with their own > 'struct damon_ctx'. > > Signed-off-by: SeongJae Park Seems like it would have been easier to create the header as you went along and avoid the need to have the bits here dropping static. Or the moves for that matter. Also, ideally have full kernel-doc for anything that forms part of an interface that is intended for use by others. Jonathan > --- > include/linux/damon.h | 71 +++++++++++++++++++++++++++++++++++++++++++ > mm/damon.c | 71 +++++++++---------------------------------- > 2 files changed, 85 insertions(+), 57 deletions(-) > create mode 100644 include/linux/damon.h > > diff --git a/include/linux/damon.h b/include/linux/damon.h > new file mode 100644 > index 000000000000..78785cb88d42 > --- /dev/null > +++ b/include/linux/damon.h > @@ -0,0 +1,71 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * DAMON api > + * > + * Copyright 2019 Amazon.com, Inc. or its affiliates. All rights reserved. > + * > + * Author: SeongJae Park > + */ > + > +#ifndef _DAMON_H_ > +#define _DAMON_H_ > + > +#include > +#include > +#include > +#include > + > +/* Represents a monitoring target region on the virtual address space */ > +struct damon_region { > + unsigned long vm_start; > + unsigned long vm_end; > + unsigned long sampling_addr; > + unsigned int nr_accesses; > + struct list_head list; > +}; > + > +/* Represents a monitoring target task */ > +struct damon_task { > + unsigned long pid; > + struct list_head regions_list; > + struct list_head list; > +}; > + > +struct damon_ctx { > + unsigned long sample_interval; > + unsigned long aggr_interval; > + unsigned long regions_update_interval; > + unsigned long min_nr_regions; > + unsigned long max_nr_regions; > + > + struct timespec64 last_aggregation; > + struct timespec64 last_regions_update; > + > + unsigned char *rbuf; > + unsigned int rbuf_len; > + unsigned int rbuf_offset; > + char *rfile_path; > + > + struct task_struct *kdamond; > + bool kdamond_stop; > + spinlock_t kdamond_lock; > + > + struct rnd_state rndseed; > + > + 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, > + unsigned long *pids, ssize_t nr_pids); > +int damon_set_recording(struct damon_ctx *ctx, > + unsigned int rbuf_len, char *rfile_path); > +int damon_set_attrs(struct damon_ctx *ctx, unsigned long s, unsigned long a, > + unsigned long r, unsigned long min, unsigned long max); > +int damon_start(struct damon_ctx *ctx); > +int damon_stop(struct damon_ctx *ctx); > + > +#endif > diff --git a/mm/damon.c b/mm/damon.c > index a7edb2dfa700..b3e9b9da5720 100644 > --- a/mm/damon.c > +++ b/mm/damon.c > @@ -9,6 +9,7 @@ > > #define pr_fmt(fmt) "damon: " fmt > > +#include > #include > #include > #include > @@ -40,60 +41,6 @@ > #define damon_for_each_task_safe(ctx, t, next) \ > list_for_each_entry_safe(t, next, &(ctx)->tasks_list, list) > > -/* Represents a monitoring target region on the virtual address space */ > -struct damon_region { > - unsigned long vm_start; > - unsigned long vm_end; > - unsigned long sampling_addr; > - unsigned int nr_accesses; > - struct list_head list; > -}; > - > -/* Represents a monitoring target task */ > -struct damon_task { > - unsigned long pid; > - struct list_head regions_list; > - struct list_head list; > -}; > - > -/* > - * For each 'sample_interval', DAMON checks whether each region is accessed or > - * not. It aggregates and keeps the access information (number of accesses to > - * each region) for each 'aggr_interval' time. And for each > - * 'regions_update_interval', damon checks whether the memory mapping of the > - * target tasks has changed (e.g., by mmap() calls from the applications) and > - * applies the changes. > - * > - * All time intervals are in micro-seconds. > - */ > -struct damon_ctx { > - unsigned long sample_interval; > - unsigned long aggr_interval; > - unsigned long regions_update_interval; > - unsigned long min_nr_regions; > - unsigned long max_nr_regions; > - > - struct timespec64 last_aggregation; > - struct timespec64 last_regions_update; > - > - unsigned char *rbuf; > - unsigned int rbuf_len; > - unsigned int rbuf_offset; > - char *rfile_path; > - > - struct task_struct *kdamond; > - bool kdamond_stop; > - spinlock_t kdamond_lock; > - > - struct rnd_state rndseed; > - > - struct list_head tasks_list; /* 'damon_task' objects */ > - > - /* callbacks */ > - void (*sample_cb)(struct damon_ctx *context); > - void (*aggregate_cb)(struct damon_ctx *context); > -}; > - > #define MAX_RFILE_PATH_LEN 256 > > /* Get a random number in [l, r) */ > @@ -961,10 +908,20 @@ static int damon_turn_kdamond(struct damon_ctx *ctx, bool on) > return 0; > } > > +int damon_start(struct damon_ctx *ctx) > +{ > + return damon_turn_kdamond(ctx, true); > +} > + > +int damon_stop(struct damon_ctx *ctx) > +{ > + return damon_turn_kdamond(ctx, false); > +} > + > /* > * This function should not be called while the kdamond is running. > */ > -static int damon_set_pids(struct damon_ctx *ctx, > +int damon_set_pids(struct damon_ctx *ctx, > unsigned long *pids, ssize_t nr_pids) > { > ssize_t i; > @@ -998,7 +955,7 @@ static int damon_set_pids(struct damon_ctx *ctx, > * > * Returns 0 on success, negative error code otherwise. > */ > -static int damon_set_recording(struct damon_ctx *ctx, > +int damon_set_recording(struct damon_ctx *ctx, > unsigned int rbuf_len, char *rfile_path) > { > size_t rfile_path_len; > @@ -1046,7 +1003,7 @@ static int damon_set_recording(struct damon_ctx *ctx, > * > * Returns 0 on success, negative error code otherwise. > */ > -static int damon_set_attrs(struct damon_ctx *ctx, unsigned long sample_int, > +int damon_set_attrs(struct damon_ctx *ctx, unsigned long sample_int, > unsigned long aggr_int, unsigned long regions_update_int, > unsigned long min_nr_reg, unsigned long max_nr_reg) > {