From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (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 4111539732C for ; Thu, 9 Jul 2026 19:18:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783624708; cv=none; b=Q287E1mrpV0muFF6vKoo5hpR1+fnSQMWnfBex+Emkx51VXrqiSRo+okCtOrJ9hzo2RdifWyHSTJpyB1IcV68oLJ/pYWFZP8JxdZOu6/N0OHvoSHR7y6AZE0dYwhk7FTmctrf2Dw3VtzEL8tcMP/JJ4uVRWDDWzVio9StJ+0IA+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783624708; c=relaxed/simple; bh=ritO5l+XD1Zkmzzc0cVAeUIZ+AMxMldftnVPIBQJRRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SZWxopj0UpqtCo+9zvxmeySjGI28p5U5nQ7O7MabqW7hmlQJOkTG+9dSV/wqL+cLIELDaGMHJOSuyXqCRjKdILGFq2jeRw2SCnGnjveCZPWLno6fRIze/u2JhMz/gLrTHMONDZhHkVYMmfIheTssMYhSgA2V4xpDaPAu0+K9sWQ= 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=LZWlH/wm; arc=none smtp.client-ip=209.85.210.50 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="LZWlH/wm" Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-7e9f1f24cbcso195381a34.0 for ; Thu, 09 Jul 2026 12:18:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783624706; x=1784229506; 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:content-type; bh=4lZy5V414EOn9MhK1F1xbwGGbvkcelbw9AoBZCDSoa0=; b=LZWlH/wmYxFtO5gw3R2MgIP0VfzRdp0oxmi5kwIy0R+NDzu3aosQhhIw1eEVADDia1 rp62yjqmLnKK71IkmI2Ae1qf8sUvrY9XTrVHsLuJ5vFMsLWrrOaTjWPzPYBIhSWmaiIJ eaU2OKIqCeqwIvqlMsNbN/5GEuYK1MqjHy3YF0fi4KXcOg/nVgeGlOxV6A3vZsNj+lot AFNG220o8385BBeKVyL16KKrWvo2tV6Ka8L2t+MTWbBfW+XMZB1s/QU+6zSXG/jRcylv l/b9y/CVijg4AXwJWBRhQms6uQHGMEmbWEr8Z1CmM2YkPbVm54s1wCPSZkoSnTwR58VR DwkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783624706; x=1784229506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=4lZy5V414EOn9MhK1F1xbwGGbvkcelbw9AoBZCDSoa0=; b=KwUx+07VhD10YUHF7Dx0bOypOFlZ2IN/iY0tHmA8pcGYpV5zQD9AoHsbMbtaG8mhtl g4cbI58KJ/RriAqdopBXkjxJqu0848EeUz3qt5TxVMZseaa1wuoy3saAPmlkoMGIBkbC NiUKhov0Yolpd29qMU+qQRkJNAbYa6nESL2IUxNbflaH7Mb6axG/8UbEAdE6ScpsXnMc 1JmM2+gu53Bik1tdOLKcad9fhy/UO/bKEbvXFPIXvpgunf3iw8HpRq1VDNb4pVRXPWuP qYyoYWj/roUECTWaN+ijH9yp3CZE7wc7XuOuRBmTlW55oVl4fLMqGW+DPbRwc6aR5UKx ABuA== X-Forwarded-Encrypted: i=1; AFNElJ/7eM5ePDN9hpGrcpBM/0Qw/YT0GxogwXOz8Iv2FJ+GTbZ17XI2rngQtw98no3QUAR0lV6b6bqgHTkq3V4=@vger.kernel.org X-Gm-Message-State: AOJu0YzNaX1r4G6f2dCBaKmDH1yZFSpfsOctLzMdVBEmjpF21X6xBN9d hQusj7YJB02vkuOQnTPj3SUmhJcFYbDUBOvsiQHfkDGpSQB9+pQEdq/h X-Gm-Gg: AfdE7cm8M2RCbljNT+FAEEGroXVDNwMXSpbIVOC0RFXN8nUsibZs3aP7qLQzHIdHAz3 JwULAWZKpTD3681h79qeUKLHQyPp2pt4kwgFMih3iNYByg9w55Yt/BS+ZtUpRSm47H3q55FW/H7 UaqFGDb2qKL4rdYySCkTSLBh2nt+HrKvy50zIA6j1STJx4JrwONWdEGYg8szO6zHBq2it1JSlf2 QLzMU8kH6S/lpbHhqmfADpBC1KsyO2ab40sVViGIvthhyi7RILUw0vDJgCqKtwu19cz9/V5hr6y 2AwunLNSJMsQJntJQ2oar4su+Z5E+6Xm95pVGnycZ09CqheiHsOGXrbd8oqLnAeqM9CJ6iXbTv5 ycPCymdsqUW5z1thzJQtXpNQZlvtvD76G1oPeeG/IjooKaNpiiVUSC8uc/52TLpfWMCTeHPhC46 ysV03FSJVRqtwxZoG5rLpYUCbO/W1lp15tDgHqPl4ayIg= X-Received: by 2002:a05:6830:26d:b0:7e9:e288:5d45 with SMTP id 46e09a7af769-7ebf291f688mr262898a34.18.1783624706057; Thu, 09 Jul 2026 12:18:26 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:70::]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7ebcb2631dfsm4741295a34.13.2026.07.09.12.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 12:18:25 -0700 (PDT) From: Joshua Hahn To: Ackerley Tng via B4 Relay Cc: Muchun Song , Oscar Salvador , David Hildenbrand , Shakeel Butt , Nhat Pham , Andrew Morton , Peter Xu , Wupeng Ma , fvdl@google.com, rientjes@google.com, jthoughton@google.com, vannapurve@google.com, erdemaktas@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ackerley Tng , stable@vger.kernel.org Subject: Re: [PATCH v2 4/5] mm: hugetlb: Return -ENOSPC on memcg charge failure Date: Thu, 9 Jul 2026 12:18:22 -0700 Message-ID: <20260709191823.2180602-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260708-hugetlb-alloc-failure-fixes-v2-4-c7f27cbb462b@google.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Wed, 08 Jul 2026 15:12:52 -0700 Ackerley Tng via B4 Relay wrote: > From: Ackerley Tng > > When mem_cgroup_charge_hugetlb() fails with -ENOMEM, alloc_hugetlb_folio() > currently propagates this error. This results in the page fault handler > returning VM_FAULT_OOM. > > Because HugeTLB allocations are high-order and use __GFP_RETRY_MAYFAIL, > they bypass the OOM killer. Returning VM_FAULT_OOM to the #PF handler > without triggering the OOM killer (or having it make progress) leads to > an infinite loop of retrying the fault. > > Avoid this loop by returning -ENOSPC when charging fails, which maps to > VM_FAULT_SIGBUS, terminating the process cleanly. > > Make mem_cgroup_charge_hugetlb() fault handling use a common error handling > path, the same handling used for hugetlb_cgroup_uncharge_cgroup{,_rsvd}(), > which also don't trigger the OOM killer and hence opt to terminate the > process with a SIGBUS. > > Fixes: 991135774c0e0 ("memcg/hugetlb: introduce mem_cgroup_charge_hugetlb") > Cc: stable@vger.kernel.org Tested-by: Joshua Hahn Reviewed-by: Joshua Hahn > Signed-off-by: Ackerley Tng > Reviewed-by: Muchun Song > --- > mm/hugetlb.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 1f3f4b964b153..3e1d99f03c70e 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -2991,7 +2991,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, > > if (ret == -ENOMEM) { > folio_put(folio); > - return ERR_PTR(-ENOMEM); > + goto err; > } > > return folio; > @@ -3014,6 +3014,17 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, > out_end_reservation: > if (map_chg != MAP_CHG_ENFORCED) > vma_end_reservation(h, vma, addr); NIT: is there a reason why the comment block below doesn't go all the way up to 80 columns? I also think that we can achieve the same effect with a shorter comment block : -) I think the essence is to answer "Why -ENOSPC and not -ENOMEM?" > +err: > + /* > + * Return -ENOSPC when this function fails to allocate or > + * charge a huge page. If a standard (PAGE_SIZE) page > + * allocation fails, the OOM killer is given a chance to run, > + * which may resolve the failure on retry. However, for > + * HugeTLB allocations, the OOM killer is not triggered. > + * Returning -ENOMEM (or anything resulting in VM_FAULT_OOM) > + * would leak to the #PF handler, causing it to loop > + * indefinitely retrying the fault. > + */ > return ERR_PTR(-ENOSPC); > } But this fix looks good otherwise and I don't think this a big deal : -) Thanks Ackerley! Joshua