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;