From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E028E39DBC3 for ; Thu, 12 Mar 2026 11:43:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773315834; cv=none; b=PeawzvGP3eDJSZvhzQJhXivMOYZZceknvppsJ41/IX6/fa/0Fw5nO23uBciqAgWkIZEfuqQsvHwrDtlr41DCrlX0aESAdyIOcjmhIEvyOP6sPugiSucr/djOi5Jemz4wX9AjM1s7Gf71UIWFSyC5lqXNZX+8k2gWS76+s+9mAiI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773315834; c=relaxed/simple; bh=hZX4YfNMOB4zNSAzPMIwnO6H/QV2S2EWO5Bch7A4i7E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZpXIWVuUn1CFnuebS266/aHsrJkbCmGU7LjoBs3pL0Xut2VshdketLhB7h5yT3yMTnVCy4M8ASQWPxVlmFxomCoRT4SlRYqw0BsU0CQzcZxM1Br2Aa/9KFTGqmExdDVeQG/GuURSOX3uO016apHAkrTir46I7JibGutUOMN4l9E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=WNX9KYPI; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="WNX9KYPI" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1773315830; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=H9BJa2FyYR/4Xd2mO+Zu5rjBKkRjbGyZ920JQKQ/ZcU=; b=WNX9KYPIJOBac5XcqnyjqN1C2HNJOyEakSmm+LNQ8BFNEwdYyo5O9rR4+ptnMYvLEmXK+W aLNXY8NTLOqEySImMa3EJFcDcDlopnZAvIJFJVmDOoI5btEENgDJvGOSApFeaiDpRcbjqq d06/2LhOKJsqCvfOWr7x7iYjck961uM= From: Hao Li To: vbabka@suse.cz, harry.yoo@oracle.com Cc: cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hao Li Subject: [PATCH] slub: clarify kmem_cache_refill_sheaf() failure behavior Date: Thu, 12 Mar 2026 19:42:25 +0800 Message-ID: <20260312114309.213731-1-hao.li@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT kmem_cache_refill_sheaf() can fail in two slightly different ways. During an in-place refill, some objects may already have been added before the function returns -ENOMEM. On the other hand, if allocation of a larger replacement sheaf fails, the original sheaf remains unchanged. Update the comment to spell out both cases explicitly for clarity. Signed-off-by: Hao Li --- mm/slub.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 11a99bd06ac7..8ae248b5b384 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5005,14 +5005,23 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, } /* - * refill a sheaf previously returned by kmem_cache_prefill_sheaf to at least - * the given size + * Refill a sheaf previously returned by kmem_cache_prefill_sheaf to at least + * the given size. * - * the sheaf might be replaced by a new one when requesting more than - * s->sheaf_capacity objects if such replacement is necessary, but the refill - * fails (returning -ENOMEM), the existing sheaf is left intact + * On success, the sheaf will contain at least @size objects. * - * In practice we always refill to full sheaf's capacity. + * On failure, there are two cases: + * + * 1. If the requested size fits within the current sheaf's capacity, the + * refill is done in place. In that case, a failed refill may still fill + * some additional objects into the existing sheaf before returning -ENOMEM. + * + * 2. If the requested size exceeds the current sheaf's capacity, a new + * larger sheaf may be allocated to replace the original one. In that case, + * if allocation of the replacement sheaf fails, the original sheaf is left + * unchanged. + * + * In practice we usually refill to the sheaf's full capacity. */ int kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp, struct slab_sheaf **sheafp, unsigned int size) -- 2.50.1