From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org, zhaochongxi2019@email.szu.edu.cn,
zhangyinan2019@email.szu.edu.cn, yuhongf@szu.edu.cn,
weizhenliang@huawei.com, sfr@canb.auug.org.au, seanga2@gmail.com,
liuyongqiang13@huawei.com, hanshenghong2019@email.szu.edu.cn,
caoyixuan2019@email.szu.edu.cn, yejiajian2018@email.szu.edu.cn,
akpm@linux-foundation.org
Subject: + tools-vm-page_owner_sortc-support-for-multi-value-selection-in-single-argument.patch added to -mm tree
Date: Tue, 15 Mar 2022 15:45:14 -0700 [thread overview]
Message-ID: <20220315224514.EC9FFC340ED@smtp.kernel.org> (raw)
The patch titled
Subject: tools/vm/page_owner_sort.c: support for multi-value selection in single argument
has been added to the -mm tree. Its filename is
tools-vm-page_owner_sortc-support-for-multi-value-selection-in-single-argument.patch
This patch should soon appear at
https://ozlabs.org/~akpm/mmots/broken-out/tools-vm-page_owner_sortc-support-for-multi-value-selection-in-single-argument.patch
and later at
https://ozlabs.org/~akpm/mmotm/broken-out/tools-vm-page_owner_sortc-support-for-multi-value-selection-in-single-argument.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated
there every 3-4 working days
------------------------------------------------------
From: Jiajian Ye <yejiajian2018@email.szu.edu.cn>
Subject: tools/vm/page_owner_sort.c: support for multi-value selection in single argument
When viewing page owner information, we may want to select blocks whose
PID/TGID/TASK_COMM_NAME appears in a user-specified list for data analysis
and aggregation. But currently page_owner_sort only supports selecting
blocks associated with only one specified PID/TGID/TASK_COMM_NAME.
Therefore, following adjustments are made to fix the problem:
1. Enhance selecting function to support the selection of multiple
PIDs/TGIDs/TASK_COMM_NAMEs.
The enhanced usages are as follows:
--pid <pidlist> Select by pid. This selects the blocks whose PID
numbers appear in <pidlist>.
--tgid <tgidlist> Select by tgid. This selects the blocks whose
TGID numbers appear in <tgidlist>.
--name <cmdlist> Select by task command name. This selects the
blocks whose task command name appear in <cmdlist>.
Where <pidlist>, <tgidlist>, <cmdlist> are single arguments in the form of
a comma-separated list,which offers a way to specify individual selecting
rules.
For example, if you want to select blocks whose tgids are 1, 2 or 3, you
have to use 4 commands as follows:
./page_owner_sort <input> <output1> --tgid=1
./page_owner_sort <input> <output2> --tgid=2
./page_owner_sort <input> <output3> --tgid=3
cat <output1> <output2> <output3> > <output>
With this patch, you can use only 1 command to obtain the same result as
above:
./page_owner_sort <input> <output1> --tgid=1,2,3
2. Update explanations of --pid, --tgid and --name in the function usage()
and the document(Documents/vm/page_owner.rst).
This work is coauthored by
Shenghong Han
Yixuan Cao
Yinan Zhang
Chongxi Zhao
Yuhong Feng
Yongqiang Liu
Link: https://lkml.kernel.org/r/20220315163902.1567-2-yejiajian2018@email.szu.edu.cn
Signed-off-by: Jiajian Ye <yejiajian2018@email.szu.edu.cn>
Cc: Shenghong Han <hanshenghong2019@email.szu.edu.cn>
Cc: Yixuan Cao <caoyixuan2019@email.szu.edu.cn>
Cc: Yinan Zhang <zhangyinan2019@email.szu.edu.cn>
Cc: Chongxi Zhao <zhaochongxi2019@email.szu.edu.cn>
Cc: Yuhong Feng <yuhongf@szu.edu.cn>
Cc: Yongqiang Liu <liuyongqiang13@huawei.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Sean Anderson <seanga2@gmail.com>
Cc: Zhenliang Wei <weizhenliang@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
Documentation/vm/page_owner.rst | 20 +++++--
tools/vm/page_owner_sort.c | 78 +++++++++++++++++++++---------
2 files changed, 72 insertions(+), 26 deletions(-)
--- a/Documentation/vm/page_owner.rst~tools-vm-page_owner_sortc-support-for-multi-value-selection-in-single-argument
+++ a/Documentation/vm/page_owner.rst
@@ -130,7 +130,6 @@ Usage
Specify culling rules.Culling syntax is key[,key[,...]].Choose a
multi-letter key from the **STANDARD FORMAT SPECIFIERS** section.
-
<rules> is a single argument in the form of a comma-separated list,
which offers a way to specify individual culling rules. The recognized
keywords are described in the **STANDARD FORMAT SPECIFIERS** section below.
@@ -138,7 +137,6 @@ Usage
the STANDARD SORT KEYS section below. Mixed use of abbreviated and
complete-form of keys is allowed.
-
Examples:
./page_owner_sort <input> <output> --cull=stacktrace
./page_owner_sort <input> <output> --cull=st,pid,name
@@ -148,9 +146,21 @@ Usage
-f Filter out the information of blocks whose memory has been released.
Select:
- --pid <PID> Select by pid.
- --tgid <TGID> Select by tgid.
- --name <command> Select by task command name.
+ --pid <pidlist> Select by pid. This selects the blocks whose process ID
+ numbers appear in <pidlist>.
+ --tgid <tgidlist> Select by tgid. This selects the blocks whose thread
+ group ID numbers appear in <tgidlist>.
+ --name <cmdlist> Select by task command name. This selects the blocks whose
+ task command name appear in <cmdlist>.
+
+ <pidlist>, <tgidlist>, <cmdlist> are single arguments in the form of a comma-separated list,
+ which offers a way to specify individual selecting rules.
+
+
+ Examples:
+ ./page_owner_sort <input> <output> --pid=1
+ ./page_owner_sort <input> <output> --tgid=1,2,3
+ ./page_owner_sort <input> <output> --name name1,name2
STANDARD FORMAT SPECIFIERS
==========================
--- a/tools/vm/page_owner_sort.c~tools-vm-page_owner_sortc-support-for-multi-value-selection-in-single-argument
+++ a/tools/vm/page_owner_sort.c
@@ -54,9 +54,12 @@ enum CULL_BIT {
CULL_STACKTRACE = 1<<5
};
struct filter_condition {
- pid_t tgid;
- pid_t pid;
- char comm[TASK_COMM_LEN];
+ pid_t *tgids;
+ int tgids_size;
+ pid_t *pids;
+ int pids_size;
+ char **comms;
+ int comms_size;
};
static struct filter_condition fc;
static regex_t order_pattern;
@@ -149,7 +152,6 @@ static int compare_free_ts(const void *p
return l1->free_ts_nsec < l2->free_ts_nsec ? -1 : 1;
}
-
static int compare_release(const void *p1, const void *p2)
{
const struct block_list *l1 = p1, *l2 = p2;
@@ -161,7 +163,6 @@ static int compare_release(const void *p
return l1->free_ts_nsec ? 1 : -1;
}
-
static int compare_cull_condition(const void *p1, const void *p2)
{
if (cull == 0)
@@ -344,22 +345,40 @@ static char *get_comm(char *buf)
return comm_str;
}
+static bool match_num_list(int num, int *list, int list_size)
+{
+ for (int i = 0; i < list_size; ++i)
+ if (list[i] == num)
+ return true;
+ return false;
+}
+
+static bool match_str_list(const char *str, char **list, int list_size)
+{
+ for (int i = 0; i < list_size; ++i)
+ if (!strcmp(list[i], str))
+ return true;
+ return false;
+}
+
static bool is_need(char *buf)
{
if ((filter & FILTER_UNRELEASE) && get_free_ts_nsec(buf) != 0)
return false;
- if ((filter & FILTER_PID) && get_pid(buf) != fc.pid)
+ if ((filter & FILTER_PID) && !match_num_list(get_pid(buf), fc.pids, fc.pids_size))
return false;
- if ((filter & FILTER_TGID) && get_tgid(buf) != fc.tgid)
+ if ((filter & FILTER_TGID) &&
+ !match_num_list(get_tgid(buf), fc.tgids, fc.tgids_size))
return false;
char *comm = get_comm(buf);
if ((filter & FILTER_COMM) &&
- strncmp(comm, fc.comm, TASK_COMM_LEN) != 0) {
+ !match_str_list(comm, fc.comms, fc.comms_size)) {
free(comm);
return false;
}
+ free(comm);
return true;
}
@@ -428,6 +447,27 @@ static bool parse_cull_args(const char *
return true;
}
+static int *parse_nums_list(char *arg_str, int *list_size)
+{
+ int size = 0;
+ char **args = explode(',', arg_str, &size);
+ int *list = calloc(size, sizeof(int));
+
+ errno = 0;
+ for (int i = 0; i < size; ++i) {
+ char *endptr = NULL;
+
+ list[i] = strtol(args[i], &endptr, 10);
+ if (errno != 0 || endptr == args[i] || *endptr != '\0') {
+ free(list);
+ return NULL;
+ }
+ }
+ *list_size = size;
+ free_explode(args, size);
+ return list;
+}
+
#define BUF_SIZE (128 * 1024)
static void usage(void)
@@ -443,9 +483,9 @@ static void usage(void)
"-r\t\tSort by memory release time.\n"
"-c\t\tCull by comparing stacktrace instead of total block.\n"
"-f\t\tFilter out the information of blocks whose memory has been released.\n"
- "--pid <PID>\tSelect by pid. This selects the information of blocks whose process ID number equals to <PID>.\n"
- "--tgid <TGID>\tSelect by tgid. This selects the information of blocks whose Thread Group ID number equals to <TGID>.\n"
- "--name <command>\n\t\tSelect by command name. This selects the information of blocks whose command name identical to <command>.\n"
+ "--pid <pidlist>\tSelect by pid. This selects the information of blocks whose process ID numbers appear in <pidlist>.\n"
+ "--tgid <tgidlist>\tSelect by tgid. This selects the information of blocks whose Thread Group ID numbers appear in <tgidlist>.\n"
+ "--name <cmdlist>\n\t\tSelect by command name. This selects the information of blocks whose command name appears in <cmdlist>.\n"
"--cull <rules>\tCull by user-defined rules. <rules> is a single argument in the form of a comma-separated list with some common fields predefined\n"
);
}
@@ -454,7 +494,7 @@ int main(int argc, char **argv)
{
int (*cmp)(const void *, const void *) = compare_num;
FILE *fin, *fout;
- char *buf, *endptr;
+ char *buf;
int ret, i, count;
struct stat st;
int opt;
@@ -500,9 +540,8 @@ int main(int argc, char **argv)
break;
case 1:
filter = filter | FILTER_PID;
- errno = 0;
- fc.pid = strtol(optarg, &endptr, 10);
- if (errno != 0 || endptr == optarg || *endptr != '\0') {
+ fc.pids = parse_nums_list(optarg, &fc.pids_size);
+ if (fc.pids == NULL) {
fprintf(stderr, "wrong/invalid pid in from the command line:%s\n",
optarg);
exit(1);
@@ -510,9 +549,8 @@ int main(int argc, char **argv)
break;
case 2:
filter = filter | FILTER_TGID;
- errno = 0;
- fc.tgid = strtol(optarg, &endptr, 10);
- if (errno != 0 || endptr == optarg || *endptr != '\0') {
+ fc.tgids = parse_nums_list(optarg, &fc.tgids_size);
+ if (fc.tgids == NULL) {
fprintf(stderr, "wrong/invalid tgid in from the command line:%s\n",
optarg);
exit(1);
@@ -520,8 +558,7 @@ int main(int argc, char **argv)
break;
case 3:
filter = filter | FILTER_COMM;
- strncpy(fc.comm, optarg, TASK_COMM_LEN);
- fc.comm[TASK_COMM_LEN-1] = '\0';
+ fc.comms = explode(',', optarg, &fc.comms_size);
break;
case 4:
if (!parse_cull_args(optarg)) {
@@ -568,7 +605,6 @@ int main(int argc, char **argv)
ret = read_block(buf, BUF_SIZE, fin);
if (ret < 0)
break;
-
add_list(buf, ret);
}
_
Patches currently in -mm which might be from yejiajian2018@email.szu.edu.cn are
tools-vm-page_owner_sortc-fix-comments.patch
tools-vm-page_owner_sortc-add-a-security-check.patch
tools-vm-page_owner_sortc-support-sorting-by-tgid-and-update-documentation.patch
tools-vm-page_owner_sort-fix-three-trivival-places.patch
tools-vm-page_owner_sort-support-for-sorting-by-task-command-name.patch
tools-vm-page_owner_sortc-support-for-selecting-by-pid-tgid-or-task-command-name.patch
tools-vm-page_owner_sortc-support-for-user-defined-culling-rules.patch
tools-vm-page_owner_sortc-use-fprintf-to-send-error-messages-to-stderr.patch
tools-vm-page_owner_sortc-support-for-multi-value-selection-in-single-argument.patch
next reply other threads:[~2022-03-15 22:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-15 22:45 Andrew Morton [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-04-04 23:19 + tools-vm-page_owner_sortc-support-for-multi-value-selection-in-single-argument.patch added to -mm tree Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220315224514.EC9FFC340ED@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=caoyixuan2019@email.szu.edu.cn \
--cc=hanshenghong2019@email.szu.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=liuyongqiang13@huawei.com \
--cc=mm-commits@vger.kernel.org \
--cc=seanga2@gmail.com \
--cc=sfr@canb.auug.org.au \
--cc=weizhenliang@huawei.com \
--cc=yejiajian2018@email.szu.edu.cn \
--cc=yuhongf@szu.edu.cn \
--cc=zhangyinan2019@email.szu.edu.cn \
--cc=zhaochongxi2019@email.szu.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.