From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 ED106C433E1 for ; Tue, 9 Jun 2020 14:21:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A402D206D5 for ; Tue, 9 Jun 2020 14:21:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="L/xGpa5B" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A402D206D5 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 4BC576B0008; Tue, 9 Jun 2020 10:21:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 46AC76B000A; Tue, 9 Jun 2020 10:21:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 334C96B000D; Tue, 9 Jun 2020 10:21:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id 1C4526B0008 for ; Tue, 9 Jun 2020 10:21:47 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D3FF0181355C8 for ; Tue, 9 Jun 2020 14:21:46 +0000 (UTC) X-FDA: 76909887012.30.stage39_380c9c126dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 24D33182018FA for ; Tue, 9 Jun 2020 14:21:44 +0000 (UTC) X-HE-Tag: stage39_380c9c126dc3 X-Filterd-Recvd-Size: 11441 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712504; x=1623248504; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=lCtpFdulZBcc+gNwg5rlkrBP9DmunmKCV7foIDqhGGw=; b=L/xGpa5BhSnNYfYiP9jafsjBeAqwKC4yKzQpcF0zAMr/ndvqhChOAGaw M6+IJd3PNU/V8r6GI+NDy69aTPGEmUKKogUjImyTK217RYAh63Cp147RO tw7rTVgdY1Cy5QjbHm8vSkP5UrO2Y+1DA3KayMd+WTpD/kmFqUOC3RBId k=; IronPort-SDR: yrI9nYiJ625dK61ZoZSXYWif1o52cVGahPtLx3H7yzm0pbk01cMhjIYilsOFHg6blhuh3KLNi2 /nzGR9YXbyGg== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="35297473" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-715bee71.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 09 Jun 2020 14:21:43 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-715bee71.us-east-1.amazon.com (Postfix) with ESMTPS id C47C2A1D00; Tue, 9 Jun 2020 14:21:30 +0000 (UTC) Received: from EX13D31EUA001.ant.amazon.com (10.43.165.15) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:21:30 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:21:13 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 04/10] tools/damon: Implement init target regions feature Date: Tue, 9 Jun 2020 16:19:35 +0200 Message-ID: <20200609141941.19184-5-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: 24D33182018FA X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park This commit updates the damon user space tool to support the initial monitoring target regions feature. 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 3620ef12a5ea..ad476cc61421 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_pids = None +debugfs_init_regions = None debugfs_monitor_on = None def set_target_pid(pid): return subprocess.call('echo %s > %s' % (pid, debugfs_pids), shell=True, executable='/bin/bash') +def set_target(pid, init_regions=[]): + rc = set_target_pid(pid) + if rc: + return rc + + if not os.path.exists(debugfs_init_regions): + return 0 + + string = ' '.join(['%s %d %d' % (pid, 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_pids + 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_pids = os.path.join(debugfs_damon, 'pids') + 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 44fa3a12af35..6ce8721d782a 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -13,7 +13,7 @@ import time import _damon -def do_record(target, is_target_cmd, attrs, old_attrs): +def do_record(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') @@ -24,8 +24,8 @@ def do_record(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) @@ -65,6 +65,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('-l', '--rbuf', metavar='', type=int, @@ -88,19 +89,20 @@ def main(args=None): args.schemes = '' 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) + do_record(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) - do_record(target, False, new_attrs, orig_attrs) + do_record(target, False, init_regions, new_attrs, orig_attrs) if __name__ == '__main__': main() diff --git a/tools/damon/schemes.py b/tools/damon/schemes.py index 2d23dfb4fd13..654345dbdb62 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) @@ -67,6 +67,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, @@ -91,19 +92,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() -- 2.17.1