From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 055A236074D for ; Tue, 28 Apr 2026 09:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777367289; cv=none; b=M4FQYIGFbQdyGTFEvnHFxEzae56sAJmtCVC2tS1ofAvBGJ44j4u36E0HSc8MN5aP3Cfu/X0koHs8QRVMsLTVGeZ8xClkJDFxHZt7JkNit25MCTu/E14+WQ/rHsxlaTAijCA/am9i0CEk/pNO4EyeXC9iOpjmLn3eVCmurvdXJlY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777367289; c=relaxed/simple; bh=Xt7xOtJoOYGE1Ruee1xXLAtljpv6FvN6WQOEUAoebWQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J28tkbOgrmi5BSFvUBz8301NM1FuFOOyFH7gqdP1E77ppQBngPohxgrTvb+/rr/qU/f/AsdlXLOBYuASKa74YXNFRlyMHUD847X3dmYPv5KFJ1JR5Q2F/ZWghbR6JHz9omUm5eGUYA5mScozXny/z4tSlAnbdNxUpuVH3u2auoo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1cCZAQoR; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=xXWEmrhn; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1cCZAQoR; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=xXWEmrhn; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1cCZAQoR"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="xXWEmrhn"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1cCZAQoR"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="xXWEmrhn" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 40BB36A81E; Tue, 28 Apr 2026 09:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1777367286; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+PLcPEDXVXa0sOl5og5Impq8NYwy8sl9J86BGnNXg6s=; b=1cCZAQoRRx5NF2kvJSPKgnH/J18umo8qqCqECuqhTE63VxfxrWE7MTGciczpUjG8R7xEIF rzMhL1zInW7VMwY14BXqBYIySvHkLoW3Y4XXCGH45VOxuMa4/0G8XQuPQXYW01+sV/QgPp FGaacetOTTI0GtUnMDxdW+O/Kid0+VA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1777367286; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+PLcPEDXVXa0sOl5og5Impq8NYwy8sl9J86BGnNXg6s=; b=xXWEmrhnZVZwZjmZPwV/Ub7Va0Iku6foqi7SkqJ7tB51KSM+Vx7pxwkyfVC00DWy/Oc20G tL+/TQ3R5TA16dCw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1777367286; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+PLcPEDXVXa0sOl5og5Impq8NYwy8sl9J86BGnNXg6s=; b=1cCZAQoRRx5NF2kvJSPKgnH/J18umo8qqCqECuqhTE63VxfxrWE7MTGciczpUjG8R7xEIF rzMhL1zInW7VMwY14BXqBYIySvHkLoW3Y4XXCGH45VOxuMa4/0G8XQuPQXYW01+sV/QgPp FGaacetOTTI0GtUnMDxdW+O/Kid0+VA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1777367286; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+PLcPEDXVXa0sOl5og5Impq8NYwy8sl9J86BGnNXg6s=; b=xXWEmrhnZVZwZjmZPwV/Ub7Va0Iku6foqi7SkqJ7tB51KSM+Vx7pxwkyfVC00DWy/Oc20G tL+/TQ3R5TA16dCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DB8C1593B0; Tue, 28 Apr 2026 09:08:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 7okNM/V48GlKXgAAD6G6ig (envelope-from ); Tue, 28 Apr 2026 09:08:05 +0000 Date: Tue, 28 Apr 2026 11:08:04 +0200 From: Oscar Salvador To: Zhao Li Cc: Andrew Morton , Muchun Song , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/hugetlb: fix subpool accounting after cgroup charge failure Message-ID: References: <20260427145247.84157-2-enderaoelyther@gmail.com> <20260428030712.66256-2-enderaoelyther@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260428030712.66256-2-enderaoelyther@gmail.com> X-Spam-Score: -4.30 X-Spam-Level: X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MISSING_XM_UA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; FREEMAIL_TO(0.00)[gmail.com]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_TLS_ALL(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo] X-Spam-Flag: NO On Tue, Apr 28, 2026 at 11:07:13AM +0800, Zhao Li wrote: > alloc_hugetlb_folio() calls hugepage_subpool_get_pages() when map_chg > is set. For subpools with max_hpages, that increments used_hpages. > If the later hugetlb cgroup charge fails, the unwind must undo that > charge even when gbl_chg > 0. I found that last sentence misleading, because we do not really care about hugetlb cgroup charge/uncharge (besides that being of the reasons we end up on error path) but rather the fact that we fiddle with subpool->used_hpages and we need to undo that when we rollback. > hugepage_subpool_put_pages() can also restore rsv_hpages if concurrent > frees move used_hpages below min_hpages between the get and put. When > that happens on the gbl_chg > 0 path, restore the matching global > reservation as well. Well, that does not quite explain the problem I think, at least not clear enough? So the problem at hand (IIUC) is that 1) if we took a global reservation 2) and concurrent hugepage_subpool_put_pages operations made used_hpages be below min_hpages, and so subpool's reservation was incremented, but we need to increment the global one as well otherwise the next time we pull a page from the spool, global resv_huge_pages will be inbalanced > Skip the gbl_chg > 0 put when max_hpages is unset. For a min_size-only > subpool, get_pages() did not change subpool state and put_pages() would > create a false reservation. > > Signed-off-by: Zhao Li > --- > Changes in v2: > - Handle rsv_hpages restoration when racing frees cross min_hpages. > - Skip gbl_chg > 0 put_pages() when max_hpages is unset. > > mm/hugetlb.c | 21 ++++++++++++++++----- > 1 file changed, 16 insertions(+), 5 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index f24bf49be047e..4065d66fdcb5c 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -3026,12 +3026,23 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, > h_cg); > out_subpool_put: > /* > - * put page to subpool iff the quota of subpool's rsv_hpages is used > - * during hugepage_subpool_get_pages. > + * map_chg means hugepage_subpool_get_pages() succeeded above. > + * If max_hpages accounting was touched, undo it. If racing frees > + * moved the subpool below min_hpages, the put path may restore a > + * subpool reservation. Restore the matching global reservation too. I would split the comment in two parts and place them within the block they belong, otherwise it sounds confusing. And maybe elaborate a little bit more. Subpools, reservations and hugetlb make a very head-spinning situation, so let us make our life easier. -- Oscar Salvador SUSE Labs