Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp646616rdb; Thu, 15 Feb 2024 10:45:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUHCiu+HuDOwkYobfnPvXgZlRJyEHvD27uMmmokbYAcI40LqxercHOpwbST3so6RLRaVFtSV+rN1XNWDmHpF+rGlkr1ysLBA25dA+YDHg== X-Google-Smtp-Source: AGHT+IF9HxyBJagWF+IKulda5H0ymfCLxgUDWQ5esknaQv+r8zFslBA6ybWnvUd/lD2Gnx2mGNS1 X-Received: by 2002:a05:6a00:1a8d:b0:6e0:84d4:e009 with SMTP id e13-20020a056a001a8d00b006e084d4e009mr2764231pfv.21.1708022745062; Thu, 15 Feb 2024 10:45:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708022745; cv=pass; d=google.com; s=arc-20160816; b=DlU4IW1mybqUpNMVy53gW3pxuxuTEoyZAxvaGJp2XITZ2FX09kCaZzIRv8HKZCpj9j tgze69PX9gxmbZhJ1FNKtWSH3Nz5V25hmH1SRQm7ZUv9ahPwZJBQtH+W89WnzqA/kAK1 FxLRC+m77o8cAt4MpWu+TQf9VQHq/dPR2VNBOKoziB+MeqzwJu1eXS9lSxvJHwS20d3b xsHiIyE2ZUsEwBTmsV6ouaafLCsThSSmLxw9DcPwv0fx1eRnGSPx+uR462eLN/gCRhUi YUkg/AB/FZwzHsKGQ4HIMpjuDCiVJjpRXVUwlu3FZQsmk+ikHKY00sZdreTMKDU3JL0I wlGQ== 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=MX5iN/R1aA7qp1uBjwVKqzgAyTA6O01vDbmEmEpF1HI=; fh=ehKi8kNWGQ5h25Xod4jlxvellAh0+h4N7jJOW8PiP+Y=; b=ZxLJVnIvkjM1Bw2aEc7d2TyczU6UWy9Ka6tG8cLhl3nEFoCCinZ7NlM1fCxxk4Tl9e MU63nqzn577U5sYF7iBEM3dTt6xvVXn9CtT7hoAwqrt8GMF73rRU7kSbc4nOXN83zVJt G2xdmT54EoF7ZqFRONmtNmhldGTz6v46WKXHCwQ6++soU8AmM3qATZTy/yMxYumHlvRF lg4yVCZK/RR4oFfCpa059QVXE2aPOEkzfhP9lU05+gFGOf4q06ilRslmAus5HvlxfqaC hY+XyEVwN1sv2V/sOCAADCCYj+Q8naPeaP9hlCqKHLrvzG0sdXFixFFJ83Sa6CBAA9Vy sBzw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="JN/LPHA6"; 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-67525-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67525-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h18-20020a056a00171200b006ddcec89d8dsi1500951pfc.194.2024.02.15.10.45.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:45:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67525-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="JN/LPHA6"; 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-67525-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67525-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EC8582923DF for ; Thu, 15 Feb 2024 18:38:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4C4538DC7; Thu, 15 Feb 2024 18:38:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="JN/LPHA6" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (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 CA864136999 for ; Thu, 15 Feb 2024 18:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708022302; cv=none; b=XNURh2vRmFYBCIcCL//vTCf3SqkQIn0GOg5Tvdl5rFLcNFKJg6Robf0u+xqxFjk6EqsFhSFmFTQ/FQqJKD/Xr9CcbTXS9377Gno3bYyKNlYzhQ17bhSXmryR3I5bOoY80H4fBgHJJ2XntJ6u7TAZhSKxYVeWxP/Z6MkOSgbT5Bg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708022302; c=relaxed/simple; bh=1qVom1rSiklCLS5RbXYjODOEuKVFGJz+okg7fDM+Ia0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=L4C6EWwt4LpTWuGzmKIW7fdOnl/T10VuidCLf84U2Qnz+OQc1MGvb1McmiznoFCOqHbjLxt56GeOMEEXB5lFCm5G9ZZ6VczxSEIBFrV6ln4vYXP5aW7YN6VXvlc4U67SjF+NZsPzm0cO0qkdFw3xitC4ZWMkeP8D8AYp/0MyaB4= 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=JN/LPHA6; arc=none smtp.client-ip=95.215.58.171 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 13:38:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708022297; 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=MX5iN/R1aA7qp1uBjwVKqzgAyTA6O01vDbmEmEpF1HI=; b=JN/LPHA6l0xQ7QMKiDnxsNR2Ab6ALTGJ4OE63oTahR1/1K8veWc90tjRp4QXqdUElopDI5 YH5NElMZRXmq24WL24GA6MqkZu9wAXmJwNLE+wgHedUF1t2ic5fKjMy5mDaNTCYjsqAX5o vtrOv4NPQDR3Mz1YWEXaxTFt9VFFDKU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Suren Baghdasaryan Cc: Michal Hocko , akpm@linux-foundation.org, vbabka@suse.cz, 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> 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: X-Migadu-Flow: FLOW_OUT On Thu, Feb 15, 2024 at 10:33:53AM -0800, Suren Baghdasaryan wrote: > On Thu, Feb 15, 2024 at 10:29 AM 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. > > We don't need 4K here. Just enough to store one line and then print > these 10 highest allocations one line at a time. This way we can also > change that 10 to any higher number we like without any side effects. There's no reason to make the change at all. If Michal thinks there's something "dangerous" about allocating a buffer here, he needs to able to explain what it is.