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 58CB2C48BC4 for ; Tue, 20 Feb 2024 20:59:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5C8F6B0080; Tue, 20 Feb 2024 15:59:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0C7F6B0081; Tue, 20 Feb 2024 15:59:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AD566B0082; Tue, 20 Feb 2024 15:59:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 783C36B0080 for ; Tue, 20 Feb 2024 15:59:40 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E71CD160870 for ; Tue, 20 Feb 2024 20:59:39 +0000 (UTC) X-FDA: 81813398478.09.BD829FA Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) by imf02.hostedemail.com (Postfix) with ESMTP id 54EA68000B for ; Tue, 20 Feb 2024 20:59:38 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ioxn8Muh; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of surenb@google.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708462778; 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=lAWvibZYCLZJ18pHlosxEIJ4ZpAXKtZDbRFFnu5UjNY=; b=WHdzNuFWGKp62VMIkeSTtzDYh7uIXiAe5DrXxjeQngmj7LQb+l2XhK9NXon1QJDlp6/cRJ whoZfejUhs6x8vPQnHkJrCdDzWh5jYLzFwLK80ImulSIc796l3TeTn2bl8MAyS3Cuk3s+1 bxlCvI8E1ykWWtY5n1PZ9i9X8nTzDLw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ioxn8Muh; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of surenb@google.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708462778; a=rsa-sha256; cv=none; b=tJ0oqqfpaqPer4cYlEY2TWNwWQ3rgkFO5GpMNFLVJ05cSVIWApWHvVlTFAwRYsVoojhZLy JmWXXI1ZI4geoXC0OKYnYLABxt5KIvQTZVi5tXYPX+CoT3+Qr66sIrvSC/GzFFifn21Dit 6pT6YkNUOSSC/ebALkMXOOGXf8mjQyo= Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-607f94d0b7cso48974937b3.3 for ; Tue, 20 Feb 2024 12:59:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708462777; x=1709067577; darn=kvack.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=ioxn8MuhcKcMJjm30WNf8pOtNKjfKly7xC60s0sg86Mp3VFPs9Y9SZS02hp47wmZhp a0PSmUbdapf7WE7W2YTEcccEX1obiLCP9oItdxjeqBeNmYfApZrjrDPzZkVadG5MIG/K hb7lXPQfR9Jt4G7dTrf72mWkDpzSe2TNsDms8yQxeuiIS39sgQGN4Q33FWbAUShaRoIA ompQL6dEUxDoNLK2OJikUmBfSCWDQGa50Qv677QOc7lcRjz0FHdhVHHhvfThXKHswPaC BrzuRUpFHbw0dsrc1Uvy10ShjCpAxBfYxaiWM1Mts4s1UaPdrS+zWa1pJU7GJAOknjeg Xsyw== 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=OCX/ye6fKy86sMCbRKOX4UBTE+ajf2YEqlMJimnBLE3OnrOMQ5zI7l5XS/LAP6qTER QSdvNTzO8tvGTkwG4sr0ZU8+I2ti0ieNHuJnE2aiRVGxAyMT3FK4JxhUw68NhwSqDdAY m6nYuO8vkctWtHHsA7N5J942Myh6a+aMF15+G7o1TeJhdLC10oVhTmec6hnY4Vb/v0Ix yixw6ragPJzsOc2hubsYueO06uDmAxmIaQItLWgTfGQ8eMRCbHc8nouM6XzEHToExxSI nWmhcOjZKmFGfT36Z94ywLSnT1y0doJMzuNAw830FIVh7jBNEcVcmXYGOdtfmpqUS278 frjA== X-Forwarded-Encrypted: i=1; AJvYcCVj5vmHyL88hPUOslT/AG9NC/vlaOaEJyjiohtRD2onzZ0pwEXze9l2yxOAyD+Kv9W7YRibzGED8HWxZZLjmeYszM0= X-Gm-Message-State: AOJu0YxIJG9vA6fa41aly746OOck0EWXRgfU91JGQQNAc+NqPZ9Ag9oq yvBb+9P6Q0s2b86ekSlWsudEHhNnb1V3FybSdB6v0J5x+sOeiLS9W6Sksahx9AWQfnXGQsgmSC2 DUIciao45ioHIshk5iV+G0qWBvbNXzjsJBzCW X-Google-Smtp-Source: AGHT+IEUBep3JbSfIFxIrjxLVKPObAawmbo2MZhL9tIpGGThj6+3JFdPMLwKRYjCckQD2YbEpyoHbPFSy5F0AEYQhEA= 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) 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 X-Rspam-User: X-Stat-Signature: y6fowk94oy7euojhrtx8ehhu99d3dp7h X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 54EA68000B X-HE-Tag: 1708462778-272702 X-HE-Meta: U2FsdGVkX1/6MmX4ys3jX/l1v9w+AHPRZooE7nOJwRChk2EKU9aWHd7HVmJmAy0nnJxYErlSaro7P4/NaYU8bHWEhCMJoQZM8r6bdXk8sG3ldjbsyInH1iZDFbN3LEOSJ6ArAbx32TgdV9usKfh9rDV8NPJyeyN7PancJ7a+sbyUbs9YrYsWGDJXvze0NMbPY9e1RZcs+p5P2c7aBTUzjMoJRIRqqapdH+/lg35EyurZtNOmDDTDLFQPuxyvyamuZQoo+IsikPfp2TKDAuPjasrAk21shaQnQKgLk5XVY2//7+dpkv7L5BKMvxhS8X4/aRPA6xG+kUNx4hOf1YGC6MkbsauphHay657UDH/MXxXprg5D421PkHZI7hW4bWMpX7kxiKmPp6p3Tx942e7DXHez0DYtACgzrqoIzQAoqRK7ASLmNHlvGeTyva0rGTZ9k+WoRKnwzOtIBi8+XnvQ3XziVCEmdG0Wj0uzbXK1kgOdBVjnG2iPHKbydpMveIvukuvkZj1Wo2CA+7NaJGkMai0w0MUFCjof4w/Fh9y+y9gl5dhvt0wJxei8ijPmn2tVfu12nI660+c2NP0XAv6S7I/0pe2G1DqtKFIVK7+23PDcMSxW9crBRR9C5FXSrwoIC9TVGRZnbR79x74WVDL82s1eGEFaTSHRoYb9Tumt4tXgicTHH7x5UuzBRt7t/bBHjbbtd4N08atqYzAdtp++RCGJf/fFQSdcO5fk8iqtvUqTMhIHz4BiVrSRUosxczDR72PfDeJBQgvfpbeOd75cNoxUEiGCUHLfRG86x0SzDl51bZWdTfC1kYJyWg+EaoeKWXr9qWUqCqG1k9iSF1YLhgwEtByDNzu4wGEHOebRqFKbX6GUn0fLaE+tbEh41QFIFqB+iR4U3z6eTE/AFUePz9ysbEN9EfXcc78OgSgOXp7ULWeDe03owLhg6PDkTqmIKPniPkmoeRKkGEU7u89 p4x829b5 CWjJt4VysQRwYabd0t7PMrY8VgrfkQkBTvbKmxxH5IFg05cBe6pFTKjfwOBs+dTdIJt+OakVGrDhSGWjKarMXAkIhNNsljb1VQbVzAVl2Sy9GoaA0OcWyZqoLfQ== 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 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. >