Received: by 10.223.176.5 with SMTP id f5csp591419wra; Tue, 30 Jan 2018 16:21:03 -0800 (PST) X-Google-Smtp-Source: AH8x225+XzESOQQtm9+d5rM+vpKh5r5d6OXaF0gXC/jPjK872nc+4M6bFaUxsmyKN543nfTxjrL0 X-Received: by 10.101.86.137 with SMTP id v9mr24929550pgs.353.1517358063288; Tue, 30 Jan 2018 16:21:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517358063; cv=none; d=google.com; s=arc-20160816; b=vAQfrfXtTj9CHqqi7mQvcffR7l0ty7Omad2ykNkSsfYWSsykGO05ziRjbzMTiYvodA uUVlQ6LtvtPTFkar+4fCm5jsqXzqwMQ40k0izdIOY71Dypq4zMbeFFWn/zHnIYtITH56 CPjIiipb4iX6VGl69GpKfC2strYu9yUCJJuQB/b8t4QXIL1NTj3Wa119hl7YYRE0i2ns Bmk0ZQ9PDdrOGJm7aw2631QO50H9FkyEyHy42pjOJZQNsLxnIAc6MC+KW4SvfMfYNZXS bu/PNPLzIKV8KwFqQ8IAnHrM1l5TQaKHnQ9cVi8Qv5TDLhsTr5YV6tXFDG2BDoCxBP9t owKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=Vxt4qPXxBkXHnKAd+9hbiMVMMJobBMCr4Ne9yDVYN5c=; b=bnrHj4edOEJqSX+7i5RVSNoWM7OTnqcy+dZQKX4oNRUKXul2lEK45sXpea+nOmHidl zIK/mw7CGChU+UZwgcil+Oi5m/DijO/ijWKIc7FcYzRMWwx2p6I3pEJ5r/npFs8JoCg1 vKQhqQNZQRfIE1Yzcj23KKPy6/9VkDwT3ZDp1Hq8Sa/OPw8VFia9SqS2jTXvUHEq+LvW ELUkzdfMVjBmY5c6bvWpaiXWVk85aeQCKSZ13WfbRfUHr0vqBjqW2bSSQg3QAkrXEOpK /zuNcN+h0ug34TYXgN9zQUiZwcxOgohvqS7nMoQA2s+jZMeCP8Al9yZoeXFi6t68e7KR OAFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AgQ5CEcr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3si10133648pgt.217.2018.01.30.16.20.16; Tue, 30 Jan 2018 16:21:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AgQ5CEcr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753989AbeA3XBF (ORCPT + 99 others); Tue, 30 Jan 2018 18:01:05 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:54514 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753861AbeA3XBE (ORCPT ); Tue, 30 Jan 2018 18:01:04 -0500 Received: by mail-it0-f66.google.com with SMTP id k131so2695027ith.4 for ; Tue, 30 Jan 2018 15:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=Vxt4qPXxBkXHnKAd+9hbiMVMMJobBMCr4Ne9yDVYN5c=; b=AgQ5CEcr59JBH1KRAdw6+Ln0cAE8y2aEKmNxec6W33HfXI6O2CDEPLfkrrQN6Kk/q7 QVxcb0NH7Q+RHD6J1TNmogCnydO4nT4sWKkFhmfBfi5JrewV34tk2KtGEEt6mcVUeY3F Kr8NN+BbQsFxsFNar57R6SDHHddUvaajitPOGxt5fl+le6eLIvZlZJou7aLeFGlVw7U1 6QvueCMJnAoDQVmyfAGWnuPk2Bjsrf4ICz6rzZYbeTiNAXDSVpU16WQEJMuXYr8cneR1 sRIOOs+PYzmrXagZi2oyo0Eh+guF0hPFa/FzGQfPtivl2/q8SeZil+g+RyXjAR6TOVmt Nzwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=Vxt4qPXxBkXHnKAd+9hbiMVMMJobBMCr4Ne9yDVYN5c=; b=E9UJAZmSbwZkdf9SK6UG4LJVboArk6xKpdeCOXXJPPb4bAsUUtGh4rwsymgUv6L4to py0jqWdK7EaeUpblzJLmkR7cUorG5iuKM3zvl9IjScJn8V1rILiktGAW8Rl9Nqugnp/0 uLGu54m8HHpsvjNjlLAdqBdj74t30vK0GIIPUDtMjyhKTVb414xlXeFuWRAbwa3Fgb2/ tR24+yO6cosbdRvgA+3UY0fEGoY1DbUFnzt2rxD5IVfZR6kFfkn/UQPO0P2lRn80yG07 FErKi08QAfxZQUBWAOOEYFjzcjPy0Yt90HqEDg0/jVPXwTXAPZdtmLvetBBlBYfJU7VR wtHQ== X-Gm-Message-State: AKwxytcjNd2RBARGmG95BSHj9D6imIhg/ZTpKXfkmkOhMNSOnUWTC1xp BtjfU0CFkSoptigCxYXDFwT1TA== X-Received: by 10.36.217.208 with SMTP id p199mr16558826itg.29.1517353263354; Tue, 30 Jan 2018 15:01:03 -0800 (PST) Received: from [2620:15c:17:3:2902:dc73:cf27:e6d8] ([2620:15c:17:3:2902:dc73:cf27:e6d8]) by smtp.gmail.com with ESMTPSA id t188sm8318891ita.23.2018.01.30.15.01.02 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Jan 2018 15:01:02 -0800 (PST) Date: Tue, 30 Jan 2018 15:01:01 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Andrew Morton cc: Naoya Horiguchi , Konstantin Khlebnikov , Vladimir Davydov , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [patch] tools, vm: new option to specify kpageflags file Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org page-types currently hardcodes /proc/kpageflags as the file to parse. This works when using the tool to examine the state of pageflags on the same system, but does not allow storing a snapshot of pageflags at a given time to debug issues nor on a different system. This allows the user to specify a saved version of kpageflags with a new page-types -F option. Signed-off-by: David Rientjes --- tools/vm/page-types.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c --- a/tools/vm/page-types.c +++ b/tools/vm/page-types.c @@ -172,6 +172,7 @@ static pid_t opt_pid; /* process to walk */ const char * opt_file; /* file or directory path */ static uint64_t opt_cgroup; /* cgroup inode */ static int opt_list_cgroup;/* list page cgroup */ +static const char * opt_kpageflags; /* kpageflags file to parse */ #define MAX_ADDR_RANGES 1024 static int nr_addr_ranges; @@ -258,7 +259,7 @@ static int checked_open(const char *pathname, int flags) * pagemap/kpageflags routines */ -static unsigned long do_u64_read(int fd, char *name, +static unsigned long do_u64_read(int fd, const char *name, uint64_t *buf, unsigned long index, unsigned long count) @@ -283,7 +284,7 @@ static unsigned long kpageflags_read(uint64_t *buf, unsigned long index, unsigned long pages) { - return do_u64_read(kpageflags_fd, PROC_KPAGEFLAGS, buf, index, pages); + return do_u64_read(kpageflags_fd, opt_kpageflags, buf, index, pages); } static unsigned long kpagecgroup_read(uint64_t *buf, @@ -293,7 +294,7 @@ static unsigned long kpagecgroup_read(uint64_t *buf, if (kpagecgroup_fd < 0) return pages; - return do_u64_read(kpagecgroup_fd, PROC_KPAGEFLAGS, buf, index, pages); + return do_u64_read(kpagecgroup_fd, opt_kpageflags, buf, index, pages); } static unsigned long pagemap_read(uint64_t *buf, @@ -743,7 +744,7 @@ static void walk_addr_ranges(void) { int i; - kpageflags_fd = checked_open(PROC_KPAGEFLAGS, O_RDONLY); + kpageflags_fd = checked_open(opt_kpageflags, O_RDONLY); if (!nr_addr_ranges) add_addr_range(0, ULONG_MAX); @@ -790,6 +791,7 @@ static void usage(void) " -N|--no-summary Don't show summary info\n" " -X|--hwpoison hwpoison pages\n" " -x|--unpoison unpoison pages\n" +" -F|--kpageflags kpageflags file to parse\n" " -h|--help Show this usage message\n" "flags:\n" " 0x10 bitfield format, e.g.\n" @@ -1013,7 +1015,7 @@ static void walk_page_cache(void) { struct stat st; - kpageflags_fd = checked_open(PROC_KPAGEFLAGS, O_RDONLY); + kpageflags_fd = checked_open(opt_kpageflags, O_RDONLY); pagemap_fd = checked_open("/proc/self/pagemap", O_RDONLY); sigaction(SIGBUS, &sigbus_action, NULL); @@ -1164,6 +1166,11 @@ static void parse_bits_mask(const char *optarg) add_bits_filter(mask, bits); } +static void parse_kpageflags(const char *name) +{ + opt_kpageflags = name; +} + static void describe_flags(const char *optarg) { uint64_t flags = parse_flag_names(optarg, 0); @@ -1188,6 +1195,7 @@ static const struct option opts[] = { { "no-summary", 0, NULL, 'N' }, { "hwpoison" , 0, NULL, 'X' }, { "unpoison" , 0, NULL, 'x' }, + { "kpageflags", 0, NULL, 'F' }, { "help" , 0, NULL, 'h' }, { NULL , 0, NULL, 0 } }; @@ -1199,7 +1207,7 @@ int main(int argc, char *argv[]) page_size = getpagesize(); while ((c = getopt_long(argc, argv, - "rp:f:a:b:d:c:ClLNXxh", opts, NULL)) != -1) { + "rp:f:a:b:d:c:ClLNXxF:h", opts, NULL)) != -1) { switch (c) { case 'r': opt_raw = 1; @@ -1242,6 +1250,9 @@ int main(int argc, char *argv[]) opt_unpoison = 1; prepare_hwpoison_fd(); break; + case 'F': + parse_kpageflags(optarg); + break; case 'h': usage(); exit(0); @@ -1251,6 +1262,9 @@ int main(int argc, char *argv[]) } } + if (!opt_kpageflags) + opt_kpageflags = PROC_KPAGEFLAGS; + if (opt_cgroup || opt_list_cgroup) kpagecgroup_fd = checked_open(PROC_KPAGECGROUP, O_RDONLY);