From nobody Fri Oct 3 16:48:55 2025 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 399ED24CEE8 for ; Wed, 27 Aug 2025 18:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756319669; cv=none; b=paHTFsktq0zMuBUbVPrvZNYkIf4x7VzYARH6tNBFiwrwC5o+FypIZ+ZNNQW4UcPc9PUQb0F9W+0ah8W0BSk9m6uUfDufWHen8mH7Qjaq9vMxPDtRWcnpOoc7Art/UtYLeH3aUxAD1bQt8aKtxsIAK/nWxyKpI9Zf7nU0AgyxLqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756319669; c=relaxed/simple; bh=Rm+NKlY2TPyPlqks5oVADvOEWm0Jfq+5H2RrlsyIHnc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NAQ1aPpqmRZ9312biAnSjY6II3TMVdaePL4Erh4XXObuqxXxIkfxCeGc7ZNfc/fPtN3RjNzKK+5UY1/mR5EK6UK5K28QGS8x60DwQwUdKOaJmdv+9/+ddptl8X2aeRjdDMEQdgJYbiKXy+Ld3d+SuEXoyyBUKwlYRBpZDMiRIfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bSbQMlDZ; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bSbQMlDZ" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-45a1b05ac1eso648445e9.1 for ; Wed, 27 Aug 2025 11:34:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756319666; x=1756924466; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IntdueGNmbqsonxIGWPXQZZdSCFC9k/C0Gxs2L8OAMA=; b=bSbQMlDZmWL5BiJm4sv0wjYM98n8A7s3FFKJJasuIPqR37p5cbKlkgNGQomxxkjwtd +EXa7Qtl4zv3YOn6XTNHZSy4ROgi50qUEbU/D0tCXKvl1Wyy3kA6nwl2Yn+zW/+V7AJy e40b7hO0YfJtPWxihR283qaKyU0YnVo9pHPZleQU994Rfdw8mWWp0v03OV+6L9izH5Xs vkrLGmacw8wnTkBghPP491EmlQt+xd1G7JCwpUQS1lVcFv8AdOtQm/NAc8i7ByG5bXva 32b0DF7H0w1bC+PDK6OgxeyOZSAgB8DIlg2K6z5ZbKLJVSyGuxm7SQK/kBBH69UTgHJ1 YXTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756319666; x=1756924466; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IntdueGNmbqsonxIGWPXQZZdSCFC9k/C0Gxs2L8OAMA=; b=pE3eNZflJrxVgok7nEwa666vLyw9HjKttlZ75LRJx2gQGj02O/q0XWcTkihBsGBDvJ WRdWNmP6tQi1pa5gNLxZUgOByc75bgYgPIcu7oxCzgMNOteF6h0dbxs+G5rucWRxYsPF 2LLzsqa7T0jy3UpFjnkEIDriCTcfmgj/dQRam9p61VFh1rdJr1mKD5pj82nr2IPH1LXs vIdXcU0n8LcFMsYAt30vKRiDp5QaNhzX1ndDPszGDMyfHnTmsbFU3eJ/I2PWUoC9d58c yINgrH74hLrUUWjApBr5PULTQMnannGGaaKeLU5GlZpSxxRN2WOKpmKWLkb+og7EoaTM WGgw== X-Forwarded-Encrypted: i=1; AJvYcCUNA0GGPwkDmzxSIQmis9UPgy4YI4e97wzoA3l5QaC3n7lin1hbtW4+jJvFUEBl7Hbxc5Mksn9BiHO8JoE=@vger.kernel.org X-Gm-Message-State: AOJu0YxdXyuudk18B13DAlZMVJpkfP+VDNCHYfXuNJa6edMGFhIaNaXX gaaMcgz8J4bhxfNB2bFp/Wt8Xhpc3SJ+kNaO1JFF1bERYKpzjRmnG2mpspROraAfUer5tg== X-Gm-Gg: ASbGncvCcHgQf/lhJ6JdsurR1BZTYQ0vZqGKo91BgkGmNDPM0Uk+B/IIBb74YEnoxsR FsBOTAxWuwfBHq/QmdzrapNCYr5eKTICV9El4IiwVjkCnyoEhEbeqobGg88gcF4T+AJ/G8MKAxR VgLWxwCmC4LdYAJwaobk+5nzTdehbqxMSGGdsEpoTC+skfzZzBsHc+HDQhtvhxxKQHCiytBZHNT Jnof2aDAQKguX/kV8TSTNa/96Yw0fkGKAVWjzFoBDt1DHW4K3cRI1pcND53AwlVYuXb8FCTapcY 4tF+brpmDshS7SDO3S3wnK/LRSOq3FwcZGTaF83bg1oBOZct9ulOu2Dm4DNKO+Y65tuhFDCjSUc OOhqiuCaKIAdD2jg/DhFHLFYp X-Google-Smtp-Source: AGHT+IFpUR8b9fvTNq2Qug4jd4Uwz8rry9LmQ0JBLOieWly9E/eJQluuoWaNnPRcfSqVFiET0281Eg== X-Received: by 2002:a05:600c:1906:b0:459:d9a2:e920 with SMTP id 5b1f17b1804b1-45b5179ccc3mr180127615e9.4.1756319666289; Wed, 27 Aug 2025 11:34:26 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:1::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b6f0f3362sm40614335e9.17.2025.08.27.11.34.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Aug 2025 11:34:25 -0700 (PDT) From: Yueyang Pan To: Suren Baghdasaryan , Andrew Morton , Vlastimil Babka , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Usama Arif Cc: linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] mm/show_mem: No print when not mem_alloc_profiling_enabled() Date: Wed, 27 Aug 2025 11:34:22 -0700 Message-ID: <308e0293e68dfadb2ca3ee5b4c650fc3d09d7a35.1756318426.git.pyyjason@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch makes print kernel memory allocation information controlled by mem_alloc_profiling_enabled() so that we won't see all zero numbers in production. Signed-off-by: Yueyang Pan --- mm/show_mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/show_mem.c b/mm/show_mem.c index 41999e94a56d..b71e222fde86 100644 --- a/mm/show_mem.c +++ b/mm/show_mem.c @@ -419,7 +419,7 @@ void __show_mem(unsigned int filter, nodemask_t *nodema= sk, int max_zone_idx) printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages)); #endif #ifdef CONFIG_MEM_ALLOC_PROFILING - { + if (mem_alloc_profiling_enabled()) { struct codetag_bytes tags[10]; size_t i, nr; =20 --=20 2.47.3 From nobody Fri Oct 3 16:48:55 2025 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 5D4152D0C8E for ; Wed, 27 Aug 2025 18:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756319671; cv=none; b=mSgclw0fXKJ9xHCcbtZv5dEIjR45/Zyt0uuu7uXITa2e21P4m5eyDaAXLL0BpXDEuWl9Y33KSJsdhJXFQIX6TyHXnCQ5lgfiezoNQR/ZEhJrqmJRPr2CFJjJXLNg9H49+PrhVma+0cL0knE/CHXDu5MQekqW7Q0DxSwoEtt1RCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756319671; c=relaxed/simple; bh=nJq64zCCsCh4Yq3xI6XA8YnoA3McWGqAk1X/hBQmSN8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ri8xfTMg08iLMc22DXyZAmteIr5e8FCwnDD8ArlYgguoA0uKrorLQPyd4DcLOyOpC8OTMQrYGf7YPzscMtLr14L63BnDnZkMiABwdc9SdCqP9LJxynqosV2//8nTfJedgLwCWPi39ox3onX+qsRwCh/wwGK54QRnwzz3QVPe5y4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NY4/5mdE; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NY4/5mdE" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-45b627ea685so955335e9.1 for ; Wed, 27 Aug 2025 11:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756319667; x=1756924467; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YA6lB2OHRh04z8ztLcpTUu2sKqTDk2Id/2bOxOEc5ac=; b=NY4/5mdELCgn0ABh67K1V3lzc/T7Y1/JJ1J5UWBZE3mN4b6NGYQMFeAB8bNFpNbUqT wmfSFdJuAnBRUggvsowiUSuTw7bd5T2tYZdmSYpeTqoKK53kiNjF4dhLKOSukghh3aK8 TRY4hBkjoLywX9PKhfq5w+7hretnqx0Y7rpXwRqqx1z56g0+7NGzXBriqq76qCxDlS1y sSyOOmOeQSOxZiDaVCe8LoQi0t6mg907GMBIi21p2/BeYukUk4wMFd1FagEahhHQQ9iB SmzJcX3DGoxuEUePLr9AK1P7yoJD5Fz0CMZgJBrHkaff5/CWQ0IK/3mMK8UQsvM74o8q q3TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756319667; x=1756924467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YA6lB2OHRh04z8ztLcpTUu2sKqTDk2Id/2bOxOEc5ac=; b=mN4oYAPLtfHxrv85+pqZZB7ruKmX5v3Er45wEW8yGPVBsw2kMpZPrBRsplLazEA+Ov 5aDeHxdmN2r2HChXprEmpLvORtCSBC0Ipn/IaNxuLZn2ZuXgpq07gI2VQQ9qMufJRiuB NLdoIhxBQIiqVvRxlZD1dcYrhB6jKVQ69VDI51KpLGJENO4h+A4T8C0OAqWaQrGvmb8Z KrsLfzZYUmku1ppjT9u6fR60PtqkALv3p+l/SZrNIRDiML2LU7Mew39ThAu8DYqRjTzR cB2ehcLJ9OAqoQJyhsB1hXAs46SWIKJ3qGCW/QMDW9Qw4X6GnDP7xtx6KJtOEbI48h52 C9Pw== X-Forwarded-Encrypted: i=1; AJvYcCVtLqr/h1/ILlcrE7IxzbxSsdiJQgNTgsVnh6BrVbcC2S50ASVExO1QY1ByniNx+9t6tR3Zb3JOraFf8HI=@vger.kernel.org X-Gm-Message-State: AOJu0YwRKFnxuO2v7q1qt/CLEf4S6qWsOrVjcVUDUD7c6GkHkR5kSIWo dtHe4AViFkQLU8PGB+tyg1zdlQ7ZjBD/vc6FA0GpOeYbon0PwTAKRv2Z X-Gm-Gg: ASbGnctpzIkUfmFsf3LcYBpf50Kuyzdd86MKKU0ZZrN7B2s3koyFwgwShi25qRSCCym dSfNPtNaYfu5gbnfj0ZZ8obgkvB0ggh6QELg7RrycTeBSxOFHPjh79O3/TV2akK9025W9GoXJU9 qCQ2xJdLpOyeKhpTe4KgW8HPVBPPhD+kF8v54bZB/+46slI5Cyehat22D9HFroo4DjtMhhKnYDz NnuArCyCN1ERJGZDB0vSYlKseAjrK73W7EGMGGERv+vh41/vkZ/hkMYWe0IxDr7BwgLHePF/qX0 2NaIfHZebtedZe/kJxDa5DyVYBxgRspRN9FD+Dx/7Hz4VZno4Kq247kXL7FiMECU+WsiC60jLqh dEAHVuNJaaCA= X-Google-Smtp-Source: AGHT+IE0hXtxhpjlhfM+hRo7ji39tkDJ8DWU2BUHg+pIVaprTDiApHeE6ZCxx0FjYX9RgVOZ2NgUxA== X-Received: by 2002:a05:600c:1c14:b0:459:d780:3604 with SMTP id 5b1f17b1804b1-45b771b5ca1mr1652945e9.3.1756319667550; Wed, 27 Aug 2025 11:34:27 -0700 (PDT) Received: from localhost ([2a03:2880:31ff::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3cce1724939sm3580972f8f.26.2025.08.27.11.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Aug 2025 11:34:27 -0700 (PDT) From: Yueyang Pan To: Suren Baghdasaryan , Andrew Morton , Vlastimil Babka , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Usama Arif Cc: linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] mm/show_mem: Add trylock while printing alloc info Date: Wed, 27 Aug 2025 11:34:23 -0700 Message-ID: <7e2bc96faab1a338829e549246189ad96e6c866b.1756318426.git.pyyjason@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In production, show_mem() can be called concurrently from two different entities, for example one from oom_kill_process() another from __alloc_pages_slowpath from another kthread. This patch adds a mutex and invokes trylock before printing out the kernel alloc info in show_mem(). This way two alloc info won't interleave with each other, which then makes parsing easier. Signed-off-by: Yueyang Pan --- mm/show_mem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/show_mem.c b/mm/show_mem.c index b71e222fde86..8814b5f8a7dc 100644 --- a/mm/show_mem.c +++ b/mm/show_mem.c @@ -23,6 +23,8 @@ EXPORT_SYMBOL(_totalram_pages); unsigned long totalreserve_pages __read_mostly; unsigned long totalcma_pages __read_mostly; =20 +static DEFINE_MUTEX(mem_alloc_profiling_mutex); + static inline void show_node(struct zone *zone) { if (IS_ENABLED(CONFIG_NUMA)) @@ -419,7 +421,7 @@ void __show_mem(unsigned int filter, nodemask_t *nodema= sk, int max_zone_idx) printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages)); #endif #ifdef CONFIG_MEM_ALLOC_PROFILING - if (mem_alloc_profiling_enabled()) { + if (mem_alloc_profiling_enabled() && mutex_trylock(&mem_alloc_profiling_m= utex)) { struct codetag_bytes tags[10]; size_t i, nr; =20 @@ -445,6 +447,7 @@ void __show_mem(unsigned int filter, nodemask_t *nodema= sk, int max_zone_idx) ct->lineno, ct->function); } } + mutex_unlock(&mem_alloc_profiling_mutex); } #endif } --=20 2.47.3