From patchwork Mon Apr 6 13:09:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11475535 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BF12913 for ; Mon, 6 Apr 2020 13:14:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BFC8F21D94 for ; Mon, 6 Apr 2020 13:14:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="sBXySGlU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BFC8F21D94 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E9B468E001F; Mon, 6 Apr 2020 09:14:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E4B978E000D; Mon, 6 Apr 2020 09:14:46 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D12BF8E001F; Mon, 6 Apr 2020 09:14:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id BB4B68E000D for ; Mon, 6 Apr 2020 09:14:46 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 63AC89899 for ; Mon, 6 Apr 2020 13:14:46 +0000 (UTC) X-FDA: 76677474972.19.box14_80ed7c902c947 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=358a57b7c=sjpark@amazon.com,,RULES_HIT:30003:30012:30034:30051:30054:30064:30070:30075,0,RBL:52.95.49.90:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:37,LUA_SUMMARY:none X-HE-Tag: box14_80ed7c902c947 X-Filterd-Recvd-Size: 9259 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Mon, 6 Apr 2020 13:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1586178886; x=1617714886; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=3Hr6eCFUJGmr0peeA91u4VbTBCp2QEbtkR27QSCgsmY=; b=sBXySGlUgd7OCQ9XCwkyqbCj6G9cBLS0l36BwT5giU6Y37kuBm4lsXr8 YCqbjGOeTbjtvcUDjPJOyZoAFLbxMIQ0RMTXE7deddXDMstV80ohCNlMH loLeSnTlm2dyqDq7s1rb4IhGPTB4JV7zG5YXfHOKTpEgw4RhmFnXj7Clp M=; IronPort-SDR: PnvmSjbBTUahDHOeAzqD7W6iFI9Xk/cGePXbXpH0agNpeIGcSFYsZmbFXdr2Yx3I3LPGWFfwQR sE7Lum2L7jGw== X-IronPort-AV: E=Sophos;i="5.72,351,1580774400"; d="scan'208";a="24290850" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 06 Apr 2020 13:14:45 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com (Postfix) with ESMTPS id 6637EA24B6; Mon, 6 Apr 2020 13:14:34 +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, 6 Apr 2020 13:14:33 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.160.65) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 6 Apr 2020 13:14:19 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v8 08/15] mm/damon: Implement access pattern recording Date: Mon, 6 Apr 2020 15:09:31 +0200 Message-ID: <20200406130938.14066-9-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200406130938.14066-1-sjpark@amazon.com> References: <20200406130938.14066-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.65] X-ClientProxiedBy: EX13D11UWB003.ant.amazon.com (10.43.161.206) To EX13D31EUA001.ant.amazon.com (10.43.165.15) 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: 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 --- include/linux/damon.h | 7 +++ mm/damon.c | 120 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 3 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index cad3ee3d78db..47fb0ec03030 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -50,6 +50,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; struct mutex kdamond_lock; @@ -66,6 +71,8 @@ int damon_set_pids(struct damon_ctx *ctx, unsigned long *pids, ssize_t nr_pids); 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); +int damon_set_recording(struct damon_ctx *ctx, + unsigned int rbuf_len, char *rfile_path); int damon_start(struct damon_ctx *ctx); int damon_stop(struct damon_ctx *ctx); diff --git a/mm/damon.c b/mm/damon.c index 608787e88118..b1363e4fdab8 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -41,6 +41,8 @@ #define damon_for_each_task_safe(ctx, t, next) \ list_for_each_entry_safe(t, next, &(ctx)->tasks_list, list) +#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)) @@ -569,16 +571,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: + * + *