From nobody Mon Feb 9 20:59:11 2026 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 E8658238C03 for ; Fri, 25 Apr 2025 08:28:26 +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=1745569708; cv=none; b=GtsPhgA2iwmcbZPEjljbF3H4C4Q86OOoweqENcsoSptYBMpj56Q/wHJbwMdWdlmrPU+Zea5WCVSCe8jJO0MRg+VkdR0dyTigTIAt1D15zdUEvNO7bmsuR9oAJFj9ohUJPecvycHQ0AlrWHT3Pu0A+E6Q+SKUXNuth67MDohKyPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745569708; c=relaxed/simple; bh=CFT5sLZplZPnoFKRoiZCQN61gOSCwNH0HyHcv6utaK4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SqrNnGxNReoRx7Qmj067qBZ9tt1JE/HdCHo905DqPeaBfFguA1B+MGO1y7TSyvFcPUxesPbEyEN7Buhn67UZRuYL3yhGEOVLKpqL4/KvCIAVHwkZs0sUzz7NHVuWa1gmg+nlrSl7oImqcs4A6hJwttwvvO4VTSUzDnB8UoXRrxM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=J9in7zht; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=3P9t9Ylj; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=J9in7zht; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=3P9t9Ylj; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="J9in7zht"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="3P9t9Ylj"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="J9in7zht"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="3P9t9Ylj" 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 31C772116A; Fri, 25 Apr 2025 08:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1745569673; h=from:from:reply-to: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; bh=bXIAVW5P7xnw20jvyagFOsbrexlNJWpF8IUNGguSNtM=; b=J9in7zhtj8kdPXCsxYEPyUmiQUQ1u/xxsf9P8gZZo/PnRMNWSgDna9jVxDOX3194v9q+WL 2g3Xg399NZ+zsbpOcyiaYVKJvohSf93y2EAurergduUVSkDXKdn5Eg1WsSnuQhhYGqc3dD GRQJXiRs3TgQmvLys/vR7fw2TuNPtgc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1745569673; h=from:from:reply-to: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; bh=bXIAVW5P7xnw20jvyagFOsbrexlNJWpF8IUNGguSNtM=; b=3P9t9Ylj/2PckfT0Pw1u6kTw21hmRLZi7KAFc68ct++rlqWruIyUUqefIOfaEIw5eXZYYm j6hoNAI9p9w1F4Bw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1745569673; h=from:from:reply-to: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; bh=bXIAVW5P7xnw20jvyagFOsbrexlNJWpF8IUNGguSNtM=; b=J9in7zhtj8kdPXCsxYEPyUmiQUQ1u/xxsf9P8gZZo/PnRMNWSgDna9jVxDOX3194v9q+WL 2g3Xg399NZ+zsbpOcyiaYVKJvohSf93y2EAurergduUVSkDXKdn5Eg1WsSnuQhhYGqc3dD GRQJXiRs3TgQmvLys/vR7fw2TuNPtgc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1745569673; h=from:from:reply-to: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; bh=bXIAVW5P7xnw20jvyagFOsbrexlNJWpF8IUNGguSNtM=; b=3P9t9Ylj/2PckfT0Pw1u6kTw21hmRLZi7KAFc68ct++rlqWruIyUUqefIOfaEIw5eXZYYm j6hoNAI9p9w1F4Bw== 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 191FF13A80; Fri, 25 Apr 2025 08:27:53 +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 0B/YBYlHC2htfwAAD6G6ig (envelope-from ); Fri, 25 Apr 2025 08:27:53 +0000 From: Vlastimil Babka Date: Fri, 25 Apr 2025 10:27:26 +0200 Subject: [PATCH v4 6/9] tools: Add sheaves support to testing infrastructure 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250425-slub-percpu-caches-v4-6-8a636982b4a4@suse.cz> References: <20250425-slub-percpu-caches-v4-0-8a636982b4a4@suse.cz> In-Reply-To: <20250425-slub-percpu-caches-v4-0-8a636982b4a4@suse.cz> To: Suren Baghdasaryan , "Liam R. Howlett" , Christoph Lameter , David Rientjes Cc: Roman Gushchin , Harry Yoo , Uladzislau Rezki , linux-mm@kvack.org, linux-kernel@vger.kernel.org, rcu@vger.kernel.org, maple-tree@lists.infradead.org, vbabka@suse.cz, "Liam R. Howlett" X-Mailer: b4 0.14.2 X-Spam-Score: -8.30 X-Spamd-Result: default: False [-8.30 / 50.00]; REPLY(-4.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]; RCVD_TLS_ALL(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_TWELVE(0.00)[13]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[linux.dev,oracle.com,gmail.com,kvack.org,vger.kernel.org,lists.infradead.org,suse.cz,Oracle.com]; R_RATELIMIT(0.00)[to_ip_from(RLsunix6otu811wnbhxcn9byqb)]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[oracle.com:email,imap1.dmz-prg2.suse.org:helo,suse.cz:mid] X-Spam-Flag: NO X-Spam-Level: From: "Liam R. Howlett" Allocate a sheaf and fill it to the count amount. Does not fill to the sheaf limit to detect incorrect allocation requests. Signed-off-by: Liam R. Howlett --- tools/include/linux/slab.h | 24 +++++++++++++ tools/testing/shared/linux.c | 84 ++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 108 insertions(+) diff --git a/tools/include/linux/slab.h b/tools/include/linux/slab.h index d1444e79f2685edb828adbce8b3fbb500c0f8844..1962d7f1abee154e1cda5dba28a= ef213088dd198 100644 --- a/tools/include/linux/slab.h +++ b/tools/include/linux/slab.h @@ -23,6 +23,13 @@ enum slab_state { FULL }; =20 +struct slab_sheaf { + struct kmem_cache *cache; + unsigned int size; + unsigned int capacity; + void *objects[]; +}; + struct kmem_cache_args { unsigned int align; unsigned int sheaf_capacity; @@ -80,4 +87,21 @@ void kmem_cache_free_bulk(struct kmem_cache *cachep, siz= e_t size, void **list); int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t siz= e, void **list); =20 +struct slab_sheaf * +kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int siz= e); + +void * +kmem_cache_alloc_from_sheaf(struct kmem_cache *s, gfp_t gfp, + struct slab_sheaf *sheaf); + +void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, + struct slab_sheaf *sheaf); +int kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp, + struct slab_sheaf **sheafp, unsigned int size); + +static inline unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf) +{ + return sheaf->size; +} + #endif /* _TOOLS_SLAB_H */ diff --git a/tools/testing/shared/linux.c b/tools/testing/shared/linux.c index f998555a1b2af4a899a468a652b04622df459ed3..e0255f53159bd3a1325d4919228= 3dd6790a5e3b8 100644 --- a/tools/testing/shared/linux.c +++ b/tools/testing/shared/linux.c @@ -181,6 +181,12 @@ int kmem_cache_alloc_bulk(struct kmem_cache *cachep, g= fp_t gfp, size_t size, if (kmalloc_verbose) pr_debug("Bulk alloc %zu\n", size); =20 + if (cachep->exec_callback) { + if (cachep->callback) + cachep->callback(cachep->private); + cachep->exec_callback =3D false; + } + pthread_mutex_lock(&cachep->lock); if (cachep->nr_objs >=3D size) { struct radix_tree_node *node; @@ -270,6 +276,84 @@ __kmem_cache_create_args(const char *name, unsigned in= t size, return ret; } =20 +struct slab_sheaf * +kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int siz= e) +{ + struct slab_sheaf *sheaf; + unsigned int capacity; + + if (size > s->sheaf_capacity) + capacity =3D size; + else + capacity =3D s->sheaf_capacity; + + sheaf =3D malloc(sizeof(*sheaf) + sizeof(void *) * s->sheaf_capacity * ca= pacity); + if (!sheaf) { + return NULL; + } + + memset(sheaf, 0, size); + sheaf->cache =3D s; + sheaf->capacity =3D capacity; + sheaf->size =3D kmem_cache_alloc_bulk(s, gfp, size, sheaf->objects); + if (!sheaf->size) { + free(sheaf); + return NULL; + } + + return sheaf; +} + +int kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp, + struct slab_sheaf **sheafp, unsigned int size) +{ + struct slab_sheaf *sheaf =3D *sheafp; + int refill; + + if (sheaf->size >=3D size) + return 0; + + if (size > sheaf->capacity) { + sheaf =3D kmem_cache_prefill_sheaf(s, gfp, size); + if (!sheaf) + return -ENOMEM; + + kmem_cache_return_sheaf(s, gfp, *sheafp); + *sheafp =3D sheaf; + return 0; + } + + refill =3D kmem_cache_alloc_bulk(s, gfp, size - sheaf->size, + &sheaf->objects[sheaf->size]); + if (!refill) + return -ENOMEM; + + sheaf->size +=3D refill; + return 0; +} + +void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, + struct slab_sheaf *sheaf) +{ + if (sheaf->size) { + //s->non_kernel +=3D sheaf->size; + kmem_cache_free_bulk(s, sheaf->size, &sheaf->objects[0]); + } + free(sheaf); +} + +void * +kmem_cache_alloc_from_sheaf(struct kmem_cache *s, gfp_t gfp, + struct slab_sheaf *sheaf) +{ + if (sheaf->size =3D=3D 0) { + printf("Nothing left in sheaf!\n"); + return NULL; + } + + return sheaf->objects[--sheaf->size]; +} + /* * Test the test infrastructure for kem_cache_alloc/free and bulk counterp= arts. */ --=20 2.49.0