From patchwork Mon Jan 31 19:23:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12731056 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 796DEC433EF for ; Mon, 31 Jan 2022 19:23:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 091C76B00EC; Mon, 31 Jan 2022 14:23:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 041C66B00EE; Mon, 31 Jan 2022 14:23:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4C1F6B00EF; Mon, 31 Jan 2022 14:23:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id D50EB6B00EC for ; Mon, 31 Jan 2022 14:23:51 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9BC96998AE for ; Mon, 31 Jan 2022 19:23:51 +0000 (UTC) X-FDA: 79091557062.25.57ED819 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 2F5C1140002 for ; Mon, 31 Jan 2022 19:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643657030; 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=FSCcYBtevS72h8Rb3ThNAKipb4CG2TPJPslkwwiiaHA=; b=aGtS4PKO7Xsp9u8JzMRaUYcbAbiBsvTHoIL1Ag2XoM7wkoBZh8nfnqazw4keV4ClWm7g/c Fs5oHdXrOtGlrJ966NevFn4cw8hTDkUn4SCjmVSWaeWnHbz4eQAQDWBV6uRPb15jY17+OC aItt33d0W3vJDMEvuHZ/Oe6hG5FztnE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-520-abdKjMwNOGWccPAZQ_acdA-1; Mon, 31 Jan 2022 14:23:25 -0500 X-MC-Unique: abdKjMwNOGWccPAZQ_acdA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 81D351006AA0; Mon, 31 Jan 2022 19:23:23 +0000 (UTC) Received: from llong.com (unknown [10.22.16.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 567BD10001AF; Mon, 31 Jan 2022 19:23:21 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Ira Weiny , Mike Rapoport , David Rientjes , Roman Gushchin , Rafael Aquini , Waiman Long Subject: [PATCH v3 1/4] lib/vsprintf: Avoid redundant work with 0 size Date: Mon, 31 Jan 2022 14:23:05 -0500 Message-Id: <20220131192308.608837-2-longman@redhat.com> In-Reply-To: <20220131192308.608837-1-longman@redhat.com> References: <20220131192308.608837-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 2F5C1140002 X-Stat-Signature: ejfpdkn1mgz7q618g49q4cwgpn7fxuzu Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aGtS4PKO; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf09.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=longman@redhat.com X-Rspam-User: nil X-HE-Tag: 1643657030-527036 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: For *scnprintf(), vsnprintf() is always called even if the input size is 0. That is a waste of time, so just return 0 in this case. Note that vsnprintf() will never return -1 to indicate an error. So skipping the call to vsnprintf() when size is 0 will have no functional impact at all. Signed-off-by: Waiman Long Acked-by: David Rientjes Reviewed-by: Sergey Senozhatsky Acked-by: Roman Gushchin Acked-by: Mike Rapoport --- lib/vsprintf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 3b8129dd374c..d419154b47bb 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -2895,13 +2895,15 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) { int i; + if (unlikely(!size)) + return 0; + i = vsnprintf(buf, size, fmt, args); if (likely(i < size)) return i; - if (size != 0) - return size - 1; - return 0; + + return size - 1; } EXPORT_SYMBOL(vscnprintf); From patchwork Mon Jan 31 19:23:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12731053 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 D395CC433FE for ; Mon, 31 Jan 2022 19:23:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F2296B00E8; Mon, 31 Jan 2022 14:23:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 57BC66B00E9; Mon, 31 Jan 2022 14:23:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43AAA8D0001; Mon, 31 Jan 2022 14:23:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 330556B00E6 for ; Mon, 31 Jan 2022 14:23:33 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E43E118205803 for ; Mon, 31 Jan 2022 19:23:32 +0000 (UTC) X-FDA: 79091556264.31.C88D68A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 7EE0FC0007 for ; Mon, 31 Jan 2022 19:23:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643657011; 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=aswR5jLflKHAA/2KWO7s8HDPhJp/8ybDJLjB9qtlMrw=; b=G5r/QS/v1hsrHgOhMUdIpqHSOMwzmn20qrK5u3oFkt5JRvgfyzRRwoTubUlmXKrkwtNMfL Hh28F2z9ZHPXOzIWaihXMuHpG+s0g04yLKMPXKMgwW6yqUIqf9kVO46gu4Ubvk0CaV/+r2 2QmiOYd36+0qv4G69FBtOJbDe1T4Nag= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-156-ZSd268VyPNOMiE_qXzRP3A-1; Mon, 31 Jan 2022 14:23:28 -0500 X-MC-Unique: ZSd268VyPNOMiE_qXzRP3A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C71591083F68; Mon, 31 Jan 2022 19:23:25 +0000 (UTC) Received: from llong.com (unknown [10.22.16.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADF7210013C1; Mon, 31 Jan 2022 19:23:23 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Ira Weiny , Mike Rapoport , David Rientjes , Roman Gushchin , Rafael Aquini , Waiman Long Subject: [PATCH v3 2/4] mm/page_owner: Use scnprintf() to avoid excessive buffer overrun check Date: Mon, 31 Jan 2022 14:23:06 -0500 Message-Id: <20220131192308.608837-3-longman@redhat.com> In-Reply-To: <20220131192308.608837-1-longman@redhat.com> References: <20220131192308.608837-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Rspam-User: nil X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7EE0FC0007 X-Stat-Signature: knytd16kjxw9x1xptbsgqw9ys7ih8z3q Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="G5r/QS/v"; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf22.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=longman@redhat.com X-HE-Tag: 1643657012-76703 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: The snprintf() function can return a length greater than the given input size. That will require a check for buffer overrun after each invocation of snprintf(). scnprintf(), on the other hand, will never return a greater length. By using scnprintf() in selected places, we can avoid some buffer overrun checks except after stack_depot_snprint() and after the last snprintf(). Signed-off-by: Waiman Long Acked-by: David Rientjes Reviewed-by: Sergey Senozhatsky Acked-by: Roman Gushchin Acked-by: Mike Rapoport --- mm/page_owner.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 99e360df9465..28dac73e0542 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -338,19 +338,16 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, if (!kbuf) return -ENOMEM; - ret = snprintf(kbuf, count, + ret = scnprintf(kbuf, count, "Page allocated via order %u, mask %#x(%pGg), pid %d, ts %llu ns, free_ts %llu ns\n", page_owner->order, page_owner->gfp_mask, &page_owner->gfp_mask, page_owner->pid, page_owner->ts_nsec, page_owner->free_ts_nsec); - if (ret >= count) - goto err; - /* Print information relevant to grouping pages by mobility */ pageblock_mt = get_pageblock_migratetype(page); page_mt = gfp_migratetype(page_owner->gfp_mask); - ret += snprintf(kbuf + ret, count - ret, + ret += scnprintf(kbuf + ret, count - ret, "PFN %lu type %s Block %lu type %s Flags %pGp\n", pfn, migratetype_names[page_mt], @@ -358,19 +355,14 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, migratetype_names[pageblock_mt], &page->flags); - if (ret >= count) - goto err; - ret += stack_depot_snprint(handle, kbuf + ret, count - ret, 0); if (ret >= count) goto err; if (page_owner->last_migrate_reason != -1) { - ret += snprintf(kbuf + ret, count - ret, + ret += scnprintf(kbuf + ret, count - ret, "Page has been migrated, last migrate reason: %s\n", migrate_reason_names[page_owner->last_migrate_reason]); - if (ret >= count) - goto err; } ret += snprintf(kbuf + ret, count - ret, "\n"); From patchwork Mon Jan 31 19:23:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12731054 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 EDAD4C4332F for ; Mon, 31 Jan 2022 19:23:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 995DD6B00E9; Mon, 31 Jan 2022 14:23:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 96AF18D0001; Mon, 31 Jan 2022 14:23:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73CB36B00EB; Mon, 31 Jan 2022 14:23:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0161.hostedemail.com [216.40.44.161]) by kanga.kvack.org (Postfix) with ESMTP id 549F96B00E6 for ; Mon, 31 Jan 2022 14:23:33 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1D886822F779 for ; Mon, 31 Jan 2022 19:23:33 +0000 (UTC) X-FDA: 79091556306.06.8780318 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 2114A100004 for ; Mon, 31 Jan 2022 19:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643657011; 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=AqKO5lknN2+Nsr0yWLMZlCagaD5YFaBIvpU1YV0vjJ8=; b=DKjX5FmFyK/4VadskiX5uBFMcFMh8U0QChWVrgQrPfiA9BanmS38F5AWJjycXKBXJKfwEu 1I4KdE+3aCWYwnxJCjDWBFhAnaEdlQyWt7Y4OGYON58ww9ST4LNy+jlAJnn7+w4NFe6sIH B+3XGm8oDUzZVmgbNP4ogZk3OKHnDZ8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-378-YH4BwOw-OHeQDi8OdBzUZA-1; Mon, 31 Jan 2022 14:23:30 -0500 X-MC-Unique: YH4BwOw-OHeQDi8OdBzUZA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 19CB48143E5; Mon, 31 Jan 2022 19:23:28 +0000 (UTC) Received: from llong.com (unknown [10.22.16.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id F296D10013C1; Mon, 31 Jan 2022 19:23:25 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Ira Weiny , Mike Rapoport , David Rientjes , Roman Gushchin , Rafael Aquini , Waiman Long Subject: [PATCH v3 3/4] mm/page_owner: Print memcg information Date: Mon, 31 Jan 2022 14:23:07 -0500 Message-Id: <20220131192308.608837-4-longman@redhat.com> In-Reply-To: <20220131192308.608837-1-longman@redhat.com> References: <20220131192308.608837-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2114A100004 X-Rspam-User: nil Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DKjX5FmF; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf05.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=longman@redhat.com X-Stat-Signature: sqnnp7jhrqxr616qfgxtsdxs8wzinber X-HE-Tag: 1643657011-787657 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: It was found that a number of offlined memcgs were not freed because they were pinned by some charged pages that were present. Even "echo 1 > /proc/sys/vm/drop_caches" wasn't able to free those pages. These offlined but not freed memcgs tend to increase in number over time with the side effect that percpu memory consumption as shown in /proc/meminfo also increases over time. In order to find out more information about those pages that pin offlined memcgs, the page_owner feature is extended to print memory cgroup information especially whether the cgroup is offlined or not. Signed-off-by: Waiman Long Acked-by: David Rientjes Acked-by: Roman Gushchin --- mm/page_owner.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/mm/page_owner.c b/mm/page_owner.c index 28dac73e0542..a471c74c7fe0 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "internal.h" @@ -325,6 +326,42 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m, seq_putc(m, '\n'); } +#ifdef CONFIG_MEMCG +/* + * Looking for memcg information and print it out + */ +static inline void print_page_owner_memcg(char *kbuf, size_t count, int *pret, + struct page *page) +{ + unsigned long memcg_data = READ_ONCE(page->memcg_data); + struct mem_cgroup *memcg; + bool onlined; + char name[80]; + + if (!memcg_data) + return; + + if (memcg_data & MEMCG_DATA_OBJCGS) + *pret += scnprintf(kbuf + *pret, count - *pret, + "Slab cache page\n"); + + memcg = page_memcg_check(page); + if (!memcg) + return; + + onlined = (memcg->css.flags & CSS_ONLINE); + cgroup_name(memcg->css.cgroup, name, sizeof(name)); + *pret += scnprintf(kbuf + *pret, count - *pret, + "Charged %sto %smemcg %s\n", + PageMemcgKmem(page) ? "(via objcg) " : "", + onlined ? "" : "offlined ", + name); +} +#else /* CONFIG_MEMCG */ +static inline void print_page_owner_memcg(char *kbuf, size_t count, int *pret, + struct page *page) { } +#endif /* CONFIG_MEMCG */ + static ssize_t print_page_owner(char __user *buf, size_t count, unsigned long pfn, struct page *page, struct page_owner *page_owner, @@ -365,6 +402,8 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, migrate_reason_names[page_owner->last_migrate_reason]); } + print_page_owner_memcg(kbuf, count, &ret, page); + ret += snprintf(kbuf + ret, count - ret, "\n"); if (ret >= count) goto err; From patchwork Mon Jan 31 19:23:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12731055 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 A92ACC433EF for ; Mon, 31 Jan 2022 19:23:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C8396B00EB; Mon, 31 Jan 2022 14:23:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 376DA6B00EC; Mon, 31 Jan 2022 14:23:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 217196B00ED; Mon, 31 Jan 2022 14:23:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 11DE36B00EB for ; Mon, 31 Jan 2022 14:23:39 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C434E998EB for ; Mon, 31 Jan 2022 19:23:38 +0000 (UTC) X-FDA: 79091556516.05.600F9F8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 563F0180008 for ; Mon, 31 Jan 2022 19:23:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643657017; 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=0Xg9VDn8wGaFMcda+Zs1goFaj5CYRr9QqJudVlDax4M=; b=RAQpvnKq5d/hv2m15Bm6EfoABIpQO1n2OiBUanKyomEXfgAZ1kI2IYKSr0lgz+sLC9kljM a6X2YojZdQIXc9A4SD5kdMieWmf3HBP1RC2lXhLf4h3aaYXGYx0vst2d2EZdpBxIZUHN2l qAMCXvD6ZDzbVjOmC+FXhjn4F1Vi88U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-104-AuHzqSQZMpyaJnb7UlIgPQ-1; Mon, 31 Jan 2022 14:23:34 -0500 X-MC-Unique: AuHzqSQZMpyaJnb7UlIgPQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 61EF839384; Mon, 31 Jan 2022 19:23:30 +0000 (UTC) Received: from llong.com (unknown [10.22.16.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4427110013C1; Mon, 31 Jan 2022 19:23:28 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Ira Weiny , Mike Rapoport , David Rientjes , Roman Gushchin , Rafael Aquini , Waiman Long Subject: [PATCH v3 4/4] mm/page_owner: Record task command name Date: Mon, 31 Jan 2022 14:23:08 -0500 Message-Id: <20220131192308.608837-5-longman@redhat.com> In-Reply-To: <20220131192308.608837-1-longman@redhat.com> References: <20220131192308.608837-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Stat-Signature: u9q597tha345wrgfrghxga5t7oe8qeu8 X-Rspam-User: nil Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RAQpvnKq; spf=none (imf06.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 563F0180008 X-HE-Tag: 1643657018-981410 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: The page_owner information currently includes the pid of the calling task. That is useful as long as the task is still running. Otherwise, the number is meaningless. To have more information about the allocating tasks that had exited by the time the page_owner information is retrieved, we need to store the command name of the task. Add a new comm field into page_owner structure to store the command name and display it when the page_owner information is retrieved. Only the first 15 characters of the command name will be copied, but that should be enough in most cases. Even for those commands with longer names, it shouldn't be hard to guess what they are. Signed-off-by: Waiman Long --- mm/page_owner.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index a471c74c7fe0..8b2b381fd986 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -20,6 +20,7 @@ * to use off stack temporal storage */ #define PAGE_OWNER_STACK_DEPTH (16) +#define PAGE_OWNER_COMM_LEN 16 struct page_owner { unsigned short order; @@ -29,6 +30,7 @@ struct page_owner { depot_stack_handle_t free_handle; u64 ts_nsec; u64 free_ts_nsec; + char comm[PAGE_OWNER_COMM_LEN]; pid_t pid; }; @@ -146,6 +148,7 @@ void __reset_page_owner(struct page *page, unsigned short order) page_owner = get_page_owner(page_ext); page_owner->free_handle = handle; page_owner->free_ts_nsec = free_ts_nsec; + page_owner->comm[0] = '\0'; page_ext = page_ext_next(page_ext); } } @@ -165,6 +168,8 @@ static inline void __set_page_owner_handle(struct page_ext *page_ext, page_owner->last_migrate_reason = -1; page_owner->pid = current->pid; page_owner->ts_nsec = local_clock(); + strlcpy(page_owner->comm, current->comm, + sizeof(page_owner->comm)); __set_bit(PAGE_EXT_OWNER, &page_ext->flags); __set_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); @@ -232,6 +237,7 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old) new_page_owner->pid = old_page_owner->pid; new_page_owner->ts_nsec = old_page_owner->ts_nsec; new_page_owner->free_ts_nsec = old_page_owner->ts_nsec; + strcpy(new_page_owner->comm, old_page_owner->comm); /* * We don't clear the bit on the old folio as it's going to be freed @@ -376,10 +382,11 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, return -ENOMEM; ret = scnprintf(kbuf, count, - "Page allocated via order %u, mask %#x(%pGg), pid %d, ts %llu ns, free_ts %llu ns\n", + "Page allocated via order %u, mask %#x(%pGg), pid %d (%s), ts %llu ns, free_ts %llu ns\n", page_owner->order, page_owner->gfp_mask, &page_owner->gfp_mask, page_owner->pid, - page_owner->ts_nsec, page_owner->free_ts_nsec); + page_owner->comm, page_owner->ts_nsec, + page_owner->free_ts_nsec); /* Print information relevant to grouping pages by mobility */ pageblock_mt = get_pageblock_migratetype(page); @@ -446,9 +453,10 @@ void __dump_page_owner(const struct page *page) else pr_alert("page_owner tracks the page as freed\n"); - pr_alert("page last allocated via order %u, migratetype %s, gfp_mask %#x(%pGg), pid %d, ts %llu, free_ts %llu\n", + pr_alert("page last allocated via order %u, migratetype %s, gfp_mask %#x(%pGg), pid %d (%s), ts %llu, free_ts %llu\n", page_owner->order, migratetype_names[mt], gfp_mask, &gfp_mask, - page_owner->pid, page_owner->ts_nsec, page_owner->free_ts_nsec); + page_owner->pid, page_owner->comm, page_owner->ts_nsec, + page_owner->free_ts_nsec); handle = READ_ONCE(page_owner->handle); if (!handle)