From nobody Tue Dec 16 19:54:50 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B67CECDB47E for ; Fri, 13 Oct 2023 19:05:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231657AbjJMTFK (ORCPT ); Fri, 13 Oct 2023 15:05:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231703AbjJMTFG (ORCPT ); Fri, 13 Oct 2023 15:05:06 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7007DBE for ; Fri, 13 Oct 2023 12:04:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697223862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IjtK2o/m5KP3/dyNmmPPz1m7WWyth7vyB+quu5YHBuU=; b=b4XcgHrvqT0gmuX7MdNm4FmHTOn1X0mOOvMtyIaIdZaVDwAWl8+Ss8Ar91CJku5lP34SJp WfYmuqA04TX9pQFOmdr0pnbTNzGFU63gauLJvTfzTY6qeMOrz5gCI/fJe3LTPnRv6mDfpo e1oBW+1yxcMCaZDt91Dq4ZvSaK8IX6k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-68-1r44kpejO3C42J4SMTd1YA-1; Fri, 13 Oct 2023 15:04:06 -0400 X-MC-Unique: 1r44kpejO3C42J4SMTd1YA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E803382A68B; Fri, 13 Oct 2023 19:04:05 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.33.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD86B2157F5A; Fri, 13 Oct 2023 19:04:05 +0000 (UTC) From: Audra Mitchell To: linux-mm@kvack.org Cc: raquini@redhat.com, akpm@linux-foundation.org, djakov@kernel.org, vbabka@suse.cz, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] mm/page_owner: Remove free_ts from page_owner output Date: Fri, 13 Oct 2023 15:03:45 -0400 Message-ID: <20231013190350.579407-2-audra@redhat.com> In-Reply-To: <20231013190350.579407-1-audra@redhat.com> References: <20231013190350.579407-1-audra@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When printing page_owner data via the sysfs interface, no free pages will ever be dumped due to the series of checks in read_page_owner(): /* * Although we do have the info about past allocation of free * pages, it's not relevant for current memory usage. */ if (!test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags)) The free_ts values are still used when dump_page_owner() is called, so keeping the field for other use cases but removing them for the typical page_owner case. Fixes: 866b48526217 ("mm/page_owner: record the timestamp of all pages duri= ng free") Signed-off-by: Audra Mitchell Acked-by: Rafael Aquini Reviewed-by: Vlastimil Babka --- mm/page_owner.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 4e2723e1b300..4f13ce7d2452 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -408,11 +408,11 @@ print_page_owner(char __user *buf, size_t count, unsi= gned long pfn, return -ENOMEM; =20 ret =3D scnprintf(kbuf, count, - "Page allocated via order %u, mask %#x(%pGg), pid %d, tgid %d (%s), ts = %llu ns, free_ts %llu ns\n", + "Page allocated via order %u, mask %#x(%pGg), pid %d, tgid %d (%s), ts = %llu ns\n", page_owner->order, page_owner->gfp_mask, &page_owner->gfp_mask, page_owner->pid, page_owner->tgid, page_owner->comm, - page_owner->ts_nsec, page_owner->free_ts_nsec); + page_owner->ts_nsec); =20 /* Print information relevant to grouping pages by mobility */ pageblock_mt =3D get_pageblock_migratetype(page); --=20 2.41.0 From nobody Tue Dec 16 19:54:50 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EFD6CDB47E for ; Fri, 13 Oct 2023 19:04:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231650AbjJMTE6 (ORCPT ); Fri, 13 Oct 2023 15:04:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231578AbjJMTE4 (ORCPT ); Fri, 13 Oct 2023 15:04:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C3BD95 for ; Fri, 13 Oct 2023 12:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697223850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W2bd7t672x7Ht0iwDNlV5Z1QF/m/zxxAw+Mep/2+SWM=; b=chJk0ROs3j49E3wOZY2+zWVdNjn676wKbYFnobRT9GCd1ZYYX/EvSDTmsiv/RxrQHE5Hht CG+xqXD5rqibw7k9v0GzQyZaHaeR1l4TWAKTgfiE+kOX+FQU0coMe+KRq6FD5nipiWx9PR 7ZOShU70cPsGvkU28+3xra889ywRcj0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-169-vGBE6-tDPteZJmvR5owYpg-1; Fri, 13 Oct 2023 15:04:06 -0400 X-MC-Unique: vGBE6-tDPteZJmvR5owYpg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B3CC85A5BA; Fri, 13 Oct 2023 19:04:06 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.33.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00BE62157F5A; Fri, 13 Oct 2023 19:04:05 +0000 (UTC) From: Audra Mitchell To: linux-mm@kvack.org Cc: raquini@redhat.com, akpm@linux-foundation.org, djakov@kernel.org, vbabka@suse.cz, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] tools/mm: Remove references to free_ts from page_owner_sort Date: Fri, 13 Oct 2023 15:03:46 -0400 Message-ID: <20231013190350.579407-3-audra@redhat.com> In-Reply-To: <20231013190350.579407-1-audra@redhat.com> References: <20231013190350.579407-1-audra@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With the removal of free timestamps from page_owner output, we no longer need to handle this case or the "unreleased" case. Remove all references to both cases. Signed-off-by: Audra Mitchell Acked-by: Rafael Aquini Reviewed-by: Vlastimil Babka --- tools/mm/page_owner_sort.c | 98 +++++--------------------------------- 1 file changed, 12 insertions(+), 86 deletions(-) diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c index 99798894b879..9c93f3f4514f 100644 --- a/tools/mm/page_owner_sort.c +++ b/tools/mm/page_owner_sort.c @@ -33,7 +33,6 @@ struct block_list { char *comm; // task command name char *stacktrace; __u64 ts_nsec; - __u64 free_ts_nsec; int len; int num; int page_num; @@ -42,18 +41,16 @@ struct block_list { int allocator; }; enum FILTER_BIT { - FILTER_UNRELEASE =3D 1<<1, - FILTER_PID =3D 1<<2, - FILTER_TGID =3D 1<<3, - FILTER_COMM =3D 1<<4 + FILTER_PID =3D 1<<1, + FILTER_TGID =3D 1<<2, + FILTER_COMM =3D 1<<3 }; enum CULL_BIT { - CULL_UNRELEASE =3D 1<<1, - CULL_PID =3D 1<<2, - CULL_TGID =3D 1<<3, - CULL_COMM =3D 1<<4, - CULL_STACKTRACE =3D 1<<5, - CULL_ALLOCATOR =3D 1<<6 + CULL_PID =3D 1<<1, + CULL_TGID =3D 1<<2, + CULL_COMM =3D 1<<3, + CULL_STACKTRACE =3D 1<<4, + CULL_ALLOCATOR =3D 1<<5 }; enum ALLOCATOR_BIT { ALLOCATOR_CMA =3D 1<<1, @@ -62,9 +59,8 @@ enum ALLOCATOR_BIT { ALLOCATOR_OTHERS =3D 1<<4 }; enum ARG_TYPE { - ARG_TXT, ARG_COMM, ARG_STACKTRACE, ARG_ALLOC_TS, ARG_FREE_TS, - ARG_CULL_TIME, ARG_PAGE_NUM, ARG_PID, ARG_TGID, ARG_UNKNOWN, ARG_FREE, - ARG_ALLOCATOR + ARG_TXT, ARG_COMM, ARG_STACKTRACE, ARG_ALLOC_TS, ARG_CULL_TIME, + ARG_PAGE_NUM, ARG_PID, ARG_TGID, ARG_UNKNOWN, ARG_ALLOCATOR }; enum SORT_ORDER { SORT_ASC =3D 1, @@ -90,7 +86,6 @@ static regex_t pid_pattern; static regex_t tgid_pattern; static regex_t comm_pattern; static regex_t ts_nsec_pattern; -static regex_t free_ts_nsec_pattern; static struct block_list *list; static int list_size; static int max_size; @@ -181,24 +176,6 @@ static int compare_ts(const void *p1, const void *p2) return l1->ts_nsec < l2->ts_nsec ? -1 : 1; } =20 -static int compare_free_ts(const void *p1, const void *p2) -{ - const struct block_list *l1 =3D p1, *l2 =3D p2; - - 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 =3D p1, *l2 =3D p2; - - if (!l1->free_ts_nsec && !l2->free_ts_nsec) - return 0; - if (l1->free_ts_nsec && l2->free_ts_nsec) - return 0; - return l1->free_ts_nsec ? 1 : -1; -} - static int compare_cull_condition(const void *p1, const void *p2) { if (cull =3D=3D 0) @@ -211,8 +188,6 @@ static int compare_cull_condition(const void *p1, const= void *p2) return compare_tgid(p1, p2); if ((cull & CULL_COMM) && compare_comm(p1, p2)) return compare_comm(p1, p2); - if ((cull & CULL_UNRELEASE) && compare_release(p1, p2)) - return compare_release(p1, p2); if ((cull & CULL_ALLOCATOR) && compare_allocator(p1, p2)) return compare_allocator(p1, p2); return 0; @@ -366,24 +341,6 @@ static __u64 get_ts_nsec(char *buf) return ts_nsec; } =20 -static __u64 get_free_ts_nsec(char *buf) -{ - __u64 free_ts_nsec; - char free_ts_nsec_str[FIELD_BUFF] =3D {0}; - char *endptr; - - search_pattern(&free_ts_nsec_pattern, free_ts_nsec_str, buf); - errno =3D 0; - free_ts_nsec =3D strtoull(free_ts_nsec_str, &endptr, 10); - if (errno !=3D 0 || endptr =3D=3D free_ts_nsec_str || *endptr !=3D '\0') { - if (debug_on) - fprintf(stderr, "wrong free_ts_nsec in follow buf:\n%s\n", buf); - return -1; - } - - return free_ts_nsec; -} - static char *get_comm(char *buf) { char *comm_str =3D malloc(TASK_COMM_LEN); @@ -411,12 +368,8 @@ static int get_arg_type(const char *arg) return ARG_COMM; else if (!strcmp(arg, "stacktrace") || !strcmp(arg, "st")) return ARG_STACKTRACE; - else if (!strcmp(arg, "free") || !strcmp(arg, "f")) - return ARG_FREE; else if (!strcmp(arg, "txt") || !strcmp(arg, "T")) return ARG_TXT; - else if (!strcmp(arg, "free_ts") || !strcmp(arg, "ft")) - return ARG_FREE_TS; else if (!strcmp(arg, "alloc_ts") || !strcmp(arg, "at")) return ARG_ALLOC_TS; else if (!strcmp(arg, "allocator") || !strcmp(arg, "ator")) @@ -471,13 +424,6 @@ static bool match_str_list(const char *str, char **lis= t, int list_size) =20 static bool is_need(char *buf) { - __u64 ts_nsec, free_ts_nsec; - - ts_nsec =3D get_ts_nsec(buf); - free_ts_nsec =3D get_free_ts_nsec(buf); - - if ((filter & FILTER_UNRELEASE) && free_ts_nsec !=3D 0 && ts_nsec < free_= ts_nsec) - return false; if ((filter & FILTER_PID) && !match_num_list(get_pid(buf), fc.pids, fc.pi= ds_size)) return false; if ((filter & FILTER_TGID) && @@ -528,7 +474,6 @@ static bool add_list(char *buf, int len, char *ext_buf) if (*list[list_size].stacktrace =3D=3D '\n') list[list_size].stacktrace++; list[list_size].ts_nsec =3D get_ts_nsec(buf); - list[list_size].free_ts_nsec =3D get_free_ts_nsec(buf); list[list_size].allocator =3D get_allocator(buf, ext_buf); list_size++; if (list_size % 1000 =3D=3D 0) { @@ -554,8 +499,6 @@ static bool parse_cull_args(const char *arg_str) cull |=3D CULL_COMM; else if (arg_type =3D=3D ARG_STACKTRACE) cull |=3D CULL_STACKTRACE; - else if (arg_type =3D=3D ARG_FREE) - cull |=3D CULL_UNRELEASE; else if (arg_type =3D=3D ARG_ALLOCATOR) cull |=3D CULL_ALLOCATOR; else { @@ -616,8 +559,6 @@ static bool parse_sort_args(const char *arg_str) sc.cmps[i] =3D compare_stacktrace; else if (arg_type =3D=3D ARG_ALLOC_TS) sc.cmps[i] =3D compare_ts; - else if (arg_type =3D=3D ARG_FREE_TS) - sc.cmps[i] =3D compare_free_ts; else if (arg_type =3D=3D ARG_TXT) sc.cmps[i] =3D compare_txt; else if (arg_type =3D=3D ARG_ALLOCATOR) @@ -679,8 +620,6 @@ static void usage(void) "-P\t\tSort by tgid.\n" "-n\t\tSort by task command name.\n" "-a\t\tSort by memory allocate time.\n" - "-r\t\tSort by memory release time.\n" - "-f\t\tFilter out the information of blocks whose memory has been releas= ed.\n" "-d\t\tPrint debug information.\n" "--pid \tSelect by pid. This selects the information of blocks = whose process ID numbers appear in .\n" "--tgid \tSelect by tgid. This selects the information of bloc= ks whose Thread Group ID numbers appear in .\n" @@ -706,7 +645,7 @@ int main(int argc, char **argv) { 0, 0, 0, 0}, }; =20 - while ((opt =3D getopt_long(argc, argv, "adfmnprstP", longopts, NULL)) != =3D -1) + while ((opt =3D getopt_long(argc, argv, "admnpstP", longopts, NULL)) !=3D= -1) switch (opt) { case 'a': set_single_cmp(compare_ts, SORT_ASC); @@ -714,18 +653,12 @@ int main(int argc, char **argv) case 'd': debug_on =3D true; break; - case 'f': - filter =3D filter | FILTER_UNRELEASE; - break; case 'm': set_single_cmp(compare_page_num, SORT_DESC); break; case 'p': set_single_cmp(compare_pid, SORT_ASC); break; - case 'r': - set_single_cmp(compare_free_ts, SORT_ASC); - break; case 's': set_single_cmp(compare_stacktrace, SORT_ASC); break; @@ -800,10 +733,8 @@ int main(int argc, char **argv) goto out_tgid; if (!check_regcomp(&comm_pattern, "tgid\\s*[0-9]*\\s*\\((.*)\\),\\s*ts")) goto out_comm; - if (!check_regcomp(&ts_nsec_pattern, "ts\\s*([0-9]*)\\s*ns,")) + if (!check_regcomp(&ts_nsec_pattern, "ts\\s*([0-9]*)\\s*ns")) goto out_ts; - if (!check_regcomp(&free_ts_nsec_pattern, "free_ts\\s*([0-9]*)\\s*ns")) - goto out_free_ts; =20 fstat(fileno(fin), &st); max_size =3D st.st_size / 100; /* hack ... */ @@ -864,9 +795,6 @@ int main(int argc, char **argv) fprintf(fout, ", "); print_allocator(fout, list[i].allocator); } - if (cull & CULL_UNRELEASE) - fprintf(fout, " (%s)", - list[i].free_ts_nsec ? "UNRELEASED" : "RELEASED"); if (cull & CULL_STACKTRACE) fprintf(fout, ":\n%s", list[i].stacktrace); fprintf(fout, "\n"); @@ -880,8 +808,6 @@ int main(int argc, char **argv) free(buf); if (list) free(list); -out_free_ts: - regfree(&free_ts_nsec_pattern); out_ts: regfree(&ts_nsec_pattern); out_comm: --=20 2.41.0 From nobody Tue Dec 16 19:54:50 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A883ACDB482 for ; Fri, 13 Oct 2023 19:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231713AbjJMTFF (ORCPT ); Fri, 13 Oct 2023 15:05:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231705AbjJMTFD (ORCPT ); Fri, 13 Oct 2023 15:05:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7CF5BF for ; Fri, 13 Oct 2023 12:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697223854; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zR5p3ioGj44ReczmQkXwckrYVMKEAFkp4XWCVgfnl84=; b=S7vm8MUJfBKHRToOJzXWHYHQK8xMj4nepiIWZ5dxKGCwpk6GsPU+6CJjr5YcJ1ECEL0n4G vEX0bn2lBWsN8S4QnxJDA9tVe8Rd4yLqv00uFv11Wu77atiE6vCAUVl/NYdkX8Z0k9pYP2 VSH7yZgnGmdrUDr0pXg7IR1Mfo8y+Os= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-275-TnrzPz-tMWW8slqjaMdDHg-1; Fri, 13 Oct 2023 15:04:10 -0400 X-MC-Unique: TnrzPz-tMWW8slqjaMdDHg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 82CEF185A795; Fri, 13 Oct 2023 19:04:06 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.33.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 482022157F5A; Fri, 13 Oct 2023 19:04:06 +0000 (UTC) From: Audra Mitchell To: linux-mm@kvack.org Cc: raquini@redhat.com, akpm@linux-foundation.org, djakov@kernel.org, vbabka@suse.cz, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] tools/mm: Filter out timestamps for correct collation Date: Fri, 13 Oct 2023 15:03:47 -0400 Message-ID: <20231013190350.579407-4-audra@redhat.com> In-Reply-To: <20231013190350.579407-1-audra@redhat.com> References: <20231013190350.579407-1-audra@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With the introduction of allocation timestamps being included in page_owner output, each record becomes unique due to the timestamp nanosecond granularity. Remove the check in add_list that tries to collate each record during processing as the memcmp() is just additional overhead at this point. Also keep the allocation timestamps, but allow collation to occur without consideration of the allocation timestamp except in the case were allocation timestamps are requested by the user (the -a option). Signed-off-by: Audra Mitchell Acked-by: Rafael Aquini Acked-by: Vlastimil Babka --- tools/mm/page_owner_sort.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c index 9c93f3f4514f..7ddabcb3a073 100644 --- a/tools/mm/page_owner_sort.c +++ b/tools/mm/page_owner_sort.c @@ -203,6 +203,21 @@ static int compare_sort_condition(const void *p1, cons= t void *p2) return cmp; } =20 +static int remove_pattern(regex_t *pattern, char *buf, int len) +{ + regmatch_t pmatch[2]; + int err; + + err =3D regexec(pattern, buf, 2, pmatch, REG_NOTBOL); + if (err !=3D 0 || pmatch[1].rm_so =3D=3D -1) + return len; + + memcpy(buf + pmatch[1].rm_so, + buf + pmatch[1].rm_eo, len - pmatch[1].rm_eo); + + return len - (pmatch[1].rm_eo - pmatch[1].rm_so); +} + static int search_pattern(regex_t *pattern, char *pattern_str, char *buf) { int err, val_len; @@ -443,13 +458,6 @@ static bool is_need(char *buf) =20 static bool add_list(char *buf, int len, char *ext_buf) { - if (list_size !=3D 0 && - len =3D=3D list[list_size-1].len && - memcmp(buf, list[list_size-1].txt, len) =3D=3D 0) { - list[list_size-1].num++; - list[list_size-1].page_num +=3D get_page_num(buf); - return true; - } if (list_size =3D=3D max_size) { fprintf(stderr, "max_size too small??\n"); return false; @@ -465,6 +473,9 @@ static bool add_list(char *buf, int len, char *ext_buf) return false; } memcpy(list[list_size].txt, buf, len); + if (sc.cmps[0] !=3D compare_ts) { + len =3D remove_pattern(&ts_nsec_pattern, list[list_size].txt, len); + } list[list_size].txt[len] =3D 0; list[list_size].len =3D len; list[list_size].num =3D 1; --=20 2.41.0 From nobody Tue Dec 16 19:54:50 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A03E7CDB482 for ; Fri, 13 Oct 2023 19:05:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231703AbjJMTFY (ORCPT ); Fri, 13 Oct 2023 15:05:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231728AbjJMTFS (ORCPT ); Fri, 13 Oct 2023 15:05:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A37FC0 for ; Fri, 13 Oct 2023 12:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697223871; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mbcGDdPDyjQuCaqCE5MIIL6VIXi6uhOqjz8GCAoYgAs=; b=QEJ7308yCLN7gdXapeovVij1isOyneLaHBywaDGmaGzM/QiG7Qsudtsb2XZx3KM48Hee7h B1D9ASSM+Gcxpw0YOUoz1lx+zMC1M9uqyOdaJqOdwGxMcM/C+eHk/7a+z0D35rCXWWmgvy 3fF1fXzTmg6Gy7njbh4xMxEBO+0WzQw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-283-jTkVSu38NWqJ-9Hlh8G7xw-1; Fri, 13 Oct 2023 15:04:07 -0400 X-MC-Unique: jTkVSu38NWqJ-9Hlh8G7xw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C9D661029F40; Fri, 13 Oct 2023 19:04:06 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.33.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F2432157F5A; Fri, 13 Oct 2023 19:04:06 +0000 (UTC) From: Audra Mitchell To: linux-mm@kvack.org Cc: raquini@redhat.com, akpm@linux-foundation.org, djakov@kernel.org, vbabka@suse.cz, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] tools/mm: Fix the default case for page_owner_sort Date: Fri, 13 Oct 2023 15:03:48 -0400 Message-ID: <20231013190350.579407-5-audra@redhat.com> In-Reply-To: <20231013190350.579407-1-audra@redhat.com> References: <20231013190350.579407-1-audra@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With the additional commands and timestamps added to the tool, the default case (-t) has been broken. Now that the allocation timestamps are saved outside of the txt field, allow us to properly sort the data by number of times the record has been seen. Furthermore prevent the misuse of the commandline arguments so only one compare option can be used. Signed-off-by: Audra Mitchell Acked-by: Rafael Aquini Acked-by: Vlastimil Babka --- tools/mm/page_owner_sort.c | 61 +++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c index 7ddabcb3a073..5a260096ebaa 100644 --- a/tools/mm/page_owner_sort.c +++ b/tools/mm/page_owner_sort.c @@ -66,6 +66,16 @@ enum SORT_ORDER { SORT_ASC =3D 1, SORT_DESC =3D -1, }; +enum COMP_FLAG { + COMP_NO_FLAG =3D 0, + COMP_ALLOC =3D 1<<0, + COMP_PAGE_NUM =3D 1<<1, + COMP_PID =3D 1<<2, + COMP_STACK =3D 1<<3, + COMP_NUM =3D 1<<4, + COMP_TGID =3D 1<<5, + COMP_COMM =3D 1<<6 +}; struct filter_condition { pid_t *pids; pid_t *tgids; @@ -644,7 +654,7 @@ int main(int argc, char **argv) { FILE *fin, *fout; char *buf, *ext_buf; - int i, count; + int i, count, compare_flag; struct stat st; int opt; struct option longopts[] =3D { @@ -656,31 +666,33 @@ int main(int argc, char **argv) { 0, 0, 0, 0}, }; =20 + compare_flag =3D COMP_NO_FLAG; + while ((opt =3D getopt_long(argc, argv, "admnpstP", longopts, NULL)) !=3D= -1) switch (opt) { case 'a': - set_single_cmp(compare_ts, SORT_ASC); + compare_flag |=3D COMP_ALLOC; break; case 'd': debug_on =3D true; break; case 'm': - set_single_cmp(compare_page_num, SORT_DESC); + compare_flag |=3D COMP_PAGE_NUM; break; case 'p': - set_single_cmp(compare_pid, SORT_ASC); + compare_flag |=3D COMP_PID; break; case 's': - set_single_cmp(compare_stacktrace, SORT_ASC); + compare_flag |=3D COMP_STACK; break; case 't': - set_single_cmp(compare_num, SORT_DESC); + compare_flag |=3D COMP_NUM; break; case 'P': - set_single_cmp(compare_tgid, SORT_ASC); + compare_flag |=3D COMP_TGID; break; case 'n': - set_single_cmp(compare_comm, SORT_ASC); + compare_flag |=3D COMP_COMM; break; case 1: filter =3D filter | FILTER_PID; @@ -728,6 +740,39 @@ int main(int argc, char **argv) exit(1); } =20 + /* Only one compare option is allowed, yet we also want handle the + * default case were no option is provided, but we still want to + * match the behavior of the -t option (compare by number of times + * a record is seen + */ + switch (compare_flag) { + case COMP_ALLOC: + set_single_cmp(compare_ts, SORT_ASC); + break; + case COMP_PAGE_NUM: + set_single_cmp(compare_page_num, SORT_DESC); + break; + case COMP_PID: + set_single_cmp(compare_pid, SORT_ASC); + break; + case COMP_STACK: + set_single_cmp(compare_stacktrace, SORT_ASC); + break; + case COMP_NO_FLAG: + case COMP_NUM: + set_single_cmp(compare_num, SORT_DESC); + break; + case COMP_TGID: + set_single_cmp(compare_tgid, SORT_ASC); + break; + case COMP_COMM: + set_single_cmp(compare_comm, SORT_ASC); + break; + default: + usage(); + exit(1); + } + fin =3D fopen(argv[optind], "r"); fout =3D fopen(argv[optind + 1], "w"); if (!fin || !fout) { --=20 2.41.0 From nobody Tue Dec 16 19:54:50 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC8A4CDB482 for ; Fri, 13 Oct 2023 19:04:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231612AbjJMTE5 (ORCPT ); Fri, 13 Oct 2023 15:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjJMTEz (ORCPT ); Fri, 13 Oct 2023 15:04:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79F3DA9 for ; Fri, 13 Oct 2023 12:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697223851; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4XvnTft2MmJ8VY609+be7Cy1Q085UedMhCWzkSGYTRU=; b=TBtcE9QH46JvR4poJuijN3KH005HjZnmH6Yil2GQTMKAAt+yMJBG8hJSunHnWgpc9atTxk k0UMwY6uClBge74NH9BwJvq8FSBOzPlhzZrLVZdUlvNQIfUCZMZ7I7UYqGCe00LtDlUdQm WYhxVCbaGsItWBjPHhiyjND/WaYuby8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-447-eVID_ZQ_N8aIESBG-T1o-A-1; Fri, 13 Oct 2023 15:04:07 -0400 X-MC-Unique: eVID_ZQ_N8aIESBG-T1o-A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D0CC801E62; Fri, 13 Oct 2023 19:04:07 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.33.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id D69472157F5A; Fri, 13 Oct 2023 19:04:06 +0000 (UTC) From: Audra Mitchell To: linux-mm@kvack.org Cc: raquini@redhat.com, akpm@linux-foundation.org, djakov@kernel.org, vbabka@suse.cz, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] tools/mm: Update the usage output to be more organized Date: Fri, 13 Oct 2023 15:03:49 -0400 Message-ID: <20231013190350.579407-6-audra@redhat.com> In-Reply-To: <20231013190350.579407-1-audra@redhat.com> References: <20231013190350.579407-1-audra@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Organize the usage options alphabetically and improve the description of some options. Also separate the more complicated cull options from the single use compare options. Signed-off-by: Audra Mitchell Acked-by: Rafael Aquini Acked-by: Vlastimil Babka --- tools/mm/page_owner_sort.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c index 5a260096ebaa..e1f264444342 100644 --- a/tools/mm/page_owner_sort.c +++ b/tools/mm/page_owner_sort.c @@ -634,19 +634,26 @@ static void print_allocator(FILE *out, int allocator) static void usage(void) { printf("Usage: ./page_owner_sort [OPTIONS] \n" - "-m\t\tSort by total memory.\n" - "-s\t\tSort by the stack trace.\n" - "-t\t\tSort by times (default).\n" - "-p\t\tSort by pid.\n" - "-P\t\tSort by tgid.\n" - "-n\t\tSort by task command name.\n" - "-a\t\tSort by memory allocate time.\n" - "-d\t\tPrint debug information.\n" - "--pid \tSelect by pid. This selects the information of blocks = whose process ID numbers appear in .\n" - "--tgid \tSelect by tgid. This selects the information of bloc= ks whose Thread Group ID numbers appear in .\n" - "--name \n\t\tSelect by command name. This selects the informat= ion of blocks whose command name appears in .\n" - "--cull \tCull by user-defined rules. is a single argument= in the form of a comma-separated list with some common fields predefined\n" - "--sort \tSpecify sort order as: [+|-]key[,[+|-]key[,...]]\n" + "-a\t\t\tSort by memory allocation time.\n" + "-m\t\t\tSort by total memory.\n" + "-n\t\t\tSort by task command name.\n" + "-p\t\t\tSort by pid.\n" + "-P\t\t\tSort by tgid.\n" + "-s\t\t\tSort by the stacktrace.\n" + "-t\t\t\tSort by number of times record is seen (default).\n\n" + "--pid \t\tSelect by pid. This selects the information" + " of\n\t\t\tblocks whose process ID numbers appear in .\n" + "--tgid \tSelect by tgid. This selects the information" + " of\n\t\t\tblocks whose Thread Group ID numbers appear in " + ".\n" + "--name \tSelect by command name. This selects the" + " information\n\t\t\tof blocks whose command name appears in" + " .\n" + "--cull \t\tCull by user-defined rules. is a " + "single\n\t\t\targument in the form of a comma-separated list " + "with some\n\t\t\tcommon fields predefined (pid, tgid, comm, " + "stacktrace, allocator)\n" + "--sort \t\tSpecify sort order as: [+|-]key[,[+|-]key[,...]]\n" ); } =20 --=20 2.41.0