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 1C665C4829E for ; Thu, 15 Feb 2024 20:33:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5939A8D0007; Thu, 15 Feb 2024 15:33:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51AA68D0001; Thu, 15 Feb 2024 15:33:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E25C8D0007; Thu, 15 Feb 2024 15:33:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2ECC88D0001 for ; Thu, 15 Feb 2024 15:33:48 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B541714024B for ; Thu, 15 Feb 2024 20:33:47 +0000 (UTC) X-FDA: 81795189294.13.CB1F75D Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) by imf20.hostedemail.com (Postfix) with ESMTP id C34AC1C0006 for ; Thu, 15 Feb 2024 20:33:45 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=uKMqNbYR; spf=pass (imf20.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708029226; h=from:from:sender: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:dkim-signature; bh=1h3mKBhbYx2gO9e1zxP9AUVbRxFOpkSn+Z2PNxlzZgw=; b=zbViwYVBaj819GbPJD+5/bXqnmaP4VGoJh+XRlFh7xNIEYgN7tlkDp3QEYKzcDN+gLN2qj r5s61T/Bczw1zLT5Jaf6zWS9wMibsjXau2FmnRsd/3mfbO6My6xZhhZdcKtl96xKVfS0CI zsIRzD/uc/vysZNwBMfwQDmgUjwcu0A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708029226; a=rsa-sha256; cv=none; b=sbUk8G1u0QNeqzNOTqHwLCEBjhxT/i8jOjch6RGlRXFvygQs+uIM+GOQrMG5kJN+Ls761q 1aoUujeVTdAM4Kv7LPIUZCHfYzxhdeYz+ACDME85dM2Ks+fYABmn6KwDVlOUdU48M/nWmj MFhNl14AqK9U2guTPSS6JaaiY6XiDrc= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=uKMqNbYR; spf=pass (imf20.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Thu, 15 Feb 2024 15:33:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708029222; 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=1h3mKBhbYx2gO9e1zxP9AUVbRxFOpkSn+Z2PNxlzZgw=; b=uKMqNbYRWjGlI+HaoeIYPI5ERvXjACozyNlWdRNl+Qg1jnpaLiF79qYZW/RTxK0qgoH1Wj xEHLKTRGoGqywmCPXSAl2Kq3qU0Ae4RnatPfkhFcJzRdH8nYJYHyebbvQZadulqXqF8Jgg hvFxKVPZazAslAUs1cKqTwK9orq6Wkw= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Vlastimil Babka Cc: Suren Baghdasaryan , Michal Hocko , akpm@linux-foundation.org, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org Subject: Re: [PATCH v3 31/35] lib: add memory allocations report in show_mem() Message-ID: References: <20240212213922.783301-1-surenb@google.com> <20240212213922.783301-32-surenb@google.com> <320cd134-b767-4f29-869b-d219793ba8a1@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <320cd134-b767-4f29-869b-d219793ba8a1@suse.cz> X-Migadu-Flow: FLOW_OUT X-Stat-Signature: mbnwfhk11oczfm4ah8rcutg7gxoaehjm X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C34AC1C0006 X-Rspam-User: X-HE-Tag: 1708029225-469967 X-HE-Meta: U2FsdGVkX1+/uWErn+51xm7gqvQT3XRKwKf8egXlOc9tOQnvuJorSfvJuVfCm5cDVCcVgzgH0IjrE1/EaXWoRj/jckpKFsuFesuVS5umOKZL1VmsLDUYyfBVmLIqexiBC9CGdlD6FqV170kqsUwZPZGpM5wNQ5UNd7TNwDhCeiSCepfgvMo2DYY9REQEN87IcU+XC+QnGvQDgYNTfRRiBvcWcTKpWNH0L7PqOjLPA3G+Ee8GN4bTHc0Bk4pB8lgzMMSfCzo/dIskxre0GoqeRMGXDeII3guw5CPZEQSTeIscUy8XpRMNmeJO67lR1F3QANRkSFXKYj2OG/qeIfeoJyKG0L4PtUB/DMtdzKWghpsq9mDBuFMbhv3o2bZhPUQM+KSPXUDOmzqGiXfVGo8TtZzImBNWW0I0yX1yi4L0xsAqSAGAdOpYrIwp1rZF8HmcwghPGZro6lHNczh099vv+NIaTXmXBsL5+1mTbQ0nA1QLF6vSFhigKMQyDNuV88orixHvqngUiax5+fssAV/oPQM6wX0sPr0ixuyzeDZ4eIum1iJchJcvoBwifUbrjoRBkngtURZkKCQAga+JV6MIcCsZNwtV+3orAUe61J0ETf17tXsyhZlUM9Cfco+hlW25vNooJ1iwTI6JNTxU3M45tfOaJXEgcRsGZS4QdHIqn29jrWbnOA9cnSFnTqV9D4tXmlVfx3npTdq9lgRWRIzDFdj7CKBQNCqQmsKPgLP0+gbFlwGF5Gju9rrEzd65BJ2THwNdlZbX9R3ypTwTci9FXPLEkP51I+k5AkkqP/gSi8fWz/7DGzEFYgekqTW97kP/KBsfN2cSZN5BQKwFlpJfXe/C42U82hziEZRMVeNktl9Q4JRi5aIwQVQ1t176JGKskzArsRL+lTi/IFtzEEWHu5JSLJNzZdMz 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: List-Subscribe: List-Unsubscribe: On Thu, Feb 15, 2024 at 09:22:07PM +0100, Vlastimil Babka wrote: > On 2/15/24 19:29, Kent Overstreet wrote: > > On Thu, Feb 15, 2024 at 08:47:59AM -0800, Suren Baghdasaryan wrote: > >> On Thu, Feb 15, 2024 at 8:45 AM Michal Hocko wrote: > >> > > >> > On Thu 15-02-24 06:58:42, Suren Baghdasaryan wrote: > >> > > On Thu, Feb 15, 2024 at 1:22 AM Michal Hocko wrote: > >> > > > > >> > > > On Mon 12-02-24 13:39:17, Suren Baghdasaryan wrote: > >> > > > [...] > >> > > > > @@ -423,4 +424,18 @@ void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx) > >> > > > > #ifdef CONFIG_MEMORY_FAILURE > >> > > > > printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages)); > >> > > > > #endif > >> > > > > +#ifdef CONFIG_MEM_ALLOC_PROFILING > >> > > > > + { > >> > > > > + struct seq_buf s; > >> > > > > + char *buf = kmalloc(4096, GFP_ATOMIC); > >> > > > > + > >> > > > > + if (buf) { > >> > > > > + printk("Memory allocations:\n"); > >> > > > > + seq_buf_init(&s, buf, 4096); > >> > > > > + alloc_tags_show_mem_report(&s); > >> > > > > + printk("%s", buf); > >> > > > > + kfree(buf); > >> > > > > + } > >> > > > > + } > >> > > > > +#endif > >> > > > > >> > > > I am pretty sure I have already objected to this. Memory allocations in > >> > > > the oom path are simply no go unless there is absolutely no other way > >> > > > around that. In this case the buffer could be preallocated. > >> > > > >> > > Good point. We will change this to a smaller buffer allocated on the > >> > > stack and will print records one-by-one. Thanks! > >> > > >> > __show_mem could be called with a very deep call chains. A single > >> > pre-allocated buffer should just do ok. > >> > >> Ack. Will do. > > > > No, we're not going to permanently burn 4k here. > > > > It's completely fine if the allocation fails, there's nothing "unsafe" > > about doing a GFP_ATOMIC allocation here. > > Well, I think without __GFP_NOWARN it will cause a warning and thus > recursion into __show_mem(), potentially infinite? Which is of course > trivial to fix, but I'd myself rather sacrifice a bit of memory to get this > potentially very useful output, if I enabled the profiling. The necessary > memory overhead of page_ext and slabobj_ext makes the printing buffer > overhead negligible in comparison? __GFP_NOWARN is a good point, we should have that. But - and correct me if I'm wrong here - doesn't an OOM kick in well before GFP_ATOMIC 4k allocations are failing? I'd expect the system to be well and truly hosed at that point. If we want this report to be 100% reliable, then yes the preallocated buffer makes sense - but I don't think 100% makes sense here; I think we can accept ~99% and give back that 4k.