Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp641170rdb; Thu, 15 Feb 2024 10:34:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXcG87SRDPEJHs3Rq2E16Lh6X+EUg3dW5unF5FJSxyAMtemTTUWSnLO3qrV/ieJLaiTHazYKJEyKmXOTsLpFbRY2aehBvEcRfhVaON3ag== X-Google-Smtp-Source: AGHT+IEqh3R/iIy8PoR/mZ5yGyn8oWfQiSM1VERBFS/lqXpBseGJMKFIyKW/ZgTu9jAQBttxgUVN X-Received: by 2002:a05:620a:383:b0:785:d9bb:b321 with SMTP id q3-20020a05620a038300b00785d9bbb321mr2704771qkm.18.1708022098712; Thu, 15 Feb 2024 10:34:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708022098; cv=pass; d=google.com; s=arc-20160816; b=eyXUJTm3YkOEVEA8vHLur74i2D7/EN7H0D+WhXcJNa1CGfZfmVY1LhXPo5DqmZccdH 0lcx7Hbz8Y8Ium9x2U7DLU0T4Ri6/dlZciZuQ9bCcX+4+yUbyISvBrIft8ps516UCXQx Ja/DE0ND02MHVhzaJ6CPh9BlwX27/0fMqLim9AZHG0CDpdVYdRxg5PUVi4fmcyBG7f5A j19cdBSp5vgo/70ljQoeh1fe9EMoc4q3uCsSdj9oFJX8U3xxwZEf7dola4tY8Dplk+RW z/WdBIZhQoZ99vqVaSwzn0p0ZSCV42FGbWV3g8p3Mef7dPoOVeVVtTaWnp0uyegO5ig7 gzgw== 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=hhfBmJirNsqHXJktLhuMpinYcutoXu2NT5NVAvXIUmQ=; fh=ehKi8kNWGQ5h25Xod4jlxvellAh0+h4N7jJOW8PiP+Y=; b=HId0v3RYMFwdct+zgw2rB7yCRTAH9+AqTHKc0OP3Zkffx2StvDvLMDw2g8I0GZlPp3 ipTPl1gV1ZqnE8Q8eTSam11KKSF3Ma1EYUX5fFSVnj33pQJJ2MnaCQoXurU4ONbHkXJH FKnTEUc9DrJDyDu6rlKBHGeWrKlvGG2xhifECoaPIlx4OKoh5L51VnId/wOfHFs8gUTx 1k+0DLs2xH+qTDsZsukqOCgoF/774mRtrj/AqAcW9hv0WWGsjpUbgZQDAobo/RBJG3ne 4mxuGsz/81aTGMxWePETVjKN/VYzq0E9i8OLEFKATMhK59Br5a/UupqmcD2f5ni4RwU7 SvuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=f0hAZFJH; 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-67515-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67515-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id sq5-20020a05620a4ac500b0078725291f84si2003576qkn.701.2024.02.15.10.34.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:34:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67515-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=f0hAZFJH; 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-67515-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67515-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 794541C22F91 for ; Thu, 15 Feb 2024 18:34:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C5D81386B2; Thu, 15 Feb 2024 18:29:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="f0hAZFJH" Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (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 D8C9D13956D for ; Thu, 15 Feb 2024 18:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708021795; cv=none; b=iNwYs9m3BR5i3OONkufNnayn5pTh7P7V7u1zLDqlhjo5nE388ug+i669BAQJTfTRLEojQ6UBAZujrSc0yH0rXKAZpqXFqWrtcLkLAUL5PrKnI15wBhH0hXE4IQw3WvG7/t8E/qFFsRMYGA3G5F4A0OxmB6oeyaNLcE0n4YvBxtQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708021795; c=relaxed/simple; bh=nqKSivlpykOU5aRvgMFi7Gq55Mo7pEcYs3weDz1dp+U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oXvdac467oo6fknRLk3NII/Oc03zBmGc15thb0poEzii96IsdSKewIcKAIewWB1J80UFKHBNThy7w/5o+zrHk/pHB+83M4lSGOvsCxkgSAyf9Acr+S0FWK0rw1taKZuPyzmTDH4eGLQ0oRo90XndJ53j7QO0gCWUQDel/hZlmmI= 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=f0hAZFJH; arc=none smtp.client-ip=95.215.58.188 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:29:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708021790; 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=hhfBmJirNsqHXJktLhuMpinYcutoXu2NT5NVAvXIUmQ=; b=f0hAZFJHOvaRSVjmLM0URBKbO2TqcjlWIG6gzkHjx3Rq8tk1kJMF+EE25IP8jdRKYN3Dfl Bx8BonKRcNfBtJGsfFzfa//oBkb7e5ag/Ca9oOO5nGM2CIMRh64J6AlUyZjhzzwIjjk+Cr CxUh4L9AQue2vyXrnfcADk++1zL8KH4= 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 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.