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 0B085C48BF8 for ; Thu, 22 Feb 2024 16:24:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FDF16B0082; Thu, 22 Feb 2024 11:24:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AD936B0083; Thu, 22 Feb 2024 11:24:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 675FB6B0085; Thu, 22 Feb 2024 11:24:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 571A96B0082 for ; Thu, 22 Feb 2024 11:24:31 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3465A40AE1 for ; Thu, 22 Feb 2024 16:24:31 +0000 (UTC) X-FDA: 81819962742.07.EE01A67 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) by imf08.hostedemail.com (Postfix) with ESMTP id 5BC7716000D for ; Thu, 22 Feb 2024 16:24:28 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=W6nBdZ1e; spf=pass (imf08.hostedemail.com: domain of mcassell411@gmail.com designates 209.85.167.172 as permitted sender) smtp.mailfrom=mcassell411@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708619068; 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=/EqmFmOYCa3OzZ9OMKnDFgfBUj0DGssnGUEfC4f0Dsk=; b=C8gSmQwFL3GE4DWnxsr/Vv12dhFODjXitQ/9NPr+dZbbwfzrGQzslhC5yKqkq6bQo7BCmW XKnsE8l4Ujvkj7j6mFo5aQdTIgS9yFByv2eNpfzhSSZU0rt269bXRIXZED97Nv2WdFAoBx qMgAq2U8Dwq3odt+HVfXs/jGSkZe62Y= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=W6nBdZ1e; spf=pass (imf08.hostedemail.com: domain of mcassell411@gmail.com designates 209.85.167.172 as permitted sender) smtp.mailfrom=mcassell411@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708619068; a=rsa-sha256; cv=none; b=oO0FGnqh84ArEWuA0iUtAgZtfjutas87CLUjwY7ZoOBhUhiWb2N2+6SZVni3vKOsMUhN7U 3/xFt1HQngcUKp34n2VY4QT0DLBzOs1ehh2xNBjuOhKxb4Qa7kGZUIYyNqw5SySvufKMFE v58tVmBs3GZJsUQm2p3/7l6Fx0MHba0= Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3c031c24fbeso1410453b6e.3 for ; Thu, 22 Feb 2024 08:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708619067; x=1709223867; 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=/EqmFmOYCa3OzZ9OMKnDFgfBUj0DGssnGUEfC4f0Dsk=; b=W6nBdZ1exMVVhck4EKRbySkUojkr+I5hagEMiqU1l5eWu3i0/EvVb6btw6f9S0H2to IGcJZQAVfWNzTZ1sYPThWNdcBU7tl2y5Tg4w1JF0/64Moxy60tgRdqZQ+pE1OK6CsvWk TyaG1Hrquou/tXt+FB0LdC7EMALeY/fQIEhU9GFFZDc0BgkNxFY5lPtm0jr0bVV0ndMa Bo48N+K+36I+II8EqKBXVuvI6PD26B5/WpTtSokEJmhFVy7rHGQW+TpTyMstcYDYcO/t LP8Tm4da6UgOzbt7rDIN7eb1kph9HTEwuUkgxlLr3gFfbyWl6BxLuF0MekHnlrFpfp49 1aDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708619067; x=1709223867; 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=/EqmFmOYCa3OzZ9OMKnDFgfBUj0DGssnGUEfC4f0Dsk=; b=OY/pFETscC1qUm5u8jY+NjFUHkz4y7n1PdGKqnf/JM+KhAkMqXHUD+93ukPrIgGgWG pfPYgjj5K5Tu38ZTg+9IKhYcTAg51pzk7krVusnv0IVQiH0qXKbUq2FtI8b0emUn7FHY yh+hrIKdFl99CyNbALlcRZ+e0V0s8z8zf/1aoIzNI6SaR7tPTspdw9HKPdTaMbkHrmNX Zh+3tta4Lig576s39k4MvEsJvCqDYyabP8W9Fr/O1Ai35iu2ZUUJNPQ58MuxPhikF5OT lzfs2F3JzVRCcsX5JRPMIkHQXn4WZCjRvhZkfnbBATYzfh86DGJViIo9SrCfv0cOp29m WBlA== X-Forwarded-Encrypted: i=1; AJvYcCWgRFcZb/3VhF8O6tZQyI9oyMBJRutzlBWjfOnkI7Ee4KAyKhj0hsalMQHh72jociEh792EsfBS8riJ5Wj17hH38Cw= X-Gm-Message-State: AOJu0YxtJrBPtlOFDHkq/KxhOb1pmH3pKVMd+vIYcbuobJe4Pokmvy2s qnH7Zqlmp8odv6KokozMLqpazsbv/7d3/sbBtH8q07zzJvS1U3hFbwy4gNAb9q7Swh5j0BiL0VA 0noE9iAgZ07zFrTHrdIYN6dAChXqGA/IKVivyVw== X-Google-Smtp-Source: AGHT+IHwo0OJPxms5ngEpqSEBC8PZ11D7hXFbOD8dnp1ziM2q2D/PE45FsO7gx3uvaqKPdF3wrszwYSjWXzcNrTqORE= X-Received: by 2002:a05:6808:13c3:b0:3c1:5482:770e with SMTP id d3-20020a05680813c300b003c15482770emr14635719oiw.10.1708619067537; Thu, 22 Feb 2024 08:24:27 -0800 (PST) MIME-Version: 1.0 References: <20240221160235.1771-1-mcassell411@gmail.com> <1547a955-cee6-40e1-8231-0bd1229de0f3@redhat.com> In-Reply-To: <1547a955-cee6-40e1-8231-0bd1229de0f3@redhat.com> From: Matthew Cassell Date: Thu, 22 Feb 2024 10:24:16 -0600 Message-ID: Subject: Re: [PATCH] mm/util.c: Added page count to __vm_enough_memory failure warning To: David Hildenbrand Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 5BC7716000D X-Rspam-User: X-Stat-Signature: qqn9hdiseweiit4jcki8tmbqd9apm1bh X-Rspamd-Server: rspam01 X-HE-Tag: 1708619068-872874 X-HE-Meta: U2FsdGVkX18fT4lgIy9YVFW9T4hs1iSvJ6yB2Ngj43M/Ot+nWoPWrAqlI3MDnYxqBgzcgqUcGOoH2vJA99DVO6AS0F2p7s4xlxX5ORCPqgurkPQNFgxthBuzJ0rxsOmCbu2OvklmfKBzLwCha3WwMujMo0LS3DaAQ8IE3AvWI4Ha7qdzGl4FoDLStJCxAhkf73E3FRc8DNWgPUc/YGd3mfNXARH0N7PRk+4Uy4pgwJpTOr/BWneMS2K3lxzABJXWOdkG8OjnsoKy89swZ0KBXpjfhmBOoz0OHavqO7K/xXinI9hGQc5q058GszIf841eRqztdGOu70rKXePkO1G8xfX9d+07xhu3OijtQT8/pOeP8VIpqS9oNoToofqCvTtRwmcM2RYzin2yEQZVt2Hs/tJ5z67R8OouVOmkAVVjF0WYEMpcumZuxQyc4j6Vt6l2ulbDKYFRjQGn+arYp1WPCIDajeHbP16BugxxoTWfrm2AiX6MDJ7AHRiwfw1D69X16ZPAi/jEA5AgCBhGEYi+MLjKBo+tsm3Kl3q3H6PS0c56JQeMZtjMcDQq49CeDLX5mO+gUXH3gVGZc+E/+C+gHr6Zd5jwH29m8M7vl5r29rEQzpqO6kCw+hp2en1EY42JeRUjtx6WZc57XrXl14wFQ2h9DLOp863WOiNxdaKCx9uZJW4I/jYrI2P1PDBRNS174OP/g8PSfeqH+zZ1y3LbB5FBIRx8K2Ti5bdea40XYkuTghxg/B2jkuRPnZXfdEAJ+QSWzB2bmdGa4GWcew3iCPyUPD15K4ztQa1mr60fn388iMOzwv5LGNl1CWet2Py1jDpyWLYzjpz6RbeAmh+cZo66kO4axnfTilPwciXGcVFKDRM90y1PY96VFkk1Ruz8+ZHo+kRVFIaFU5IH3gv9n8odzoJRlvf5QIJq4cmhlbcyL44muMpRBv67RWhV4Rp9zzozs48R3HfQJ2HjadB j7b8kP2a I+kdsRBDTgQ9ZtPMcUk3VFhYuj5S6fd/LJsLjCwMeXwGnp8OQE6GWEiOMg7Y5CUQJIqL8PFjjsDmfp6sU5WAypfux5mmK97p4StcH7OVoT4CGJvMgVZW+Oj3s8FUpwyuE5K95EiFMocA16Hdgg4xJjrkFR/vO4nJYHXAggcasDZOjMzhMPKQsXAdCUg/Fz3ZKJZSfKih4HfK6fYNAwwFJ+2sZIGaMbMIBOaZe/PbeMA1TFoEqYJLn8D7SIRvaKJJJ1wCmPK3dJALs1aQj5BwFvKZeJliBiot7wjPHoYO1K0wrhjIdbZOv8DyFwT40yJ1BwRbp7bt73wlp38qQhC3IdSbPSvK4p9AsWBE7k9mradXuixoZpXM1I2YfuiMFi63RFhybCl0X3SKyZu/kEmkeJivuUtc1Cto4q95Sp27KfjwpE0wU4xwcW0nEBbwrBkJZUkTi 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: Resending due to plain-text email issue that caused mailing list to get ski= pped. Thank you for the feedback. I agree with you and would prefer to use bytes/kbytes. Here are the 2 concerns that led to me keeping it as pages: 1. Reduce the impact of the patch. Here is the call trace to reach the failure warning: <=E2=80=A6 usual mmap() stuff =E2=80=A6> mmap_region() -> security_enough_memory_mm() -> __vm_enough_memory() Within mmap_region(), the length variable originally passed to mmap() gets right-shifted to get the page count. My first thought was to add an additional an additional argument to security_enough_memory_mm() of type unsigned long to keep that variable, but saw a handful of calls to it that would have to conform to the change. Not that I do not think this debug statement does not warrant that, I felt the less impact, the better. 2. Concerned about losing bits. When converting back to bytes I was worried about the loss of precision and printing that number back to users: unsigned long bytes_failed =3D pages << (PAGE_SHIFT); On Thu, Feb 22, 2024 at 6:18=E2=80=AFAM David Hildenbrand wrote: > > On 21.02.24 17:02, Matthew Cassell wrote: > > Commit 44b414c8715c5dcf53288 ("mm/util.c: add warning if __vm_enough_me= mory > > fails") adds debug information which gives the process id and executabl= e name > > should __vm_enough_memory() fail. Adding the number of pages to the fai= lure > > message would benefit application developers and system administrators = in > > debugging overambitious memory requests by providing a point of referen= ce 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) =3D=3D 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: 1141, comm: a.out, pages: 262145, not > > enough memory for the allocation > > > > Signed-off-by: Matthew Cassell > > --- > > mm/util.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/mm/util.c b/mm/util.c > > index 5a6a9802583b..c0afb56f16ea 100644 > > --- a/mm/util.c > > +++ b/mm/util.c > > @@ -976,8 +976,8 @@ int __vm_enough_memory(struct mm_struct *mm, long p= ages, 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); > > + pr_warn_ratelimited("%s: pid: %d, comm: %s, pages: %ld, not enoug= h memory for the allocation\n", > > + __func__, current->pid, current->comm, pages)= ; > > vm_unacct_memory(pages); > > > > return -ENOMEM; > > I wonder if "bytes"/"kbytes" instead of pages would be more appropriate > here. > > Often, this will fail due to mmap() [where we pass a size from user > space] and also "vm.overcommit_kbytes" is not in pages. > > -- > Cheers, > > David / dhildenb >