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 3920CC48BEB for ; Wed, 21 Feb 2024 18:26:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EBFC6B007E; Wed, 21 Feb 2024 13:26:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 875496B0081; Wed, 21 Feb 2024 13:26:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EDF16B0082; Wed, 21 Feb 2024 13:26:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5CB296B007E for ; Wed, 21 Feb 2024 13:26:20 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 32CF0160B1D for ; Wed, 21 Feb 2024 18:26:20 +0000 (UTC) X-FDA: 81816640920.19.9A9E976 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) by imf05.hostedemail.com (Postfix) with ESMTP id 5E9F810001A for ; Wed, 21 Feb 2024 18:26:18 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=toFsQPtQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of surenb@google.com designates 209.85.219.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=1708539978; 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=vXrmA+YUNbHeZInMv385ll0KIlZ9s0pW+epVCXD2DyE=; b=JQW9xystpYeqnLxFf0voiJolYtGsdxwPhhBnVDy/tiIqxW9lpc7mnas44bQJaKufnXUrPq /Cc12tJhdZojL/NljV2vvsBedbBt0j2lvPXasdyMfSKFMI/s55CMW+qrJh/3S1eVMTRFUd wZqEMrvH8sSq+wFdHlhtuhLr5YQqN/k= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=toFsQPtQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of surenb@google.com designates 209.85.219.171 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708539978; a=rsa-sha256; cv=none; b=MrwO2aUCQZxN0B4bk3HIGRapm/4g6pqP9uCGODLl+AEgiHpCeg9iI/gy9t//JPjACWAaJ1 MAjypjjRYbVe5du3CZNSbnMbowHCCN3KWRGg5lP0AlGAsc09XfUpcRbqZrrNrFeyXSMPUa F1+nsL6MWQHqRgHFO+vvQcWnyH8wAeE= Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-dc6dcd9124bso982735276.1 for ; Wed, 21 Feb 2024 10:26:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708539977; x=1709144777; 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=vXrmA+YUNbHeZInMv385ll0KIlZ9s0pW+epVCXD2DyE=; b=toFsQPtQgc1bq3NHVcNKYXkTK6xbyGOGfxH0i3p/cLGqUR3qPy7ztJsTGoNKUBDOBk yCXsqmBiXacmPFRx1hhq0YkTih3ZOVv9hljN9TXW0ANcW96SQblycd8PeSkmfUIbBR9Y GvIzehrVQf8XqdtE/Pw4bGcjZcinVFdnV90HT1mpqIfYEFWzJ2rROnNKhok2KGZtGOtB A9EqiWkMPKph/l9igit1x662j7QVM6VDw0XsEyI7aQPv+8G432Mmyi4c5hoMF88FHutb TKBEaI3MqbCXTM6KpuFHsyTcxNpdhIbgyKBwQ0ynS5m/Cnjhzy6uSJsNVrjhJa/gaZZj l/+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708539977; x=1709144777; 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=vXrmA+YUNbHeZInMv385ll0KIlZ9s0pW+epVCXD2DyE=; b=nbJuAKzBdbUtmRzU6W2pqbWa/4JSGX9LEcCyX3IdeLt+0h8bKnC1lPzxALE6fY8p1r gYSTYQRN3ZkVwu0JCsowupWHbVEkbJP2IaxCGSXbNTsFQrRay/ZEix4RfYbRDBqyy2xQ FB2TZZqrkYukLZTZryhMBhUJKzPfmmhKXp7Dv1K/bAV3Xib6fX2bHdBuoUmPdgOlgiTE EbYFDnOho+RcpQ1ARVAB4OLna5WcRu2Z51O2ETCY3amWnef7kiGl5lN1MCHIKjtonSFD phGDSJK2zvQjzB24/zOO2boQ05LnD/WdEqnOMWFcUGVfPzdqSXy21V5FTFy0+W8/1E+o IR6Q== X-Forwarded-Encrypted: i=1; AJvYcCV2ZrmaCpjZMBavuDE8/Zu/QtnSH9jSR/LVSUDmK9zd6Nv9YbKLJPvdhQyT87qM/CFNyW3QEwm6dqjCoreztEzBKZY= X-Gm-Message-State: AOJu0YyOh5yL8VDGSki2ifyJnsqYRjwCY2UJc5Q2f161uH+DegAGGZeO Yr8tSLFcxy5oH+CqyEGuUJy9sP+7x+SlJ4Z9/bie2asSa+V5W6nzHJZ+4H2oel/vkrfGthRWomT Vzp2XM1R1TCAJtg5Lkt2MoJbITBo5NE1mYIBE X-Google-Smtp-Source: AGHT+IFqS8tJn14NncAWY62WTNABteq4kVyKmIkcCAlDBmY1N2BQti8G3zCHf537pCEhp7uq+qbCNuxgh3NLwozuq4M= X-Received: by 2002:a5b:bcc:0:b0:dc7:32ae:f0a with SMTP id c12-20020a5b0bcc000000b00dc732ae0f0amr80411ybr.65.1708539977180; Wed, 21 Feb 2024 10:26:17 -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: Wed, 21 Feb 2024 10:26:04 -0800 Message-ID: Subject: Re: [PATCH v3 31/35] lib: add memory allocations report in show_mem() To: Tetsuo Handa Cc: Vlastimil Babka , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 5E9F810001A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 6wwihekwrd79xtjf9iqd9w3tewo3gwqy X-HE-Tag: 1708539978-312277 X-HE-Meta: U2FsdGVkX1/81pzD5nKqdXXU2GEKnx3HPd0tGJxAcGsANJ3/rbzpWEN7BSr5O+h9Wkl7N6D16q7ByBxkTQag4T3uNcGToz5Z4O4wTT6gtHXFWiN1G288UYqsOm95hHRJhpBNfhO5TisMk059ZrPean3U3AO8hRL0K1ytmuum/b/P8GOugJ4abgE097KLm+8nR4PugsGiekgnjSEgIj8cM0oCgSqbgvE5MamQ/NELYj5Y8N/YfbwnuhsiX7V4V6DJIavRbfnxqOfvxjrgy2B/GN4fGS8xGvEqdvJcILXsyoy0dDBllK2TpT3Wc7XSU0VNLrnBLGvXj7oyawOp0ApcUwkC255n0l9/N1uLbr05RxQl9/RY3G7sWZwuvoIBdEwp2wBf63cgcriBz+MeMUcNMNPBBbxzYjtyvMOh1IkInQX7mxOduYDpPYHYsPCPiL6KmqN3GUOZBeWGQRHzzVkD/rWXidspsctlO+EqLNpoFqhifWvAhl5x/i2ovpqZtBbtV6n7EZSormJT0Ja7w6ioBIdRlFfwsI40ksoItgMY5QGTYQMG174IxFUeRTnpRMKBqeq4yqLO5K+TZCFyneUDAfix06FvVeHQGZaH/Svi8+w4pxn46xgKd3gJT3iaR9lJZBzSZjT+uHkNqRXoFMcMsXpnjt8sPMTZwxXtlOONbG7Wa9v5t9m+ap3SBHdtY6UW5SCCl4BzupqO3vsxVsVLZDaolNuNv3Q4uLqvgeUtrkKTu94/+J9p8KX4R+qHXNK89AbXszrxiRwdtPINKg0MuLEEJDQdTXWzaaEeTBxIYszy0EY+UeKZgb3LLDplLYUYQEUVyucu1B6OlUfGpyvx7BtfVlKDRVT7Cma8NuCL9BFaV8NvqrisMyzlc9nplxr2OVkq2DtcpgFlcJANJXDczUw3n+OaQvMAS8mBrcUnbuaOGsWJ33XmLwK7WG30vlUTgoWNwZrRDe9CdEV1UNB VpJv3af1 9Zl90+PWF0+ZEV/nglPJfq+0rEDSMg0A7EeucIRIiceQFA4XC+GDfdQzASgdhGFbnjkUcdn990zA6KwpFBEi372uGtuLrSAdSyqJDLii0eKwKpWifByFtrzhVaYkLdDpLQiEN51FH1xjoWR+Akqz9PV4XYTL9+rF3Y8UNgW3bHgBu1+EWg0vWHGo2idpImk+ziZtWjZpER+kGO7duONmhnnM2hua1NRIYJLTD++Y94fX8s4Szrxh+XKWhubBkscwZf8Rss87ADblDsnKOlspzx1jv9rE9taR8KM9IfvKUSWmFb+4tXZ4uiaRWI5FQS0bZ1yA6adRQSTSdJP/O0ZldplJPpQ== 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 Wed, Feb 21, 2024 at 5:22=E2=80=AFAM Tetsuo Handa wrote: > > On 2024/02/21 3:27, Vlastimil Babka wrote: > > I'm sure more such scenarios exist, Cc: Tetsuo who I recall was an expe= rt on > > this topic. > > "[PATCH v3 10/35] lib: code tagging framework" says that codetag_lock_mod= ule_list() > calls down_read() (i.e. sleeping operation), and > "[PATCH v3 31/35] lib: add memory allocations report in show_mem()" says = that > __show_mem() calls alloc_tags_show_mem_report() after kmalloc(GFP_ATOMIC)= (i.e. > non-sleeping operation) but alloc_tags_show_mem_report() calls down_read(= ) via > codetag_lock_module_list() !? > > If __show_mem() might be called from atomic context (e.g. kmalloc(GFP_ATO= MIC)), > this will be a sleep in atomic bug. > If __show_mem() might be called while semaphore is held for write, > this will be a read-lock after write-lock deadlock bug. > > Not the matter of whether to allocate buffer statically or dynamically. > Please don't hold a lock when trying to report memory usage. Thanks for catching this, Tetsuo! Yes, we take the read-lock here to ensure that the list of modules is stable. I'm thinking I can replace the down_read() with down_read_trylock() and if we fail (there is a race with module load/unload) we will skip generating this report. The probability of racing with module load/unload while in OOM state I think is quite low, so skipping this report should not cause much information loss. > >