Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp699734rdb; Thu, 15 Feb 2024 12:33:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW2JK1D+1ezq4UHwsGCw6UfCxn1L6j4XbcZ73KFCpnDdzNcxAIOhH3uj73A7MZsV6Q2ZtQj6A17aj0JrxJ9BzaUDejP0LcpUjOFL/udmA== X-Google-Smtp-Source: AGHT+IGwiKZGCnng/JUZR/9Pg5nzA/HS5fKObCSiKz6B4UJHDj9n3wex9nEOlEiz10X0uCBTLsaA X-Received: by 2002:a17:906:416:b0:a3c:865f:b246 with SMTP id d22-20020a170906041600b00a3c865fb246mr1824417eja.21.1708029238847; Thu, 15 Feb 2024 12:33:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708029238; cv=pass; d=google.com; s=arc-20160816; b=rOtcxWVGFsbU2yTm70F9EhLzm2DdWcBBZgDn4/L7F9EFZBI1ts5Sz+v7WlD2Ma94bs XyZdNI2SAwqeEA00nThCY9yBiCPn8PXyhU5Qk0iLS0nkxOfGmkXHo/IoZYe9/aK9aBgy vkh8PQDJ2urXCxAFhRFA0+Ldy51DeO6yJ596xgnnnWE9iTK1Zw9ju5earQDPDK2zYtET 79FnYD+6Jv9qDlQ2/pU2IhG3o2P7gEBNME54zKhG2qPHxc1lHwMn+rJzbwh1K1RQUnxr jq+YzFAZF+748h2qxH0McIkbnpBinu6qY3/McPKvxHcuLA5t3IQSPByaJ/1fxdmNfq+F HDvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:dkim-signature:date; bh=1h3mKBhbYx2gO9e1zxP9AUVbRxFOpkSn+Z2PNxlzZgw=; fh=Z1oiWE6w/L54M/flN/Si8YFXMT4vwuce+Gv47tQRNAk=; b=qz3wHGexSOjoNb5OHEOMJ/820GWEFODh5L3pBvtmK7jxXkn0hDqUOyyaByPPULk6AO qvxYIjdLWGC12T25D7kNB6dsD+1NVlSTbvLw8pwN18YPEW89UFQGc8cjdvQ2mqAZXSEj eUpSO5eBH+s+a97ceVkY0xSHlz8wpsJw7jYX1Cq40mlBrRJV9YpvDFcEAklmNBiDHD3C lv3fDg0lV0OLXfqmgycSfXupgbMdo6q2BeyONL1TONzrW4ChyVg1MVZDRUAULh+8dRjK uMBVScbgZS3ry5boJOovm6TMv2bqNygcG+Rej8Dxtq/FM8k6QGPtvfxT/nNwY91ZYrdC On4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=uKMqNbYR; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-67656-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67656-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h8-20020a170906260800b00a3c02c21607si964843ejc.357.2024.02.15.12.33.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 12:33:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67656-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=uKMqNbYR; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-67656-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67656-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9AA431F243D6 for ; Thu, 15 Feb 2024 20:33:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DFDC13B2A9; Thu, 15 Feb 2024 20:33:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="uKMqNbYR" Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62B8413AA41 for ; Thu, 15 Feb 2024 20:33:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708029227; cv=none; b=oVotSxPfu77InxZYEMdaynWlmx0ss21ruCA0imjWj4fX2x22coqKJOLkLePk43afSNAGq43bKbQtkX0l8UxPRkr7D0S/mxa/r7yZsmrgnBIZyhXeJf0F7wQuoa5HJwK3v3QtIPTkaHmKzBUumJD+BOwgdkcJBk2oPQCtHw8tzr0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708029227; c=relaxed/simple; bh=svZI8lR5yuLAKcmkdT/NwJ0LBFg7C4bhwIEcPtd4wK8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RFIPX2lNxJghhoxPzqhN2DbNNaen5IVc6UMUWa5rfs0U54A/I8mrLk8/5k1hVtqRMejP47Lrf9ZIEYqXC/fXcp9edcGzfBLCKPizFHxIig8UQIRvaIInWp8wKYaVPq68ye7Vcy8Jg/nOCNo7/z5x7XRg+jk0h6oIIR7FWHtTlE8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=uKMqNbYR; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.