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 90530C433F5 for ; Mon, 31 Jan 2022 21:43:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17DF56B011B; Mon, 31 Jan 2022 16:43:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12DCF8D0024; Mon, 31 Jan 2022 16:43:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01BEC6B011E; Mon, 31 Jan 2022 16:43:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id E82206B011B for ; Mon, 31 Jan 2022 16:43:55 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 95FA3824C45B for ; Mon, 31 Jan 2022 21:43:55 +0000 (UTC) X-FDA: 79091910030.28.453C812 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 98EDEC0005 for ; Mon, 31 Jan 2022 21:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643665433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T2vOsI9mzkRFCto94nwtjznBsJWt/XMYQapLVHPa3ks=; b=eUpfWd6yHSn4oMKh/aTUYjlDhC7dvgWi1ZG2tHLW7gP7bY7zLDQtXx8JfGcN75h4Ge5wCL OtxhDp9e2ll243TwQhMCd0itQTBXrZxW0JeaC+NlkaS5Cay5nA7xZmc6gXTWfYohAgi7N+ VZnHQzpHvNdE/+eeBSq6rAK3rcRkF38= 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-661-aWHuSTTpNl-LHIiBlIK70A-1; Mon, 31 Jan 2022 16:43:50 -0500 X-MC-Unique: aWHuSTTpNl-LHIiBlIK70A-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 F30338143E5; Mon, 31 Jan 2022 21:43:47 +0000 (UTC) Received: from [10.22.16.244] (unknown [10.22.16.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92BFA1037F4B; Mon, 31 Jan 2022 21:43:32 +0000 (UTC) Message-ID: <4234fc60-5d65-1089-555a-734218aa6f9c@redhat.com> Date: Mon, 31 Jan 2022 16:43:32 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v3 3/4] mm/page_owner: Print memcg information Content-Language: en-US To: Mike Rapoport 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 References: <20220131192308.608837-1-longman@redhat.com> <20220131192308.608837-4-longman@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Stat-Signature: uikj9ms5gjkximzuit67h8hibrkmfqhm X-Rspam-User: nil Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eUpfWd6y; spf=none (imf10.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 98EDEC0005 X-HE-Tag: 1643665434-59991 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 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. > >> + >> + 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. > >> +#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; See my comments above. Cheers, Longman