Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2396439ybv; Mon, 24 Feb 2020 04:35:24 -0800 (PST) X-Google-Smtp-Source: APXvYqytkIudh2d9EI71FrjGTDuKy68IH8h2Ht2hlsm1Fg3U5dzY+DzElLSjBH4xQVvvtJk6fV38 X-Received: by 2002:a9d:10d:: with SMTP id 13mr28339716otu.238.1582547724472; Mon, 24 Feb 2020 04:35:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582547724; cv=none; d=google.com; s=arc-20160816; b=oIzgGXtSqXVj3qzZgvmLKrL55jBHiQVW9ww60RiXYQ8hAYyNxM1pX+xk5TEdlZRMyu pNFabl397CYCgq17ictEsF95Fi9WUwYl2mUhq86cLLGb1nXKhGBJNSchBiNxGuzvNi6W fX0n0KNxMs/ehwKOm/fU8TXntNgjoEFbZyVMaxwL96SDktYA5m2hS/FHChvXmptIwkmU B9iqbAYfsV8D6NVwDMSam6OydP211PIIYkydkQVkaLZof6L/G0BoGPsMjE+ptKiH3d8N KfjSHKOQgUZ3xogO1DGMkbwN9MYqAwWm0h/AmKuaojkNRswKXocg0ocU1VzwPrxO7pbs ekwQ== 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=6F42Pz9VHRMpkkqcn1LuAE/92vxAuhPzf3zYCHXXs9U=; b=uC74R3YUI8wVeDV3Yiplyl2f2pGZdXk0VbzjrdDRKk+/S5RefJzek3xWfSjZ9nOmEW o2fCYxqoM8CCi3FiLtOHLUpjwOipO9hKJqeLdxpwIizyFLohfWK/7P7dsk3GO1Wpx/UA +7dphUK/6VkNyu9WLthbHGq7pw3YI7sOeqU9WncCgFKKNvrPqXA8h4Y7nfhIoDeEjLv2 DNvyYS3BF33+FJ7bggb7WhVT2G45zcgntwQA9PnpC5C44Tuh4Gz3OVrBPilPJh7tQm2q GnBeUbOPNVMeAZJD477tZQaFf1SeIIN0rdBrbK4cpf1cZxVjfUrD+fFLJdGInJk9cZc0 ABZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=WuIb25md; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o7si4808261oie.265.2020.02.24.04.35.12; Mon, 24 Feb 2020 04:35:24 -0800 (PST) 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; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=WuIb25md; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727444AbgBXMeF (ORCPT + 99 others); Mon, 24 Feb 2020 07:34:05 -0500 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:62823 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726778AbgBXMeF (ORCPT ); Mon, 24 Feb 2020 07:34:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1582547644; x=1614083644; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=6F42Pz9VHRMpkkqcn1LuAE/92vxAuhPzf3zYCHXXs9U=; b=WuIb25mdJsKOl5W1WUPfaS5Kdrgd4Zui46cMM+yfDJRHoKq968/CV7tW MMeX5/sUvoxKtBC0Z6DzPatUe1lbbPnBAVGxQwf9oZxIISg2Dkwq5Jv7e AMrPgCAzC/c6GXLGoIZ7wbrn3xyKHAAzqqh4DLA2eoKv6u8mvFSkC1hv+ I=; IronPort-SDR: nC8HwCmLIZjw5y//Js9KbxmgKURlqkRSom/tqt987gO2PK1zVlF1V8Rd3bSaWQz602DTMNViNt lSe6ffVTTKLQ== X-IronPort-AV: E=Sophos;i="5.70,480,1574121600"; d="scan'208";a="18295463" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-87a10be6.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 24 Feb 2020 12:33:47 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-87a10be6.us-west-2.amazon.com (Postfix) with ESMTPS id D9FE2A2694; Mon, 24 Feb 2020 12:33:44 +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.1236.3; Mon, 24 Feb 2020 12:33:44 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.53) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 24 Feb 2020 12:33:32 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v6 06/14] mm/damon: Implement access pattern recording Date: Mon, 24 Feb 2020 13:30:39 +0100 Message-ID: <20200224123047.32506-7-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200224123047.32506-1-sjpark@amazon.com> References: <20200224123047.32506-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.53] X-ClientProxiedBy: EX13D19UWC003.ant.amazon.com (10.43.162.184) 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 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 --- 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: + * + *