From patchwork Thu Feb 22 19:46:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Cassell X-Patchwork-Id: 205026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp175351dyb; Thu, 22 Feb 2024 11:57:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVsETCrK4fbWR9K6jRHMarcmwxAP7t/B37DwWFZAv2uXC8TOy2mvIwAxm91pwEy+iEEbt2ewYT9fCZ53pcMBZIfQKeEJA== X-Google-Smtp-Source: AGHT+IGCHVFY0S3KtZmtKuSk3wuND5UB6kJPQKcB6F4EAxTyBOSmmQpkHHrNYuHNnxOyy0+bWrxS X-Received: by 2002:a17:906:f80a:b0:a3e:3bc0:64f5 with SMTP id kh10-20020a170906f80a00b00a3e3bc064f5mr10651059ejb.64.1708631857396; Thu, 22 Feb 2024 11:57:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708631857; cv=pass; d=google.com; s=arc-20160816; b=z28OfFwUhxevDK0cuCuhI8Ne0lNXC0DufzaZHIQbCSCIqpFe2v13O+HNpv5mjDyUmz V7/pCZNCs0Yw+cSa4AIAv4RZKaX328IaofVGsnJlmH5czIrBnggZ0rugqUwavPyaKJ35 rB4/g6+aMsMOWVzVMsm0VDjIfPIBnbmfOiwkr3ACmy2uXy7jyHXqRONxh6ECnxPkxhpS rGzYOddt5eWN2wq1+Oma4Mo9WjbtZUaUzR7UAj1YmUQPWZpUbLrVBCU3RNlXZmAYRyOo gfapHZMglk5VP0R4UCb9+RIId9KeLE9MRv+x3zHWApnUcECXInSGGIraY43lcRcChiuP N5IQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=avkomLKBJ3sytSufqOwSv0efxNpypNMAMWMqdPXHCPw=; fh=oqv1ddGGEPdj/mi4nHnW27cfY2c0nBKT6ATVFRyVl78=; b=MNa/QLkM43lZydtNdu9ugJSoGcAexs9A1lj5eafcXl9NmH/Kb5dYBQVotU2Kfkvnf7 QdE8rUzu9udVW8sVIYdaOR9AuF6dc7j0gPgkg5DdJsnSVvPx3KE10iiFv9H551YqAaS1 /GkpRV+FhTRG1y3Mjt8lUrap2kQFuK815FES5RX0ADEr8u8UgDj6KHW/75OM/Rh+6+rw bQb6QwdymSz+dj4LPndzWoh4qPrmfstp26F11mXwNgZbL/XpdGGH9XF2GEX8lXO7Q5SO OMBxxSJCFz4bmc8DYrdYWG6fF3DxH4V6dTITSKJtqxYkQfXXfe1JWVr3aEB0UbpjQb/4 o1QQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GIa4R+sd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-77278-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77278-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q11-20020a170906a08b00b00a3e0b7e7222si5911986ejy.438.2024.02.22.11.57.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 11:57:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77278-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GIa4R+sd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-77278-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77278-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3D4431F22EC7 for ; Thu, 22 Feb 2024 19:46:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D82596AFA0; Thu, 22 Feb 2024 19:46:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GIa4R+sd" Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.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 AD61A14B815 for ; Thu, 22 Feb 2024 19:46:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708631184; cv=none; b=WfP/Es5WLePKOhtj/ogM535itVKtETimYmyX+BpXEl/JL7XRmbrre7TR7ZZD38GfD73eJLHjV83o0m3c/INTu1Qw457QdZjd052QfFa3oP6rTeGAZCJ6GiU+iIhiA6eGSdZDvOfg3NLnpyQtpuhAT62WgubQ2SytZo5B9keE0EA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708631184; c=relaxed/simple; bh=QR8wsxpn61c6bZNiH82UFjpggpnzUY5VC+cjL5uh/lA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=fTnVOJP089cJtTVcgIsVlg53K0qXzJV/vAi96mQiBnvsTC24QhcSLyxcvJ5XmmJnRnb9gA+MpjZE9sEyAfmTUgqdN8yH26MGoeqdhFviCI5Qx3h99RNHXUrNbXrPC5xDpjpZtwTUruXHOoVKCr9nRl/e8c8nitsqLStiYlTeXCA= 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=GIa4R+sd; arc=none smtp.client-ip=209.85.222.173 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 Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-787a843003eso4304885a.0 for ; Thu, 22 Feb 2024 11:46:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708631181; x=1709235981; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=avkomLKBJ3sytSufqOwSv0efxNpypNMAMWMqdPXHCPw=; b=GIa4R+sdDVomfRLT/+ndwTYR9VrAiqB3vrtQyxnwT6llT2HWKBLrP1oQsca/5F2uGJ tzWdtUdx9+HqzLPJ9c2LKg7fUz1w6Y2mMX9DGreVPQeDjh2rXmeQ/UBFje7zTcCKYdtb tItRfqHJYJoBu1CWZXMhsTW1qSveDyjgCx9M4Chb90d74+K3GqY2D60INn9e7044kKN4 jCjnIWkqxlZypnbn7MfLFSupOnN/hCJxBY+1LmXYotLVirisNnUeNyV8C2idMLNylZfO U4BTvg6sNXNBx+zWR+yn/NYoIkSlM2ezMjon4yygMSWDkYt9eKfTBno7vJricMPh8o05 ThMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708631181; x=1709235981; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=avkomLKBJ3sytSufqOwSv0efxNpypNMAMWMqdPXHCPw=; b=BwBpNaUv2kRbMAezGonOJV8LR4GPUZ8FSi5FODw9gasFkAE5fzmjc3igvNiXsBSuhi wtXubUbld6OUHCLmzgjMMhAaONhAg45DsXAQFILdmq5n1NrBuxP8pMXriIG3ao5mNvxP K6Ttkh36ofH5tr4hIjiJqtInZ2vf6iDdMap89BzcfmtICcnhyqOWM6cvrqUHGMi9R0yf kHlH5xhVaUnv/oDRahyER1JMunPSFzv5rv0re1s4u/abMZN6XGZsUzc16tVm7qYO/2Sf vpekuExkjJluyd0a7IPaCDw+59UmuipdXCXrK4NBSFdy4pP42dYwxBQ0okltWhXrt59x DnGA== X-Forwarded-Encrypted: i=1; AJvYcCUmAeGfuVrU75NwjkTqI7pDIN4XwO1LrXXmxAvY1uHP3apnkvjP+wyLLUkcaM66QDVrfatFF9IcsrOrnfKE6VCpqeKjq5innLchqc/U X-Gm-Message-State: AOJu0YxrZj3637ZwXYxkPNRsiW97lFEGdvJhFMlcxcjz1pqrHrBjPQDm sTSSiSHmr/dZ5eGzUl3L6eUOmUwu+RrVyJvfLsbwYzd4hKMOPqoB X-Received: by 2002:a05:620a:88c:b0:787:aa2e:22c5 with SMTP id b12-20020a05620a088c00b00787aa2e22c5mr10566qka.72.1708631181512; Thu, 22 Feb 2024 11:46:21 -0800 (PST) Received: from localhost.localdomain (024-171-058-032.res.spectrum.com. [24.171.58.32]) by smtp.gmail.com with ESMTPSA id dy4-20020a05620a60c400b007872ade6cf1sm5626389qkb.71.2024.02.22.11.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 11:46:21 -0800 (PST) From: Matthew Cassell To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@redhat.com, mcassell411@gmail.com Subject: [PATCH v2] mm/util.c: Added byte count to __vm_enough_memory failure warning Date: Thu, 22 Feb 2024 19:46:17 +0000 Message-Id: <20240222194617.1255-1-mcassell411@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791630358492632626 X-GMAIL-MSGID: 1791630358492632626 Commit 44b414c8715c5dcf53288 ("mm/util.c: add warning if __vm_enough_memory fails") adds debug information which gives the process id and executable name should __vm_enough_memory() fail. Adding the number of pages to the failure message would benefit application developers and system administrators in debugging overambitious memory requests by providing a point of reference to the amount of memory causing __vm_enough_memory() to fail. 1. Set appropriate kernel tunable to reach code path for failure message: # echo 2 > /proc/sys/vm/overcommit_memory 2. Test program to generate failure - requests 1 gibibyte per iteration: #include #include int main(int argc, char **argv) { for(;;) { if(malloc(1<<30) == NULL) break; printf("allocated 1 GiB\n"); } return 0; } 3. Output: Before: __vm_enough_memory: pid: 1218, comm: a.out, not enough memory for the allocation After: __vm_enough_memory: pid: 1137, comm: a.out, bytes: 1073741824, not enough memory for the allocation Signed-off-by: Matthew Cassell --- Changed the debug output from the number of pages to the number of bytes. mm/util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/util.c b/mm/util.c index 5a6a9802583b..6710efaf1802 100644 --- a/mm/util.c +++ b/mm/util.c @@ -942,6 +942,7 @@ EXPORT_SYMBOL_GPL(vm_memory_committed); int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin) { long allowed; + unsigned long bytes_failed; vm_acct_memory(pages); @@ -976,8 +977,9 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin) if (percpu_counter_read_positive(&vm_committed_as) < allowed) return 0; error: - pr_warn_ratelimited("%s: pid: %d, comm: %s, not enough memory for the allocation\n", - __func__, current->pid, current->comm); + bytes_failed = pages << PAGE_SHIFT; + pr_warn_ratelimited("%s: pid: %d, comm: %s, bytes: %lu not enough memory for the allocation\n", + __func__, current->pid, current->comm, bytes_failed); vm_unacct_memory(pages); return -ENOMEM;