Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp459596ybh; Tue, 10 Mar 2020 02:03:01 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsWOf5h4s2BlC3bxUU2vm7RPf+s3T0b2jLfx+4VqoeSHwly4H/48csMiPJHZ4em9u8+7RVp X-Received: by 2002:a9d:600d:: with SMTP id h13mr10371232otj.213.1583830981188; Tue, 10 Mar 2020 02:03:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583830981; cv=none; d=google.com; s=arc-20160816; b=mguCDhldiwFDR7AM+n5JexMTEZXlS6IWhjfg4xLXj8FU7NObraFsfQWF/PdN6PDMFZ Ip37WBzHIcEJrnU9bwhhFfzQadvUU36ps1rQwT/yGackA1x0qVkmkDvwjKRwecflAtQD nv9GW/FJBNi/YMJvEVKD83AQ6cGjN0EibGi5une9ztphatY9pITiPMsvR0xXAHY9fNhp 9H0tc8NZZstLS222DoV2RQqk0z6mHkfu22p8641KOPjFcsIaA/4yYZrri71krqBc03G5 lBSzBD3bvvE9yF+qT5Km4mDc/sHwuY4eXsDUiyBiqTjpnRHvKIowlZmxCUki9+am/Gfe GVkQ== 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=tETCmDJJ5S9hzAQhm27NQInS3pWrIylhE305fAvNJuY=; b=guhhwljTpSSyR0gKAH16+FV7Mv8mVpyOhd9wNOQb/KaVR29bwnX3H9TGHvHYCHWpxd ak89FaLwCLAJ5yQbKxLJw6BmFx/fx7avO/bV4G/8u1My7O+wt1hHBfYy9+FmlrqqiDHY 1zt/A0D/fh4Hl9OYeSab4SqtrdP8MJj0E5piI2kjv5Ark2OLYcJPOy5eDWSQeU6OLFVW hoYtDMXODbMFNOXabMQZzoUz+ktr0rFYfzmY2uEH9E1AkUKyvZZsdG0hQA2rxTFFkCsI zvfYseQaiudRnWltizIwgaQbRv1rg8d/T7aTaVXJgNzAsxX1RGVZmtGNMVZv2b3/FKGh 42+A== 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 a59si8041420otb.8.2020.03.10.02.02.37; Tue, 10 Mar 2020 02:03:01 -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 S1726731AbgCJJBi (ORCPT + 99 others); Tue, 10 Mar 2020 05:01:38 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:2535 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726389AbgCJJBh (ORCPT ); Tue, 10 Mar 2020 05:01:37 -0400 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 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: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: > + * > + *