From: Sean Anderson <seanga2@gmail.com>
To: weizhenliang <weizhenliang@huawei.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Changhee Han <ch0.han@lge.com>,
Tang Bin <tangbin@cmss.chinamobile.com>,
Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Subject: Re: [PATCH v2 1/2] tools/vm/page_owner_sort.c: Sort by stacktrace before culling
Date: Thu, 25 Nov 2021 11:26:59 -0500 [thread overview]
Message-ID: <bf1b7d78-9945-c3be-ff1b-53cf5d3f0878@gmail.com> (raw)
In-Reply-To: <22bad523dffb4681a201e6fedef7c50d@huawei.com>
On 11/25/21 4:46 AM, weizhenliang wrote:
> On 2021/11/25 3:37, Sean Anderson <seanga2@gmail.com> wrote:
>
>> static int compare_num(const void *p1, const void *p2) @@ -121,6
>> +122,7 @@ static void add_list(char *buf, int len)
>> list[list_size].page_num = get_page_num(buf);
>> memcpy(list[list_size].txt, buf, len); list[list_size].txt[len] = 0;
>> + list[list_size].stacktrace = strchr(list[list_size].txt, '\n');
>
> When read_block gets an empty line, buf is "\n", then the stacktrace is NULL
>
>> list_size++;
>> if (list_size % 1000 == 0) {
>> printf("loaded %d\r", list_size);
>> @@ -199,7 +201,7 @@ int main(int argc, char **argv)
>>
>> printf("sorting ....\n");
>>
>> - qsort(list, list_size, sizeof(list[0]), compare_txt);
>> + qsort(list, list_size, sizeof(list[0]), compare_stacktrace);
>>
>> list2 = malloc(sizeof(*list) * list_size); if (!list2) { @@ -211,7
>> +213,7 @@ int main(int argc, char **argv)
>>
>> for (i = count = 0; i < list_size; i++) { if (count == 0 ||
>> - strcmp(list2[count-1].txt, list[i].txt) != 0) {
>> + strcmp(list2[count-1].stacktrace, list[i].stacktrace) != 0) {
>
> And when stacktrace is NULL, a segmentation fault will be triggered here.
Ah, whoops. Looks like I check for this in compare_stacktrace but not here.
>> list2[count++] = list[i];
>> } else {
>> list2[count-1].num += list[i].num;
>
> 1. Maybe you can check whether the ret of read_block is 0 before add_list,
> or whether the len of buf is 0 in add_list
I think this is the best route.
Since this seems to have already been applied I've sent a follow-up patch.
--Sean
next prev parent reply other threads:[~2021-11-25 16:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-25 9:46 [PATCH v2 1/2] tools/vm/page_owner_sort.c: Sort by stacktrace before culling weizhenliang
2021-11-25 16:26 ` Sean Anderson [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-11-24 19:37 Sean Anderson
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=bf1b7d78-9945-c3be-ff1b-53cf5d3f0878@gmail.com \
--to=seanga2@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ch0.han@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tangbin@cmss.chinamobile.com \
--cc=weizhenliang@huawei.com \
--cc=zhangshengju@cmss.chinamobile.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).