From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42201C18E5B for ; Tue, 10 Mar 2020 09:01:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F187C20663 for ; Tue, 10 Mar 2020 09:01:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F187C20663 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=Huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A18636B0007; Tue, 10 Mar 2020 05:01:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A22A6B0008; Tue, 10 Mar 2020 05:01:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 869226B000A; Tue, 10 Mar 2020 05:01:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0134.hostedemail.com [216.40.44.134]) by kanga.kvack.org (Postfix) with ESMTP id 694D16B0007 for ; Tue, 10 Mar 2020 05:01:39 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 23B6E8248047 for ; Tue, 10 Mar 2020 09:01:39 +0000 (UTC) X-FDA: 76578859518.10.cap79_82c3a64fe7243 X-HE-Tag: cap79_82c3a64fe7243 X-Filterd-Recvd-Size: 8305 Received: from huawei.com (lhrrgout.huawei.com [185.176.76.210]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 09:01:37 +0000 (UTC) Received: from lhreml704-cah.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id 7416A3F7CDEB21F6EF8A; Tue, 10 Mar 2020 09:01:36 +0000 (GMT) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by lhreml704-cah.china.huawei.com (10.201.108.45) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 10 Mar 2020 09:01:36 +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:35 +0000 Date: Tue, 10 Mar 2020 09:01:34 +0000 From: Jonathan Cameron To: SeongJae Park CC: , SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v6 06/14] mm/damon: Implement access pattern recording Message-ID: <20200310090134.000052fb@Huawei.com> In-Reply-To: <20200224123047.32506-7-sjpark@amazon.com> References: <20200224123047.32506-1-sjpark@amazon.com> <20200224123047.32506-7-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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, 24 Feb 2020 13:30:39 +0100 SeongJae Park wrote: > From: SeongJae Park > > This commit implements the recording feature of DAMON. If this feature > is enabled, DAMON writes the monitored access patterns in its binary > format into a file which specified by the user. This is already able to > be implemented by each user using the callbacks. However, as the > recording is expected to be used widely, this commit implements the > feature in the DAMON, for more convenience and efficiency. > > Signed-off-by: SeongJae Park I guess this work whilst you are still developing, but I'm not convinced writing to a file should be a standard feature... > --- > mm/damon.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 123 insertions(+), 3 deletions(-) > > diff --git a/mm/damon.c b/mm/damon.c > index 554720778e8a..a7edb2dfa700 100644 > --- a/mm/damon.c > +++ b/mm/damon.c > @@ -76,6 +76,11 @@ struct damon_ctx { > 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; > @@ -89,6 +94,8 @@ struct damon_ctx { > void (*aggregate_cb)(struct damon_ctx *context); > }; > > +#define MAX_RFILE_PATH_LEN 256 > + > /* Get a random number in [l, r) */ > #define damon_rand(ctx, l, r) (l + prandom_u32_state(&ctx->rndseed) % (r - l)) > > @@ -550,16 +557,81 @@ static bool kdamond_aggregate_interval_passed(struct damon_ctx *ctx) > } > > /* > - * Reset the aggregated monitoring results > + * Flush the content in the result buffer to the result file > + */ > +static void damon_flush_rbuffer(struct damon_ctx *ctx) > +{ > + ssize_t sz; > + loff_t pos; > + struct file *rfile; > + > + while (ctx->rbuf_offset) { > + pos = 0; > + rfile = filp_open(ctx->rfile_path, O_CREAT | O_RDWR | O_APPEND, > + 0644); > + if (IS_ERR(rfile)) { > + pr_err("Cannot open the result file %s\n", > + ctx->rfile_path); > + return; > + } > + > + sz = kernel_write(rfile, ctx->rbuf, ctx->rbuf_offset, &pos); > + filp_close(rfile, NULL); > + > + ctx->rbuf_offset -= sz; > + } > +} > + > +/* > + * Write a data into the result buffer > + */ > +static void damon_write_rbuf(struct damon_ctx *ctx, void *data, ssize_t size) > +{ > + if (!ctx->rbuf_len || !ctx->rbuf) > + return; > + if (ctx->rbuf_offset + size > ctx->rbuf_len) > + damon_flush_rbuffer(ctx); > + > + memcpy(&ctx->rbuf[ctx->rbuf_offset], data, size); > + ctx->rbuf_offset += size; > +} > + > +/* > + * Flush the aggregated monitoring results to the result buffer > + * > + * Stores current tracking results to the result buffer and reset 'nr_accesses' > + * of each regions. The format for the result buffer is as below: > + * > + *