From patchwork Fri Feb 14 16:27:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13975230 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 3230FC021A4 for ; Fri, 14 Feb 2025 16:28:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B59A3280005; Fri, 14 Feb 2025 11:28:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE3F8280004; Fri, 14 Feb 2025 11:28:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 918C0280005; Fri, 14 Feb 2025 11:28:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6D40F280004 for ; Fri, 14 Feb 2025 11:28:17 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1FCADA066D for ; Fri, 14 Feb 2025 16:28:17 +0000 (UTC) X-FDA: 83119082634.09.B8B85C5 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf07.hostedemail.com (Postfix) with ESMTP id DACD340013 for ; Fri, 14 Feb 2025 16:28:14 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=RpkB5Uve; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=D6XOFrAu; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=RpkB5Uve; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=D6XOFrAu; spf=pass (imf07.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739550495; 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=PjFVlcsr+qf6NE7vGqH0rVwP/2BNHmoTxp+iBx2dj3o=; b=FPnRLlJjBaqPKuonekjBBYEE7y/sDbbdYIdrlXlhJo2OO8xCJ6k6k8OvZKX8R/n2C6F+AL WLwp7yeEh7tBHRD8bWGyOM+9FHDN3UY4MMuvh1N/t02guXxSqIp8JA8nY1vvdyvf9vLKNx L0DWclzkslNrBtw/EVv7S219Doj5c/g= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=RpkB5Uve; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=D6XOFrAu; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=RpkB5Uve; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=D6XOFrAu; spf=pass (imf07.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739550495; a=rsa-sha256; cv=none; b=4t98X3bLWg48BmvbxibeewYtTz98lT49lGjEcFqHd+l2mP490ldw7nI3YUgz3LmVvBdpBU oqAlEt3jKbJkIuse+49jTwbXhXOTqwP4L060l9M5zAdZmva4s8euYWUCG9+8LDgTo7+1or DAP/drVxJQIV9KzEC0JLAR4+tJSH/kM= 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 224D821182; Fri, 14 Feb 2025 16:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1739550463; 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=PjFVlcsr+qf6NE7vGqH0rVwP/2BNHmoTxp+iBx2dj3o=; b=RpkB5UvecXy4Ua+2FL04BYhw8d9UY3RMcc6XMyHNgP9SRds35S0Hnf2XzB/k8+96swccWP WRBv0chQmw2cYz7EtmaVqslic/UDrdMXrLMRtXpfQg1g/QAr4UqpGSAdd7hnUbtz8ljiRD FXIUEYbx1B4Vx+3NmIRR8oVPdq51ivU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1739550463; 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=PjFVlcsr+qf6NE7vGqH0rVwP/2BNHmoTxp+iBx2dj3o=; b=D6XOFrAuPAhH4kRBbF+xAHLxarL2LQ4Y/N9zhKF+KqFbNnAM+Zt6qY2S0fc1rb8buisBCd dvO2JhlgCaSm/hDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1739550463; 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=PjFVlcsr+qf6NE7vGqH0rVwP/2BNHmoTxp+iBx2dj3o=; b=RpkB5UvecXy4Ua+2FL04BYhw8d9UY3RMcc6XMyHNgP9SRds35S0Hnf2XzB/k8+96swccWP WRBv0chQmw2cYz7EtmaVqslic/UDrdMXrLMRtXpfQg1g/QAr4UqpGSAdd7hnUbtz8ljiRD FXIUEYbx1B4Vx+3NmIRR8oVPdq51ivU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1739550463; 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=PjFVlcsr+qf6NE7vGqH0rVwP/2BNHmoTxp+iBx2dj3o=; b=D6XOFrAuPAhH4kRBbF+xAHLxarL2LQ4Y/N9zhKF+KqFbNnAM+Zt6qY2S0fc1rb8buisBCd dvO2JhlgCaSm/hDA== 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 0E61713285; Fri, 14 Feb 2025 16:27:43 +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 IM1BA/9ur2eHSAAAD6G6ig (envelope-from ); Fri, 14 Feb 2025 16:27:43 +0000 From: Vlastimil Babka Date: Fri, 14 Feb 2025 17:27:45 +0100 Subject: [PATCH RFC v2 09/10] tools: Add sheafs support to testing infrastructure MIME-Version: 1.0 Message-Id: <20250214-slub-percpu-caches-v2-9-88592ee0966a@suse.cz> References: <20250214-slub-percpu-caches-v2-0-88592ee0966a@suse.cz> In-Reply-To: <20250214-slub-percpu-caches-v2-0-88592ee0966a@suse.cz> To: Suren Baghdasaryan , "Liam R. Howlett" , Christoph Lameter , David Rientjes Cc: Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Uladzislau Rezki , linux-mm@kvack.org, linux-kernel@vger.kernel.org, rcu@vger.kernel.org, maple-tree@lists.infradead.org, "Liam R. Howlett" X-Mailer: b4 0.14.2 X-Rspam-User: X-Stat-Signature: ehjr6pm4as5t6mdsh6pwaycsh9bb5eoc X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: DACD340013 X-HE-Tag: 1739550494-611886 X-HE-Meta: U2FsdGVkX18eeGrtDKn77zI23QuPr9wz5PmZ8/nWrs7wMt65HKaCZIg0CnwoodekIVOX1pD+rSOXDQeCDlCr9LiEKNFsHX0uXx8Vox7H1WoIhw4sd6dAI7lPhkHWXq3Cch0TocekR/C4AVnLY8QZc6qu2K5XPISrG7b4dKIOmxzSVBEP6GgZXJCRE4nXJXol2trVwv+z1Baye/BAgpQxrdoU928G03CDl4rjxNSC+BtFCHpq0xcYBViAzwSJ5uxGZep5+3nK9x1b9+hhw+Vbk2nAhW8MQ9VouumKhDVlRrZgJBiB01Ocu037ouP7cZCSSxNHtdBoBUaU/x54DYsJVB20H69zSyAxNlyntp+yX/0NXS8ZhGXEU09mcQoalDgzQVoQCFZIHbpvrPgBSmSsYiSmKkkxm5ECJtVk1EjuwZZS4Eb2wDrQysMtTKb/NqdX0RJRRtxuMZECCJn4RgmEDH3A/qZdNz2v27K/myFTcUPCrQp6WzDAngQjTzTM3/udq+Cah2pNL1NS88J26KydWCKb77TOxn5KgnS7lIxRLYVuHqczHLXq5oPlo7EU/U+1nV8u9ZeD7j0jwS1TLI9IbpqSSYmw5bSclRUrNOfJ2FrfX2stmCZ807RF+w5CNgpDx8Cb1amUARKPUNO+xbHNFslh0OIN8/qovGpGklHYStk011116Nc5qHjKPqRZ0Er4t0EgII372tO4bXsYmL1HhrycXD2mgjQQY6bp1hDzJvLWWW/LVBHBnQlGP9HPk58CApkkkwjqPA9QzP+gWFfCDLUZuoI5m7CC3HfH8AurdYWo0ZYB2ofAFAgKtDDkpbTwJxzDGHgwqbScuej02aFdaVMpFQWl1sVRl445Rp8WOGl9j74RopevLQ0A0fTwj0pericBHK2ylICCuDAJtioL/TdEiraEUdCdE5kgbi8Xu/jGMyI3/PO7LCdzu3ZPYjAZEgiHdFQDAw65/fgOtgD HeUPI5H1 KR0rlw568R2aAJKCbAfGwKX1tqUE1RDeSmGkZrQ2HaJkVb5vv+F57Rvu5Pq42qvl0bxJOClOq2BE5fNhI8e3Il1gdL7+xgxijz6YVmW2bw9r2dDWlCb/fEjjMzzFVGSwHgH7nI9ABq6iPdF3sBGhpX47pEYiF7rab0juchzBm/X3p76LznnUcrdBYLomKWxgzzVh4gCBFyIgfv8ixZ5QO01wa+VDQqqIdTql+Xr1hR7qk1l0MHM0tva/Ev5UYQImQfOMx0RCMMrXa4UcxlTAjqRFHBVeFOCqdaqrLmyzDB5ynLFJlR1BcXFcpMVbW9RZ0sN+1l1DGVQIsTtZJoOP4blo0XA== 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: 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 a475364cfd9fcdb10db252aab18ea3a620326b6b..0b6b42c9921fc402b4f3d4f681a95c9067d128db 100644 --- a/tools/include/linux/slab.h +++ b/tools/include/linux/slab.h @@ -22,6 +22,13 @@ enum slab_state { FULL }; +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; @@ -79,4 +86,21 @@ void kmem_cache_free_bulk(struct kmem_cache *cachep, size_t size, void **list); int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size, void **list); +struct slab_sheaf * +kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size); + +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 9f5fd722f27f1d3877be8927be30409cd74ab3c3..a61c755c3c87e80036a5173115e955bfe7d5a80c 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, gfp_t gfp, size_t size, if (kmalloc_verbose) pr_debug("Bulk alloc %lu\n", size); + if (cachep->exec_callback) { + if (cachep->callback) + cachep->callback(cachep->private); + cachep->exec_callback = false; + } + pthread_mutex_lock(&cachep->lock); if (cachep->nr_objs >= size) { struct radix_tree_node *node; @@ -270,6 +276,84 @@ __kmem_cache_create_args(const char *name, unsigned int size, return ret; } +struct slab_sheaf * +kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size) +{ + struct slab_sheaf *sheaf; + unsigned int capacity; + + if (size > s->sheaf_capacity) + capacity = size; + else + capacity = s->sheaf_capacity; + + sheaf = malloc(sizeof(*sheaf) + sizeof(void *) * s->sheaf_capacity * capacity); + if (!sheaf) { + return NULL; + } + + memset(sheaf, 0, size); + sheaf->cache = s; + sheaf->capacity = capacity; + sheaf->size = 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 = *sheafp; + int refill; + + if (sheaf->size >= size) + return 0; + + if (size > sheaf->capacity) { + sheaf = kmem_cache_prefill_sheaf(s, gfp, size); + if (!sheaf) + return -ENOMEM; + + kmem_cache_return_sheaf(s, gfp, *sheafp); + *sheafp = sheaf; + return 0; + } + + refill = kmem_cache_alloc_bulk(s, gfp, size - sheaf->size, + &sheaf->objects[sheaf->size]); + if (!refill) + return -ENOMEM; + + sheaf->size += 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 += 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 == 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 counterparts. */