From patchwork Mon Aug 31 10:47:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11746115 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 7DFC21575 for ; Mon, 31 Aug 2020 10:48:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3EB0520936 for ; Mon, 31 Aug 2020 10:48:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="sei81R8C" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EB0520936 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 718FB6B0003; Mon, 31 Aug 2020 06:48:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6C97D6B0005; Mon, 31 Aug 2020 06:48:30 -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 590866B0006; Mon, 31 Aug 2020 06:48:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 430186B0003 for ; Mon, 31 Aug 2020 06:48:30 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id F3ED12465 for ; Mon, 31 Aug 2020 10:48:29 +0000 (UTC) X-FDA: 77210539980.04.alarm56_3d106172708f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id CAB318008843 for ; Mon, 31 Aug 2020 10:48:29 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5052c6ed3=sjpark@amazon.com,,RULES_HIT:30003:30051:30054:30056:30064:30070:30080,0,RBL:52.95.48.154:@amazon.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10;04yfij53jnyf6csemourn1fezse63ycnaauuqabhi8y3iwrzta6zo431sii3yf4.dkzzgd63c7sdswrw4o18b6yrqrma86xrpaydhj1rz1wixf6agifxbawejub5i48.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:23,LUA_SUMMARY:none X-HE-Tag: alarm56_3d106172708f X-Filterd-Recvd-Size: 8737 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Mon, 31 Aug 2020 10:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598870909; x=1630406909; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=c1UuIiNQ4tKf+PjubMku+iTkAyx0wbyj2J7tAMnPRis=; b=sei81R8CmHVistig3+uRbPIyTkvK509bBtP1Uv+HVkgiuse1L6mlX+1V lOsGC/mENVVsNA9gDCf1LSbmKdXueCj8fA4z959v/1czO5IPjAjeTBaWS FM4bmwFg2ouZu8c2cuvaHEBG8N5S5VvtSY7d374V5ZdR8G1OqXBNVDH9B I=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="52524420" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-6f38efd9.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 31 Aug 2020 10:48:25 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-6f38efd9.us-west-2.amazon.com (Postfix) with ESMTPS id 12B5FA29EF; Mon, 31 Aug 2020 10:48:21 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:48:03 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 01/10] mm/damon/debugfs: Allow users to set initial monitoring target regions Date: Mon, 31 Aug 2020 12:47:21 +0200 Message-ID: <20200831104730.28970-2-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) X-Rspamd-Queue-Id: CAB318008843 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 users would want to monitor only a part of the entire virtual memory address space. The '->init_target_regions' callback is therefore provided, but only programming interface can use it. For the reason, this commit introduces a new debugfs file, 'init_region'. 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: This commit also makes the default '->init_target_regions' callback, 'kdamon_init_vm_regions()' to do nothing if the user has set the initial target regions already. 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.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 152 insertions(+), 4 deletions(-) diff --git a/mm/damon.c b/mm/damon.c index 7e3c8c82a010..9815d22fc4de 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -2001,6 +2001,147 @@ static ssize_t debugfs_record_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 = snprintf(&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 debugfs_init_regions_read(struct file *file, char __user *buf, + size_t count, loff_t *ppos) +{ + struct damon_ctx *ctx = &damon_user_ctx; + 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 (nr_damon_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 debugfs_init_regions_write(struct file *file, + const char __user *buf, size_t count, + loff_t *ppos) +{ + struct damon_ctx *ctx = &damon_user_ctx; + 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 debugfs_attrs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { @@ -2077,6 +2218,12 @@ static const struct file_operations record_fops = { .write = debugfs_record_write, }; +static const struct file_operations init_regions_fops = { + .owner = THIS_MODULE, + .read = debugfs_init_regions_read, + .write = debugfs_init_regions_write, +}; + static const struct file_operations attrs_fops = { .owner = THIS_MODULE, .read = debugfs_attrs_read, @@ -2087,10 +2234,11 @@ static struct dentry *debugfs_root; static int __init damon_debugfs_init(void) { - const char * const file_names[] = {"attrs", "record", "schemes", - "target_ids", "monitor_on"}; - const struct file_operations *fops[] = {&attrs_fops, &record_fops, - &schemes_fops, &target_ids_fops, &monitor_on_fops}; + const char * const file_names[] = {"attrs", "init_regions", "record", + "schemes", "target_ids", "monitor_on"}; + const struct file_operations *fops[] = {&attrs_fops, + &init_regions_fops, &record_fops, &schemes_fops, + &target_ids_fops, &monitor_on_fops}; int i; debugfs_root = debugfs_create_dir("damon", NULL); From patchwork Mon Aug 31 10:47:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11746117 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 119E71575 for ; Mon, 31 Aug 2020 10:48:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C5FB9206F0 for ; Mon, 31 Aug 2020 10:48:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="AFGYf5Vs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C5FB9206F0 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 14D796B0005; Mon, 31 Aug 2020 06:48:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0FE116B0006; Mon, 31 Aug 2020 06:48:47 -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 F07DB6B0007; Mon, 31 Aug 2020 06:48:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id DB3A06B0005 for ; Mon, 31 Aug 2020 06:48:46 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9C3F6181AEF0B for ; Mon, 31 Aug 2020 10:48:46 +0000 (UTC) X-FDA: 77210540652.06.death96_5912e9d2708f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 52669100516A5 for ; Mon, 31 Aug 2020 10:48:46 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5052c6ed3=sjpark@amazon.com,,RULES_HIT:30003:30029:30034:30051:30054:30064:30080,0,RBL:52.95.48.154:@amazon.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10;04yrceky5nzcy873zb3nu74cure4rocpzfxdby9znrgyi8h7fos7m7ewmdr4m8b.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: death96_5912e9d2708f X-Filterd-Recvd-Size: 11301 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Mon, 31 Aug 2020 10:48:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598870926; x=1630406926; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=eFQ5FjEXjCcRqP315OtcZTEl8DRR0ETd5Jfrqerv8aI=; b=AFGYf5VsYcdNz+i1BHOK3eYlficxh54SZFIm4fQni9OKY0lEPoKEuW91 YRVkdNwzhU1yCLENXEx1A+ssDT8UsOQqcWGDC/Rvymz23KWpUsB/WLS/i zSH2AZYdQLV5gLbdEjTcRa4XmU0v+eExongyeA0b6n2HT82GmwfGPPetT 4=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="52524448" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-22cc717f.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 31 Aug 2020 10:48:42 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-22cc717f.us-west-2.amazon.com (Postfix) with ESMTPS id 3672DA1E23; Mon, 31 Aug 2020 10:48:39 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:48:21 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 02/10] tools/damon: Support init target regions specification Date: Mon, 31 Aug 2020 12:47:22 +0200 Message-ID: <20200831104730.28970-3-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) X-Rspamd-Queue-Id: 52669100516A5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 Mon Aug 31 10:47:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11746119 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 6F92C138A for ; Mon, 31 Aug 2020 10:49:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3397521534 for ; Mon, 31 Aug 2020 10:49:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="p0R7EftX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3397521534 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 803C56B0006; Mon, 31 Aug 2020 06:49:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 78CFC6B0007; Mon, 31 Aug 2020 06:49:03 -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 67DD76B0008; Mon, 31 Aug 2020 06:49:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id 50B8A6B0006 for ; Mon, 31 Aug 2020 06:49:03 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 14388180AD806 for ; Mon, 31 Aug 2020 10:49:03 +0000 (UTC) X-FDA: 77210541366.02.egg70_30079c12708f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id D2F6D10097AA0 for ; Mon, 31 Aug 2020 10:49:02 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5052c6ed3=sjpark@amazon.com,,RULES_HIT:30003:30012:30054:30064:30070:30080,0,RBL:207.171.184.29:@amazon.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100;04ygjphskas89wsjpcypigr335xprophngb36by4hcntbd9ca1zsp8gmfp9416m.a7s7uzp9mzwibojsz85nbnwdxwge5x9iewur95s57peh955o65pfna85jgjyws7.r-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: egg70_30079c12708f X-Filterd-Recvd-Size: 5831 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Mon, 31 Aug 2020 10:49:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598870943; x=1630406943; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=t83U6iMpHB5Ra5CmTIpP+H+t+wsO9yd9cZKiYQA2Yh0=; b=p0R7EftXuarf/HHv6Hcs3Ya5PieOrPDy0DIp76jrU6bM8fpwaUvfor+9 WYgF5b9SsNxQ4NDIoRqX2qwlrea5sKCf++CiLrG5zDDqL15x3zX+jPECg bNdtSc8EKK1xbBYShp/sir6679ArXKcDcvi5/Y2uzKtM1PDcdwuGxjZZp w=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="72355524" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 31 Aug 2020 10:48:59 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com (Postfix) with ESMTPS id CE26CA261F; Mon, 31 Aug 2020 10:48:56 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:48:38 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 03/10] mm/damon-test: Add more unit tests for 'init_regions' Date: Mon, 31 Aug 2020 12:47:23 +0200 Message-ID: <20200831104730.28970-4-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) X-Rspamd-Queue-Id: D2F6D10097AA0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 more test cases for the new feature, 'init_regions'. Signed-off-by: SeongJae Park Reviewed-by: Brendan Higgins --- mm/damon-test.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/mm/damon-test.h b/mm/damon-test.h index 71413ffc1dcb..e67e8fb17eca 100644 --- a/mm/damon-test.h +++ b/mm/damon-test.h @@ -161,6 +161,58 @@ static void damon_test_set_recording(struct kunit *test) KUNIT_EXPECT_STREQ(test, ctx->rfile_path, "foo"); } +static void damon_test_set_init_regions(struct kunit *test) +{ + struct damon_ctx *ctx = &damon_user_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); +} + static void __link_vmas(struct vm_area_struct *vmas, ssize_t nr_vmas) { int i, j; @@ -645,6 +697,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_regions), KUNIT_CASE(damon_test_set_targets), KUNIT_CASE(damon_test_set_recording), + KUNIT_CASE(damon_test_set_init_regions), KUNIT_CASE(damon_test_three_regions_in_vmas), KUNIT_CASE(damon_test_aggregate), KUNIT_CASE(damon_test_write_rbuf), From patchwork Mon Aug 31 10:47:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11746121 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 1C2C6138A for ; Mon, 31 Aug 2020 10:49:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DC58A206F0 for ; Mon, 31 Aug 2020 10:49:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="W36zoldO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC58A206F0 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 36FAD6B0007; Mon, 31 Aug 2020 06:49:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 345E46B0008; Mon, 31 Aug 2020 06:49:30 -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 237B96B000A; Mon, 31 Aug 2020 06:49:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id 0D41D6B0007 for ; Mon, 31 Aug 2020 06:49:30 -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 C7F50249F for ; Mon, 31 Aug 2020 10:49:29 +0000 (UTC) X-FDA: 77210542458.22.key85_40018152708f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 9B08F18038E67 for ; Mon, 31 Aug 2020 10:49:29 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5052c6ed3=sjpark@amazon.com,,RULES_HIT:30034:30054:30056:30064:30070,0,RBL:72.21.196.25:@amazon.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100;04yggoupdwby47endyy7u65gwa568opsxtobaunagcq7pc3n56at8yyse3op6w3.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:24,LUA_SUMMARY:none X-HE-Tag: key85_40018152708f X-Filterd-Recvd-Size: 4486 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Mon, 31 Aug 2020 10:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598870969; x=1630406969; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=IDHkic1gYAf9g3QrAFwx1LEoduynRqvj1VEruhEXvww=; b=W36zoldOZS3F37t67SxARmTJLcm8VbAIBqGZuLTz+vqbx1g+/Azs031l 9KOgI/9B8fcdxXJ7bmnPxK5+W2P2myXnw2/gJ5LttsDGrJqhn0iE2SAub kWkh7eblF4PNYhbo1DYkqb5yMuliT0WCUxksz1gBaPbXkU9Flqj0rICd8 I=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="50991436" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 31 Aug 2020 10:49:25 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com (Postfix) with ESMTPS id DFDA2A218C; Mon, 31 Aug 2020 10:49:13 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:48:56 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 04/10] selftests/damon/_chk_record: Do not check number of gaps Date: Mon, 31 Aug 2020 12:47:24 +0200 Message-ID: <20200831104730.28970-5-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) X-Rspamd-Queue-Id: 9B08F18038E67 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 Mon Aug 31 10:47:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11746125 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 03ABF138A for ; Mon, 31 Aug 2020 10:49:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BBC0B206F0 for ; Mon, 31 Aug 2020 10:49:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="u/xZp60R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BBC0B206F0 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 063416B0003; Mon, 31 Aug 2020 06:49:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F2D2E6B0008; Mon, 31 Aug 2020 06:49:37 -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 E1F9D6B000A; Mon, 31 Aug 2020 06:49:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id CDDBC6B0003 for ; Mon, 31 Aug 2020 06:49:37 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 09E573632 for ; Mon, 31 Aug 2020 10:49:36 +0000 (UTC) X-FDA: 77210542794.05.prose67_35055a52708f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id AF505180196AB for ; Mon, 31 Aug 2020 10:49:36 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5052c6ed3=sjpark@amazon.com,,RULES_HIT:30003:30054:30064:30070:30080,0,RBL:207.171.190.10:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10;04yfhgziu1byi96t9ompyn3tfbmm5opho4d4zpweyut56z6ysf75779qgbhjzty.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:24,LUA_SUMMARY:none X-HE-Tag: prose67_35055a52708f X-Filterd-Recvd-Size: 5981 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Mon, 31 Aug 2020 10:49:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598870976; x=1630406976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=TaBhL5HojO46LzRrtNTJtjXeDGLmPmatGGRehayYLuY=; b=u/xZp60RNqzVJhtwyaOlrUJwTViXxDYEPW8kKSu3hO1SjypXMdQSK7S8 JJ8RX8r7KWWngf+y3Y2H6eGxsKrpKsFQabON3Kc3KDLi7mJt1FodziU92 gOAk78IH8b5NToSgEwLzoK54XMulxPwGNIJaPEiApxu5BTd5xDekuAp6Z c=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="71144192" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-119b4f96.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 31 Aug 2020 10:49:33 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-119b4f96.us-west-2.amazon.com (Postfix) with ESMTPS id 11D311A0476; Mon, 31 Aug 2020 10:49:30 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:49:13 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 05/10] Docs/admin-guide/mm/damon: Document 'init_regions' feature Date: Mon, 31 Aug 2020 12:47:25 +0200 Message-ID: <20200831104730.28970-6-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) X-Rspamd-Queue-Id: AF505180196AB X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 Mon Aug 31 10:47:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11746127 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 121BF138A for ; Mon, 31 Aug 2020 10:49:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C7365206F0 for ; Mon, 31 Aug 2020 10:49:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="fuEqAiyL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7365206F0 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 0D8B56B0005; Mon, 31 Aug 2020 06:49:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0AF886B0008; Mon, 31 Aug 2020 06:49:56 -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 EEC528E0003; Mon, 31 Aug 2020 06:49:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id D8FE26B0005 for ; Mon, 31 Aug 2020 06:49:55 -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 9FB221F08 for ; Mon, 31 Aug 2020 10:49:55 +0000 (UTC) X-FDA: 77210543550.06.hook23_270734f2708f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 4F70C100516B1 for ; Mon, 31 Aug 2020 10:49:55 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5052c6ed3=sjpark@amazon.com,,RULES_HIT:30003:30012:30051:30054:30064:30070,0,RBL:207.171.184.25:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10;04yfnrgw8sgirk5bwqcthbiuzh7niyp41se1zpmtc7prnnd3db9beozz5s5njsa.jap3ujt57rqwjim9u4qydejsbp9xy3qjgm197fufogco5k43ojtzdo4eo4w4qgh.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: hook23_270734f2708f X-Filterd-Recvd-Size: 11470 Received: from smtp-fw-9101.amazon.com (smtp-fw-9101.amazon.com [207.171.184.25]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Mon, 31 Aug 2020 10:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598870995; x=1630406995; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=7crF3FKPqWt3cMPJkrXHleBoN5AqZg9Ge4umfcPJG48=; b=fuEqAiyLODoO3NFFrDEFkvGzHl5mtFag+LsOxPi9omIgE3XKuMR/Eigc m6Ca+J2TCEqL4QTCEMeW2CGoPkxYL0Dcg6kVUEpHLbfYjSkiq2kXPkWAr gyjRmCTGgawyAwjaTB/gCpNESbMuuZlqo6P08d9zHp+lpbabjyynWsRx6 o=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="64177142" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2c-1968f9fa.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 31 Aug 2020 10:49:52 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-1968f9fa.us-west-2.amazon.com (Postfix) with ESMTPS id 2BB2DA1802; Mon, 31 Aug 2020 10:49:48 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:49:30 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 06/10] mm/damon: Implement callbacks for physical memory monitoring Date: Mon, 31 Aug 2020 12:47:26 +0200 Message-ID: <20200831104730.28970-7-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) X-Rspamd-Queue-Id: 4F70C100516B1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 four callbacks (->init_target_regions, ->update_target_regions, ->prepare_access_check, and ->check_accesses) for the basic access monitoring of the physical memory address space. By setting the callback pointers to point those, 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 | 6 ++ mm/damon.c | 214 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 0e790af9c23a..306fa221ceae 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -242,6 +242,12 @@ unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx); bool kdamond_vm_target_valid(struct damon_target *t); void kdamond_vm_cleanup(struct damon_ctx *ctx); +/* Reference callback implementations for physical memory */ +void kdamond_init_phys_regions(struct damon_ctx *ctx); +void kdamond_update_phys_regions(struct damon_ctx *ctx); +void kdamond_prepare_phys_access_checks(struct damon_ctx *ctx); +unsigned int kdamond_check_phys_accesses(struct damon_ctx *ctx); + int damon_set_targets(struct damon_ctx *ctx, unsigned long *ids, ssize_t nr_ids); int damon_set_attrs(struct damon_ctx *ctx, unsigned long sample_int, diff --git a/mm/damon.c b/mm/damon.c index 9815d22fc4de..464209039bf8 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -26,11 +26,14 @@ #include #include #include +#include #include #include #include #include +#include #include +#include #include #include #include @@ -547,6 +550,18 @@ void kdamond_init_vm_regions(struct damon_ctx *ctx) } } +/* + * 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 kdamond_init_phys_regions(struct damon_ctx *ctx) +{ +} + /* * Functions for the dynamic monitoring target regions update */ @@ -630,6 +645,19 @@ void kdamond_update_vm_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 '->aggregate_cb', or implement their + * version of this and set the '->init_target_regions' of their damon_ctx to + * point it. + */ +void kdamond_update_phys_regions(struct damon_ctx *ctx) +{ +} + /* * Functions for the access checking of the regions */ @@ -805,6 +833,192 @@ unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) return max_nr_accesses; } +/* 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_phys_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_page_mkold(struct page *page, struct vm_area_struct *vma, + unsigned long addr, void *arg) +{ + damon_mkold(vma->vm_mm, addr); + return true; +} + +static void damon_phys_mkold(unsigned long paddr) +{ + struct page *page = damon_phys_get_page(PHYS_PFN(paddr)); + struct rmap_walk_control rwc = { + .rmap_one = damon_page_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_prepare_phys_access_check(struct damon_ctx *ctx, + struct damon_region *r) +{ + r->sampling_addr = damon_rand(r->ar.start, r->ar.end); + + damon_phys_mkold(r->sampling_addr); +} + +void kdamond_prepare_phys_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_prepare_phys_access_check(ctx, r); + } +} + +struct damon_phys_access_chk_result { + unsigned long page_sz; + bool accessed; +}; + +static bool damon_page_accessed(struct page *page, struct vm_area_struct *vma, + unsigned long addr, void *arg) +{ + struct damon_phys_access_chk_result *result = arg; + + result->accessed = damon_young(vma->vm_mm, addr, &result->page_sz); + + /* If accessed, stop walking */ + return !result->accessed; +} + +static bool damon_phys_young(unsigned long paddr, unsigned long *page_sz) +{ + struct page *page = damon_phys_get_page(PHYS_PFN(paddr)); + struct damon_phys_access_chk_result result = { + .page_sz = PAGE_SIZE, + .accessed = false, + }; + struct rmap_walk_control rwc = { + .arg = &result, + .rmap_one = damon_page_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_check_phys_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_phys_young(r->sampling_addr, &last_page_sz); + if (last_accessed) + r->nr_accesses++; + + last_addr = r->sampling_addr; +} + +unsigned int kdamond_check_phys_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_check_phys_access(ctx, r); + max_nr_accesses = max(r->nr_accesses, max_nr_accesses); + } + } + + return max_nr_accesses; +} /* * Functions for the target validity check and cleanup From patchwork Mon Aug 31 10:47:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11746129 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 0D89B13A4 for ; Mon, 31 Aug 2020 10:50:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE7B3206F0 for ; Mon, 31 Aug 2020 10:50:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="vasZcCXI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE7B3206F0 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 2368A6B0006; Mon, 31 Aug 2020 06:50:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1C2236B0008; Mon, 31 Aug 2020 06:50:14 -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 0AE8C6B000A; Mon, 31 Aug 2020 06:50:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id E88F86B0006 for ; Mon, 31 Aug 2020 06:50:13 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 99F6C2495 for ; Mon, 31 Aug 2020 10:50:13 +0000 (UTC) X-FDA: 77210544306.18.kick56_33026872708f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 64599100EC663 for ; Mon, 31 Aug 2020 10:50:13 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5052c6ed3=sjpark@amazon.com,,RULES_HIT:30003:30051:30054:30064:30070:30080,0,RBL:72.21.196.25:@amazon.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100;04yrfxad4t3hwbsozqnaegx6nt6f9yp9de83h7wtazmdxy9mfrsitraux4cy6kn.akoqna1n3bdoab3ufksr1hpgm7iz1j5rmdrpfnbrgghz9rjesfwmz5hqjgpqh8z.s-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: kick56_33026872708f X-Filterd-Recvd-Size: 5672 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Mon, 31 Aug 2020 10:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598871013; x=1630407013; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=7XLAfjNDxAGlOXL+oVVQMgpD8ljZ3iheJ5Jq9ck8vb8=; b=vasZcCXIPYk3rI5o8AkvNBTlOMtuZ5fBlP21WZMi+8WdprsFUKEcfNmV tdsMA+fd96Nrtj85aA2ZWz5j/xJ5o3k5zLQCmbCPa7lYKEE/6qIwEEnyt 2IBrn9xXXkkFV+GbJ5fcW//SaO5XFM+bru27KqsBQISzymyQTNDG1DDmK k=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="50991505" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-53356bf6.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 31 Aug 2020 10:50:09 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-53356bf6.us-west-2.amazon.com (Postfix) with ESMTPS id 1AF37A1EAD; Mon, 31 Aug 2020 10:50:06 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:49:48 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 07/10] mm/damon/debugfs: Support physical memory monitoring Date: Mon, 31 Aug 2020 12:47:27 +0200 Message-ID: <20200831104730.28970-8-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) X-Rspamd-Queue-Id: 64599100EC663 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 debugfs interface 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 callbacks of the monitoring context for the debugfs user for physical memory. This will internally add one fake monitoring target process, which has pid as -1. Unlike the virtual memory monitoring, DAMON debugfs will not automatically set the monitoring target region. Therefore, users should also set the monitoring target address region using the 'init_regions' debugfs file. While doing this, the 'pid' in the input should be '-1'. Finally, the physical memory monitoring will not automatically terminated because it has fake monitoring target process. The user should explicitly turn off the monitoring by writing 'off' to the 'monitor_on' debugfs file. Signed-off-by: SeongJae Park --- mm/damon.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/mm/damon.c b/mm/damon.c index 464209039bf8..98f52580bd5d 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -2127,9 +2127,29 @@ static ssize_t debugfs_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 */ + ctx->init_target_regions = kdamond_init_phys_regions; + ctx->update_target_regions = kdamond_update_phys_regions; + ctx->prepare_access_checks = kdamond_prepare_phys_access_checks; + ctx->check_accesses = kdamond_check_phys_accesses; + ctx->target_valid = NULL; + ctx->cleanup = NULL; + + /* target id is meaningless here, but we set it just for fun */ + snprintf(kbuf, count, "42 "); + } else { + /* Configure the context for virtual memory monitoring */ + ctx->init_target_regions = kdamond_init_vm_regions; + ctx->update_target_regions = kdamond_update_vm_regions; + ctx->prepare_access_checks = kdamond_prepare_vm_access_checks; + ctx->check_accesses = kdamond_check_vm_accesses; + ctx->target_valid = kdamond_vm_target_valid; + ctx->cleanup = kdamond_vm_cleanup; + if (!strncmp(kbuf, "pidfd ", 6)) { + received_pidfds = true; + nrs = &kbuf[6]; + } } targets = str_to_target_ids(nrs, ret, &nr_targets); From patchwork Mon Aug 31 10:47:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11746131 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 138A51575 for ; Mon, 31 Aug 2020 10:50:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D51F12068F for ; Mon, 31 Aug 2020 10:50:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="JeJyRUy/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D51F12068F 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 19AF66B0008; Mon, 31 Aug 2020 06:50:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 172276B000A; Mon, 31 Aug 2020 06:50:28 -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 0604F6B000C; Mon, 31 Aug 2020 06:50:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id E402B6B0008 for ; Mon, 31 Aug 2020 06:50:27 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 92BF9181AEF0B for ; Mon, 31 Aug 2020 10:50:27 +0000 (UTC) X-FDA: 77210544894.21.wool22_5310d4e2708f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 55F33180442C3 for ; Mon, 31 Aug 2020 10:50:27 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5052c6ed3=sjpark@amazon.com,,RULES_HIT:30003:30029:30054:30064:30070,0,RBL:207.171.190.10:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10;04yrkqfukhwbzta4z8g1wmnwohjg8yp886ujju5wcad46atqwc1wymuuh7z79qa.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:25,LUA_SUMMARY:none X-HE-Tag: wool22_5310d4e2708f X-Filterd-Recvd-Size: 6014 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Mon, 31 Aug 2020 10:50:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598871026; x=1630407026; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=kg6Pid/S3uyECtsR9/ZQNoRBSFk6tXHhc71xqlOp1H8=; b=JeJyRUy/pvC6OqcelFYbIutWq32kst6p67ZYSct1AMSqrbrTBopRcgH2 ODI/WBs/kQhMeEBiBLRhZbWO6IIvbxYZaO2ISA2F+n06LpOnHREp8Cd9n UyQgcwuiWJzXqEM+WQuKGB9u35GaX/gsEBrjTv78SvL6a6XgbNNg9K7jh 8=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="71144314" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-a7fdc47a.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 31 Aug 2020 10:50:25 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-a7fdc47a.us-west-2.amazon.com (Postfix) with ESMTPS id 33366C06C5; Mon, 31 Aug 2020 10:50:23 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:50:05 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 08/10] tools/damon/record: Support physical memory monitoring Date: Mon, 31 Aug 2020 12:47:28 +0200 Message-ID: <20200831104730.28970-9-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) X-Rspamd-Queue-Id: 55F33180442C3 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 Mon Aug 31 10:47:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11746133 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 A618C13A4 for ; Mon, 31 Aug 2020 10:50:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6635520EDD for ; Mon, 31 Aug 2020 10:50:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="u3EvXxcW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6635520EDD 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 A9B396B0005; Mon, 31 Aug 2020 06:50:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A71F26B0007; Mon, 31 Aug 2020 06:50:58 -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 988676B000A; Mon, 31 Aug 2020 06:50:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 828D16B0007 for ; Mon, 31 Aug 2020 06:50:58 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3FE5B824556B for ; Mon, 31 Aug 2020 10:50:58 +0000 (UTC) X-FDA: 77210546196.25.cry56_3a037d02708f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 148C41804E3A8 for ; Mon, 31 Aug 2020 10:50:58 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5052c6ed3=sjpark@amazon.com,,RULES_HIT:30003:30029:30045:30051:30054:30064:30070:30080,0,RBL:72.21.198.25:@amazon.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100;04ygayojekgiuuyjmgrybm1tcy7h8ypyw8fpwuyec4uk51bkxf41qtujq889iz5.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:26,LUA_SUMMARY:none X-HE-Tag: cry56_3a037d02708f X-Filterd-Recvd-Size: 10267 Received: from smtp-fw-4101.amazon.com (smtp-fw-4101.amazon.com [72.21.198.25]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Mon, 31 Aug 2020 10:50:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598871058; x=1630407058; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=VIt0QPHvmvqG4Kch/PM9e/Zwtiyux2gOnoeb9rYl0nc=; b=u3EvXxcWA1GbEg72WZ2T/cgIQad75WZNHFhXjzCfvrak0Clt9BJtR3oJ QGlR6ZlenLV2FDNM7HSfggImLbza08l7tTzLknpVHCrRP9GrXIikl5PRE tsOp66LBkFGI9W0h2JpsMv2EEieigjvSLxFFEcrvm1qtyi59BH8OAezR7 I=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="51175390" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-e7be2041.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 31 Aug 2020 10:50:53 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-e7be2041.us-west-2.amazon.com (Postfix) with ESMTPS id 497EBA06E4; Mon, 31 Aug 2020 10:50:40 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:50:23 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 09/10] tools/damon/record: Support NUMA specific recording Date: Mon, 31 Aug 2020 12:47:29 +0200 Message-ID: <20200831104730.28970-10-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) X-Rspamd-Queue-Id: 148C41804E3A8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 Mon Aug 31 10:47:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11746135 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 5C8EE1575 for ; Mon, 31 Aug 2020 10:51:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D0A8206F0 for ; Mon, 31 Aug 2020 10:51:17 +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="eH1DrX6e" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D0A8206F0 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 606566B0007; Mon, 31 Aug 2020 06:51:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5B6C16B000A; Mon, 31 Aug 2020 06:51:16 -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 4CC898E0003; Mon, 31 Aug 2020 06:51:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id 387466B0007 for ; Mon, 31 Aug 2020 06:51:16 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id ECC29180AD801 for ; Mon, 31 Aug 2020 10:51:15 +0000 (UTC) X-FDA: 77210546910.03.sail44_5c103c22708f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id BF47C28A4E8 for ; Mon, 31 Aug 2020 10:51:15 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5052c6ed3=sjpark@amazon.com,,RULES_HIT:30003:30025:30051:30054:30064:30070:30071:30090,0,RBL:52.95.49.90:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04yf5e4ud8a1wjrupcfgxoaiagycwyc586wgmzejucc4mjxbbmrzmf9n5g7o8ak.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:26,LUA_SUMMARY:none X-HE-Tag: sail44_5c103c22708f X-Filterd-Recvd-Size: 12194 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Mon, 31 Aug 2020 10:51: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=1598871076; x=1630407076; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qGKT1F1qVkIMFajZCvJm8BTClvxWeUPf3j13t8snc08=; b=eH1DrX6ecrvF3dEH1mcN4nPB/NyhD8cyXaWPGal7LRbpAZ3/s23ls7YR 5yrPy/Rztq/cNtCABb+0VAHDq3+YDfuJD946lIwqSbCqL++5wTDW96iqZ PkHKxQNzRYU7mMXWkcgppeHWtOU+GTRsvaXDoPcw6SYGzCtICVY6/lvas A=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="51088567" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-e7be2041.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 31 Aug 2020 10:51:11 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-e7be2041.us-west-2.amazon.com (Postfix) with ESMTPS id 449F6A1C5F; Mon, 31 Aug 2020 10:50:58 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:50:41 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 10/10] Docs/DAMON: Document physical memory monitoring support Date: Mon, 31 Aug 2020 12:47:30 +0200 Message-ID: <20200831104730.28970-11-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) X-Rspamd-Queue-Id: BF47C28A4E8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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?