Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1978887rdb; Tue, 20 Feb 2024 12:59:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVp+ZY6+kwlPUs8RArgIuj1/TOR1ESOGK6jboJm+e7vwB1L+zkNnTT68sumU6UM5kuvdhaj1I2CMFPdHfsbWUvGtNcwyUtahuq+zCVVJw== X-Google-Smtp-Source: AGHT+IGe4wczNeeleLBHiXHIBko9izgs/XKGec6UjQAXFwNx7oPZ8mggfAeoOy2+gu6cmOiVCtam X-Received: by 2002:a17:906:6bcf:b0:a3f:1cd:6a04 with SMTP id t15-20020a1709066bcf00b00a3f01cd6a04mr2207785ejs.62.1708462793527; Tue, 20 Feb 2024 12:59:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708462793; cv=pass; d=google.com; s=arc-20160816; b=wJIeh6r5Vnfb/+ixL1U4zOPMxd56Sos10zz1EpZ8c/VVD6m+3pyOXXmuKoj33TmcJu CFwLOy6yxEJaixCxPY1lmenU5tlX3XYKDXg2zTXUeDT99HVZ6W9AhVvbDCnQYnxBNjO9 XmLtetS5e+VBkjBd+Q5tiRH/btadfICY3ywnlScASPkWa1AdwS8Sg6Y97O7K1F54orGB czjUSVt9V/Y8IaHnh1OuJHlyB6E45MANnMjoky3FZbC8oSUbOFCCxiBgE+JzbkzLllqb uTVJQsaKTgS26WLsn+387cSEObjByBvoOIG2NuuSXcKp5r5EO6NpWHIlwn31eVbKKtjn N6hw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=lAWvibZYCLZJ18pHlosxEIJ4ZpAXKtZDbRFFnu5UjNY=; fh=aYzy28FAJ3Lj9ip/dRYd8mJeTKm/9+GW6l9GK6LErc4=; b=xjDOfcSRkxvto2flje5AMLFLHSmbftz6gX6SIWhLUhwQwg+j624pP5Kv7OyujsM8j4 OVeDgUuaIsvr1UrIXLGNJ+4ewUHfuEFrhRslhpXo4qwSk6UzWhjUGTaKOE+U/4EfC7u7 hrzuNQEsCN1nzvltTIEorjcg26qf75KweCODLWKimK2ZQQSUjKRpYcTmzqQ6HZ4pLv+r RKcblgoRmPrlhH5JbCSqprd52gvrVCc4Wbv4u1nSYI7B+apluIDs0fCyfmMH2diwngpg bV/Urch1UezUFH4KPYrEon33kmrs72wkHy8UJuWg7oV6up9wbhdsQ8+qySKWV4LtX3Yy tcfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RpASEgxw; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73705-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73705-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lt5-20020a170906fa8500b00a3e657fb11esi2695231ejb.500.2024.02.20.12.59.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 12:59:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73705-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RpASEgxw; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73705-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73705-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 254091F23912 for ; Tue, 20 Feb 2024 20:59:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4167314F9C8; Tue, 20 Feb 2024 20:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RpASEgxw" Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50B4B1509AE for ; Tue, 20 Feb 2024 20:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708462780; cv=none; b=Jol42Na/xOgQzoOEKTa9KwuNgJ2nxEgB7w4+drxZFssIFL78QxdmcHKHaMy2XFqNYMPrPlpoYNHhMG6bucw4DCT6eiaA0wXXHgc1aso06pqihpr3i7WjjqzDC4yQ6ZUczzY+EtwIKcdDWHocLnDPPjfh2idvatSTrzgxqli//b8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708462780; c=relaxed/simple; bh=lAWvibZYCLZJ18pHlosxEIJ4ZpAXKtZDbRFFnu5UjNY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=N86mFZRQNikAf0N9/AqkhPhphzfotHJaGmX3vAOkAV6bAxWULVaZ14mi3JRYQdp4unTO36wdsR5giUxasZHnTCENi+U7Ra4kqlB5z/WVoydmLgDXY4HwAfbjSPzQ6+pPK41mMo84puhGA1zj2QEkA0oi0NTZTslvJPBj/sDXB8c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RpASEgxw; arc=none smtp.client-ip=209.85.128.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6080a3eecd4so39484957b3.2 for ; Tue, 20 Feb 2024 12:59:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708462777; x=1709067577; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lAWvibZYCLZJ18pHlosxEIJ4ZpAXKtZDbRFFnu5UjNY=; b=RpASEgxwkOgocmvj8fdC72Q+wuzIgJgO+as12KY3i+3OKhqA0Ur+2USxl5/WxSw7GT n/AMBdCT+NTGrnnWMXZNONo+JRE2hKpdLW4UQg+45cK1Vr17TS6vIb4n2/DhEHIy4d7e viLLUOpZyT8mEju/VwiV32CdbT3D3Db5FmEh33LidWpziEM3Xm6EyhVWeEmbumCQVMwh 3EvUT49/Gu+st7rv1CM9V40ySq27BReRViIotx1s9womXle68aBdsps1pt5ryPw3uboK Wu/FLi2Y7MjnzUpQD8y9evXWvjXFJw41+uWmmnpaTaYrNcDOQLMgcV4e9aA76TuP0gVN ICIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708462777; x=1709067577; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lAWvibZYCLZJ18pHlosxEIJ4ZpAXKtZDbRFFnu5UjNY=; b=vevmDRIXf1ejNSFJxaqFYZr4R6iAiVtzCXNP0uIIJeMIfGdfsP9hPdaBujvD0FTFhS O+93w6C4z81Q4CQXub8a3sk0Hx3zuXCQPWB0/31ufmichhJ2FLgrjiF6eggOktWySHBj XLsc9mTcrh9Q1aCqtFXBj/EW3vq4B3qcyTJ5Et1e+N2qYl+nZJ1MWu9jJonqkPVlpA5v o69zRSkUknxTRwoTpD4yu+JVeoFtvUt8APRmf/mmTJ6Lreom1twmyYoYXor6kfg30+4G 0HvPxbBR4DQacuEB8IGT3fpS6MqxuP2oNCFjruLeW2K8Yf1YL3kSL65UuyUTWDtcfD3L hZXQ== X-Forwarded-Encrypted: i=1; AJvYcCVlI4U1IC/aiyXIdF7Xsd2tZxGDg3W7vuQ9yLO4Q9Guw/MF1jYDeJxyALLc6aLx3HH9V4MLuDRenrEwUnodUxu/JR86X2jJOv8onHd7 X-Gm-Message-State: AOJu0YxcXQc4PEUql3NadnqVX64/hY6d4SoouAexc61tg1cviP2BSo3i sc572MI2uVHxvppCJVQaQSWaCkaiseB5U0WLzDz6oAYUPd0WWFvF/NUa11lmOBagnntt3+elown POJO0G6WOjeCk83d89zy5qOk6fXCoJNoMQjbl X-Received: by 2002:a81:7c55:0:b0:607:910c:9cb3 with SMTP id x82-20020a817c55000000b00607910c9cb3mr16089286ywc.36.1708462776952; Tue, 20 Feb 2024 12:59:36 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <320cd134-b767-4f29-869b-d219793ba8a1@suse.cz> <20240215180742.34470209@gandalf.local.home> <20240215181648.67170ed5@gandalf.local.home> <20240215182729.659f3f1c@gandalf.local.home> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 20 Feb 2024 12:59:23 -0800 Message-ID: Subject: Re: [PATCH v3 31/35] lib: add memory allocations report in show_mem() To: Vlastimil Babka Cc: Kent Overstreet , Steven Rostedt , 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, 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, Tetsuo Handa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 20, 2024 at 10:27=E2=80=AFAM Vlastimil Babka w= rote: > > On 2/19/24 18:17, Suren Baghdasaryan wrote: > > On Thu, Feb 15, 2024 at 3:56=E2=80=AFPM Kent Overstreet > > wrote: > >> > >> On Thu, Feb 15, 2024 at 06:27:29PM -0500, Steven Rostedt wrote: > >> > All this, and we are still worried about 4k for useful debugging :-/ > > > > I was planning to refactor this function to print one record at a time > > with a smaller buffer but after discussing with Kent, he has plans to > > reuse this function and having the report in one buffer is needed for > > that. > > We are printing to console, AFAICS all the code involved uses plain print= k() > I think it would be way easier to have a function using printk() for this > use case than the seq_buf which is more suitable for /proc and friends. T= hen > all concerns about buffers would be gone. It wouldn't be that much of a c= ode > duplication? Ok, after discussing this with Kent, I'll change this patch to provide a function returning N top consumers (the array and N will be provided by the caller) and then we can print one record at a time with much less memory needed. That should address reusability concerns, will use memory more efficiently and will allow for more flexibility (more/less than 10 records if needed). Thanks for the feedback, everyone! > > >> Every additional 4k still needs justification. And whether we burn a > >> reserve on this will have no observable effect on user output in > >> remotely normal situations; if this allocation ever fails, we've alrea= dy > >> been in an OOM situation for awhile and we've already printed out this > >> report many times, with less memory pressure where the allocation woul= d > >> have succeeded. > > > > I'm not sure this claim will always be true, specifically in the case > > of low-end devices with relatively low amounts of reserves and in the > > That's right, GFP_ATOMIC failures can easily happen without prior OOMs. > Consider a system where userspace allocations fill the memory as they > usually do, up to high watermark. Then a burst of packets is received and > handled by GFP_ATOMIC allocations that deplete the reserves and can't cau= se > OOMs (OOM is when we fail to reclaim anything, but we are allocating from= a > context that can't reclaim), so the very first report would be an GFP_ATO= MIC > failure and now it can't allocate that buffer for printing. > > I'm sure more such scenarios exist, Cc: Tetsuo who I recall was an expert= on > this topic. > > > presence of a possible quick memory usage spike. We should also > > consider a case when panic_on_oom is set. All we get is one OOM > > report, so we get only one chance to capture this report. In any case, > > I don't yet have data to prove or disprove this claim but it will be > > interesting to test it with data from the field once the feature is > > deployed. > > > > For now I think with Vlastimil's __GFP_NOWARN suggestion the code > > becomes safe and the only risk is to lose this report. If we get cases > > with reports missing this data, we can easily change to reserved > > memory. >