Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2534316rdb; Wed, 21 Feb 2024 10:28:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUB6oKSKigEWSu8AAOeaogMZXTuZSKTkNt2FDc0Wcuw0+wTbiVo4y2vQHScmC0FOBdmnls+KYRcUrkUg+7v6PJTxrlIW6qa8Hxcpdt2lw== X-Google-Smtp-Source: AGHT+IH4SiJMcK9DlRK7WNrUcu2OrfgHyHbADrmhOp09FTgfqPNXjHcOI+WLYJqMQJhNHkmohO3v X-Received: by 2002:a05:6214:27c8:b0:68f:8921:6924 with SMTP id ge8-20020a05621427c800b0068f89216924mr10499131qvb.12.1708540110382; Wed, 21 Feb 2024 10:28:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708540110; cv=pass; d=google.com; s=arc-20160816; b=X/bHeXNAKZOZSJS11Slej8iKZC0MkykrzV8VbJSYg+8nw8d60hvwwZqHEz3E01VIvN kh9DNhUwix2DVtkBAzdrT321bWN14LOCEfeJ+2ryf8QNVS7SLc5qbjopL56im9MipSPY jYO8b6htDlhQE3ho9jCTSeZPASDDObGo4MPa0IaxfwyIiJvCraZtrraqWtZHp3MKHkuz OhzvQ/d6XS7tnUWrBhiWyUTPvx7JPHC1tOnFjfZ6hJIwXrPKrA9+OkFHn3dNLtIQkSJn jQEfmLtktNKVSarpo3sdnmpMq4LWwji14PgvQw2c81Iie/vCTSzV6w0R5t264dmHSwp0 uWrA== 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=vXrmA+YUNbHeZInMv385ll0KIlZ9s0pW+epVCXD2DyE=; fh=EgAHRtX52RyM0/xxzjK5RNSvk0v3xTbfJkNP6g4bKvg=; b=XAUdT88eg+VkDil06934M+37FsVrj3PNv3H+96iYp59NJVqGcYrQNeoXZEuU2jtHUx 1ta0RA1UU3bgvTcF0wWIsycqz1u7RIa9kb/OYIn03hrWqlnfmY1B1Ga95Ze3K21TkG17 2PQNg+vaCdM9MVvnOhRw5LlPlyhSeh1B04ilfzSSq5mBfp4s3ECGAlAarqH6BmmQyPSa TzjN6r2ORBrM/nthyDLCo9e+i1Cm9oTw/H24Ga8kmru6eXgwN55kOuC6HINjBijIw36O iWNyqyUpYK3Im33DP+IJWzmdM8V7PeTt4nuWkF0xQqoQluuumDxX9BHtfAOSlHsKURRj 5QMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=J3+Zb8DB; 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-75292-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 7-20020a0562140d0700b0068f3fccc51csi11229258qvh.271.2024.02.21.10.28.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 10:28:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75292-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=J3+Zb8DB; 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-75292-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75292-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 19D3A1C24176 for ; Wed, 21 Feb 2024 18:28:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 733968565E; Wed, 21 Feb 2024 18:26:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="J3+Zb8DB" Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (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 8A76285276 for ; Wed, 21 Feb 2024 18:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708539980; cv=none; b=IY1+OkCHiaOJkseKyCrax2BHWdLt8nt6ubgY065yDdYJVWUY9bWsoiED952EcBLsThCLgbDFqcuMYsQhy/FZ6piSbDfGQ2wD5UGt0gy/shLOOvGRbe7AN9iBUhZyX058cO2Xl9JVBCF9cccaBJV9TnaFSqedYRAWxbdMONRLaN4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708539980; c=relaxed/simple; bh=vXrmA+YUNbHeZInMv385ll0KIlZ9s0pW+epVCXD2DyE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ZBrqFV3RXCzSkmXzmnwxQi95SIjdmtGp494sswLj06g76FOHNoo3XblGc0b0vf8ji+StxORcpJdZCCeeHoPbxIVc3wbtal53XgsVT56L3EIm+3Bn/MW0E5ODhaU0wuPz5zTF0hndV+Kpn81peJ7pdVMuI0DUcB8GeM8uW9XRFTU= 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=J3+Zb8DB; arc=none smtp.client-ip=209.85.219.173 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-f173.google.com with SMTP id 3f1490d57ef6-dc238cb1b17so1069495276.0 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=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=vXrmA+YUNbHeZInMv385ll0KIlZ9s0pW+epVCXD2DyE=; b=J3+Zb8DBBkreOEG4kHviLtCxTCWFW7dxUW2IgpbLFMfqcu/ambpyUkvdiTearxqjq7 scgkHr+EcfVdCDFWhJlFe/Q/lbZB3/f2k7FUfXaxGOopsN/qfyzioyjqN3t9q3AMxcs/ XB1Mb82/xx/b7WyQDwPbzf2lNJH6BsZiryalu0zYDMyOUxwE+ouWKmdP4Bj5UssYDymS gVIE/9FsxRSJKtCxgNoce3+4bKfCWfWJiPqYGbAJt0sifLpth6YgcOVG5CMPr25K7Fin pGkYdGt+PWryalhijrwoZzmJ9RqbIWsfJ8mpnIz2CHbiNtuKaaN6eePFhXapiQ+F/2jy QNfw== 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=t4bKTvJGUirpPQGyIZIO3lNKA5Q1KEC6CHcZzOnRASOaITz/WNJU1N2QqbZLcFlS42 O6mehKd7dFvZtBqUqHWA8/P0B5b8F6wuhNp9hzzSGQtjU9nW3MaC5XyQFfIyzSoJqHmg M8+8kCpl1Ph30SRtbpgTX5yTw+MeeBlO885Mxa6CErh+P5Zu+UuJc16qdasEW/WXyy5E 8VjXifd55PhBbes2F6jdtTDTrIYcr9lEhkw+vtoEQ9mC410zw3XXGM1s00195dsWmYVE Ugir/F8QsmA87Ji1izzM+9+2ZxtWGnD+KzbW242XseD3n5+n54PevPeXYBQoq7BXrN2b 0nrg== X-Forwarded-Encrypted: i=1; AJvYcCVyz0CpiHyDrlC2TQnyockminSMVEwHNcOWfyGh89uwUl7+p5tG7kOnxFQTaSQHROxuMnezSnnBQN+pyOm3rBjk5vNBfbZYfdoZ+ask X-Gm-Message-State: AOJu0YxrJ6GFZw2YKIW2ePS2hRRs12sn94fxXnELEukPPvqE7DyBxJco MfHsxS64PNOZgNs1tnPrWHsr+deOkVDKKRUrm79dkGG9m5S5VLABhugmI7br0eiI2N1Msg/oItH 60SU1jpga/EDzwFYsATivKV4gODd9V07OvUu7 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) 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: 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 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. > >