Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp647151rdb; Thu, 15 Feb 2024 10:46:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXyVvdLOQdYgx5/xzH+s/oW5NIxfP6nuLdZctDm09BJP0mA+25gODuYDxmoSg3B5oewZlzIGCRw2PZO43IPJZNOc2eae0B0vzbl3mZ9yg== X-Google-Smtp-Source: AGHT+IFArivLJ8NuH0o+Fchw8cxXEwCrznlh0mntaNDR4dYwgQKRcnPP4+8MFWq8zQtA0scRHfwb X-Received: by 2002:a17:90a:ab02:b0:299:1ad0:968d with SMTP id m2-20020a17090aab0200b002991ad0968dmr1593575pjq.48.1708022812711; Thu, 15 Feb 2024 10:46:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708022812; cv=pass; d=google.com; s=arc-20160816; b=gsXIQ3RKSNY0krqOOD9GhPORySUMq57Unjncsktp4M40RjHLetZhhbFxgoa4CwbLPp IebZ0fcSTt8P58msQt9I73Sr67TB7h6JVOo3fP7ZkRo3vZgR0/7hzB06XzdA3xGK2FYg soajFwbWSRrOV//UVWgjZJ01ArDnPYqIRMi5ViGQHT/4oV1jQbsjPV4ZSl/17c9jM5+0 +B1w/iTBZubm0Kzuptp5wpyQwHcL/sWSK318AMgt9FDX8UMZ4k3QOrtSDqzb0Y7+ofFR b64n2DdHE6sV30y6bV3ga5eJDeuRfY/++i7BlrSYSH8yiQlRCbXo9XwdZOuR/cPzWCiB NvPQ== 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=c/zbyo2KXw6JhtuTeO6vuT3ARKuU8XObNaLi3n/GNPQ=; fh=k8LovuhasCg3gb7ZTTBaGpNvvlOuBngk4AAM5EYm1po=; b=U5+qeFX3OWAxhkq8ufo8BjIlOjAJPX3UPT5qngz98AoOiA4V/5raq2A75bPR3uf38/ Fe9xncjoGKEsd+1y2WzmmeNnWCo7XtttvSVzmd7afJx03+HPqaK9OyiHp6m5cPuGncbK nPrkv+OxnfYu2vke3y/CZDld/R7s+0VJhyLmPvpGaPqSj/hj1ADzjC4zMw6b/L8blAs4 eyBhD7TWASmNb3R1Cn2Vum1SL+rlAi45b69HmeHE6J26iqZ32EI6mQ0Yqe9nFBPbn4b2 oJX+EDKsFSI0zPtS4SQFo/a5mj9ioTRw1YlYcapyGMjJyjPLbdkJp/UCPdtmADrXE7A+ o6oQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HPZiK8qO; 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-67519-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67519-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y3-20020a17090ad70300b00298de865fefsi2965792pju.4.2024.02.15.10.46.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:46:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67519-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HPZiK8qO; 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-67519-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67519-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 09FC7290BC8 for ; Thu, 15 Feb 2024 18:36:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 19E5E13A245; Thu, 15 Feb 2024 18:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HPZiK8qO" Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (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 31F3B139565 for ; Thu, 15 Feb 2024 18:34:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708022050; cv=none; b=WXj31KIi7XVyWcSMrFmDWb6zs1YCsHBOISglurTmJHc2c/8tSjmkVPFq2MKKHWmRRaIiTM9g0McaMKTiNIV4EdOclk59AncB3/UuwHDXDZm44ippezfvyZi7R+TjaYQEXhnG6wharUbAAKxrzM/ZhEpD+s6hl34HbTKzbh2Qsek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708022050; c=relaxed/simple; bh=EkHV+pK0QXOWaf9RwSvvipbxHFbyApBZyCN11/BLKS4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=N/x2fHMy73dGLhf0tC3+OARZ9YQkJKcuh9xUpMRwHYDDuWNyJwNiM+iIY+ljnWEcL/UiyaA3QYrWqiLW0ovzFZL5jT81rgyLAJNXvEYXQ/9rLr0mjbciWicc4i7fb8822EfENrThtFQlXRqUsYCFCoga4u95vJzy2VRktTMaRUM= 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=HPZiK8qO; arc=none smtp.client-ip=209.85.219.182 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-yb1-f182.google.com with SMTP id 3f1490d57ef6-dcc80d6006aso1282717276.0 for ; Thu, 15 Feb 2024 10:34:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708022047; x=1708626847; 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=c/zbyo2KXw6JhtuTeO6vuT3ARKuU8XObNaLi3n/GNPQ=; b=HPZiK8qOi6j8eHtrVWkMY3/y5zdg/R+snoTpxl7otDapqq8U5nGISzOlEkPxZVJOdI XR6njoQyRhO65h5YNcGuFvkesKajuM20CnxqrI9baL2knQfhsz9i1+UJTfO/Fwv2mWTf ktaaM3njCRzf4blGVz++m8/G8b/gI10LhL7Lo9omGw4CKaE33N35IUtraESVDyXf3BoB +kSU70ufu2xuFOyyFPJ3MNb80cNFbgtERN/ovjHCNXsLMp8aiUnGWyQ+KIEnZK5WjyH6 fjfew7jLvJTyZxNKc/fe0U0yIcdA0rN1LrHpAsojFlar/bktGjvn9Bhpp1YDl4RdPR2v cRdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708022047; x=1708626847; 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=c/zbyo2KXw6JhtuTeO6vuT3ARKuU8XObNaLi3n/GNPQ=; b=AF1PfP8DapZ/egYdb9mnzxMLiCThQyA0tK9+3/aV+7oFDtLD2J1HFDkKp7OKxPwZpz IH9g900RH7lxlLrkAXVsllgiLtdBBYJfop8RkC5F/hUW5dIHI0pKu0WTjsdXahHehe1S bLStSpUHPGEjYo/rXR1lnaY6v3EFxuN4X2UCTeccnoT0SDoPqUvuacPud5141M1+mc7j 9+QyqI4RJxskkpRE93gidk348DUMBKea4yJVKRuYoueXVTMiJQmBzoEhazeTzeuLj8n1 qb7dQuS9ephph3n1EBfO43yK1EuLEzTRb5BXEgdBRtOm1z/iEy+5oPSkaVa079gP0Yga kbUQ== X-Forwarded-Encrypted: i=1; AJvYcCVIU7pEPBFBuInN3mCpWdzkPiTu5GFWLIuKYuhMQHd8i/a1ZjcyIax/CfjMD6v6FrwylKlqJxyO4khQ1dky0/JLrfNyNyAXAhvUhwk3 X-Gm-Message-State: AOJu0YzUUulXU4dV8GQCmJeqjXG+6wza0wHVrH6P8PT3nZlzv0j5gab/ MLN2T872zp4CyT/Hi/WCmjIhCX98107UN4Oc9RHfEQxtppmoPGKfQ692e0JHju8oZWdaoBKe8E5 emUmujxukSSOHP/bFaEXNWVPWuo+QEhU809Nd X-Received: by 2002:a25:bac5:0:b0:dc6:a223:bb3b with SMTP id a5-20020a25bac5000000b00dc6a223bb3bmr2333936ybk.46.1708022046848; Thu, 15 Feb 2024 10:34:06 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240212213922.783301-1-surenb@google.com> <20240212213922.783301-32-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 15 Feb 2024 10:33:53 -0800 Message-ID: Subject: Re: [PATCH v3 31/35] lib: add memory allocations report in show_mem() To: Kent Overstreet 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 15, 2024 at 10:29=E2=80=AFAM Kent Overstreet wrote: > > On Thu, Feb 15, 2024 at 08:47:59AM -0800, Suren Baghdasaryan wrote: > > On Thu, Feb 15, 2024 at 8:45=E2=80=AFAM Michal Hocko = wrote: > > > > > > On Thu 15-02-24 06:58:42, Suren Baghdasaryan wrote: > > > > On Thu, Feb 15, 2024 at 1:22=E2=80=AFAM Michal Hocko wrote: > > > > > > > > > > On Mon 12-02-24 13:39:17, Suren Baghdasaryan wrote: > > > > > [...] > > > > > > @@ -423,4 +424,18 @@ void __show_mem(unsigned int filter, nodem= ask_t *nodemask, int max_zone_idx) > > > > > > #ifdef CONFIG_MEMORY_FAILURE > > > > > > printk("%lu pages hwpoisoned\n", atomic_long_read(&num_po= isoned_pages)); > > > > > > #endif > > > > > > +#ifdef CONFIG_MEM_ALLOC_PROFILING > > > > > > + { > > > > > > + struct seq_buf s; > > > > > > + char *buf =3D 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 allocati= ons 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 th= e > > > > 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. > > It's completely fine if the allocation fails, there's nothing "unsafe" > about doing a GFP_ATOMIC allocation here.