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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 77C72C433EF for ; Sat, 11 Sep 2021 22:25:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EBB2661039 for ; Sat, 11 Sep 2021 22:25:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EBB2661039 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id DF7706B0071; Sat, 11 Sep 2021 18:25:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7F866B0072; Sat, 11 Sep 2021 18:25:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFA3F900002; Sat, 11 Sep 2021 18:25:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id ACFA66B0071 for ; Sat, 11 Sep 2021 18:25:27 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5165529DEC for ; Sat, 11 Sep 2021 22:25:27 +0000 (UTC) X-FDA: 78576725094.23.C426807 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf17.hostedemail.com (Postfix) with ESMTP id E6D57F000136 for ; Sat, 11 Sep 2021 22:25:26 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 993B360FDC; Sat, 11 Sep 2021 22:25:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1631399125; bh=5BUD4+/LJTOHGqd73XGo3uzyhbhaAoHyT1tJJkbBUiw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=i00EjmEZhgu2lmeaQCTk225xlYEmtMR5kW6zLx/y4FG5xG/E5V2n33sO05K55ErDS nxMIiIrAS7Ziu9aV33WO7833Oz9Tuw8jx+iTy6wIuzPpzQMEbJbBvlhMn+qqzKmpJI ZINWgWOQbGr/j+KJy+eOEtabh+D1ohKsHOs7hWv8= Date: Sat, 11 Sep 2021 15:25:20 -0700 From: Andrew Morton To: Zhenliang Wei Cc: , , , , , Subject: Re: [PATCH] tools/vm/page_owner_sort.c: count and sort by mem Message-Id: <20210911152520.45d6e3ed690b652a4d49a1c0@linux-foundation.org> In-Reply-To: <1631243023-47849-1-git-send-email-weizhenliang@huawei.com> References: <1631243023-47849-1-git-send-email-weizhenliang@huawei.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=i00EjmEZ; spf=pass (imf17.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E6D57F000136 X-Stat-Signature: c4hegar6iynqzg9opn81msx93ag13cgf X-HE-Tag: 1631399126-867592 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: On Fri, 10 Sep 2021 11:03:43 +0800 Zhenliang Wei wrote: > When viewing page owner information, we may be more concerned about the > total memory than the number of stack occurrences. Therefore, the > following adjustments are made: > 1. Added the statistics on the total number of pages. > 2. Added the optional parameter "-m" to configure the program to sort by > memory (total pages). > Why does it add regexp matching to add_list()? Presumably this is some enhancement to the user interface which I cannot see documented in the changelog or the code comments, Can we please add/maintain a full description of the user interface in, I guess, Documentation/vm/page_owner.rst? > @@ -59,12 +65,50 @@ static int compare_num(const void *p1, const void *p2) > return l2->num - l1->num; > } > > +static int compare_page_num(const void *p1, const void *p2) > +{ > + const struct block_list *l1 = p1, *l2 = p2; > + > + return l2->page_num - l1->page_num; > +} > + > +static int get_page_num(char *buf) > +{ > + int err, val_len, order_val; > + char order_str[4] = {0}; > + char *endptr; > + regmatch_t pmatch[2]; > + > + err = regexec(&order_pattern, buf, 2, pmatch, REG_NOTBOL); > + if (err != 0 || pmatch[1].rm_so == -1) { > + printf("no order pattern in %s\n", buf); Shouldn't error messages normally be directed to stderr? We aren't very consistent about this but it was the accepted thing to do 20-30 years ago, lol. > + return 0; > + } > + val_len = pmatch[1].rm_eo - pmatch[1].rm_so; > + if (val_len > 2) /* max_order should not exceed 2 digits */ > + goto wrong_order; > + > + memcpy(order_str, buf + pmatch[1].rm_so, val_len); > + > + errno = 0; > + order_val = strtol(order_str, &endptr, 10); > + if (errno != 0 || endptr == order_str || *endptr != '\0') > + goto wrong_order; > + > + return 1 << order_val; > + > +wrong_order: > + printf("wrong order in follow buf:\n%s\n", buf); > + return 0; > +} > + > static void add_list(char *buf, int len) > { > if (list_size != 0 && > len == list[list_size-1].len && > memcmp(buf, list[list_size-1].txt, len) == 0) { > list[list_size-1].num++; > + list[list_size-1].page_num += get_page_num(buf); > return; > } > if (list_size == max_size) { > @@ -74,6 +118,7 @@ static void add_list(char *buf, int len) > list[list_size].txt = malloc(len+1); > list[list_size].len = len; > list[list_size].num = 1; > + list[list_size].page_num = get_page_num(buf); > memcpy(list[list_size].txt, buf, len); > list[list_size].txt[len] = 0; > list_size++; > @@ -85,6 +130,13 @@ static void add_list(char *buf, int len) > > #define BUF_SIZE (128 * 1024) > > +static void usage(void) > +{ > + printf("Usage: ./page_owner_sort [-m] \n" > + "-m Sort by total memory. If not set this option, sort by times\n" s/If not set this option/If this option is unset/