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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B143AC433F5 for ; Tue, 1 Feb 2022 06:24:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B68F78D0053; Tue, 1 Feb 2022 01:24:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B18AE8D0028; Tue, 1 Feb 2022 01:24:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E01C8D0053; Tue, 1 Feb 2022 01:24:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8DC0E8D0028 for ; Tue, 1 Feb 2022 01:24:31 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5671F18194D48 for ; Tue, 1 Feb 2022 06:24:31 +0000 (UTC) X-FDA: 79093221942.31.3747158 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id A1B14140002 for ; Tue, 1 Feb 2022 06:24:29 +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 B1EE96148E; Tue, 1 Feb 2022 06:23:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 035C9C340EB; Tue, 1 Feb 2022 06:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643696601; bh=HfcgLdgc3B7KCIDeYVDCOGK+3kcF0wgKikBnzg+bTCw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hkLUp/IB2GCcNukU/n/SN3b4hGrNAVgSg9olTqdDrlQh72GPdsAAVGRf0TV8xX057 qFFxIfxMqcDSpcR4vUWfClWa+KHHdR0nJfmXPM09CDY4QLolTZLqehrDSkIWngO+s9 r0ezCld7Bnw/YR4G7Rzgpjk8S7tyOWf9en8aAW1dKA09kMoohjG5KCMG+QiHpzVtzN UgegvrFmT6sm501g8kg1Xm84rV9G5XmIzK0CBNRLfSHV7D7s2Kaw2R60x7P8M6hWCr f6hIiAGIHpVsMk9NsXdCgaQZYKGZxXJcOYv7BQ9EHrfnZ57lIdjJTFBgG7/YYvdQFd SQZxnXbIRRgYA== Date: Tue, 1 Feb 2022 08:23:10 +0200 From: Mike Rapoport To: Waiman Long Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Ira Weiny , David Rientjes , Roman Gushchin , Rafael Aquini Subject: Re: [PATCH v3 3/4] mm/page_owner: Print memcg information Message-ID: References: <20220131192308.608837-1-longman@redhat.com> <20220131192308.608837-4-longman@redhat.com> <4234fc60-5d65-1089-555a-734218aa6f9c@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4234fc60-5d65-1089-555a-734218aa6f9c@redhat.com> X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: A1B14140002 X-Stat-Signature: ws8cx9nc1zzskwuy68fhk4b9nmbcpo5o Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="hkLUp/IB"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org X-Rspam-User: nil X-HE-Tag: 1643696669-745548 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 Mon, Jan 31, 2022 at 04:43:32PM -0500, Waiman Long wrote: > > On 1/31/22 15:51, Mike Rapoport wrote: > > On Mon, Jan 31, 2022 at 02:23:07PM -0500, Waiman Long wrote: > > > 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 > > > --- > > > 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"); > > Don't we need to check for overflow here? > > See my previous patch 2 and the reason I used scnprintf() is that it never > return a length that is >= the given size. So overflow won't happen. The > final snprintf() in print_page_owner() will detect buffer overflow. Right, I've missed that > > > + > > > + 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); > > Ditto > > > > > +} > > > +#else /* CONFIG_MEMCG */ > > > +static inline void print_page_owner_memcg(char *kbuf, size_t count, int *pret, > > > + struct page *page) { } > > I think #ifdef inside the print_page_owner_memcg() functions will be > > simpler and clearer. > > Yes, I see both styles used in kernel code though this style is probably > more common. I will keep this unless there is a good reason to do otherwise. Having #ifdef inside the function is safer wrt future updates. It's often happens that non-default arm of #ifdef is forgotten. Besides, it's several lines less. > > > +#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 can go over count here. > > Why not make print_page_owner_memcg() an int so that the call will be > > consistent with other calls in print_page_owner(): > > > > ret += print_page_owner_memcg(kbuf, count, page); > > if (ret >= count) > > goto err; I still think that 'int print_page_owner_memcg()' is clearer and more readable. > See my comments above. > > Cheers, > Longman > -- Sincerely yours, Mike.