From patchwork Fri Mar 25 01:09:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12791118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65C04C433F5 for ; Fri, 25 Mar 2022 01:09:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED6D48D0009; Thu, 24 Mar 2022 21:09:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E87738D0002; Thu, 24 Mar 2022 21:09:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D76F18D0009; Thu, 24 Mar 2022 21:09:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id C8F0E8D0002 for ; Thu, 24 Mar 2022 21:09:31 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8D6F3A32D6 for ; Fri, 25 Mar 2022 01:09:31 +0000 (UTC) X-FDA: 79281125742.27.ED782B1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 0A78640005 for ; Fri, 25 Mar 2022 01:09:30 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 39087617B4; Fri, 25 Mar 2022 01:09:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91833C340EE; Fri, 25 Mar 2022 01:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1648170569; bh=2IFH8W3AxHUPucqXzAAGwgn/SCDG1NngfymN9bkp7n8=; h=Date:To:From:In-Reply-To:Subject:From; b=efNhAqU/H8QpFEeAUk+Al1DGhuQ6ythcpCgvIw/xRgO8nDv5t8JQildSu35ZY/To4 DSj/B8uw2oXu89qZ9IgQa6YgwRGZh3qzlRKEmvz/tTvX20RuAyjaxqMkQuTfzLzw1Z LQRsFBZ8yomzUq2PxAScM0KkSGnWeX1kWpTunMP0= Date: Thu, 24 Mar 2022 18:09:29 -0700 To: zhangyinan2019@email.szu.edu.cn,weizhenliang@huawei.com,sfr@canb.auug.org.au,seanga2@gmail.com,hanshenghong2019@email.szu.edu.cn,caoyixuan2019@email.szu.edu.cn,yejiajian2018@email.szu.edu.cn,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220324180758.96b1ac7e17675d6bc474485e@linux-foundation.org> Subject: [patch 018/114] tools/vm/page_owner_sort: fix three trivival places Message-Id: <20220325010929.91833C340EE@smtp.kernel.org> Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="efNhAqU/"; spf=pass (imf11.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0A78640005 X-Stat-Signature: 7jy76bijwnuonhmqu363igddq83jspi3 X-HE-Tag: 1648170570-201599 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: Jiajian Ye Subject: tools/vm/page_owner_sort: fix three trivival places The following adjustments are made: 1. Instead of using another array to cull the blocks after sorting, reuse the old array. So there is no need to malloc a new array. 2. When enabling '-f' option to filter out the blocks which have been released, only add those have not been released in the list, rather than add all of blocks in the list and then do the filtering when printing the result. 3. When enabling '-c' option to cull the blocks by comparing stacktrace, print the stacetrace rather than the total block. Link: https://lkml.kernel.org/r/20220306030640.43054-1-yejiajian2018@email.szu.edu.cn Signed-off-by: Jiajian Ye Cc: Cc: Sean Anderson Cc: Stephen Rothwell Cc: Yixuan Cao Cc: Cc: Zhenliang Wei Signed-off-by: Andrew Morton --- tools/vm/page_owner_sort.c | 37 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) --- a/tools/vm/page_owner_sort.c~tools-vm-page_owner_sort-fix-three-trivival-places +++ a/tools/vm/page_owner_sort.c @@ -42,6 +42,8 @@ static regex_t free_ts_nsec_pattern; static struct block_list *list; static int list_size; static int max_size; +static int cull_st; +static int filter; int read_block(char *buf, int buf_size, FILE *fin) { @@ -245,6 +247,9 @@ static void add_list(char *buf, int len) exit(1); } + list[list_size].free_ts_nsec = get_free_ts_nsec(buf); + if (filter == 1 && list[list_size].free_ts_nsec != 0) + return; list[list_size].txt = malloc(len+1); if (!list[list_size].txt) { printf("Out of memory\n"); @@ -257,10 +262,11 @@ static void add_list(char *buf, int len) memcpy(list[list_size].txt, buf, len); list[list_size].txt[len] = 0; list[list_size].stacktrace = strchr(list[list_size].txt, '\n') ?: ""; + if (*list[list_size].stacktrace == '\n') + list[list_size].stacktrace++; list[list_size].pid = get_pid(buf); list[list_size].tgid = get_tgid(buf); list[list_size].ts_nsec = get_ts_nsec(buf); - list[list_size].free_ts_nsec = get_free_ts_nsec(buf); list_size++; if (list_size % 1000 == 0) { printf("loaded %d\r", list_size); @@ -288,12 +294,9 @@ static void usage(void) int main(int argc, char **argv) { int (*cmp)(const void *, const void *) = compare_num; - int cull_st = 0; - int filter = 0; FILE *fin, *fout; char *buf; int ret, i, count; - struct block_list *list2; struct stat st; int opt; @@ -376,11 +379,7 @@ int main(int argc, char **argv) else qsort(list, list_size, sizeof(list[0]), compare_txt); - list2 = malloc(sizeof(*list) * list_size); - if (!list2) { - printf("Out of memory\n"); - exit(1); - } + printf("culling\n"); @@ -388,21 +387,23 @@ int main(int argc, char **argv) for (i = count = 0; i < list_size; i++) { if (count == 0 || - strcmp(*(&list2[count-1].txt+offset), *(&list[i].txt+offset)) != 0) { - list2[count++] = list[i]; + strcmp(*(&list[count-1].txt+offset), *(&list[i].txt+offset)) != 0) { + list[count++] = list[i]; } else { - list2[count-1].num += list[i].num; - list2[count-1].page_num += list[i].page_num; + list[count-1].num += list[i].num; + list[count-1].page_num += list[i].page_num; } } - qsort(list2, count, sizeof(list[0]), cmp); + qsort(list, count, sizeof(list[0]), cmp); for (i = 0; i < count; i++) { - if (filter == 1 && list2[i].free_ts_nsec != 0) - continue; - fprintf(fout, "%d times, %d pages:\n%s\n", - list2[i].num, list2[i].page_num, list2[i].txt); + if (cull_st == 0) + fprintf(fout, "%d times, %d pages:\n%s\n", + list[i].num, list[i].page_num, list[i].txt); + else + fprintf(fout, "%d times, %d pages:\n%s\n", + list[i].num, list[i].page_num, list[i].stacktrace); } regfree(&order_pattern); regfree(&pid_pattern);