From patchwork Wed Dec 16 09:42:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8F7CC4361B for ; Wed, 16 Dec 2020 09:43:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2E84823105 for ; Wed, 16 Dec 2020 09:43:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E84823105 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 1611C6B006C; Wed, 16 Dec 2020 04:43:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1129F6B006E; Wed, 16 Dec 2020 04:43:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 030E96B0070; Wed, 16 Dec 2020 04:43:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id E1CE96B006C for ; Wed, 16 Dec 2020 04:43:26 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A8E6E19451 for ; Wed, 16 Dec 2020 09:43:26 +0000 (UTC) X-FDA: 77598657612.17.brake18_0f11c152742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 88E88180CF5E0 for ; Wed, 16 Dec 2020 09:43:26 +0000 (UTC) X-HE-Tag: brake18_0f11c152742b X-Filterd-Recvd-Size: 8653 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608111806; x=1639647806; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=6T3WVe6Az0tu/tWkPM96Y026XUAvJ40yYSLrebOuGng=; b=rFdURPDJH3H5eBu/l2sAW5Eb/i5QiecIEAGjZ18xOk5QtiuTTCSkLVmJ cJhOpkJXXxnbkjPjO+35PrFoJOibOKTd0sBICjLQr9ywo311dOjwXb2h7 Sgl+HXrQ1jlPzjejnz/Snli0svEdss/TMQNZwn2rbT6NJBnSRW2FAecY5 4=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="71565066" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 16 Dec 2020 09:43:18 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com (Postfix) with ESMTPS id C4B5AA1F1D; Wed, 16 Dec 2020 09:43:15 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:42:59 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 01/13] damon/dbgfs: Allow users to set initial monitoring target regions Date: Wed, 16 Dec 2020 10:42:09 +0100 Message-ID: <20201216094221.11898-2-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park Some 'damon-dbgfs' users would want to monitor only a part of the entire virtual memory address space. The framework users in the kernel space could use '->init_target_regions' callback or even set the regions inside the context struct as they want, but 'damon-dbgfs' users cannot. For the reason, this commit introduces a new debugfs file, 'init_region'. 'damon-dbgfs' users can specify which initial monitoring target address regions they want by writing special input to the file. The input should describe each region in each line in below form: Note that the regions will be updated to cover entire memory mapped regions after 'regions update interval'. If you want the regions to not be updated after the initial setting, you could set the interval as a very long time, say, a few decades. Signed-off-by: SeongJae Park --- mm/damon/dbgfs.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 3 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index 06295c986dc3..2f1ec6ebd9f0 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -492,6 +492,147 @@ static ssize_t dbgfs_target_ids_write(struct file *file, return ret; } +static ssize_t sprint_init_regions(struct damon_ctx *c, char *buf, ssize_t len) +{ + struct damon_target *t; + struct damon_region *r; + int written = 0; + int rc; + + damon_for_each_target(t, c) { + damon_for_each_region(r, t) { + rc = scnprintf(&buf[written], len - written, + "%lu %lu %lu\n", + t->id, r->ar.start, r->ar.end); + if (!rc) + return -ENOMEM; + written += rc; + } + } + return written; +} + +static ssize_t dbgfs_init_regions_read(struct file *file, char __user *buf, + size_t count, loff_t *ppos) +{ + struct damon_ctx *ctx = file->private_data; + char *kbuf; + ssize_t len; + + kbuf = kmalloc(count, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + mutex_lock(&ctx->kdamond_lock); + if (ctx->kdamond) { + mutex_unlock(&ctx->kdamond_lock); + return -EBUSY; + } + + len = sprint_init_regions(ctx, kbuf, count); + mutex_unlock(&ctx->kdamond_lock); + if (len < 0) + goto out; + len = simple_read_from_buffer(buf, count, ppos, kbuf, len); + +out: + kfree(kbuf); + return len; +} + +static int add_init_region(struct damon_ctx *c, + unsigned long target_id, struct damon_addr_range *ar) +{ + struct damon_target *t; + struct damon_region *r, *prev; + int rc = -EINVAL; + + if (ar->start >= ar->end) + return -EINVAL; + + damon_for_each_target(t, c) { + if (t->id == target_id) { + r = damon_new_region(ar->start, ar->end); + if (!r) + return -ENOMEM; + damon_add_region(r, t); + if (damon_nr_regions(t) > 1) { + prev = damon_prev_region(r); + if (prev->ar.end > r->ar.start) { + damon_destroy_region(r); + return -EINVAL; + } + } + rc = 0; + } + } + return rc; +} + +static int set_init_regions(struct damon_ctx *c, const char *str, ssize_t len) +{ + struct damon_target *t; + struct damon_region *r, *next; + int pos = 0, parsed, ret; + unsigned long target_id; + struct damon_addr_range ar; + int err; + + damon_for_each_target(t, c) { + damon_for_each_region_safe(r, next, t) + damon_destroy_region(r); + } + + while (pos < len) { + ret = sscanf(&str[pos], "%lu %lu %lu%n", + &target_id, &ar.start, &ar.end, &parsed); + if (ret != 3) + break; + err = add_init_region(c, target_id, &ar); + if (err) + goto fail; + pos += parsed; + } + + return 0; + +fail: + damon_for_each_target(t, c) { + damon_for_each_region_safe(r, next, t) + damon_destroy_region(r); + } + return err; +} + +static ssize_t dbgfs_init_regions_write(struct file *file, + const char __user *buf, size_t count, + loff_t *ppos) +{ + struct damon_ctx *ctx = file->private_data; + char *kbuf; + ssize_t ret = count; + int err; + + kbuf = user_input_str(buf, count, ppos); + if (IS_ERR(kbuf)) + return PTR_ERR(kbuf); + + mutex_lock(&ctx->kdamond_lock); + if (ctx->kdamond) { + ret = -EBUSY; + goto unlock_out; + } + + err = set_init_regions(ctx, kbuf, ret); + if (err) + ret = err; + +unlock_out: + mutex_unlock(&ctx->kdamond_lock); + kfree(kbuf); + return ret; +} + static ssize_t dbgfs_kdamond_pid_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { @@ -553,6 +694,13 @@ static const struct file_operations target_ids_fops = { .write = dbgfs_target_ids_write, }; +static const struct file_operations init_regions_fops = { + .owner = THIS_MODULE, + .open = damon_dbgfs_open, + .read = dbgfs_init_regions_read, + .write = dbgfs_init_regions_write, +}; + static const struct file_operations kdamond_pid_fops = { .owner = THIS_MODULE, .open = damon_dbgfs_open, @@ -562,9 +710,9 @@ static const struct file_operations kdamond_pid_fops = { static int dbgfs_fill_ctx_dir(struct dentry *dir, struct damon_ctx *ctx) { const char * const file_names[] = {"attrs", "record", "schemes", - "target_ids", "kdamond_pid"}; - const struct file_operations *fops[] = {&attrs_fops, - &record_fops, &schemes_fops, &target_ids_fops, + "target_ids", "init_regions", "kdamond_pid"}; + const struct file_operations *fops[] = {&attrs_fops, &record_fops, + &schemes_fops, &target_ids_fops, &init_regions_fops, &kdamond_pid_fops}; int i; From patchwork Wed Dec 16 09:42:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33370C4361B for ; Wed, 16 Dec 2020 09:43:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 89E5023137 for ; Wed, 16 Dec 2020 09:43:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89E5023137 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 CAC2B6B0070; Wed, 16 Dec 2020 04:43:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C35796B0071; Wed, 16 Dec 2020 04:43:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4E326B0072; Wed, 16 Dec 2020 04:43:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id 9C4316B0070 for ; Wed, 16 Dec 2020 04:43:55 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 61D6D13907 for ; Wed, 16 Dec 2020 09:43:55 +0000 (UTC) X-FDA: 77598658830.12.patch61_3b090232742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 3E4D81801A124 for ; Wed, 16 Dec 2020 09:43:55 +0000 (UTC) X-HE-Tag: patch61_3b090232742b X-Filterd-Recvd-Size: 11319 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:43: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=1608111835; x=1639647835; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=eFQ5FjEXjCcRqP315OtcZTEl8DRR0ETd5Jfrqerv8aI=; b=XSysKHS9m7S7dsoQuMl/VpTJSwse+3dnp/q9a/UCo/xMVHLJj2g4hPti UkoOBtGDGiZ/RD4WwKekiK4qE5PI78QA2lbVIce0oYFRjSoxz6PeLSMNR T9auAppFMIjwXoDqGYEjTt9nCd1YY2tvgfnd20OAXAIjKZdx6FPSPY0UR I=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="69443516" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1a-807d4a99.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 16 Dec 2020 09:43:47 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1a-807d4a99.us-east-1.amazon.com (Postfix) with ESMTPS id BAF54A1DCA; Wed, 16 Dec 2020 09:43:34 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:43:18 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 02/13] tools/damon: Support init target regions specification Date: Wed, 16 Dec 2020 10:42:10 +0100 Message-ID: <20201216094221.11898-3-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit updates the damon user space tool to support the initial monitoring target regions specification. Signed-off-by: SeongJae Park --- tools/damon/_damon.py | 39 +++++++++++++++++++++++++++++++++++++++ tools/damon/record.py | 12 +++++++----- tools/damon/schemes.py | 12 +++++++----- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/tools/damon/_damon.py b/tools/damon/_damon.py index a4f6c03c23e4..a22ec3777c16 100644 --- a/tools/damon/_damon.py +++ b/tools/damon/_damon.py @@ -12,12 +12,25 @@ debugfs_attrs = None debugfs_record = None debugfs_schemes = None debugfs_target_ids = None +debugfs_init_regions = None debugfs_monitor_on = None def set_target_id(tid): with open(debugfs_target_ids, 'w') as f: f.write('%s\n' % tid) +def set_target(tid, init_regions=[]): + rc = set_target_id(tid) + if rc: + return rc + + if not os.path.exists(debugfs_init_regions): + return 0 + + string = ' '.join(['%s %d %d' % (tid, r[0], r[1]) for r in init_regions]) + return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions), + shell=True, executable='/bin/bash') + def turn_damon(on_off): return subprocess.call("echo %s > %s" % (on_off, debugfs_monitor_on), shell=True, executable="/bin/bash") @@ -97,6 +110,7 @@ def chk_update_debugfs(debugfs): global debugfs_record global debugfs_schemes global debugfs_target_ids + global debugfs_init_regions global debugfs_monitor_on debugfs_damon = os.path.join(debugfs, 'damon') @@ -104,6 +118,7 @@ def chk_update_debugfs(debugfs): debugfs_record = os.path.join(debugfs_damon, 'record') debugfs_schemes = os.path.join(debugfs_damon, 'schemes') debugfs_target_ids = os.path.join(debugfs_damon, 'target_ids') + debugfs_init_regions = os.path.join(debugfs_damon, 'init_regions') debugfs_monitor_on = os.path.join(debugfs_damon, 'monitor_on') if not os.path.isdir(debugfs_damon): @@ -131,6 +146,26 @@ def cmd_args_to_attrs(args): return Attrs(sample_interval, aggr_interval, regions_update_interval, min_nr_regions, max_nr_regions, rbuf_len, rfile_path, schemes) +def cmd_args_to_init_regions(args): + regions = [] + for arg in args.regions.split(): + addrs = arg.split('-') + try: + if len(addrs) != 2: + raise Exception('two addresses not given') + start = int(addrs[0]) + end = int(addrs[1]) + if start >= end: + raise Exception('start >= end') + if regions and regions[-1][1] > start: + raise Exception('regions overlap') + except Exception as e: + print('Wrong \'--regions\' argument (%s)' % e) + exit(1) + + regions.append([start, end]) + return regions + def set_attrs_argparser(parser): parser.add_argument('-d', '--debugfs', metavar='', type=str, default='/sys/kernel/debug', help='debugfs mounted path') @@ -144,3 +179,7 @@ def set_attrs_argparser(parser): default=10, help='minimal number of regions') parser.add_argument('-m', '--maxr', metavar='<# regions>', type=int, default=1000, help='maximum number of regions') + +def set_init_regions_argparser(parser): + parser.add_argument('-r', '--regions', metavar='"- ..."', + type=str, default='', help='monitoring target address regions') diff --git a/tools/damon/record.py b/tools/damon/record.py index 6d1cbe593b94..11fd54001472 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -24,7 +24,7 @@ def pidfd_open(pid): return syscall(NR_pidfd_open, pid, 0) -def do_record(target, is_target_cmd, attrs, old_attrs, pidfd): +def do_record(target, is_target_cmd, init_regions, attrs, old_attrs, pidfd): if os.path.isfile(attrs.rfile_path): os.rename(attrs.rfile_path, attrs.rfile_path + '.old') @@ -48,8 +48,8 @@ def do_record(target, is_target_cmd, attrs, old_attrs, pidfd): # only for reference of the pidfd usage. target = 'pidfd %s' % fd - if _damon.set_target_id(target): - print('target id setting (%s) failed' % target) + if _damon.set_target(target, init_regions): + print('target setting (%s, %s) failed' % (target, init_regions)) cleanup_exit(old_attrs, -2) if _damon.turn_damon('on'): print('could not turn on damon' % target) @@ -91,6 +91,7 @@ def chk_permission(): def set_argparser(parser): _damon.set_attrs_argparser(parser) + _damon.set_init_regions_argparser(parser) parser.add_argument('target', type=str, metavar='', help='the target command or the pid to record') parser.add_argument('--pidfd', action='store_true', @@ -117,19 +118,20 @@ def main(args=None): args.schemes = '' pidfd = args.pidfd new_attrs = _damon.cmd_args_to_attrs(args) + init_regions = _damon.cmd_args_to_init_regions(args) target = args.target target_fields = target.split() if not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): - do_record(target, True, new_attrs, orig_attrs, pidfd) + do_record(target, True, init_regions, new_attrs, orig_attrs, pidfd) else: try: pid = int(target) except: print('target \'%s\' is neither a command, nor a pid' % target) exit(1) - do_record(target, False, new_attrs, orig_attrs, pidfd) + do_record(target, False, init_regions, new_attrs, orig_attrs, pidfd) if __name__ == '__main__': main() diff --git a/tools/damon/schemes.py b/tools/damon/schemes.py index 9095835f6133..cfec89854a08 100644 --- a/tools/damon/schemes.py +++ b/tools/damon/schemes.py @@ -14,7 +14,7 @@ import time import _convert_damos import _damon -def run_damon(target, is_target_cmd, attrs, old_attrs): +def run_damon(target, is_target_cmd, init_regions, attrs, old_attrs): if os.path.isfile(attrs.rfile_path): os.rename(attrs.rfile_path, attrs.rfile_path + '.old') @@ -27,8 +27,8 @@ def run_damon(target, is_target_cmd, attrs, old_attrs): if is_target_cmd: p = subprocess.Popen(target, shell=True, executable='/bin/bash') target = p.pid - if _damon.set_target_pid(target): - print('pid setting (%s) failed' % target) + if _damon.set_target(target, init_regions): + print('target setting (%s, %s) failed' % (target, init_regions)) cleanup_exit(old_attrs, -2) if _damon.turn_damon('on'): print('could not turn on damon' % target) @@ -68,6 +68,7 @@ def chk_permission(): def set_argparser(parser): _damon.set_attrs_argparser(parser) + _damon.set_init_regions_argparser(parser) parser.add_argument('target', type=str, metavar='', help='the target command or the pid to record') parser.add_argument('-c', '--schemes', metavar='', type=str, @@ -92,19 +93,20 @@ def main(args=None): args.out = 'null' args.schemes = _convert_damos.convert(args.schemes, args.sample, args.aggr) new_attrs = _damon.cmd_args_to_attrs(args) + init_regions = _damon.cmd_args_to_init_regions(args) target = args.target target_fields = target.split() if not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): - run_damon(target, True, new_attrs, orig_attrs) + run_damon(target, True, init_regions, new_attrs, orig_attrs) else: try: pid = int(target) except: print('target \'%s\' is neither a command, nor a pid' % target) exit(1) - run_damon(target, False, new_attrs, orig_attrs) + run_damon(target, False, init_regions, new_attrs, orig_attrs) if __name__ == '__main__': main() From patchwork Wed Dec 16 09:42:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 411F1C4361B for ; Wed, 16 Dec 2020 09:44:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A151C23123 for ; Wed, 16 Dec 2020 09:44:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A151C23123 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 0C5D86B0071; Wed, 16 Dec 2020 04:44:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 09C126B0072; Wed, 16 Dec 2020 04:44:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1C0C6B0073; Wed, 16 Dec 2020 04:44:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0161.hostedemail.com [216.40.44.161]) by kanga.kvack.org (Postfix) with ESMTP id DC5C36B0071 for ; Wed, 16 Dec 2020 04:44:19 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A9EA2180AD811 for ; Wed, 16 Dec 2020 09:44:19 +0000 (UTC) X-FDA: 77598659838.16.use69_2d02d342742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 86C04100E9C22 for ; Wed, 16 Dec 2020 09:44:19 +0000 (UTC) X-HE-Tag: use69_2d02d342742b X-Filterd-Recvd-Size: 5821 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608111859; x=1639647859; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=7yi+fK26byzJlIHOanuP6VWvC5tjIzmEY8cq5qHToUo=; b=WUSLe7727rcDY9vMfBOeSuyPMt/oqmuUEXTQAaDWi1+QdSuiEDQ6f4xk Ix1pbAX40iAxcLq/6v2jktiSqko2YorhwTGYDyCa2X97BYHudKJsJ7KXR qjBkBoCMqYMFKGzFVX/Nw00vMcl80YDF+duSxkI50mRtzpahr6WZ2X6rI I=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="103495154" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-303d0b0e.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 16 Dec 2020 09:44:08 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1e-303d0b0e.us-east-1.amazon.com (Postfix) with ESMTPS id B0448A073C; Wed, 16 Dec 2020 09:43:55 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:43:38 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 03/13] damon/dbgfs-test: Add a unit test case for 'init_regions' Date: Wed, 16 Dec 2020 10:42:11 +0100 Message-ID: <20201216094221.11898-4-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit adds another test case for the new feature, 'init_regions'. Signed-off-by: SeongJae Park Reviewed-by: Brendan Higgins --- mm/damon/dbgfs-test.h | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/mm/damon/dbgfs-test.h b/mm/damon/dbgfs-test.h index ce9c6784ad47..91138b53fe2a 100644 --- a/mm/damon/dbgfs-test.h +++ b/mm/damon/dbgfs-test.h @@ -189,12 +189,67 @@ static void damon_dbgfs_test_aggregate(struct kunit *test) damon_destroy_ctx(ctx); } + +static void damon_dbgfs_test_set_init_regions(struct kunit *test) +{ + struct damon_ctx *ctx = damon_new_ctx(DAMON_ADAPTIVE_TARGET); + unsigned long ids[] = {1, 2, 3}; + /* Each line represents one region in `` `` */ + char * const valid_inputs[] = {"2 10 20\n 2 20 30\n2 35 45", + "2 10 20\n", + "2 10 20\n1 39 59\n1 70 134\n 2 20 25\n", + ""}; + /* Reading the file again will show sorted, clean output */ + char * const valid_expects[] = {"2 10 20\n2 20 30\n2 35 45\n", + "2 10 20\n", + "1 39 59\n1 70 134\n2 10 20\n2 20 25\n", + ""}; + char * const invalid_inputs[] = {"4 10 20\n", /* target not exists */ + "2 10 20\n 2 14 26\n", /* regions overlap */ + "1 10 20\n2 30 40\n 1 5 8"}; /* not sorted by address */ + char *input, *expect; + int i, rc; + char buf[256]; + + damon_set_targets(ctx, ids, 3); + + /* Put valid inputs and check the results */ + for (i = 0; i < ARRAY_SIZE(valid_inputs); i++) { + input = valid_inputs[i]; + expect = valid_expects[i]; + + rc = set_init_regions(ctx, input, strnlen(input, 256)); + KUNIT_EXPECT_EQ(test, rc, 0); + + memset(buf, 0, 256); + sprint_init_regions(ctx, buf, 256); + + KUNIT_EXPECT_STREQ(test, (char *)buf, expect); + } + /* Put invlid inputs and check the return error code */ + for (i = 0; i < ARRAY_SIZE(invalid_inputs); i++) { + input = invalid_inputs[i]; + pr_info("input: %s\n", input); + rc = set_init_regions(ctx, input, strnlen(input, 256)); + KUNIT_EXPECT_EQ(test, rc, -EINVAL); + + memset(buf, 0, 256); + sprint_init_regions(ctx, buf, 256); + + KUNIT_EXPECT_STREQ(test, (char *)buf, ""); + } + + damon_set_targets(ctx, NULL, 0); + damon_destroy_ctx(ctx); +} + static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_dbgfs_test_str_to_target_ids), KUNIT_CASE(damon_dbgfs_test_set_targets), KUNIT_CASE(damon_dbgfs_test_set_recording), KUNIT_CASE(damon_dbgfs_test_write_rbuf), KUNIT_CASE(damon_dbgfs_test_aggregate), + KUNIT_CASE(damon_dbgfs_test_set_init_regions), {}, }; From patchwork Wed Dec 16 09:42:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A65DC0018C for ; Wed, 16 Dec 2020 09:44:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B6E3A23123 for ; Wed, 16 Dec 2020 09:44:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6E3A23123 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 3F9986B0072; Wed, 16 Dec 2020 04:44:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D0238D0002; Wed, 16 Dec 2020 04:44:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E6A66B0074; Wed, 16 Dec 2020 04:44:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0147.hostedemail.com [216.40.44.147]) by kanga.kvack.org (Postfix) with ESMTP id 18BD36B0072 for ; Wed, 16 Dec 2020 04:44:26 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D828517877 for ; Wed, 16 Dec 2020 09:44:25 +0000 (UTC) X-FDA: 77598660090.25.desk83_0c1430a2742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id B6DF0180142F6 for ; Wed, 16 Dec 2020 09:44:25 +0000 (UTC) X-HE-Tag: desk83_0c1430a2742b X-Filterd-Recvd-Size: 4504 Received: from smtp-fw-4101.amazon.com (smtp-fw-4101.amazon.com [72.21.198.25]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608111865; x=1639647865; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=IDHkic1gYAf9g3QrAFwx1LEoduynRqvj1VEruhEXvww=; b=E8e2hkfg799fA0R2RJSjqBhUKDkYJu5jHe6WA3U4CX32AvSBUZrh+gi9 A3N0hY5sN4d5kLgcr7AbQT+XYBGmNnhKjU9AVVOw/9fx0u3Eq4smHUsOq /REuxpZwG95YAfJzZV47EucYVlPSLesyf5zdXkt7SEFyrbG3nwsB8X0Os M=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="69703750" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2c-579b7f5b.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 16 Dec 2020 09:44:14 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2c-579b7f5b.us-west-2.amazon.com (Postfix) with ESMTPS id 1C7C6A217F; Wed, 16 Dec 2020 09:44:14 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:43:56 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 04/13] selftests/damon/_chk_record: Do not check number of gaps Date: Wed, 16 Dec 2020 10:42:12 +0100 Message-ID: <20201216094221.11898-5-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park Now the regions can be explicitly set as users want. Therefore checking the number of gaps doesn't make sense. Remove the condition. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_chk_record.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tools/testing/selftests/damon/_chk_record.py b/tools/testing/selftests/damon/_chk_record.py index 73e128904319..5f11be64abed 100644 --- a/tools/testing/selftests/damon/_chk_record.py +++ b/tools/testing/selftests/damon/_chk_record.py @@ -37,12 +37,9 @@ def chk_task_info(f): print('too many regions: %d > %d' % (nr_regions, max_nr_regions)) exit(1) - nr_gaps = 0 eaddr = 0 for r in range(nr_regions): saddr = struct.unpack('L', f.read(8))[0] - if eaddr and saddr != eaddr: - nr_gaps += 1 eaddr = struct.unpack('L', f.read(8))[0] nr_accesses = struct.unpack('I', f.read(4))[0] @@ -56,9 +53,6 @@ def chk_task_info(f): print('too high nr_access: expected %d but %d' % (max_nr_accesses, nr_accesses)) exit(1) - if nr_gaps != 2: - print('number of gaps are not two but %d' % nr_gaps) - exit(1) def parse_time_us(bindat): sec = struct.unpack('l', bindat[0:8])[0] From patchwork Wed Dec 16 09:42:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60AF7C4361B for ; Wed, 16 Dec 2020 09:44:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DAFFE233CF for ; Wed, 16 Dec 2020 09:44:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DAFFE233CF 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 1AE196B006C; Wed, 16 Dec 2020 04:44:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 184F56B006E; Wed, 16 Dec 2020 04:44:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09CB76B0073; Wed, 16 Dec 2020 04:44:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0155.hostedemail.com [216.40.44.155]) by kanga.kvack.org (Postfix) with ESMTP id E8B8C6B006C for ; Wed, 16 Dec 2020 04:44:48 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B5007180A6070 for ; Wed, 16 Dec 2020 09:44:48 +0000 (UTC) X-FDA: 77598661056.07.curve04_3e14c052742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id A6C8E1811CE58 for ; Wed, 16 Dec 2020 09:44:48 +0000 (UTC) X-HE-Tag: curve04_3e14c052742b X-Filterd-Recvd-Size: 5984 Received: from smtp-fw-4101.amazon.com (smtp-fw-4101.amazon.com [72.21.198.25]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:44:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608111888; x=1639647888; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=TaBhL5HojO46LzRrtNTJtjXeDGLmPmatGGRehayYLuY=; b=U57bEHOVKugNQayXIYwU6V4UhUFiT2aXe9ET/KKTdzpzgs1SQRJtfK5b uX8W57zW72ZRH629gOs2I5sqVtA/FxSXsGMhRT0pjm7faM6XqxehX9NK1 Q0sDySmjaKZcHYq59b0JFZrYpzsjlRmj0qCj3kk4tNpjAxVmlHMf2n/Lq k=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="69703881" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-c5104f52.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 16 Dec 2020 09:44:44 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-c5104f52.us-west-2.amazon.com (Postfix) with ESMTPS id 26284A1DA0; Wed, 16 Dec 2020 09:44:31 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:44:14 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 05/13] Docs/admin-guide/mm/damon: Document 'init_regions' feature Date: Wed, 16 Dec 2020 10:42:13 +0100 Message-ID: <20201216094221.11898-6-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit adds description of the 'init_regions' feature in the DAMON usage document. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 41 +++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index 96278227f925..cf0d44ce0ac9 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -281,8 +281,9 @@ for at least 100 milliseconds using below commands:: debugfs Interface ================= -DAMON exports five files, ``attrs``, ``target_ids``, ``record``, ``schemes`` -and ``monitor_on`` under its debugfs directory, ``/damon/``. +DAMON exports six files, ``attrs``, ``target_ids``, ``init_regions``, +``record``, ``schemes`` and ``monitor_on`` under its debugfs directory, +``/damon/``. Attributes @@ -321,6 +322,42 @@ check it again:: Note that setting the target ids doesn't start the monitoring. +Initial Monitoring Target Regions +--------------------------------- + +In case of the debugfs based monitoring, DAMON automatically sets and updates +the monitoring target regions so that entire memory mappings of target +processes can be covered. However, users might want to limit the monitoring +region to specific address ranges, such as the heap, the stack, or specific +file-mapped area. Or, some users might know the initial access pattern of +their workloads and therefore want to set optimal initial regions for the +'adaptive regions adjustment'. + +In such cases, users can explicitly set the initial monitoring target regions +as they want, by writing proper values to the ``init_regions`` file. Each line +of the input should represent one region in below form.:: + + + +The ``target id`` should already in ``target_ids`` file, and the regions should +be passed in address order. For example, below commands will set a couple of +address ranges, ``1-100`` and ``100-200`` as the initial monitoring target +region of process 42, and another couple of address ranges, ``20-40`` and +``50-100`` as that of process 4242.:: + + # cd /damon + # echo "42 1 100 + 42 100 200 + 4242 20 40 + 4242 50 100" > init_regions + +Note that this sets the initial monitoring target regions only. In case of +virtual memory monitoring, DAMON will automatically updates the boundary of the +regions after one ``regions update interval``. Therefore, users should set the +``regions update interval`` large enough in this case, if they don't want the +update. + + Record ------ From patchwork Wed Dec 16 09:42:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F340EC4361B for ; Wed, 16 Dec 2020 09:45:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 64D4F2312E for ; Wed, 16 Dec 2020 09:45:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64D4F2312E 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 D95D46B006E; Wed, 16 Dec 2020 04:45:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D44FC6B0070; Wed, 16 Dec 2020 04:45:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0CD96B0073; Wed, 16 Dec 2020 04:45:12 -0500 (EST) 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 A52146B006E for ; Wed, 16 Dec 2020 04:45:12 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7662A1AD91 for ; Wed, 16 Dec 2020 09:45:12 +0000 (UTC) X-FDA: 77598662064.30.fly40_2c070602742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 5365B180D6064 for ; Wed, 16 Dec 2020 09:45:12 +0000 (UTC) X-HE-Tag: fly40_2c070602742b X-Filterd-Recvd-Size: 10860 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608111912; x=1639647912; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=Lj6+I9XWmZiqjVkd1Bor2fLoWLXqVAIP/n4Y2agFqYw=; b=KEBPieXdYkinAbSA2clUIAqnoIqjYXMYwUfPDti23oPzAzyePTb2jCxi FjFUcnuKCOvbvQf1Tbe9Z4SrR4akz889WG9ExETlf7Ym1jR03o1ZkL1Vc H5qUhYyPZ+e+j3krLXHhKe9Sv1/iEmVUJLQxA00sDRDWUlBIYTRbnvVPZ E=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="69443702" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-87a10be6.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 16 Dec 2020 09:45:07 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2c-87a10be6.us-west-2.amazon.com (Postfix) with ESMTPS id DF141A1EBF; Wed, 16 Dec 2020 09:44:55 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:44:36 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 06/13] mm/damon/vaddr: Separate commonly usable functions Date: Wed, 16 Dec 2020 10:42:14 +0100 Message-ID: <20201216094221.11898-7-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit moves functions in the default virtual address spaces monitoring primitives that commonly usable from other address spaces like physical address space into a header file. Those will be reused by the physical address space monitoring primitives in the following commit. Signed-off-by: SeongJae Park --- mm/damon/Makefile | 2 +- mm/damon/prmtv-common.c | 104 ++++++++++++++++++++++++++++++++++++++ mm/damon/prmtv-common.h | 21 ++++++++ mm/damon/vaddr.c | 108 +--------------------------------------- 4 files changed, 128 insertions(+), 107 deletions(-) create mode 100644 mm/damon/prmtv-common.c create mode 100644 mm/damon/prmtv-common.h diff --git a/mm/damon/Makefile b/mm/damon/Makefile index fed4be3bace3..99b1bfe01ff5 100644 --- a/mm/damon/Makefile +++ b/mm/damon/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DAMON) := core.o -obj-$(CONFIG_DAMON_VADDR) += vaddr.o +obj-$(CONFIG_DAMON_VADDR) += prmtv-common.o vaddr.o obj-$(CONFIG_DAMON_DBGFS) += dbgfs.o diff --git a/mm/damon/prmtv-common.c b/mm/damon/prmtv-common.c new file mode 100644 index 000000000000..6cdb96cbc9ef --- /dev/null +++ b/mm/damon/prmtv-common.c @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Common Primitives for Data Access Monitoring + * + * Author: SeongJae Park + */ + +#include "prmtv-common.h" + +static void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, + unsigned long addr) +{ + bool referenced = false; + struct page *page = pte_page(*pte); + + if (pte_young(*pte)) { + referenced = true; + *pte = pte_mkold(*pte); + } + +#ifdef CONFIG_MMU_NOTIFIER + if (mmu_notifier_clear_young(mm, addr, addr + PAGE_SIZE)) + referenced = true; +#endif /* CONFIG_MMU_NOTIFIER */ + + if (referenced) + set_page_young(page); + + set_page_idle(page); +} + +static void damon_pmdp_mkold(pmd_t *pmd, struct mm_struct *mm, + unsigned long addr) +{ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + bool referenced = false; + struct page *page = pmd_page(*pmd); + + if (pmd_young(*pmd)) { + referenced = true; + *pmd = pmd_mkold(*pmd); + } + +#ifdef CONFIG_MMU_NOTIFIER + if (mmu_notifier_clear_young(mm, addr, + addr + ((1UL) << HPAGE_PMD_SHIFT))) + referenced = true; +#endif /* CONFIG_MMU_NOTIFIER */ + + if (referenced) + set_page_young(page); + + set_page_idle(page); +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ +} + +void damon_va_mkold(struct mm_struct *mm, unsigned long addr) +{ + pte_t *pte = NULL; + pmd_t *pmd = NULL; + spinlock_t *ptl; + + if (follow_pte_pmd(mm, addr, NULL, &pte, &pmd, &ptl)) + return; + + if (pte) { + damon_ptep_mkold(pte, mm, addr); + pte_unmap_unlock(pte, ptl); + } else { + damon_pmdp_mkold(pmd, mm, addr); + spin_unlock(ptl); + } +} + +bool damon_va_young(struct mm_struct *mm, unsigned long addr, + unsigned long *page_sz) +{ + pte_t *pte = NULL; + pmd_t *pmd = NULL; + spinlock_t *ptl; + bool young = false; + + if (follow_pte_pmd(mm, addr, NULL, &pte, &pmd, &ptl)) + return false; + + *page_sz = PAGE_SIZE; + if (pte) { + young = pte_young(*pte); + if (!young) + young = !page_is_idle(pte_page(*pte)); + pte_unmap_unlock(pte, ptl); + return young; + } + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + young = pmd_young(*pmd); + if (!young) + young = !page_is_idle(pmd_page(*pmd)); + spin_unlock(ptl); + *page_sz = ((1UL) << HPAGE_PMD_SHIFT); +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + + return young; +} diff --git a/mm/damon/prmtv-common.h b/mm/damon/prmtv-common.h new file mode 100644 index 000000000000..a66a6139b4fc --- /dev/null +++ b/mm/damon/prmtv-common.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Common Primitives for Data Access Monitoring + * + * Author: SeongJae Park + */ + +#include +#include +#include +#include +#include +#include +#include + +/* Get a random number in [l, r) */ +#define damon_rand(l, r) (l + prandom_u32_max(r - l)) + +void damon_va_mkold(struct mm_struct *mm, unsigned long addr); +bool damon_va_young(struct mm_struct *mm, unsigned long addr, + unsigned long *page_sz); diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 2075f07f728b..915b12329c6e 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -8,22 +8,14 @@ #define pr_fmt(fmt) "damon-va: " fmt #include -#include -#include -#include -#include -#include -#include -#include + +#include "prmtv-common.h" #ifdef CONFIG_DAMON_VADDR_KUNIT_TEST #undef DAMON_MIN_REGION #define DAMON_MIN_REGION 1 #endif -/* Get a random number in [l, r) */ -#define damon_rand(l, r) (l + prandom_u32_max(r - l)) - /* * 't->id' should be the pointer to the relevant 'struct pid' having reference * count. Caller must put the returned task, unless it is NULL. @@ -370,71 +362,6 @@ void damon_va_update_regions(struct damon_ctx *ctx) } } -static void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, - unsigned long addr) -{ - bool referenced = false; - struct page *page = pte_page(*pte); - - if (pte_young(*pte)) { - referenced = true; - *pte = pte_mkold(*pte); - } - -#ifdef CONFIG_MMU_NOTIFIER - if (mmu_notifier_clear_young(mm, addr, addr + PAGE_SIZE)) - referenced = true; -#endif /* CONFIG_MMU_NOTIFIER */ - - if (referenced) - set_page_young(page); - - set_page_idle(page); -} - -static void damon_pmdp_mkold(pmd_t *pmd, struct mm_struct *mm, - unsigned long addr) -{ -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - bool referenced = false; - struct page *page = pmd_page(*pmd); - - if (pmd_young(*pmd)) { - referenced = true; - *pmd = pmd_mkold(*pmd); - } - -#ifdef CONFIG_MMU_NOTIFIER - if (mmu_notifier_clear_young(mm, addr, - addr + ((1UL) << HPAGE_PMD_SHIFT))) - referenced = true; -#endif /* CONFIG_MMU_NOTIFIER */ - - if (referenced) - set_page_young(page); - - set_page_idle(page); -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -} - -static void damon_va_mkold(struct mm_struct *mm, unsigned long addr) -{ - pte_t *pte = NULL; - pmd_t *pmd = NULL; - spinlock_t *ptl; - - if (follow_pte_pmd(mm, addr, NULL, &pte, &pmd, &ptl)) - return; - - if (pte) { - damon_ptep_mkold(pte, mm, addr); - pte_unmap_unlock(pte, ptl); - } else { - damon_pmdp_mkold(pmd, mm, addr); - spin_unlock(ptl); - } -} - /* * Functions for the access checking of the regions */ @@ -463,37 +390,6 @@ void damon_va_prepare_access_checks(struct damon_ctx *ctx) } } -static bool damon_va_young(struct mm_struct *mm, unsigned long addr, - unsigned long *page_sz) -{ - pte_t *pte = NULL; - pmd_t *pmd = NULL; - spinlock_t *ptl; - bool young = false; - - if (follow_pte_pmd(mm, addr, NULL, &pte, &pmd, &ptl)) - return false; - - *page_sz = PAGE_SIZE; - if (pte) { - young = pte_young(*pte); - if (!young) - young = !page_is_idle(pte_page(*pte)); - pte_unmap_unlock(pte, ptl); - return young; - } - -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - young = pmd_young(*pmd); - if (!young) - young = !page_is_idle(pmd_page(*pmd)); - spin_unlock(ptl); - *page_sz = ((1UL) << HPAGE_PMD_SHIFT); -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ - - return young; -} - /* * Check whether the region was accessed after the last preparation * From patchwork Wed Dec 16 09:42:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4034CC4361B for ; Wed, 16 Dec 2020 09:46:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A116723123 for ; Wed, 16 Dec 2020 09:46:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A116723123 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 1FAC26B006C; Wed, 16 Dec 2020 04:46:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 184D76B0071; Wed, 16 Dec 2020 04:46:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04C776B0072; Wed, 16 Dec 2020 04:46:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id DDC346B006C for ; Wed, 16 Dec 2020 04:46:06 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8884510FD0 for ; Wed, 16 Dec 2020 09:46:06 +0000 (UTC) X-FDA: 77598664332.02.rule28_5e1384b2742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 6A22110097AA0 for ; Wed, 16 Dec 2020 09:46:06 +0000 (UTC) X-HE-Tag: rule28_5e1384b2742b X-Filterd-Recvd-Size: 11667 Received: from smtp-fw-9101.amazon.com (smtp-fw-9101.amazon.com [207.171.184.25]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608111966; x=1639647966; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=SUQT16FeXJgUgtw4aF8cUXAdkk10Wp5q3gpjNNGwgdo=; b=fF6mCZYN58ojOPGVgaOSl4NZiU9wUVNEPdpD7Jojy5UXUWCyxi/wWn0u N8hLpDTUp6rZzthWT0ULOmIDj5fhyfrfNIuw217Q/RgFKM2ogMuJ2FdKB CbvE8Q0X6ES8sxDdblNQ1nKS2ZqBsxK2To4/MPEVhcplJ09KIBoScYBq8 0=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="96475241" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 16 Dec 2020 09:45:57 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com (Postfix) with ESMTPS id 50515C1D11; Wed, 16 Dec 2020 09:45:53 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:44:58 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 07/13] mm/damon: Implement primitives for physical address space monitoring Date: Wed, 16 Dec 2020 10:42:15 +0100 Message-ID: <20201216094221.11898-8-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit implements the primitives for the basic access monitoring of the physical memory address space. By using this, users can easily monitor the accesses to the physical memory. Internally, it uses the PTE Accessed bit, as similar to that of the virtual memory support. Also, it supports only user memory pages, as idle page tracking also does, for the same reason. If the monitoring target physical memory address range contains non-user memory pages, access check of the pages will do nothing but simply treat the pages as not accessed. Users who want to use other access check primitives and/or monitor the non-user memory regions could implement and use their own callbacks. Signed-off-by: SeongJae Park --- include/linux/damon.h | 10 ++ mm/damon/Kconfig | 9 ++ mm/damon/Makefile | 1 + mm/damon/paddr.c | 222 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 242 insertions(+) create mode 100644 mm/damon/paddr.c diff --git a/include/linux/damon.h b/include/linux/damon.h index ed7e86207e53..ea2fd054b2ef 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -376,4 +376,14 @@ void damon_va_set_primitives(struct damon_ctx *ctx); #endif /* CONFIG_DAMON_VADDR */ +#ifdef CONFIG_DAMON_PADDR + +/* Monitoring primitives for the physical memory address space */ +void damon_pa_prepare_access_checks(struct damon_ctx *ctx); +unsigned int damon_pa_check_accesses(struct damon_ctx *ctx); +bool damon_pa_target_valid(void *t); +void damon_pa_set_primitives(struct damon_ctx *ctx); + +#endif /* CONFIG_DAMON_PADDR */ + #endif /* _DAMON_H */ diff --git a/mm/damon/Kconfig b/mm/damon/Kconfig index 455995152697..89c06ac8c9eb 100644 --- a/mm/damon/Kconfig +++ b/mm/damon/Kconfig @@ -33,6 +33,15 @@ config DAMON_VADDR This builds the default data access monitoring primitives for DAMON that works for virtual address spaces. +config DAMON_PADDR + bool "Data access monitoring primitives for the physical address space" + depends on DAMON && MMU + select PAGE_EXTENSION if !64BIT + select PAGE_IDLE_FLAG + help + This builds the default data access monitoring primitives for DAMON + that works for physical address spaces. + config DAMON_VADDR_KUNIT_TEST bool "Test for DAMON primitives" if !KUNIT_ALL_TESTS depends on DAMON_VADDR && KUNIT=y diff --git a/mm/damon/Makefile b/mm/damon/Makefile index 99b1bfe01ff5..8d9b0df79702 100644 --- a/mm/damon/Makefile +++ b/mm/damon/Makefile @@ -2,4 +2,5 @@ obj-$(CONFIG_DAMON) := core.o obj-$(CONFIG_DAMON_VADDR) += prmtv-common.o vaddr.o +obj-$(CONFIG_DAMON_PADDR) += prmtv-common.o paddr.o obj-$(CONFIG_DAMON_DBGFS) += dbgfs.o diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c new file mode 100644 index 000000000000..b120f672cc57 --- /dev/null +++ b/mm/damon/paddr.c @@ -0,0 +1,222 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * DAMON Primitives for The Physical Address Space + * + * Author: SeongJae Park + */ + +#define pr_fmt(fmt) "damon-pa: " fmt + +#include + +#include "prmtv-common.h" + +/* + * This has no implementations for 'init_target_regions()' and + * 'update_target_regions()'. Users should set the initial regions and update + * regions by themselves in the 'before_start' and 'after_aggregation' + * callbacks, respectively. Or, they can implement and use their own version + * of the primitives. + */ + +/* + * Get a page by pfn if it is in the LRU list. Otherwise, returns NULL. + * + * The body of this function is stollen from the 'page_idle_get_page()'. We + * steal rather than reuse it because the code is quite simple. + */ +static struct page *damon_pa_get_page(unsigned long pfn) +{ + struct page *page = pfn_to_online_page(pfn); + pg_data_t *pgdat; + + if (!page || !PageLRU(page) || + !get_page_unless_zero(page)) + return NULL; + + pgdat = page_pgdat(page); + spin_lock_irq(&pgdat->lru_lock); + if (unlikely(!PageLRU(page))) { + put_page(page); + page = NULL; + } + spin_unlock_irq(&pgdat->lru_lock); + return page; +} + +static bool __damon_pa_mkold(struct page *page, struct vm_area_struct *vma, + unsigned long addr, void *arg) +{ + damon_va_mkold(vma->vm_mm, addr); + return true; +} + +static void damon_pa_mkold(unsigned long paddr) +{ + struct page *page = damon_pa_get_page(PHYS_PFN(paddr)); + struct rmap_walk_control rwc = { + .rmap_one = __damon_pa_mkold, + .anon_lock = page_lock_anon_vma_read, + }; + bool need_lock; + + if (!page) + return; + + if (!page_mapped(page) || !page_rmapping(page)) { + set_page_idle(page); + put_page(page); + return; + } + + need_lock = !PageAnon(page) || PageKsm(page); + if (need_lock && !trylock_page(page)) { + put_page(page); + return; + } + + rmap_walk(page, &rwc); + + if (need_lock) + unlock_page(page); + put_page(page); +} + +static void __damon_pa_prepare_access_check(struct damon_ctx *ctx, + struct damon_region *r) +{ + r->sampling_addr = damon_rand(r->ar.start, r->ar.end); + + damon_pa_mkold(r->sampling_addr); +} + +void damon_pa_prepare_access_checks(struct damon_ctx *ctx) +{ + struct damon_target *t; + struct damon_region *r; + + damon_for_each_target(t, ctx) { + damon_for_each_region(r, t) + __damon_pa_prepare_access_check(ctx, r); + } +} + +struct damon_pa_access_chk_result { + unsigned long page_sz; + bool accessed; +}; + +static bool damon_pa_accessed(struct page *page, struct vm_area_struct *vma, + unsigned long addr, void *arg) +{ + struct damon_pa_access_chk_result *result = arg; + + result->accessed = damon_va_young(vma->vm_mm, addr, &result->page_sz); + + /* If accessed, stop walking */ + return !result->accessed; +} + +static bool damon_pa_young(unsigned long paddr, unsigned long *page_sz) +{ + struct page *page = damon_pa_get_page(PHYS_PFN(paddr)); + struct damon_pa_access_chk_result result = { + .page_sz = PAGE_SIZE, + .accessed = false, + }; + struct rmap_walk_control rwc = { + .arg = &result, + .rmap_one = damon_pa_accessed, + .anon_lock = page_lock_anon_vma_read, + }; + bool need_lock; + + if (!page) + return false; + + if (!page_mapped(page) || !page_rmapping(page)) { + if (page_is_idle(page)) + result.accessed = false; + else + result.accessed = true; + put_page(page); + goto out; + } + + need_lock = !PageAnon(page) || PageKsm(page); + if (need_lock && !trylock_page(page)) { + put_page(page); + return NULL; + } + + rmap_walk(page, &rwc); + + if (need_lock) + unlock_page(page); + put_page(page); + +out: + *page_sz = result.page_sz; + return result.accessed; +} + +/* + * Check whether the region was accessed after the last preparation + * + * mm 'mm_struct' for the given virtual address space + * r the region of physical address space that needs to be checked + */ +static void __damon_pa_check_access(struct damon_ctx *ctx, + struct damon_region *r) +{ + static unsigned long last_addr; + static unsigned long last_page_sz = PAGE_SIZE; + static bool last_accessed; + + /* If the region is in the last checked page, reuse the result */ + if (ALIGN_DOWN(last_addr, last_page_sz) == + ALIGN_DOWN(r->sampling_addr, last_page_sz)) { + if (last_accessed) + r->nr_accesses++; + return; + } + + last_accessed = damon_pa_young(r->sampling_addr, &last_page_sz); + if (last_accessed) + r->nr_accesses++; + + last_addr = r->sampling_addr; +} + +unsigned int damon_pa_check_accesses(struct damon_ctx *ctx) +{ + struct damon_target *t; + struct damon_region *r; + unsigned int max_nr_accesses = 0; + + damon_for_each_target(t, ctx) { + damon_for_each_region(r, t) { + __damon_pa_check_access(ctx, r); + max_nr_accesses = max(r->nr_accesses, max_nr_accesses); + } + } + + return max_nr_accesses; +} + +bool damon_pa_target_valid(void *t) +{ + return true; +} + +void damon_pa_set_primitives(struct damon_ctx *ctx) +{ + ctx->primitive.init_target_regions = NULL; + ctx->primitive.update_target_regions = NULL; + ctx->primitive.prepare_access_checks = damon_pa_prepare_access_checks; + ctx->primitive.check_accesses = damon_pa_check_accesses; + ctx->primitive.reset_aggregated = NULL; + ctx->primitive.target_valid = damon_pa_target_valid; + ctx->primitive.cleanup = NULL; + ctx->primitive.apply_scheme = NULL; +} From patchwork Wed Dec 16 09:42:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F16D3C4361B for ; Wed, 16 Dec 2020 09:49:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 829332313B for ; Wed, 16 Dec 2020 09:49:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 829332313B 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 0489F6B0072; Wed, 16 Dec 2020 04:49:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 002306B0073; Wed, 16 Dec 2020 04:49:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E53086B0074; Wed, 16 Dec 2020 04:49:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id CC3B56B0072 for ; Wed, 16 Dec 2020 04:49:31 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8B52B8249980 for ; Wed, 16 Dec 2020 09:49:31 +0000 (UTC) X-FDA: 77598672942.12.steel38_54180f72742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 5F95818054D2D for ; Wed, 16 Dec 2020 09:49:31 +0000 (UTC) X-HE-Tag: steel38_54180f72742b X-Filterd-Recvd-Size: 5368 Received: from smtp-fw-9103.amazon.com (smtp-fw-9103.amazon.com [207.171.188.200]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608112170; x=1639648170; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=jk1a1eNXyHawqdXbc/seXg9Qwshk6tmctCaAv0I6QJY=; b=stWTVIo3oDNPxYQKhdmGxUNbhgCeWUhYdlQn5ecpzPsfhfgkdsIG1edA UJB1D8ldT5yoMmYqc/EMOODRZ5F/9ILor/3zQcsbDEbxJITdrt+O17K1S kExdlGgtfnG+NbS5Wvq0j4cVHgAt6bP5ks7tcltCx30VuNyDpythIrrCK 4=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="903546665" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9103.sea19.amazon.com with ESMTP; 16 Dec 2020 09:49:28 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com (Postfix) with ESMTPS id CCD37C1D03; Wed, 16 Dec 2020 09:45:57 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:45:24 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 08/13] damon/dbgfs: Support physical memory monitoring Date: Wed, 16 Dec 2020 10:42:16 +0100 Message-ID: <20201216094221.11898-9-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit makes the 'damon-dbgfs' to support the physical memory monitoring, in addition to the virtual memory monitoring. Users can do the physical memory monitoring by writing a special keyword, 'paddr\n' to the 'pids' debugfs file. Then, DAMON will check the special keyword and configure the monitoring context to run using the primitives for physical memory. This will internally add one fake monitoring target process, which has target id 42. Unlike the virtual memory monitoring, the monitoring target region will not be automatically set. Therefore, users should also set the monitoring target address region using the 'init_regions' debugfs file. Finally, the physical memory monitoring will not automatically terminated. The user should explicitly turn off the monitoring by writing 'off' to the 'monitor_on' debugfs file. Signed-off-by: SeongJae Park --- mm/damon/Kconfig | 2 +- mm/damon/dbgfs.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/damon/Kconfig b/mm/damon/Kconfig index 89c06ac8c9eb..38f4cfce72dd 100644 --- a/mm/damon/Kconfig +++ b/mm/damon/Kconfig @@ -56,7 +56,7 @@ config DAMON_VADDR_KUNIT_TEST config DAMON_DBGFS bool "DAMON debugfs interface" - depends on DAMON_VADDR && DEBUG_FS + depends on DAMON_VADDR && DAMON_PADDR && DEBUG_FS help This builds the debugfs interface for DAMON. The user space admins can use the interface for arbitrary data access monitoring. diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index 2f1ec6ebd9f0..ea03d7d5b879 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -462,6 +462,15 @@ static ssize_t dbgfs_target_ids_write(struct file *file, return PTR_ERR(kbuf); nrs = kbuf; + if (!strncmp(kbuf, "paddr\n", count)) { + /* Configure the context for physical memory monitoring */ + damon_pa_set_primitives(ctx); + /* target id is meaningless here, but we set it just for fun */ + scnprintf(kbuf, count, "42 "); + } else { + /* Configure the context for virtual memory monitoring */ + damon_va_set_primitives(ctx); + } targets = str_to_target_ids(nrs, ret, &nr_targets); if (!targets) { From patchwork Wed Dec 16 09:42:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CFBEC4361B for ; Wed, 16 Dec 2020 09:46:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFC6123124 for ; Wed, 16 Dec 2020 09:46:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFC6123124 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 61AEC6B0071; Wed, 16 Dec 2020 04:46:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A2FF6B0072; Wed, 16 Dec 2020 04:46:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4957B6B0073; Wed, 16 Dec 2020 04:46:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0141.hostedemail.com [216.40.44.141]) by kanga.kvack.org (Postfix) with ESMTP id 328406B0071 for ; Wed, 16 Dec 2020 04:46:11 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id EF73D8249980 for ; Wed, 16 Dec 2020 09:46:10 +0000 (UTC) X-FDA: 77598664500.10.trick44_0d135462742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id CD46C16A4AB for ; Wed, 16 Dec 2020 09:46:10 +0000 (UTC) X-HE-Tag: trick44_0d135462742b X-Filterd-Recvd-Size: 6034 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608111970; x=1639647970; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=kg6Pid/S3uyECtsR9/ZQNoRBSFk6tXHhc71xqlOp1H8=; b=IlUMkzsM5C8+Cxxz3dG4YJSBvJJyDja/PFU8pFCMc/A3E+LbiaYmI0Uc aUu3wxzVfVpdH+b4MzT/NV48hp6X04rBZKkrat80hBaorg9/p26QtE6m6 Ag0eFAacLjO6K+pze6KW0LyuNPcly1Samdxo1VTTlHfGcGUaj428NqYQ7 U=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="103495486" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-22cc717f.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 16 Dec 2020 09:46:09 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-22cc717f.us-west-2.amazon.com (Postfix) with ESMTPS id 62653A1BCB; Wed, 16 Dec 2020 09:46:05 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:45:48 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 09/13] tools/damon/record: Support physical memory monitoring Date: Wed, 16 Dec 2020 10:42:17 +0100 Message-ID: <20201216094221.11898-10-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit allows users to record the data accesses on physical memory address space by passing 'paddr' as target to 'damo-record'. If the init regions are given, the regions will be monitored. Else, it will monitor biggest conitguous 'System RAM' region in '/proc/iomem' and monitor the region. Signed-off-by: SeongJae Park --- tools/damon/_damon.py | 2 ++ tools/damon/record.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/damon/_damon.py b/tools/damon/_damon.py index a22ec3777c16..6ff278117e84 100644 --- a/tools/damon/_damon.py +++ b/tools/damon/_damon.py @@ -27,6 +27,8 @@ def set_target(tid, init_regions=[]): if not os.path.exists(debugfs_init_regions): return 0 + if tid == 'paddr': + tid = 42 string = ' '.join(['%s %d %d' % (tid, r[0], r[1]) for r in init_regions]) return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions), shell=True, executable='/bin/bash') diff --git a/tools/damon/record.py b/tools/damon/record.py index 11fd54001472..6fd0b59c73e0 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -101,6 +101,29 @@ def set_argparser(parser): parser.add_argument('-o', '--out', metavar='', type=str, default='damon.data', help='output file path') +def default_paddr_region(): + "Largest System RAM region becomes the default" + ret = [] + with open('/proc/iomem', 'r') as f: + # example of the line: '100000000-42b201fff : System RAM' + for line in f: + fields = line.split(':') + if len(fields) != 2: + continue + name = fields[1].strip() + if name != 'System RAM': + continue + addrs = fields[0].split('-') + if len(addrs) != 2: + continue + start = int(addrs[0], 16) + end = int(addrs[1], 16) + + sz_region = end - start + if not ret or sz_region > (ret[1] - ret[0]): + ret = [start, end] + return ret + def main(args=None): global orig_attrs if not args: @@ -122,7 +145,11 @@ def main(args=None): target = args.target target_fields = target.split() - if not subprocess.call('which %s &> /dev/null' % target_fields[0], + if target == 'paddr': # physical memory address space + if not init_regions: + init_regions = [default_paddr_region()] + do_record(target, False, init_regions, new_attrs, orig_attrs, pidfd) + elif not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): do_record(target, True, init_regions, new_attrs, orig_attrs, pidfd) else: From patchwork Wed Dec 16 09:42:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B787C4361B for ; Wed, 16 Dec 2020 09:46:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 911F52313B for ; Wed, 16 Dec 2020 09:46:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 911F52313B 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 185A46B0072; Wed, 16 Dec 2020 04:46:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 135258D0003; Wed, 16 Dec 2020 04:46:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 024AF8D0002; Wed, 16 Dec 2020 04:46:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id DC4586B0072 for ; Wed, 16 Dec 2020 04:46:48 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9D59811924 for ; Wed, 16 Dec 2020 09:46:48 +0000 (UTC) X-FDA: 77598666096.02.pen88_130569f2742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 8053E10097AA1 for ; Wed, 16 Dec 2020 09:46:48 +0000 (UTC) X-HE-Tag: pen88_130569f2742b X-Filterd-Recvd-Size: 10285 Received: from smtp-fw-4101.amazon.com (smtp-fw-4101.amazon.com [72.21.198.25]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:46:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608112008; x=1639648008; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=VIt0QPHvmvqG4Kch/PM9e/Zwtiyux2gOnoeb9rYl0nc=; b=AAic3abPSbbIav3NNMa2OVfVqAi0wDjOwznYOQhKethh76BquvWVL0H/ VTEKV+tSUOeJ5+VF6p3BOYy+olQMHklgDV5Mgie5qlJPjUS6taP/9RRws 8CXpjKk1i4xoli5heXg6lWq7Mh97V2XzPYJaf7435bEbpLQLuAqCbI2Oy 0=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="69704117" 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-4101.iad4.amazon.com with ESMTP; 16 Dec 2020 09:46:45 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com (Postfix) with ESMTPS id 069A0A07ED; Wed, 16 Dec 2020 09:46:41 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:46:23 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 10/13] tools/damon/record: Support NUMA specific recording Date: Wed, 16 Dec 2020 10:42:18 +0100 Message-ID: <20201216094221.11898-11-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit updates the DAMON user space tool (damo-record) for NUMA specific physical memory monitoring. With this change, users can monitor accesses to physical memory of specific NUMA node. Signed-off-by: SeongJae Park --- tools/damon/_paddr_layout.py | 147 +++++++++++++++++++++++++++++++++++ tools/damon/record.py | 18 ++++- 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 tools/damon/_paddr_layout.py diff --git a/tools/damon/_paddr_layout.py b/tools/damon/_paddr_layout.py new file mode 100644 index 000000000000..561c2b6729f6 --- /dev/null +++ b/tools/damon/_paddr_layout.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import os + +class PaddrRange: + start = None + end = None + nid = None + state = None + name = None + + def __init__(self, start, end, nid, state, name): + self.start = start + self.end = end + self.nid = nid + self.state = state + self.name = name + + def interleaved(self, prange): + if self.end <= prange.start: + return None + if prange.end <= self.start: + return None + return [max(self.start, prange.start), min(self.end, prange.end)] + + def __str__(self): + return '%x-%x, nid %s, state %s, name %s' % (self.start, self.end, + self.nid, self.state, self.name) + +class MemBlock: + nid = None + index = None + state = None + + def __init__(self, nid, index, state): + self.nid = nid + self.index = index + self.state = state + + def __str__(self): + return '%d (%s)' % (self.index, self.state) + + def __repr__(self): + return self.__str__() + +def readfile(file_path): + with open(file_path, 'r') as f: + return f.read() + +def collapse_ranges(ranges): + ranges = sorted(ranges, key=lambda x: x.start) + merged = [] + for r in ranges: + if not merged: + merged.append(r) + continue + last = merged[-1] + if last.end != r.start or last.nid != r.nid or last.state != r.state: + merged.append(r) + else: + last.end = r.end + return merged + +def memblocks_to_ranges(blocks, block_size): + ranges = [] + for b in blocks: + ranges.append(PaddrRange(b.index * block_size, + (b.index + 1) * block_size, b.nid, b.state, None)) + + return collapse_ranges(ranges) + +def memblock_ranges(): + SYSFS='/sys/devices/system/node' + sz_block = int(readfile('/sys/devices/system/memory/block_size_bytes'), 16) + sys_nodes = [x for x in os.listdir(SYSFS) if x.startswith('node')] + + blocks = [] + for sys_node in sys_nodes: + nid = int(sys_node[4:]) + + sys_node_files = os.listdir(os.path.join(SYSFS, sys_node)) + for f in sys_node_files: + if not f.startswith('memory'): + continue + index = int(f[6:]) + sys_state = os.path.join(SYSFS, sys_node, f, 'state') + state = readfile(sys_state).strip() + + blocks.append(MemBlock(nid, index, state)) + + return memblocks_to_ranges(blocks, sz_block) + +def iomem_ranges(): + ranges = [] + + with open('/proc/iomem', 'r') as f: + # example of the line: '100000000-42b201fff : System RAM' + for line in f: + fields = line.split(':') + if len(fields) < 2: + continue + name = ':'.join(fields[1:]).strip() + addrs = fields[0].split('-') + if len(addrs) != 2: + continue + start = int(addrs[0], 16) + end = int(addrs[1], 16) + 1 + ranges.append(PaddrRange(start, end, None, None, name)) + + return ranges + +def integrate(memblock_parsed, iomem_parsed): + merged = [] + + for r in iomem_parsed: + for r2 in memblock_parsed: + if r2.start <= r.start and r.end <= r2.end: + r.nid = r2.nid + r.state = r2.state + merged.append(r) + elif r2.start <= r.start and r.start < r2.end and r2.end < r.end: + sub = PaddrRange(r2.end, r.end, None, None, r.name) + iomem_parsed.append(sub) + r.end = r2.end + r.nid = r2.nid + r.state = r2.state + merged.append(r) + merged = sorted(merged, key=lambda x: x.start) + return merged + +def paddr_ranges(): + return integrate(memblock_ranges(), iomem_ranges()) + +def pr_ranges(ranges): + print('#%12s %13s\tnode\tstate\tresource\tsize' % ('start', 'end')) + for r in ranges: + print('%13d %13d\t%s\t%s\t%s\t%d' % (r.start, r.end, r.nid, + r.state, r.name, r.end - r.start)) + +def main(): + ranges = paddr_ranges() + + pr_ranges(ranges) + +if __name__ == '__main__': + main() diff --git a/tools/damon/record.py b/tools/damon/record.py index 6fd0b59c73e0..e9d6bfc70ead 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -12,6 +12,7 @@ import subprocess import time import _damon +import _paddr_layout def pidfd_open(pid): import ctypes @@ -98,6 +99,8 @@ def set_argparser(parser): help='use pidfd type target id') parser.add_argument('-l', '--rbuf', metavar='', type=int, default=1024*1024, help='length of record result buffer') + parser.add_argument('--numa_node', metavar='', type=int, + help='if target is \'paddr\', limit it to the numa node') parser.add_argument('-o', '--out', metavar='', type=str, default='damon.data', help='output file path') @@ -124,6 +127,15 @@ def default_paddr_region(): ret = [start, end] return ret +def paddr_region_of(numa_node): + regions = [] + paddr_ranges = _paddr_layout.paddr_ranges() + for r in paddr_ranges: + if r.nid == numa_node and r.name == 'System RAM': + regions.append([r.start, r.end]) + + return regions + def main(args=None): global orig_attrs if not args: @@ -142,12 +154,16 @@ def main(args=None): pidfd = args.pidfd new_attrs = _damon.cmd_args_to_attrs(args) init_regions = _damon.cmd_args_to_init_regions(args) + numa_node = args.numa_node target = args.target target_fields = target.split() if target == 'paddr': # physical memory address space if not init_regions: - init_regions = [default_paddr_region()] + if numa_node: + init_regions = paddr_region_of(numa_node) + else: + init_regions = [default_paddr_region()] do_record(target, False, init_regions, new_attrs, orig_attrs, pidfd) elif not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): From patchwork Wed Dec 16 09:42:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C265C4361B for ; Wed, 16 Dec 2020 09:51:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AD1322313B for ; Wed, 16 Dec 2020 09:51:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD1322313B 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 1F0D76B0073; Wed, 16 Dec 2020 04:51:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A1206B0074; Wed, 16 Dec 2020 04:51:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0920B8D0002; Wed, 16 Dec 2020 04:51:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id E72CC6B0073 for ; Wed, 16 Dec 2020 04:51:53 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B2E4B19B3B for ; Wed, 16 Dec 2020 09:51:53 +0000 (UTC) X-FDA: 77598678906.03.root67_5004e6e2742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 959A528A4E8 for ; Wed, 16 Dec 2020 09:51:53 +0000 (UTC) X-HE-Tag: root67_5004e6e2742b X-Filterd-Recvd-Size: 12226 Received: from smtp-fw-9103.amazon.com (smtp-fw-9103.amazon.com [207.171.188.200]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:51:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608112312; x=1639648312; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qGKT1F1qVkIMFajZCvJm8BTClvxWeUPf3j13t8snc08=; b=S9mfGPH6TlpAbKZhPCDQXIYkTaXujw2YuXVw/YQ8SdSoW8SMsdmjIQjj qG0NmEpIbKmz7Z/OZ8EUxO1u+rKOW7msQeZeFUeUSSiyCDPXr5HOU6ZgQ uLV4dpREju0NJ/VIw/3WgAf67K4hAuUa9b36ybjgr19fU0asSxk1S330V s=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="903547195" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2c-87a10be6.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9103.sea19.amazon.com with ESMTP; 16 Dec 2020 09:51:51 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2c-87a10be6.us-west-2.amazon.com (Postfix) with ESMTPS id EB466A0262; Wed, 16 Dec 2020 09:47:19 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:47:02 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 11/13] Docs/DAMON: Document physical memory monitoring support Date: Wed, 16 Dec 2020 10:42:19 +0100 Message-ID: <20201216094221.11898-12-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit 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? From patchwork Wed Dec 16 09:42:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11977145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD840C4361B for ; Wed, 16 Dec 2020 09:47:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 44AE623123 for ; Wed, 16 Dec 2020 09:47:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44AE623123 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 C0A316B006C; Wed, 16 Dec 2020 04:47:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B92E66B0071; Wed, 16 Dec 2020 04:47:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A821C6B0073; Wed, 16 Dec 2020 04:47:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0186.hostedemail.com [216.40.44.186]) by kanga.kvack.org (Postfix) with ESMTP id 916A46B006C for ; Wed, 16 Dec 2020 04:47:46 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5A241181AF5F4 for ; Wed, 16 Dec 2020 09:47:46 +0000 (UTC) X-FDA: 77598668532.25.fowl37_4b161a02742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 371231814904B for ; Wed, 16 Dec 2020 09:47:46 +0000 (UTC) X-HE-Tag: fowl37_4b161a02742b X-Filterd-Recvd-Size: 10642 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:47: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=1608112066; x=1639648066; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=OfAxiI1TGWAm938TQnf2Mv9tv9ZVjwG7ArzBDalULAM=; b=sJ53I7/Pap+zgm8gP+tFXpZi7ePwl0qSPwm2qtrtuY7mQ7erm0K4aUHA roTBQ6kMKL7R8yrcegIk8d1qSMMgSK5VXmEXBydu1MDIq19FxjopeP5zs sfUOe4XJF2ks99yas/zwTVeBJJ794uKVQXFxIGkiSoyZLGJmxLw6TyoFo c=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="71565777" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-41350382.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 16 Dec 2020 09:47:43 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-41350382.us-west-2.amazon.com (Postfix) with ESMTPS id A18FAC28E8; Wed, 16 Dec 2020 09:47:39 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:47:21 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 12/13] mm/damon/paddr: Separate commonly usable functions Date: Wed, 16 Dec 2020 10:42:20 +0100 Message-ID: <20201216094221.11898-13-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit moves functions in the default physical address space monitoring primitives that commonly usable from other use cases like page granularity idleness monitoring to prmtv-common. Signed-off-by: SeongJae Park --- mm/damon/paddr.c | 122 ---------------------------------------- mm/damon/prmtv-common.c | 122 ++++++++++++++++++++++++++++++++++++++++ mm/damon/prmtv-common.h | 4 ++ 3 files changed, 126 insertions(+), 122 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index b120f672cc57..143ddc0e5917 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -19,69 +19,6 @@ * of the primitives. */ -/* - * Get a page by pfn if it is in the LRU list. Otherwise, returns NULL. - * - * The body of this function is stollen from the 'page_idle_get_page()'. We - * steal rather than reuse it because the code is quite simple. - */ -static struct page *damon_pa_get_page(unsigned long pfn) -{ - struct page *page = pfn_to_online_page(pfn); - pg_data_t *pgdat; - - if (!page || !PageLRU(page) || - !get_page_unless_zero(page)) - return NULL; - - pgdat = page_pgdat(page); - spin_lock_irq(&pgdat->lru_lock); - if (unlikely(!PageLRU(page))) { - put_page(page); - page = NULL; - } - spin_unlock_irq(&pgdat->lru_lock); - return page; -} - -static bool __damon_pa_mkold(struct page *page, struct vm_area_struct *vma, - unsigned long addr, void *arg) -{ - damon_va_mkold(vma->vm_mm, addr); - return true; -} - -static void damon_pa_mkold(unsigned long paddr) -{ - struct page *page = damon_pa_get_page(PHYS_PFN(paddr)); - struct rmap_walk_control rwc = { - .rmap_one = __damon_pa_mkold, - .anon_lock = page_lock_anon_vma_read, - }; - bool need_lock; - - if (!page) - return; - - if (!page_mapped(page) || !page_rmapping(page)) { - set_page_idle(page); - put_page(page); - return; - } - - need_lock = !PageAnon(page) || PageKsm(page); - if (need_lock && !trylock_page(page)) { - put_page(page); - return; - } - - rmap_walk(page, &rwc); - - if (need_lock) - unlock_page(page); - put_page(page); -} - static void __damon_pa_prepare_access_check(struct damon_ctx *ctx, struct damon_region *r) { @@ -101,65 +38,6 @@ void damon_pa_prepare_access_checks(struct damon_ctx *ctx) } } -struct damon_pa_access_chk_result { - unsigned long page_sz; - bool accessed; -}; - -static bool damon_pa_accessed(struct page *page, struct vm_area_struct *vma, - unsigned long addr, void *arg) -{ - struct damon_pa_access_chk_result *result = arg; - - result->accessed = damon_va_young(vma->vm_mm, addr, &result->page_sz); - - /* If accessed, stop walking */ - return !result->accessed; -} - -static bool damon_pa_young(unsigned long paddr, unsigned long *page_sz) -{ - struct page *page = damon_pa_get_page(PHYS_PFN(paddr)); - struct damon_pa_access_chk_result result = { - .page_sz = PAGE_SIZE, - .accessed = false, - }; - struct rmap_walk_control rwc = { - .arg = &result, - .rmap_one = damon_pa_accessed, - .anon_lock = page_lock_anon_vma_read, - }; - bool need_lock; - - if (!page) - return false; - - if (!page_mapped(page) || !page_rmapping(page)) { - if (page_is_idle(page)) - result.accessed = false; - else - result.accessed = true; - put_page(page); - goto out; - } - - need_lock = !PageAnon(page) || PageKsm(page); - if (need_lock && !trylock_page(page)) { - put_page(page); - return NULL; - } - - rmap_walk(page, &rwc); - - if (need_lock) - unlock_page(page); - put_page(page); - -out: - *page_sz = result.page_sz; - return result.accessed; -} - /* * Check whether the region was accessed after the last preparation * diff --git a/mm/damon/prmtv-common.c b/mm/damon/prmtv-common.c index 6cdb96cbc9ef..6c2e760e086c 100644 --- a/mm/damon/prmtv-common.c +++ b/mm/damon/prmtv-common.c @@ -102,3 +102,125 @@ bool damon_va_young(struct mm_struct *mm, unsigned long addr, return young; } + +/* + * Get a page by pfn if it is in the LRU list. Otherwise, returns NULL. + * + * The body of this function is stollen from the 'page_idle_get_page()'. We + * steal rather than reuse it because the code is quite simple. + */ +static struct page *damon_pa_get_page(unsigned long pfn) +{ + struct page *page = pfn_to_online_page(pfn); + pg_data_t *pgdat; + + if (!page || !PageLRU(page) || + !get_page_unless_zero(page)) + return NULL; + + pgdat = page_pgdat(page); + spin_lock_irq(&pgdat->lru_lock); + if (unlikely(!PageLRU(page))) { + put_page(page); + page = NULL; + } + spin_unlock_irq(&pgdat->lru_lock); + return page; +} + +static bool __damon_pa_mkold(struct page *page, struct vm_area_struct *vma, + unsigned long addr, void *arg) +{ + damon_va_mkold(vma->vm_mm, addr); + return true; +} + +void damon_pa_mkold(unsigned long paddr) +{ + struct page *page = damon_pa_get_page(PHYS_PFN(paddr)); + struct rmap_walk_control rwc = { + .rmap_one = __damon_pa_mkold, + .anon_lock = page_lock_anon_vma_read, + }; + bool need_lock; + + if (!page) + return; + + if (!page_mapped(page) || !page_rmapping(page)) { + set_page_idle(page); + put_page(page); + return; + } + + need_lock = !PageAnon(page) || PageKsm(page); + if (need_lock && !trylock_page(page)) { + put_page(page); + return; + } + + rmap_walk(page, &rwc); + + if (need_lock) + unlock_page(page); + put_page(page); +} + +struct damon_pa_access_chk_result { + unsigned long page_sz; + bool accessed; +}; + +static bool damon_pa_accessed(struct page *page, struct vm_area_struct *vma, + unsigned long addr, void *arg) +{ + struct damon_pa_access_chk_result *result = arg; + + result->accessed = damon_va_young(vma->vm_mm, addr, &result->page_sz); + + /* If accessed, stop walking */ + return !result->accessed; +} + +bool damon_pa_young(unsigned long paddr, unsigned long *page_sz) +{ + struct page *page = damon_pa_get_page(PHYS_PFN(paddr)); + struct damon_pa_access_chk_result result = { + .page_sz = PAGE_SIZE, + .accessed = false, + }; + struct rmap_walk_control rwc = { + .arg = &result, + .rmap_one = damon_pa_accessed, + .anon_lock = page_lock_anon_vma_read, + }; + bool need_lock; + + if (!page) + return false; + + if (!page_mapped(page) || !page_rmapping(page)) { + if (page_is_idle(page)) + result.accessed = false; + else + result.accessed = true; + put_page(page); + goto out; + } + + need_lock = !PageAnon(page) || PageKsm(page); + if (need_lock && !trylock_page(page)) { + put_page(page); + return NULL; + } + + rmap_walk(page, &rwc); + + if (need_lock) + unlock_page(page); + put_page(page); + +out: + *page_sz = result.page_sz; + return result.accessed; +} diff --git a/mm/damon/prmtv-common.h b/mm/damon/prmtv-common.h index a66a6139b4fc..fbe9452bd040 100644 --- a/mm/damon/prmtv-common.h +++ b/mm/damon/prmtv-common.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -19,3 +20,6 @@ void damon_va_mkold(struct mm_struct *mm, unsigned long addr); bool damon_va_young(struct mm_struct *mm, unsigned long addr, unsigned long *page_sz); + +void damon_pa_mkold(unsigned long paddr); +bool damon_pa_young(unsigned long paddr, unsigned long *page_sz); From patchwork Wed Dec 16 09:42: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: 11977147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3103FC4361B for ; Wed, 16 Dec 2020 09:48:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A955E2313B for ; Wed, 16 Dec 2020 09:48:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A955E2313B 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 2B9E66B0072; Wed, 16 Dec 2020 04:48:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 242F16B0073; Wed, 16 Dec 2020 04:48:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 158DD6B0074; Wed, 16 Dec 2020 04:48:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id F3C456B0072 for ; Wed, 16 Dec 2020 04:48:12 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id BF9551813708F for ; Wed, 16 Dec 2020 09:48:12 +0000 (UTC) X-FDA: 77598669624.21.elbow90_0b021872742b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 7FF9F1815525F for ; Wed, 16 Dec 2020 09:48:12 +0000 (UTC) X-HE-Tag: elbow90_0b021872742b X-Filterd-Recvd-Size: 9952 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 09:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608112092; x=1639648092; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=LG3J7fvqAIYDCK52FqgXfz7XsABi7oMW6Ndy9IE+r0A=; b=rFnCCo6I0jM40Q2mLMboZanLIZIysaPVRRvFZGGTH3XAar0nTBftuqah UHwQO67Q9kdsF9Z/Q6hPAQBWrZdttQYa6CFrxOvcJOTJ7kA1B5+0px1ms fASBHr0vmUSoFi1Wak0MWpZ1vKuILK+lLEPTVGbNHiF2MoUx7eKuuxqF0 w=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208";a="73004863" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 16 Dec 2020 09:48:02 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com (Postfix) with ESMTPS id 3797AA1CD2; Wed, 16 Dec 2020 09:47:59 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.31) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 09:47:41 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v10 13/13] mm/damon: Implement primitives for page granularity idleness monitoring Date: Wed, 16 Dec 2020 10:42:21 +0100 Message-ID: <20201216094221.11898-14-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216094221.11898-1-sjpark@amazon.com> References: <20201216094221.11898-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.31] X-ClientProxiedBy: EX13D16UWB001.ant.amazon.com (10.43.161.17) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park The lightweight and upper-bound limited monitoring overhead of DAMON is available due to its core mechanisms, namely region-based sampling and adaptive regions adjustment. However, there could be some use cases that don't need such fancy mechanisms. The page-granularity idleness monitoring is a good example. Because the metadata for DAMON's overhead control mechanism only wastes memory in such cases, DAMON allows users to eliminate such overhead using arbitrary type monitoring targets. This commit implements a monitoring primitive supporting the page-granularity idleness monitoring using the arbitrary type target feature. It's almost same to Idle Page Tracking, but incur much less kernel - user context changes compared to it. Nevertheless, this patch provides only kernel space API. This feature will be exported to the user space via the debugfs interface in near future. Signed-off-by: SeongJae Park --- include/linux/damon.h | 27 ++++++++++++++ include/trace/events/damon.h | 19 ++++++++++ mm/damon/Kconfig | 9 +++++ mm/damon/Makefile | 1 + mm/damon/paddr.c | 2 -- mm/damon/pgidle.c | 69 ++++++++++++++++++++++++++++++++++++ 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 mm/damon/pgidle.c diff --git a/include/linux/damon.h b/include/linux/damon.h index ea2fd054b2ef..220e59299f19 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -386,4 +386,31 @@ void damon_pa_set_primitives(struct damon_ctx *ctx); #endif /* CONFIG_DAMON_PADDR */ +#ifdef CONFIG_DAMON_PGIDLE + +/* + * struct damon_pfns_range - Represents a pfn range of [@start, @end). + * @start: Start pfn of the range (inclusive). + * @end: End pfn of the range (exclusive). + * + * In case of the page granularity idleness monitoring, an instance of this + * struct is pointed by &damon_ctx.arbitrary_target. + */ +struct damon_pfns_range { + unsigned long start; + unsigned long end; +}; + +bool damon_pgi_is_idle(unsigned long pfn, unsigned long *pg_size); + +/* Monitoring primitives for page granularity idleness monitoring */ + +void damon_pgi_prepare_access_checks(struct damon_ctx *ctx); +unsigned int damon_pgi_check_accesses(struct damon_ctx *ctx); +bool damon_pgi_target_valid(void *t); +void damon_pgi_set_primitives(struct damon_ctx *ctx); + +#endif /* CONFIG_DAMON_PGIDLE */ + + #endif /* _DAMON_H */ diff --git a/include/trace/events/damon.h b/include/trace/events/damon.h index 2f422f4f1fb9..f0c9f1d801cf 100644 --- a/include/trace/events/damon.h +++ b/include/trace/events/damon.h @@ -37,6 +37,25 @@ TRACE_EVENT(damon_aggregated, __entry->start, __entry->end, __entry->nr_accesses) ); +TRACE_EVENT(damon_pgi, + + TP_PROTO(unsigned long pfn, bool accessed), + + TP_ARGS(pfn, accessed), + + TP_STRUCT__entry( + __field(unsigned long, pfn) + __field(bool, accessed) + ), + + TP_fast_assign( + __entry->pfn = pfn; + __entry->accessed = accessed; + ), + + TP_printk("pfn=%lu accessed=%u", __entry->pfn, __entry->accessed) +); + #endif /* _TRACE_DAMON_H */ /* This part must be outside protection */ diff --git a/mm/damon/Kconfig b/mm/damon/Kconfig index 38f4cfce72dd..eeefb5b633b6 100644 --- a/mm/damon/Kconfig +++ b/mm/damon/Kconfig @@ -42,6 +42,15 @@ config DAMON_PADDR This builds the default data access monitoring primitives for DAMON that works for physical address spaces. +config DAMON_PGIDLE + bool "Data access monitoring primitives for page granularity idleness" + depends on DAMON && MMU + select PAGE_EXTENSION if !64BIT + select PAGE_IDLE_FLAG + help + This builds the default data access monitoring primitives for DAMON + that works for page granularity idleness monitoring. + config DAMON_VADDR_KUNIT_TEST bool "Test for DAMON primitives" if !KUNIT_ALL_TESTS depends on DAMON_VADDR && KUNIT=y diff --git a/mm/damon/Makefile b/mm/damon/Makefile index 8d9b0df79702..017799e5670a 100644 --- a/mm/damon/Makefile +++ b/mm/damon/Makefile @@ -3,4 +3,5 @@ obj-$(CONFIG_DAMON) := core.o obj-$(CONFIG_DAMON_VADDR) += prmtv-common.o vaddr.o obj-$(CONFIG_DAMON_PADDR) += prmtv-common.o paddr.o +obj-$(CONFIG_DAMON_PGIDLE) += prmtv-common.o pgidle.o obj-$(CONFIG_DAMON_DBGFS) += dbgfs.o diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 143ddc0e5917..95d7f3b745a9 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -7,8 +7,6 @@ #define pr_fmt(fmt) "damon-pa: " fmt -#include - #include "prmtv-common.h" /* diff --git a/mm/damon/pgidle.c b/mm/damon/pgidle.c new file mode 100644 index 000000000000..dd8297371eaf --- /dev/null +++ b/mm/damon/pgidle.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * DAMON Primitives for Page Granularity Idleness Monitoring + * + * Author: SeongJae Park + */ + +#define pr_fmt(fmt) "damon-pgi: " fmt + +#include + +#include "prmtv-common.h" + +#include + +bool damon_pgi_is_idle(unsigned long pfn, unsigned long *pg_size) +{ + return damon_pa_young(PFN_PHYS(pfn), pg_size); +} + +/* + * This has no implementations for 'init_target_regions()' and + * 'update_target_regions()'. Users should set the initial regions and update + * regions by themselves in the 'before_start' and 'after_aggregation' + * callbacks, respectively. Or, they can implement and use their own version + * of the primitives. + */ + +void damon_pgi_prepare_access_checks(struct damon_ctx *ctx) +{ + struct damon_pfns_range *target = ctx->arbitrary_target; + unsigned long pfn; + + for (pfn = target->start; pfn < target->end; pfn++) + damon_pa_mkold(PFN_PHYS(pfn)); +} + +unsigned int damon_pgi_check_accesses(struct damon_ctx *ctx) +{ + struct damon_pfns_range *target = ctx->arbitrary_target; + unsigned long pfn; + unsigned long pg_size = 0; + + for (pfn = target->start; pfn < target->end; pfn++) { + pg_size = 0; + trace_damon_pgi(pfn, damon_pa_young(PFN_PHYS(pfn), &pg_size)); + if (pg_size > PAGE_SIZE) + pfn += pg_size / PAGE_SIZE - 1; + } + + return 0; +} + +bool damon_pgi_target_valid(void *target) +{ + return true; +} + +void damon_pgi_set_primitives(struct damon_ctx *ctx) +{ + ctx->primitive.init_target_regions = NULL; + ctx->primitive.update_target_regions = NULL; + ctx->primitive.prepare_access_checks = damon_pgi_prepare_access_checks; + ctx->primitive.check_accesses = damon_pgi_check_accesses; + ctx->primitive.reset_aggregated = NULL; + ctx->primitive.target_valid = damon_pgi_target_valid; + ctx->primitive.cleanup = NULL; + ctx->primitive.apply_scheme = NULL; +}