From patchwork Wed Oct 7 07:14:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11819841 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 266C16CB for ; Wed, 7 Oct 2020 07:22:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B47F7207EA for ; Wed, 7 Oct 2020 07:22:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="izglYSq4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B47F7207EA 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 017C0900003; Wed, 7 Oct 2020 03:22:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F083A900002; Wed, 7 Oct 2020 03:22:52 -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 DD0E0900003; Wed, 7 Oct 2020 03:22:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id AF272900002 for ; Wed, 7 Oct 2020 03:22:52 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 040A81802CCB3 for ; Wed, 7 Oct 2020 07:22:52 +0000 (UTC) X-FDA: 77344287384.15.egg64_0e0750d271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 17396180286E2 for ; Wed, 7 Oct 2020 07:15:17 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=542e595a5=sjpark@amazon.com,,RULES_HIT:30003:30051:30054:30056:30064:30070:30080,0,RBL:52.95.49.90:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04y8acadgk9omg4wmjy1gr8ystz9ayc5wtoss3pw7oyzi5jhg9iuw6krfnwn3ck.5dbzhb1rqm3hy15egfjsgtf5isqzdgotgj8wiqe3ahtn7estkzf945djg45fsxd.4-lbl8.mailshell.net-223.238.255.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:24,LUA_SUMMARY:none X-HE-Tag: egg64_0e0750d271cd X-Filterd-Recvd-Size: 8653 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602054916; x=1633590916; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=OxApDNVBe9qJrgKMXpVHXXem1zXkEyX41XgSrJ5ico4=; b=izglYSq4Ixoe7yY7ZGzN5swP1eOo/D22sXd38EY5B823NCNIMoVFVqcG TsIE7BQf8rdok08kyOMAE9vl3rb+meLkx4NcvWdsrFA4Nx8eJtTEJJ9S2 PkBRoLJPCTqxVbu57Eouxqg+okwCaqB+kOyevV7Qi8X2lg+z8OkQtQhiM U=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="58523428" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-74cf8b49.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 07 Oct 2020 07:15:15 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1d-74cf8b49.us-east-1.amazon.com (Postfix) with ESMTPS id CC8FAC09AE; Wed, 7 Oct 2020 07:15:03 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:14:47 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 01/10] damon/dbgfs: Allow users to set initial monitoring target regions Date: Wed, 7 Oct 2020 09:14:00 +0200 Message-ID: <20201007071409.12174-2-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 Some 'damon-dbgfs' users would want to monitor only a part of the entire virtual memory address space. The framework users in the kernel space could use '->init_target_regions' callback or even set the regions inside the context struct as they want, but 'damon-dbgfs' users cannot. For the reason, this commit introduces a new debugfs file, 'init_region'. 'damon-dbgfs' users can specify which initial monitoring target address regions they want by writing special input to the file. The input should describe each region in each line in below form: Note that the regions will be updated to cover entire memory mapped regions after 'regions update interval'. If you want the regions to not be updated after the initial setting, you could set the interval as a very long time, say, a few decades. Signed-off-by: SeongJae Park --- mm/damon/dbgfs.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 3 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index 9390ed9b9304..28076557ea86 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -523,6 +523,147 @@ static ssize_t dbgfs_target_ids_write(struct file *file, return ret; } +static ssize_t sprint_init_regions(struct damon_ctx *c, char *buf, ssize_t len) +{ + struct damon_target *t; + struct damon_region *r; + int written = 0; + int rc; + + damon_for_each_target(t, c) { + damon_for_each_region(r, t) { + rc = scnprintf(&buf[written], len - written, + "%lu %lu %lu\n", + t->id, r->ar.start, r->ar.end); + if (!rc) + return -ENOMEM; + written += rc; + } + } + return written; +} + +static ssize_t dbgfs_init_regions_read(struct file *file, char __user *buf, + size_t count, loff_t *ppos) +{ + struct damon_ctx *ctx = file->private_data; + char *kbuf; + ssize_t len; + + kbuf = kmalloc(count, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + mutex_lock(&ctx->kdamond_lock); + if (ctx->kdamond) { + mutex_unlock(&ctx->kdamond_lock); + return -EBUSY; + } + + len = sprint_init_regions(ctx, kbuf, count); + mutex_unlock(&ctx->kdamond_lock); + if (len < 0) + goto out; + len = simple_read_from_buffer(buf, count, ppos, kbuf, len); + +out: + kfree(kbuf); + return len; +} + +static int add_init_region(struct damon_ctx *c, + unsigned long target_id, struct damon_addr_range *ar) +{ + struct damon_target *t; + struct damon_region *r, *prev; + int rc = -EINVAL; + + if (ar->start >= ar->end) + return -EINVAL; + + damon_for_each_target(t, c) { + if (t->id == target_id) { + r = damon_new_region(ar->start, ar->end); + if (!r) + return -ENOMEM; + damon_add_region(r, t); + if (damon_nr_regions(t) > 1) { + prev = damon_prev_region(r); + if (prev->ar.end > r->ar.start) { + damon_destroy_region(r); + return -EINVAL; + } + } + rc = 0; + } + } + return rc; +} + +static int set_init_regions(struct damon_ctx *c, const char *str, ssize_t len) +{ + struct damon_target *t; + struct damon_region *r, *next; + int pos = 0, parsed, ret; + unsigned long target_id; + struct damon_addr_range ar; + int err; + + damon_for_each_target(t, c) { + damon_for_each_region_safe(r, next, t) + damon_destroy_region(r); + } + + while (pos < len) { + ret = sscanf(&str[pos], "%lu %lu %lu%n", + &target_id, &ar.start, &ar.end, &parsed); + if (ret != 3) + break; + err = add_init_region(c, target_id, &ar); + if (err) + goto fail; + pos += parsed; + } + + return 0; + +fail: + damon_for_each_target(t, c) { + damon_for_each_region_safe(r, next, t) + damon_destroy_region(r); + } + return err; +} + +static ssize_t dbgfs_init_regions_write(struct file *file, + const char __user *buf, size_t count, + loff_t *ppos) +{ + struct damon_ctx *ctx = file->private_data; + char *kbuf; + ssize_t ret = count; + int err; + + kbuf = user_input_str(buf, count, ppos); + if (IS_ERR(kbuf)) + return PTR_ERR(kbuf); + + mutex_lock(&ctx->kdamond_lock); + if (ctx->kdamond) { + ret = -EBUSY; + goto unlock_out; + } + + err = set_init_regions(ctx, kbuf, ret); + if (err) + ret = err; + +unlock_out: + mutex_unlock(&ctx->kdamond_lock); + kfree(kbuf); + return ret; +} + static ssize_t dbgfs_kdamond_pid_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { @@ -584,6 +725,13 @@ static const struct file_operations target_ids_fops = { .write = dbgfs_target_ids_write, }; +static const struct file_operations init_regions_fops = { + .owner = THIS_MODULE, + .open = damon_dbgfs_open, + .read = dbgfs_init_regions_read, + .write = dbgfs_init_regions_write, +}; + static const struct file_operations kdamond_pid_fops = { .owner = THIS_MODULE, .open = damon_dbgfs_open, @@ -593,9 +741,9 @@ static const struct file_operations kdamond_pid_fops = { static int dbgfs_fill_ctx_dir(struct dentry *dir, struct damon_ctx *ctx) { const char * const file_names[] = {"attrs", "record", "schemes", - "target_ids", "kdamond_pid"}; - const struct file_operations *fops[] = {&attrs_fops, - &record_fops, &schemes_fops, &target_ids_fops, + "target_ids", "init_regions", "kdamond_pid"}; + const struct file_operations *fops[] = {&attrs_fops, &record_fops, + &schemes_fops, &target_ids_fops, &init_regions_fops, &kdamond_pid_fops}; int i; From patchwork Wed Oct 7 07:14:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11819847 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 633876CB for ; Wed, 7 Oct 2020 07:23:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E6C5420797 for ; Wed, 7 Oct 2020 07:23:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="QWKCXFMA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6C5420797 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 1ED0B900004; Wed, 7 Oct 2020 03:23:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1993B900002; Wed, 7 Oct 2020 03:23:19 -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 06302900004; Wed, 7 Oct 2020 03:23:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id D01DF900002 for ; Wed, 7 Oct 2020 03:23:18 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 74C625830 for ; Wed, 7 Oct 2020 07:23:18 +0000 (UTC) X-FDA: 77344288476.02.frogs86_080b502271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id AF5E310202423 for ; Wed, 7 Oct 2020 07:15:39 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=542e595a5=sjpark@amazon.com,,RULES_HIT:30003:30029:30034:30051:30054:30064:30080,0,RBL:207.171.184.25:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10;04ygox6sxk6mcot1o9zispj8knxfyycpzfxdby9znrgyi8h7fos7m7ewmdr4m8b.oaisssaesix88geqbm51jub4g1s4ckqmm6b34zxirjcyjrdgjmbsbs9bp18s4e5.w-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: frogs86_080b502271cd X-Filterd-Recvd-Size: 11330 Received: from smtp-fw-9101.amazon.com (smtp-fw-9101.amazon.com [207.171.184.25]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602054939; x=1633590939; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=eFQ5FjEXjCcRqP315OtcZTEl8DRR0ETd5Jfrqerv8aI=; b=QWKCXFMAuCAZQNAJD1zPBpMuRQQAO6wKnUqEnsktR0KwdxBzbVIieHgs 1/mu1PQSpfg0YCUP+o+GJZsgVfro/UWUSs58YUVJZ26pEOeuMwCtJ1YQH U6wkUD1+hrkKeWzrRTwCjNF82Y7UsP9GhC6/DSsMU8xN3UuP3tuKYR/FA s=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="74032911" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 07 Oct 2020 07:15:35 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com (Postfix) with ESMTPS id 42A03A1D5B; Wed, 7 Oct 2020 07:15:21 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:15:05 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 02/10] tools/damon: Support init target regions specification Date: Wed, 7 Oct 2020 09:14:01 +0200 Message-ID: <20201007071409.12174-3-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 updates the damon user space tool to support the initial monitoring target regions specification. Signed-off-by: SeongJae Park --- tools/damon/_damon.py | 39 +++++++++++++++++++++++++++++++++++++++ tools/damon/record.py | 12 +++++++----- tools/damon/schemes.py | 12 +++++++----- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/tools/damon/_damon.py b/tools/damon/_damon.py index a4f6c03c23e4..a22ec3777c16 100644 --- a/tools/damon/_damon.py +++ b/tools/damon/_damon.py @@ -12,12 +12,25 @@ debugfs_attrs = None debugfs_record = None debugfs_schemes = None debugfs_target_ids = None +debugfs_init_regions = None debugfs_monitor_on = None def set_target_id(tid): with open(debugfs_target_ids, 'w') as f: f.write('%s\n' % tid) +def set_target(tid, init_regions=[]): + rc = set_target_id(tid) + if rc: + return rc + + if not os.path.exists(debugfs_init_regions): + return 0 + + string = ' '.join(['%s %d %d' % (tid, r[0], r[1]) for r in init_regions]) + return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions), + shell=True, executable='/bin/bash') + def turn_damon(on_off): return subprocess.call("echo %s > %s" % (on_off, debugfs_monitor_on), shell=True, executable="/bin/bash") @@ -97,6 +110,7 @@ def chk_update_debugfs(debugfs): global debugfs_record global debugfs_schemes global debugfs_target_ids + global debugfs_init_regions global debugfs_monitor_on debugfs_damon = os.path.join(debugfs, 'damon') @@ -104,6 +118,7 @@ def chk_update_debugfs(debugfs): debugfs_record = os.path.join(debugfs_damon, 'record') debugfs_schemes = os.path.join(debugfs_damon, 'schemes') debugfs_target_ids = os.path.join(debugfs_damon, 'target_ids') + debugfs_init_regions = os.path.join(debugfs_damon, 'init_regions') debugfs_monitor_on = os.path.join(debugfs_damon, 'monitor_on') if not os.path.isdir(debugfs_damon): @@ -131,6 +146,26 @@ def cmd_args_to_attrs(args): return Attrs(sample_interval, aggr_interval, regions_update_interval, min_nr_regions, max_nr_regions, rbuf_len, rfile_path, schemes) +def cmd_args_to_init_regions(args): + regions = [] + for arg in args.regions.split(): + addrs = arg.split('-') + try: + if len(addrs) != 2: + raise Exception('two addresses not given') + start = int(addrs[0]) + end = int(addrs[1]) + if start >= end: + raise Exception('start >= end') + if regions and regions[-1][1] > start: + raise Exception('regions overlap') + except Exception as e: + print('Wrong \'--regions\' argument (%s)' % e) + exit(1) + + regions.append([start, end]) + return regions + def set_attrs_argparser(parser): parser.add_argument('-d', '--debugfs', metavar='', type=str, default='/sys/kernel/debug', help='debugfs mounted path') @@ -144,3 +179,7 @@ def set_attrs_argparser(parser): default=10, help='minimal number of regions') parser.add_argument('-m', '--maxr', metavar='<# regions>', type=int, default=1000, help='maximum number of regions') + +def set_init_regions_argparser(parser): + parser.add_argument('-r', '--regions', metavar='"- ..."', + type=str, default='', help='monitoring target address regions') diff --git a/tools/damon/record.py b/tools/damon/record.py index 6d1cbe593b94..11fd54001472 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -24,7 +24,7 @@ def pidfd_open(pid): return syscall(NR_pidfd_open, pid, 0) -def do_record(target, is_target_cmd, attrs, old_attrs, pidfd): +def do_record(target, is_target_cmd, init_regions, attrs, old_attrs, pidfd): if os.path.isfile(attrs.rfile_path): os.rename(attrs.rfile_path, attrs.rfile_path + '.old') @@ -48,8 +48,8 @@ def do_record(target, is_target_cmd, attrs, old_attrs, pidfd): # only for reference of the pidfd usage. target = 'pidfd %s' % fd - if _damon.set_target_id(target): - print('target id setting (%s) failed' % target) + if _damon.set_target(target, init_regions): + print('target setting (%s, %s) failed' % (target, init_regions)) cleanup_exit(old_attrs, -2) if _damon.turn_damon('on'): print('could not turn on damon' % target) @@ -91,6 +91,7 @@ def chk_permission(): def set_argparser(parser): _damon.set_attrs_argparser(parser) + _damon.set_init_regions_argparser(parser) parser.add_argument('target', type=str, metavar='', help='the target command or the pid to record') parser.add_argument('--pidfd', action='store_true', @@ -117,19 +118,20 @@ def main(args=None): args.schemes = '' pidfd = args.pidfd new_attrs = _damon.cmd_args_to_attrs(args) + init_regions = _damon.cmd_args_to_init_regions(args) target = args.target target_fields = target.split() if not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): - do_record(target, True, new_attrs, orig_attrs, pidfd) + do_record(target, True, init_regions, new_attrs, orig_attrs, pidfd) else: try: pid = int(target) except: print('target \'%s\' is neither a command, nor a pid' % target) exit(1) - do_record(target, False, new_attrs, orig_attrs, pidfd) + do_record(target, False, init_regions, new_attrs, orig_attrs, pidfd) if __name__ == '__main__': main() diff --git a/tools/damon/schemes.py b/tools/damon/schemes.py index 9095835f6133..cfec89854a08 100644 --- a/tools/damon/schemes.py +++ b/tools/damon/schemes.py @@ -14,7 +14,7 @@ import time import _convert_damos import _damon -def run_damon(target, is_target_cmd, attrs, old_attrs): +def run_damon(target, is_target_cmd, init_regions, attrs, old_attrs): if os.path.isfile(attrs.rfile_path): os.rename(attrs.rfile_path, attrs.rfile_path + '.old') @@ -27,8 +27,8 @@ def run_damon(target, is_target_cmd, attrs, old_attrs): if is_target_cmd: p = subprocess.Popen(target, shell=True, executable='/bin/bash') target = p.pid - if _damon.set_target_pid(target): - print('pid setting (%s) failed' % target) + if _damon.set_target(target, init_regions): + print('target setting (%s, %s) failed' % (target, init_regions)) cleanup_exit(old_attrs, -2) if _damon.turn_damon('on'): print('could not turn on damon' % target) @@ -68,6 +68,7 @@ def chk_permission(): def set_argparser(parser): _damon.set_attrs_argparser(parser) + _damon.set_init_regions_argparser(parser) parser.add_argument('target', type=str, metavar='', help='the target command or the pid to record') parser.add_argument('-c', '--schemes', metavar='', type=str, @@ -92,19 +93,20 @@ def main(args=None): args.out = 'null' args.schemes = _convert_damos.convert(args.schemes, args.sample, args.aggr) new_attrs = _damon.cmd_args_to_attrs(args) + init_regions = _damon.cmd_args_to_init_regions(args) target = args.target target_fields = target.split() if not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): - run_damon(target, True, new_attrs, orig_attrs) + run_damon(target, True, init_regions, new_attrs, orig_attrs) else: try: pid = int(target) except: print('target \'%s\' is neither a command, nor a pid' % target) exit(1) - run_damon(target, False, new_attrs, orig_attrs) + run_damon(target, False, init_regions, new_attrs, orig_attrs) if __name__ == '__main__': main() From patchwork Wed Oct 7 07:14:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11819835 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 95AB1618 for ; Wed, 7 Oct 2020 07:22:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2065120870 for ; Wed, 7 Oct 2020 07:22:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="HfWHpnNJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2065120870 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 DD22C6B005C; Wed, 7 Oct 2020 03:22:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D5B8B900002; Wed, 7 Oct 2020 03:22:17 -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 BFE456B0068; Wed, 7 Oct 2020 03:22:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id 94AD96B005C for ; Wed, 7 Oct 2020 03:22:17 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 38FF2180364CE for ; Wed, 7 Oct 2020 07:22:17 +0000 (UTC) X-FDA: 77344285914.27.tax25_3811411271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id F3DE117F1B for ; Wed, 7 Oct 2020 07:15:56 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=542e595a5=sjpark@amazon.com,,RULES_HIT:30003:30012:30054:30064:30070:30080,0,RBL:207.171.184.25:@amazon.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100;04y8c9de3fachdu6zjaqxehfd4nd7och9c31cd9t9am4ecm8z4nzte8be5jwnzn.xpbfa6b8abkp1pfy6z64xuaasoqofbgjtn1r95s57peh6ffxunogwzrts4gaggm.a-lbl8.mailshell.net-223.238.255.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:25,LUA_SUMMARY:none X-HE-Tag: tax25_3811411271cd X-Filterd-Recvd-Size: 5797 Received: from smtp-fw-9101.amazon.com (smtp-fw-9101.amazon.com [207.171.184.25]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602054957; x=1633590957; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=nbNskFUf5I9SudJVFLFnLIHvjIM0C7eogr6WrZtj68U=; b=HfWHpnNJJSY3LIr8UNrrt8B7AVTd/ZaAh2qpL07S0E2AYoUFDVbB+BqR JE91DGzIOXXwrqO0E6ChUl/gsXhHz6AuWGmavEpL+/hDrOKdpj/gqFP9u bccm/ap4BB5ew1xoWoeJQDg2KyK8ArSJfZ54a8+SdGCN/X/1ZvwYJi55z w=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="74032971" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-57e1d233.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 07 Oct 2020 07:15:53 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1e-57e1d233.us-east-1.amazon.com (Postfix) with ESMTPS id B8F73141641; Wed, 7 Oct 2020 07:15:40 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:15:24 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 03/10] damon/dbgfs-test: Add a unit test case for 'init_regions' Date: Wed, 7 Oct 2020 09:14:02 +0200 Message-ID: <20201007071409.12174-4-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 adds another test case for the new feature, 'init_regions'. Signed-off-by: SeongJae Park Reviewed-by: Brendan Higgins --- mm/damon/dbgfs-test.h | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/mm/damon/dbgfs-test.h b/mm/damon/dbgfs-test.h index ce9c6784ad47..2189f8f2a28e 100644 --- a/mm/damon/dbgfs-test.h +++ b/mm/damon/dbgfs-test.h @@ -189,12 +189,67 @@ static void damon_dbgfs_test_aggregate(struct kunit *test) damon_destroy_ctx(ctx); } + +static void damon_dbgfs_test_set_init_regions(struct kunit *test) +{ + struct damon_ctx *ctx = damon_new_ctx(); + unsigned long ids[] = {1, 2, 3}; + /* Each line represents one region in `` `` */ + char * const valid_inputs[] = {"2 10 20\n 2 20 30\n2 35 45", + "2 10 20\n", + "2 10 20\n1 39 59\n1 70 134\n 2 20 25\n", + ""}; + /* Reading the file again will show sorted, clean output */ + char * const valid_expects[] = {"2 10 20\n2 20 30\n2 35 45\n", + "2 10 20\n", + "1 39 59\n1 70 134\n2 10 20\n2 20 25\n", + ""}; + char * const invalid_inputs[] = {"4 10 20\n", /* target not exists */ + "2 10 20\n 2 14 26\n", /* regions overlap */ + "1 10 20\n2 30 40\n 1 5 8"}; /* not sorted by address */ + char *input, *expect; + int i, rc; + char buf[256]; + + damon_set_targets(ctx, ids, 3); + + /* Put valid inputs and check the results */ + for (i = 0; i < ARRAY_SIZE(valid_inputs); i++) { + input = valid_inputs[i]; + expect = valid_expects[i]; + + rc = set_init_regions(ctx, input, strnlen(input, 256)); + KUNIT_EXPECT_EQ(test, rc, 0); + + memset(buf, 0, 256); + sprint_init_regions(ctx, buf, 256); + + KUNIT_EXPECT_STREQ(test, (char *)buf, expect); + } + /* Put invlid inputs and check the return error code */ + for (i = 0; i < ARRAY_SIZE(invalid_inputs); i++) { + input = invalid_inputs[i]; + pr_info("input: %s\n", input); + rc = set_init_regions(ctx, input, strnlen(input, 256)); + KUNIT_EXPECT_EQ(test, rc, -EINVAL); + + memset(buf, 0, 256); + sprint_init_regions(ctx, buf, 256); + + KUNIT_EXPECT_STREQ(test, (char *)buf, ""); + } + + damon_set_targets(ctx, NULL, 0); + damon_destroy_ctx(ctx); +} + static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_dbgfs_test_str_to_target_ids), KUNIT_CASE(damon_dbgfs_test_set_targets), KUNIT_CASE(damon_dbgfs_test_set_recording), KUNIT_CASE(damon_dbgfs_test_write_rbuf), KUNIT_CASE(damon_dbgfs_test_aggregate), + KUNIT_CASE(damon_dbgfs_test_set_init_regions), {}, }; From patchwork Wed Oct 7 07:14:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11819867 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 CA067618 for ; Wed, 7 Oct 2020 07:24:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F5C220797 for ; Wed, 7 Oct 2020 07:24:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="GYEONk0U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F5C220797 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 8C3C7900009; Wed, 7 Oct 2020 03:24:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 899CB900007; Wed, 7 Oct 2020 03:24:51 -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 7622A900009; Wed, 7 Oct 2020 03:24:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0089.hostedemail.com [216.40.44.89]) by kanga.kvack.org (Postfix) with ESMTP id 4B3B4900007 for ; Wed, 7 Oct 2020 03:24:51 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DDB89824999B for ; Wed, 7 Oct 2020 07:24:50 +0000 (UTC) X-FDA: 77344292340.08.spoon16_190750f271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 7244218088720 for ; Wed, 7 Oct 2020 07:16:16 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=542e595a5=sjpark@amazon.com,,RULES_HIT:30034:30054:30056:30064:30070,0,RBL:207.171.184.29:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10;04yfas9d71en6ox415tpjnnn3z1k3ypsxtobaunagcq7pc3n56at8yyse3op6w3.xgs9wjcnurmo6iraxnw7n8nc5timk5wtphgwnr6xw83uqhw1i4sdjpiyu53equ7.y-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: spoon16_190750f271cd X-Filterd-Recvd-Size: 4515 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602054976; x=1633590976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=IDHkic1gYAf9g3QrAFwx1LEoduynRqvj1VEruhEXvww=; b=GYEONk0U1Ta9VrAH/P+5wgpRPB8p3pYXDQQEsUQNpXsKLPiSnF917V5m W4KGZzWGgbR9FAC8vEDr1BEMbkRLkvpcpSbqfCygzcNMg1e+4BC17bWsi jZD3zd/oVoYqnLln6fhlYBzUaL7xSmDhvnqBtfSPWN2iTSL8sHkg2T/v8 M=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="82208436" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-67b371d8.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 07 Oct 2020 07:16:10 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1a-67b371d8.us-east-1.amazon.com (Postfix) with ESMTPS id 2C746A18E8; Wed, 7 Oct 2020 07:15:57 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:15:41 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 04/10] selftests/damon/_chk_record: Do not check number of gaps Date: Wed, 7 Oct 2020 09:14:03 +0200 Message-ID: <20201007071409.12174-5-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 Now the regions can be explicitly set as users want. Therefore checking the number of gaps doesn't make sense. Remove the condition. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_chk_record.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tools/testing/selftests/damon/_chk_record.py b/tools/testing/selftests/damon/_chk_record.py index 73e128904319..5f11be64abed 100644 --- a/tools/testing/selftests/damon/_chk_record.py +++ b/tools/testing/selftests/damon/_chk_record.py @@ -37,12 +37,9 @@ def chk_task_info(f): print('too many regions: %d > %d' % (nr_regions, max_nr_regions)) exit(1) - nr_gaps = 0 eaddr = 0 for r in range(nr_regions): saddr = struct.unpack('L', f.read(8))[0] - if eaddr and saddr != eaddr: - nr_gaps += 1 eaddr = struct.unpack('L', f.read(8))[0] nr_accesses = struct.unpack('I', f.read(4))[0] @@ -56,9 +53,6 @@ def chk_task_info(f): print('too high nr_access: expected %d but %d' % (max_nr_accesses, nr_accesses)) exit(1) - if nr_gaps != 2: - print('number of gaps are not two but %d' % nr_gaps) - exit(1) def parse_time_us(bindat): sec = struct.unpack('l', bindat[0:8])[0] From patchwork Wed Oct 7 07:14:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11819869 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 BA30F6CB for ; Wed, 7 Oct 2020 07:25:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6984C2083B for ; Wed, 7 Oct 2020 07:25:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="YUMdoEkR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6984C2083B 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 9AC5B900003; Wed, 7 Oct 2020 03:25:32 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 982DA900002; Wed, 7 Oct 2020 03:25:32 -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 87296900003; Wed, 7 Oct 2020 03:25:32 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0177.hostedemail.com [216.40.44.177]) by kanga.kvack.org (Postfix) with ESMTP id 5A708900002 for ; Wed, 7 Oct 2020 03:25:32 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 04B8C3621 for ; Wed, 7 Oct 2020 07:25:32 +0000 (UTC) X-FDA: 77344294104.13.brass39_48155af271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id B0CFB180AE7F3 for ; Wed, 7 Oct 2020 07:16:44 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=542e595a5=sjpark@amazon.com,,RULES_HIT:30003:30054:30064:30070:30080,0,RBL:207.171.184.25:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10;04yfk7e9qe1e5m9i4og7qxbu9qtyyypho4d4zpweyut56z6ysf75779qgbhjzty.qht5tmy5qm637jdia3c9z6wq8dyozy19mp85uzmbn815ywo35t51xbxr4jzoegq.a-lbl8.mailshell.net-223.238.255.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:23,LUA_SUMMARY:none X-HE-Tag: brass39_48155af271cd X-Filterd-Recvd-Size: 5995 Received: from smtp-fw-9101.amazon.com (smtp-fw-9101.amazon.com [207.171.184.25]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:16:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602055004; x=1633591004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=TaBhL5HojO46LzRrtNTJtjXeDGLmPmatGGRehayYLuY=; b=YUMdoEkR/nlSQj/RPy+5GWgHAGnX894MKFUi1ArA63g7np8Npdag2yJ+ ZBud9L8YeKmhsLNswNv5P6EoGcsvs8Zge1sR3BuvnigcBtzOLcIu48AFX 1n5oFOlHzG1bsRyFRhXsF35/BHkY8fNyPHdWVTfxvzkYA105wIpdN48rC k=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="74033079" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-2c665b5d.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 07 Oct 2020 07:16:29 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1d-2c665b5d.us-east-1.amazon.com (Postfix) with ESMTPS id D1559A1C5D; Wed, 7 Oct 2020 07:16:16 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:16:00 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 05/10] Docs/admin-guide/mm/damon: Document 'init_regions' feature Date: Wed, 7 Oct 2020 09:14:04 +0200 Message-ID: <20201007071409.12174-6-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 adds description of the 'init_regions' feature in the DAMON usage document. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 41 +++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index 96278227f925..cf0d44ce0ac9 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -281,8 +281,9 @@ for at least 100 milliseconds using below commands:: debugfs Interface ================= -DAMON exports five files, ``attrs``, ``target_ids``, ``record``, ``schemes`` -and ``monitor_on`` under its debugfs directory, ``/damon/``. +DAMON exports six files, ``attrs``, ``target_ids``, ``init_regions``, +``record``, ``schemes`` and ``monitor_on`` under its debugfs directory, +``/damon/``. Attributes @@ -321,6 +322,42 @@ check it again:: Note that setting the target ids doesn't start the monitoring. +Initial Monitoring Target Regions +--------------------------------- + +In case of the debugfs based monitoring, DAMON automatically sets and updates +the monitoring target regions so that entire memory mappings of target +processes can be covered. However, users might want to limit the monitoring +region to specific address ranges, such as the heap, the stack, or specific +file-mapped area. Or, some users might know the initial access pattern of +their workloads and therefore want to set optimal initial regions for the +'adaptive regions adjustment'. + +In such cases, users can explicitly set the initial monitoring target regions +as they want, by writing proper values to the ``init_regions`` file. Each line +of the input should represent one region in below form.:: + + + +The ``target id`` should already in ``target_ids`` file, and the regions should +be passed in address order. For example, below commands will set a couple of +address ranges, ``1-100`` and ``100-200`` as the initial monitoring target +region of process 42, and another couple of address ranges, ``20-40`` and +``50-100`` as that of process 4242.:: + + # cd /damon + # echo "42 1 100 + 42 100 200 + 4242 20 40 + 4242 50 100" > init_regions + +Note that this sets the initial monitoring target regions only. In case of +virtual memory monitoring, DAMON will automatically updates the boundary of the +regions after one ``regions update interval``. Therefore, users should set the +``regions update interval`` large enough in this case, if they don't want the +update. + + Record ------ From patchwork Wed Oct 7 07:14:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11819861 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 4DE1F618 for ; Wed, 7 Oct 2020 07:24:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DF1062083B for ; Wed, 7 Oct 2020 07:24:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="j1SJJaek" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF1062083B 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 03A6C900006; Wed, 7 Oct 2020 03:24:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 010686B0062; Wed, 7 Oct 2020 03:24:20 -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 E1CF5900006; Wed, 7 Oct 2020 03:24:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id B5AE76B005C for ; Wed, 7 Oct 2020 03:24:20 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4ABF23630 for ; Wed, 7 Oct 2020 07:24:20 +0000 (UTC) X-FDA: 77344291080.16.cart57_5915064271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id E023E1020E144 for ; Wed, 7 Oct 2020 07:16:47 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=542e595a5=sjpark@amazon.com,,RULES_HIT:30003:30012:30051:30054:30064:30070,0,RBL:72.21.196.25:@amazon.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100;04ygjjih7c7xii5983n1aew349jopocpgux1amj3r68ieeq3i843zfseukbiar9.apbo46eew4n8j95y9ex1srb946o8136azmurnoaouyu5qo388y3mhgo4aiintes.n-lbl8.mailshell.net-223.238.255.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:24,LUA_SUMMARY:none X-HE-Tag: cart57_5915064271cd X-Filterd-Recvd-Size: 11580 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:16:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602055008; x=1633591008; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=mIRY6jCt/Ds1TCdCRs9402VAL7E+NUH/LhRYNea7uTg=; b=j1SJJaek0A3bIniCFyu3jSwIoDuQ3vx95Q2xhTo+T/B63VWPsQEcmDyu e9ltvv1R5qJ+0IwFq0B1KXUdkHIRtph/a/HFd1MhZGrb97poq5AUB7Ixe 4GgB4Bvs5fSrNADScSICpflpwALtcmDhosPzMTn8cNiAelkUBJPGvT9E/ w=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="58285950" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 07 Oct 2020 07:16:46 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1e-c7c08562.us-east-1.amazon.com (Postfix) with ESMTPS id F33342421A8; Wed, 7 Oct 2020 07:16:33 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:16:17 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 06/10] damon/primitives: Implement callbacks for physical address space monitoring Date: Wed, 7 Oct 2020 09:14:05 +0200 Message-ID: <20201007071409.12174-7-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 primitives for the basic access monitoring of the physical memory address space. By using this, users can easily monitor the accesses to the physical memory. Internally, it uses the PTE Accessed bit, as similar to that of the virtual memory support. Also, it supports only user memory pages, as idle page tracking also does, for the same reason. If the monitoring target physical memory address range contains non-user memory pages, access check of the pages will do nothing but simply treat the pages as not accessed. Users who want to use other access check primitives and/or monitor the non-user memory regions could implement and use their own callbacks. Signed-off-by: SeongJae Park --- include/linux/damon.h | 9 +- mm/damon/primitives.c | 236 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+), 1 deletion(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index decd1374eaa5..afc22b4ea752 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -335,7 +335,14 @@ int damon_va_apply_scheme(struct damon_ctx *context, struct damon_target *t, struct damon_region *r, struct damos *scheme); void damon_va_set_primitives(struct damon_ctx *ctx); -#endif /* CONFIG_DAMON_PRIMITIVES */ +/* Reference callback implementations for physical memory */ +void damon_pa_init_regions(struct damon_ctx *ctx); +void damon_pa_update_regions(struct damon_ctx *ctx); +void damon_pa_prepare_access_checks(struct damon_ctx *ctx); +unsigned int damon_pa_check_accesses(struct damon_ctx *ctx); +bool damon_pa_target_valid(struct damon_target *t); +void damon_pa_set_primitives(struct damon_ctx *ctx); +#endif /* CONFIG_DAMON_PRIMITIVES */ #endif diff --git a/mm/damon/primitives.c b/mm/damon/primitives.c index 01c1ef3f7ff9..462997f9f140 100644 --- a/mm/damon/primitives.c +++ b/mm/damon/primitives.c @@ -12,7 +12,9 @@ #include #include #include +#include #include +#include #include #include @@ -656,4 +658,238 @@ void damon_va_set_primitives(struct damon_ctx *ctx) ctx->primitive.apply_scheme = damon_va_apply_scheme; } +/* + * Primitives for the physical address space + */ + +/* + * The initial regions construction function for the physical address space. + * + * This default version does nothing in actual. Users should set the initial + * regions by themselves before passing their damon_ctx to 'damon_start()', or + * implement their version of this and set '->init_target_regions' of their + * damon_ctx to point it. + */ +void damon_pa_init_regions(struct damon_ctx *ctx) +{ +} + +/* + * The dynamic monitoring target regions update function for the physical + * address space. + * + * This default version does nothing in actual. Users should update the + * regions in other callbacks such as '->after_aggregation', or implement their + * version of this and set the '->init_target_regions' of their damon_ctx to + * point it. + */ +void damon_pa_update_regions(struct damon_ctx *ctx) +{ +} + +/* access check functions for physical address based regions */ + +/* + * Get a page by pfn if it is in the LRU list. Otherwise, returns NULL. + * + * The body of this function is stollen from the 'page_idle_get_page()'. We + * steal rather than reuse it because the code is quite simple. + */ +static struct page *damon_pa_get_page(unsigned long pfn) +{ + struct page *page = pfn_to_online_page(pfn); + pg_data_t *pgdat; + + if (!page || !PageLRU(page) || + !get_page_unless_zero(page)) + return NULL; + + pgdat = page_pgdat(page); + spin_lock_irq(&pgdat->lru_lock); + if (unlikely(!PageLRU(page))) { + put_page(page); + page = NULL; + } + spin_unlock_irq(&pgdat->lru_lock); + return page; +} + +static bool __damon_pa_mkold(struct page *page, struct vm_area_struct *vma, + unsigned long addr, void *arg) +{ + damon_va_mkold(vma->vm_mm, addr); + return true; +} + +static void damon_pa_mkold(unsigned long paddr) +{ + struct page *page = damon_pa_get_page(PHYS_PFN(paddr)); + struct rmap_walk_control rwc = { + .rmap_one = __damon_pa_mkold, + .anon_lock = page_lock_anon_vma_read, + }; + bool need_lock; + + if (!page) + return; + + if (!page_mapped(page) || !page_rmapping(page)) { + set_page_idle(page); + put_page(page); + return; + } + + need_lock = !PageAnon(page) || PageKsm(page); + if (need_lock && !trylock_page(page)) { + put_page(page); + return; + } + + rmap_walk(page, &rwc); + + if (need_lock) + unlock_page(page); + put_page(page); +} + +static void __damon_pa_prepare_access_check(struct damon_ctx *ctx, + struct damon_region *r) +{ + r->sampling_addr = damon_rand(r->ar.start, r->ar.end); + + damon_pa_mkold(r->sampling_addr); +} + +void damon_pa_prepare_access_checks(struct damon_ctx *ctx) +{ + struct damon_target *t; + struct damon_region *r; + + damon_for_each_target(t, ctx) { + damon_for_each_region(r, t) + __damon_pa_prepare_access_check(ctx, r); + } +} + +struct damon_pa_access_chk_result { + unsigned long page_sz; + bool accessed; +}; + +static bool damon_pa_accessed(struct page *page, struct vm_area_struct *vma, + unsigned long addr, void *arg) +{ + struct damon_pa_access_chk_result *result = arg; + + result->accessed = damon_va_young(vma->vm_mm, addr, &result->page_sz); + + /* If accessed, stop walking */ + return !result->accessed; +} + +static bool damon_pa_young(unsigned long paddr, unsigned long *page_sz) +{ + struct page *page = damon_pa_get_page(PHYS_PFN(paddr)); + struct damon_pa_access_chk_result result = { + .page_sz = PAGE_SIZE, + .accessed = false, + }; + struct rmap_walk_control rwc = { + .arg = &result, + .rmap_one = damon_pa_accessed, + .anon_lock = page_lock_anon_vma_read, + }; + bool need_lock; + + if (!page) + return false; + + if (!page_mapped(page) || !page_rmapping(page)) { + if (page_is_idle(page)) + result.accessed = false; + else + result.accessed = true; + put_page(page); + goto out; + } + + need_lock = !PageAnon(page) || PageKsm(page); + if (need_lock && !trylock_page(page)) { + put_page(page); + return NULL; + } + + rmap_walk(page, &rwc); + + if (need_lock) + unlock_page(page); + put_page(page); + +out: + *page_sz = result.page_sz; + return result.accessed; +} + +/* + * Check whether the region was accessed after the last preparation + * + * mm 'mm_struct' for the given virtual address space + * r the region of physical address space that needs to be checked + */ +static void __damon_pa_check_access(struct damon_ctx *ctx, + struct damon_region *r) +{ + static unsigned long last_addr; + static unsigned long last_page_sz = PAGE_SIZE; + static bool last_accessed; + + /* If the region is in the last checked page, reuse the result */ + if (ALIGN_DOWN(last_addr, last_page_sz) == + ALIGN_DOWN(r->sampling_addr, last_page_sz)) { + if (last_accessed) + r->nr_accesses++; + return; + } + + last_accessed = damon_pa_young(r->sampling_addr, &last_page_sz); + if (last_accessed) + r->nr_accesses++; + + last_addr = r->sampling_addr; +} + +unsigned int damon_pa_check_accesses(struct damon_ctx *ctx) +{ + struct damon_target *t; + struct damon_region *r; + unsigned int max_nr_accesses = 0; + + damon_for_each_target(t, ctx) { + damon_for_each_region(r, t) { + __damon_pa_check_access(ctx, r); + max_nr_accesses = max(r->nr_accesses, max_nr_accesses); + } + } + + return max_nr_accesses; +} + +bool damon_pa_target_valid(struct damon_target *t) +{ + if (!mutex_is_locked(&page_idle_lock)) + return false; + return true; +} + +void damon_pa_set_primitives(struct damon_ctx *ctx) +{ + ctx->primitive.init_target_regions = damon_pa_init_regions; + ctx->primitive.update_target_regions = damon_pa_update_regions; + ctx->primitive.prepare_access_checks = damon_pa_prepare_access_checks; + ctx->primitive.check_accesses = damon_pa_check_accesses; + ctx->primitive.target_valid = damon_pa_target_valid; + ctx->primitive.cleanup = NULL; + ctx->primitive.apply_scheme = NULL; +} + #include "primitives-test.h" From patchwork Wed Oct 7 07:14:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11819865 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 82A6B6CB for ; Wed, 7 Oct 2020 07:24:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3A84C20797 for ; Wed, 7 Oct 2020 07:24:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="FknP0FPb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A84C20797 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 E922B6B005C; Wed, 7 Oct 2020 03:24:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E458F900007; Wed, 7 Oct 2020 03:24:40 -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 C94156B0068; Wed, 7 Oct 2020 03:24:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0206.hostedemail.com [216.40.44.206]) by kanga.kvack.org (Postfix) with ESMTP id 9C17D6B005C for ; Wed, 7 Oct 2020 03:24:40 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 433CD1EE6 for ; Wed, 7 Oct 2020 07:24:40 +0000 (UTC) X-FDA: 77344291920.06.low38_2a0486a271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 9A8371017200C for ; Wed, 7 Oct 2020 07:17:10 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=542e595a5=sjpark@amazon.com,,RULES_HIT:30003:30051:30054:30064:30070:30080,0,RBL:52.95.48.154:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04y8z7wakjpz1bqjmnb1az1pfmkgsoc67j6gi51gc38fwfbssqo7cpk5g4mauba.7nzc1yn19sqy6rm5zpxj1wcb7xo36kcwxjzz36yrz9ee7tf1n5edh4no7o77c17.y-lbl8.mailshell.net-223.238.255.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:24,LUA_SUMMARY:none X-HE-Tag: low38_2a0486a271cd X-Filterd-Recvd-Size: 5024 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602055030; x=1633591030; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=0TPx4DnhcZ8KiVDLDYWFNaniT35+H2YSfcBfIDd9jFc=; b=FknP0FPbkl92dUECnQrTyD6hD2sH8xsDLq5jsXKqFSEv2Xo6MIOUiqoO Us/ALCbJcmgKpZhgwUAPeGm5XbmDFsuMEI/hU5p4Zq3nfjlhir/CVSoD5 FbIAQDJ3ph1p4e9Fr3uen3JzkC0Dblx8n9OOepqq4jlwgULk4lMY4vw7n s=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="59960935" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1a-715bee71.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 07 Oct 2020 07:17:09 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1a-715bee71.us-east-1.amazon.com (Postfix) with ESMTPS id 9AF97A17C5; Wed, 7 Oct 2020 07:16:57 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:16:41 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 07/10] damon/dbgfs: Support physical memory monitoring Date: Wed, 7 Oct 2020 09:14:06 +0200 Message-ID: <20201007071409.12174-8-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 makes the 'damon-dbgfs' to support the physical memory monitoring, in addition to the virtual memory monitoring. Users can do the physical memory monitoring by writing a special keyword, 'paddr\n' to the 'pids' debugfs file. Then, DAMON will check the special keyword and configure the monitoring context to run using the primitives for physical memory. This will internally add one fake monitoring target process, which has target id 42. Unlike the virtual memory monitoring, the monitoring target region will not be automatically set. Therefore, users should also set the monitoring target address region using the 'init_regions' debugfs file. Finally, the physical memory monitoring will not automatically terminated. The user should explicitly turn off the monitoring by writing 'off' to the 'monitor_on' debugfs file. Signed-off-by: SeongJae Park --- mm/damon/dbgfs.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index 28076557ea86..8a80f4cc2fef 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -484,10 +484,19 @@ static ssize_t dbgfs_target_ids_write(struct file *file, return PTR_ERR(kbuf); nrs = kbuf; - - if (!strncmp(kbuf, "pidfd ", 6)) { - received_pidfds = true; - nrs = &kbuf[6]; + if (!strncmp(kbuf, "paddr\n", count)) { + /* Configure the context for physical memory monitoring */ + damon_pa_set_primitives(ctx); + /* target id is meaningless here, but we set it just for fun */ + scnprintf(kbuf, count, "42 "); + } else { + /* Configure the context for virtual memory monitoring */ + damon_va_set_primitives(ctx); + + if (!strncmp(kbuf, "pidfd ", 6)) { + received_pidfds = true; + nrs = &kbuf[6]; + } } targets = str_to_target_ids(nrs, ret, &nr_targets); From patchwork Wed Oct 7 07:14:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11819855 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 A01286CB for ; Wed, 7 Oct 2020 07:24:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 513972083B for ; Wed, 7 Oct 2020 07:24:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="EvdSLF4O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 513972083B 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 8C64B900002; Wed, 7 Oct 2020 03:23:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 876DF6B0062; Wed, 7 Oct 2020 03:23:59 -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 78BD2900002; Wed, 7 Oct 2020 03:23:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0108.hostedemail.com [216.40.44.108]) by kanga.kvack.org (Postfix) with ESMTP id 4C0326B005C for ; Wed, 7 Oct 2020 03:23:59 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D3E6D3630 for ; Wed, 7 Oct 2020 07:23:58 +0000 (UTC) X-FDA: 77344290156.29.ring31_1309977271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id A9F40180260DF for ; Wed, 7 Oct 2020 07:17:32 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=542e595a5=sjpark@amazon.com,,RULES_HIT:30003:30029:30054:30064:30070,0,RBL:52.95.48.154:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04y89o8ymha1ty8pn5t3h8f7x133wop886ujju5wcad46atqwc1wymuuh7z79qa.yyuejhx8oq8j7cx916mfc48fsjxb433f4kh7sf36z3hgxjbho6udbgs7jqzwik3.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: ring31_1309977271cd X-Filterd-Recvd-Size: 6018 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:17:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602055052; x=1633591052; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=kg6Pid/S3uyECtsR9/ZQNoRBSFk6tXHhc71xqlOp1H8=; b=EvdSLF4OE51VlLKsOURHIYW5dXBE57FJxnoDTDlMD/ucWT9I8VS0j2bW hyo/G9isLM7wsm9U0bAX21/vwpsJ7nKrNWfgejbNk+zU/2dFKMF/OIR4i Zt8kL40CFiMzwHJrCbzeVO5e3abvDGDVbnk1pCbL74+qcng/DElNdfisx U=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="59960978" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 07 Oct 2020 07:17:31 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com (Postfix) with ESMTPS id DEE0BA0576; Wed, 7 Oct 2020 07:17:19 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:17:03 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 08/10] tools/damon/record: Support physical memory monitoring Date: Wed, 7 Oct 2020 09:14:07 +0200 Message-ID: <20201007071409.12174-9-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 allows users to record the data accesses on physical memory address space by passing 'paddr' as target to 'damo-record'. If the init regions are given, the regions will be monitored. Else, it will monitor biggest conitguous 'System RAM' region in '/proc/iomem' and monitor the region. Signed-off-by: SeongJae Park --- tools/damon/_damon.py | 2 ++ tools/damon/record.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/damon/_damon.py b/tools/damon/_damon.py index a22ec3777c16..6ff278117e84 100644 --- a/tools/damon/_damon.py +++ b/tools/damon/_damon.py @@ -27,6 +27,8 @@ def set_target(tid, init_regions=[]): if not os.path.exists(debugfs_init_regions): return 0 + if tid == 'paddr': + tid = 42 string = ' '.join(['%s %d %d' % (tid, r[0], r[1]) for r in init_regions]) return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions), shell=True, executable='/bin/bash') diff --git a/tools/damon/record.py b/tools/damon/record.py index 11fd54001472..6fd0b59c73e0 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -101,6 +101,29 @@ def set_argparser(parser): parser.add_argument('-o', '--out', metavar='', type=str, default='damon.data', help='output file path') +def default_paddr_region(): + "Largest System RAM region becomes the default" + ret = [] + with open('/proc/iomem', 'r') as f: + # example of the line: '100000000-42b201fff : System RAM' + for line in f: + fields = line.split(':') + if len(fields) != 2: + continue + name = fields[1].strip() + if name != 'System RAM': + continue + addrs = fields[0].split('-') + if len(addrs) != 2: + continue + start = int(addrs[0], 16) + end = int(addrs[1], 16) + + sz_region = end - start + if not ret or sz_region > (ret[1] - ret[0]): + ret = [start, end] + return ret + def main(args=None): global orig_attrs if not args: @@ -122,7 +145,11 @@ def main(args=None): target = args.target target_fields = target.split() - if not subprocess.call('which %s &> /dev/null' % target_fields[0], + if target == 'paddr': # physical memory address space + if not init_regions: + init_regions = [default_paddr_region()] + do_record(target, False, init_regions, new_attrs, orig_attrs, pidfd) + elif not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): do_record(target, True, init_regions, new_attrs, orig_attrs, pidfd) else: From patchwork Wed Oct 7 07:14:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11819863 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 93ECA6CB for ; Wed, 7 Oct 2020 07:24:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2E0B92083B for ; Wed, 7 Oct 2020 07:24:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="quyD5IZw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E0B92083B 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 5B830900004; Wed, 7 Oct 2020 03:24:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 58E766B0062; Wed, 7 Oct 2020 03:24:39 -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 4A52B900004; Wed, 7 Oct 2020 03:24:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id 1D5B86B005C for ; Wed, 7 Oct 2020 03:24:39 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9F7FB1EE6 for ; Wed, 7 Oct 2020 07:24:38 +0000 (UTC) X-FDA: 77344291836.22.bean92_590625b271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 78BFF180A0941 for ; Wed, 7 Oct 2020 07:17:53 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=542e595a5=sjpark@amazon.com,,RULES_HIT:30003:30029:30045:30051:30054:30064:30070:30080,0,RBL:52.95.48.154:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04ygrcuhojpa1iu8fnzqgm19rzajaypyw8fpwuyec4uk51bkxf41qtujq889iz5.odg5rswruqtppyurc35me1s95hma6ctxjsrbcgw88r84wndkmpxbq439zdgyixk.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: bean92_590625b271cd X-Filterd-Recvd-Size: 10285 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:17:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602055073; x=1633591073; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=VIt0QPHvmvqG4Kch/PM9e/Zwtiyux2gOnoeb9rYl0nc=; b=quyD5IZwwKWRxnnYcMchrvFxhujZFmR18Q+4rnO2eEQybWG+LwI9LPYw VOeJajiIn0APxPSZxWB8EHzVLefyQe1Tb26LSns5weUrxmmSYZj+CeUh2 1LqMuVwe1K38wMpECuUbnm8fKgtkHE5mmm/esDSbOmCyxRxSCdpeU3MKt 8=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="59961004" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1a-807d4a99.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 07 Oct 2020 07:17:52 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1a-807d4a99.us-east-1.amazon.com (Postfix) with ESMTPS id AEBC2A1D99; Wed, 7 Oct 2020 07:17:40 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:17:24 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 09/10] tools/damon/record: Support NUMA specific recording Date: Wed, 7 Oct 2020 09:14:08 +0200 Message-ID: <20201007071409.12174-10-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 updates the DAMON user space tool (damo-record) for NUMA specific physical memory monitoring. With this change, users can monitor accesses to physical memory of specific NUMA node. Signed-off-by: SeongJae Park --- tools/damon/_paddr_layout.py | 147 +++++++++++++++++++++++++++++++++++ tools/damon/record.py | 18 ++++- 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 tools/damon/_paddr_layout.py diff --git a/tools/damon/_paddr_layout.py b/tools/damon/_paddr_layout.py new file mode 100644 index 000000000000..561c2b6729f6 --- /dev/null +++ b/tools/damon/_paddr_layout.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import os + +class PaddrRange: + start = None + end = None + nid = None + state = None + name = None + + def __init__(self, start, end, nid, state, name): + self.start = start + self.end = end + self.nid = nid + self.state = state + self.name = name + + def interleaved(self, prange): + if self.end <= prange.start: + return None + if prange.end <= self.start: + return None + return [max(self.start, prange.start), min(self.end, prange.end)] + + def __str__(self): + return '%x-%x, nid %s, state %s, name %s' % (self.start, self.end, + self.nid, self.state, self.name) + +class MemBlock: + nid = None + index = None + state = None + + def __init__(self, nid, index, state): + self.nid = nid + self.index = index + self.state = state + + def __str__(self): + return '%d (%s)' % (self.index, self.state) + + def __repr__(self): + return self.__str__() + +def readfile(file_path): + with open(file_path, 'r') as f: + return f.read() + +def collapse_ranges(ranges): + ranges = sorted(ranges, key=lambda x: x.start) + merged = [] + for r in ranges: + if not merged: + merged.append(r) + continue + last = merged[-1] + if last.end != r.start or last.nid != r.nid or last.state != r.state: + merged.append(r) + else: + last.end = r.end + return merged + +def memblocks_to_ranges(blocks, block_size): + ranges = [] + for b in blocks: + ranges.append(PaddrRange(b.index * block_size, + (b.index + 1) * block_size, b.nid, b.state, None)) + + return collapse_ranges(ranges) + +def memblock_ranges(): + SYSFS='/sys/devices/system/node' + sz_block = int(readfile('/sys/devices/system/memory/block_size_bytes'), 16) + sys_nodes = [x for x in os.listdir(SYSFS) if x.startswith('node')] + + blocks = [] + for sys_node in sys_nodes: + nid = int(sys_node[4:]) + + sys_node_files = os.listdir(os.path.join(SYSFS, sys_node)) + for f in sys_node_files: + if not f.startswith('memory'): + continue + index = int(f[6:]) + sys_state = os.path.join(SYSFS, sys_node, f, 'state') + state = readfile(sys_state).strip() + + blocks.append(MemBlock(nid, index, state)) + + return memblocks_to_ranges(blocks, sz_block) + +def iomem_ranges(): + ranges = [] + + with open('/proc/iomem', 'r') as f: + # example of the line: '100000000-42b201fff : System RAM' + for line in f: + fields = line.split(':') + if len(fields) < 2: + continue + name = ':'.join(fields[1:]).strip() + addrs = fields[0].split('-') + if len(addrs) != 2: + continue + start = int(addrs[0], 16) + end = int(addrs[1], 16) + 1 + ranges.append(PaddrRange(start, end, None, None, name)) + + return ranges + +def integrate(memblock_parsed, iomem_parsed): + merged = [] + + for r in iomem_parsed: + for r2 in memblock_parsed: + if r2.start <= r.start and r.end <= r2.end: + r.nid = r2.nid + r.state = r2.state + merged.append(r) + elif r2.start <= r.start and r.start < r2.end and r2.end < r.end: + sub = PaddrRange(r2.end, r.end, None, None, r.name) + iomem_parsed.append(sub) + r.end = r2.end + r.nid = r2.nid + r.state = r2.state + merged.append(r) + merged = sorted(merged, key=lambda x: x.start) + return merged + +def paddr_ranges(): + return integrate(memblock_ranges(), iomem_ranges()) + +def pr_ranges(ranges): + print('#%12s %13s\tnode\tstate\tresource\tsize' % ('start', 'end')) + for r in ranges: + print('%13d %13d\t%s\t%s\t%s\t%d' % (r.start, r.end, r.nid, + r.state, r.name, r.end - r.start)) + +def main(): + ranges = paddr_ranges() + + pr_ranges(ranges) + +if __name__ == '__main__': + main() diff --git a/tools/damon/record.py b/tools/damon/record.py index 6fd0b59c73e0..e9d6bfc70ead 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -12,6 +12,7 @@ import subprocess import time import _damon +import _paddr_layout def pidfd_open(pid): import ctypes @@ -98,6 +99,8 @@ def set_argparser(parser): help='use pidfd type target id') parser.add_argument('-l', '--rbuf', metavar='', type=int, default=1024*1024, help='length of record result buffer') + parser.add_argument('--numa_node', metavar='', type=int, + help='if target is \'paddr\', limit it to the numa node') parser.add_argument('-o', '--out', metavar='', type=str, default='damon.data', help='output file path') @@ -124,6 +127,15 @@ def default_paddr_region(): ret = [start, end] return ret +def paddr_region_of(numa_node): + regions = [] + paddr_ranges = _paddr_layout.paddr_ranges() + for r in paddr_ranges: + if r.nid == numa_node and r.name == 'System RAM': + regions.append([r.start, r.end]) + + return regions + def main(args=None): global orig_attrs if not args: @@ -142,12 +154,16 @@ def main(args=None): pidfd = args.pidfd new_attrs = _damon.cmd_args_to_attrs(args) init_regions = _damon.cmd_args_to_init_regions(args) + numa_node = args.numa_node target = args.target target_fields = target.split() if target == 'paddr': # physical memory address space if not init_regions: - init_regions = [default_paddr_region()] + if numa_node: + init_regions = paddr_region_of(numa_node) + else: + init_regions = [default_paddr_region()] do_record(target, False, init_regions, new_attrs, orig_attrs, pidfd) elif not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): From patchwork Wed Oct 7 07:14:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11819857 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 9EFB2618 for ; Wed, 7 Oct 2020 07:24:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3EFDF20797 for ; Wed, 7 Oct 2020 07:24:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="YCHV0Igc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EFDF20797 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 4A540900003; Wed, 7 Oct 2020 03:24:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4576B6B0062; Wed, 7 Oct 2020 03:24:08 -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 31EC3900003; Wed, 7 Oct 2020 03:24:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0044.hostedemail.com [216.40.44.44]) by kanga.kvack.org (Postfix) with ESMTP id 05EB26B005C for ; Wed, 7 Oct 2020 03:24:07 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A5ACF3630 for ; Wed, 7 Oct 2020 07:24:07 +0000 (UTC) X-FDA: 77344290534.29.wood09_0a17d4d271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id C006A180385D3 for ; Wed, 7 Oct 2020 07:18:15 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=542e595a5=sjpark@amazon.com,,RULES_HIT:30003:30025:30051:30054:30064:30070:30071:30090,0,RBL:207.171.184.29:@amazon.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100;04yrfmzjcm9w31uysfzb5ax5dxnqbyc586wgmzejucc4mjxbbmrzmf9n5g7o8ak.ixhrec4mq6zzjmftdju8msng6ht5hodk9e9dsxbetmgwqkgr4g9qh9bpnsz99rr.h-lbl8.mailshell.net-223.238.255.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:23,LUA_SUMMARY:none X-HE-Tag: wood09_0a17d4d271cd X-Filterd-Recvd-Size: 12224 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602055095; x=1633591095; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qGKT1F1qVkIMFajZCvJm8BTClvxWeUPf3j13t8snc08=; b=YCHV0IgcRt8wzCU077pvNXes1HKkdZ7f0Y3vZPMCE+m8vxHaoW1k6ooe 2CDOjs7xeBVvs+N5wpUZbrAMDqHFHVxPRwLggqmiotISjNJBOuT3mtghJ aE6mDGPzdKFFeBpE1RmpmvGOZnAaOXk2D5zIg48ungG/MxSbbN5iEJGi2 0=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="82208862" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-98acfc19.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 07 Oct 2020 07:18:11 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1d-98acfc19.us-east-1.amazon.com (Postfix) with ESMTPS id 6DA43A1E6F; Wed, 7 Oct 2020 07:17:59 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:17:43 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 10/10] Docs/DAMON: Document physical memory monitoring support Date: Wed, 7 Oct 2020 09:14:09 +0200 Message-ID: <20201007071409.12174-11-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 updates the DAMON documents for the physical memory monitoring support. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 42 ++++++++++++++++---- Documentation/vm/damon/design.rst | 29 +++++++++----- Documentation/vm/damon/faq.rst | 5 +-- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index cf0d44ce0ac9..3e2f1519c96a 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -10,15 +10,16 @@ DAMON provides below three interfaces for different users. This is for privileged people such as system administrators who want a just-working human-friendly interface. Using this, users can use the DAMON’s major features in a human-friendly way. It may not be highly tuned for - special cases, though. It supports only virtual address spaces monitoring. + special cases, though. It supports both virtual and physical address spaces + monitoring. - *debugfs interface.* This is for privileged user space programmers who want more optimized use of DAMON. Using this, users can use DAMON’s major features by reading from and writing to special debugfs files. Therefore, you can write and use your personalized DAMON debugfs wrapper programs that reads/writes the debugfs files instead of you. The DAMON user space tool is also a reference - implementation of such programs. It supports only virtual address spaces - monitoring. + implementation of such programs. It supports both virtual and physical + address spaces monitoring. - *Kernel Space Programming Interface.* This is for kernel space programmers. Using this, users can utilize every feature of DAMON most flexibly and efficiently by writing kernel space @@ -49,8 +50,10 @@ Recording Data Access Pattern The ``record`` subcommand records the data access pattern of target workloads in a file (``./damon.data`` by default). You can specify the target with 1) -the command for execution of the monitoring target process, or 2) pid of -running target process. Below example shows a command target usage:: +the command for execution of the monitoring target process, 2) pid of running +target process, or 3) the special keyword, 'paddr', if you want to monitor the +system's physical memory address space. Below example shows a command target +usage:: # cd /tools/damon/ # damo record "sleep 5" @@ -61,6 +64,15 @@ of the process. Below example shows a pid target usage:: # sleep 5 & # damo record `pidof sleep` +Finally, below example shows the use of the special keyword, 'paddr':: + + # damo record paddr + +In this case, the monitoring target regions defaults to the largetst 'System +RAM' region specified in '/proc/iomem' file. Note that the initial monitoring +target region is maintained rather than dynamically updated like the virtual +memory address spaces monitoring case. + The location of the recorded file can be explicitly set using ``-o`` option. You can further tune this by setting the monitoring attributes. To know about the monitoring attributes in detail, please refer to the @@ -319,20 +331,34 @@ check it again:: # cat target_ids 42 4242 +Users can also monitor the physical memory address space of the system by +writing a special keyword, "``paddr\n``" to the file. Because physical address +space monitoring doesn't support multiple targets, reading the file will show a +fake value, ``42``, as below:: + + # cd /damon + # echo paddr > target_ids + # cat target_ids + 42 + Note that setting the target ids doesn't start the monitoring. Initial Monitoring Target Regions --------------------------------- -In case of the debugfs based monitoring, DAMON automatically sets and updates -the monitoring target regions so that entire memory mappings of target -processes can be covered. However, users might want to limit the monitoring +In case of the virtual address space monitoring, DAMON automatically sets and +updates the monitoring target regions so that entire memory mappings of target +processes can be covered. However, users might want to limit the monitoring region to specific address ranges, such as the heap, the stack, or specific file-mapped area. Or, some users might know the initial access pattern of their workloads and therefore want to set optimal initial regions for the 'adaptive regions adjustment'. +In contrast, DAMON do not automatically sets and updates the monitoring target +regions in case of physical memory monitoring. Therefore, users should set the +monitoring target regions by themselves. + In such cases, users can explicitly set the initial monitoring target regions as they want, by writing proper values to the ``init_regions`` file. Each line of the input should represent one region in below form.:: diff --git a/Documentation/vm/damon/design.rst b/Documentation/vm/damon/design.rst index 727d72093f8f..0666e19018fd 100644 --- a/Documentation/vm/damon/design.rst +++ b/Documentation/vm/damon/design.rst @@ -35,27 +35,34 @@ two parts: 1. Identification of the monitoring target address range for the address space. 2. Access check of specific address range in the target space. -DAMON currently provides the implementation of the primitives for only the -virtual address spaces. Below two subsections describe how it works. +DAMON currently provides the implementations of the primitives for the physical +and virtual address spaces. Below two subsections describe how those work. PTE Accessed-bit Based Access Check ----------------------------------- -The implementation for the virtual address space uses PTE Accessed-bit for -basic access checks. It finds the relevant PTE Accessed bit from the address -by walking the page table for the target task of the address. In this way, the -implementation finds and clears the bit for next sampling target address and -checks whether the bit set again after one sampling period. This could disturb -other kernel subsystems using the Accessed bits, namely Idle page tracking and -the reclaim logic. To avoid such disturbances, DAMON makes it mutually -exclusive with Idle page tracking and uses ``PG_idle`` and ``PG_young`` page -flags to solve the conflict with the reclaim logic, as Idle page tracking does. +Both of the implementations for physical and virtual address spaces use PTE +Accessed-bit for basic access checks. Only one difference is the way of +finding the relevant PTE Accessed bit(s) from the address. While the +implementation for the virtual address walks the page table for the target task +of the address, the implementation for the physical address walks every page +table having a mapping to the address. In this way, the implementations find +and clear the bit(s) for next sampling target address and checks whether the +bit(s) set again after one sampling period. This could disturb other kernel +subsystems using the Accessed bits, namely Idle page tracking and the reclaim +logic. To avoid such disturbances, DAMON makes it mutually exclusive with Idle +page tracking and uses ``PG_idle`` and ``PG_young`` page flags to solve the +conflict with the reclaim logic, as Idle page tracking does. VMA-based Target Address Range Construction ------------------------------------------- +This is only for the virtual address space primitives implementation. That for +the physical address space simply asks users to manually set the monitoring +target address ranges. + Only small parts in the super-huge virtual address space of the processes are mapped to the physical memory and accessed. Thus, tracking the unmapped address regions is just wasteful. However, because DAMON can deal with some diff --git a/Documentation/vm/damon/faq.rst b/Documentation/vm/damon/faq.rst index 088128bbf22b..6469d54c480f 100644 --- a/Documentation/vm/damon/faq.rst +++ b/Documentation/vm/damon/faq.rst @@ -43,10 +43,9 @@ constructions and actual access checks can be implemented and configured on the DAMON core by the users. In this way, DAMON users can monitor any address space with any access check technique. -Nonetheless, DAMON provides vma tracking and PTE Accessed bit check based +Nonetheless, DAMON provides vma/rmap tracking and PTE Accessed bit check based implementations of the address space dependent functions for the virtual memory -by default, for a reference and convenient use. In near future, we will -provide those for physical memory address space. +and the physical memory by default, for a reference and convenient use. Can I simply monitor page granularity?