From patchwork Wed May 4 01:07:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 12836619 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 57E3EC4332F for ; Wed, 4 May 2022 01:07:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDC6C6B0078; Tue, 3 May 2022 21:07:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3DF58D0003; Tue, 3 May 2022 21:07:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCB068D0002; Tue, 3 May 2022 21:07:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A529B6B0078 for ; Tue, 3 May 2022 21:07:48 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 8330F80303 for ; Wed, 4 May 2022 01:07:48 +0000 (UTC) X-FDA: 79426273416.30.105CC3F Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf29.hostedemail.com (Postfix) with ESMTP id 2036D120094 for ; Wed, 4 May 2022 01:07:42 +0000 (UTC) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243N1sI8003197; Wed, 4 May 2022 01:07:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=Bk/NQTe80ctz+CIzie1mLHIq7xE/egasLlc8YSDwCjo=; b=tJ+5vs828owYwljeDpRyd1i+oJH6hrdJXTp9mMUcVPLbuNMnI4hVyH2eMuqZSNQV5W6O FsrIMvgrtRDvII4SKPa3OWJxzHaazhqRO6CchnryvuTLmx2vtbipFCGmJqmMOTJrSCcw t0qVEksJydUGpXYkB6oG5Dvh1srFlqka4trh7GdrNC/EQF7XbThEYrU5rzEMIuAvDN+G 4uy+vOkTKAqpby5fe+90Ty5poMQd0A40+lVRbNdpUqY/ha4Wm2UdfXJ4ggtdGL83BDA+ kexDOCqYhQ3VPs09B8eWxAiFjH7LiR+h7ffiALJ5V4LZomYvNzwEydDOvPkzLagoS82Q 3Q== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frw0apxss-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 May 2022 01:07:46 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24415XlS004554; Wed, 4 May 2022 01:07:45 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2175.outbound.protection.outlook.com [104.47.55.175]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fsvbmuyt7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 May 2022 01:07:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffHyCckwa1aIjRpobZ8CBI5HcJTwTYqaHoezhWAFJKsONVsHfIYeKpqfSUzhK5Rm125fMuwhkUsn2juQVkgfKl6FDjeiD2tRzlYBBbYzjzVN0RC5M8wc3cP75ckuit0UrOSU/OwKlNINbBBj53B6/ehrjjguAvo2fada7rmCMa9VmgwviY4WYif6gx9fnVyNz2WJNIG6CDD7+lEg7YNeK76Wounb/Su/yJSHgMaGc4gNib/nz6lWBWoJwRIeTsWrpwaJ+qwGIO49HPHn6J9wOSKxX9qNveJF0al6PwTtmNkpC05alKKnomRzp4pjlLVC6fwdC9rTg/lt0WvnNTJINg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Bk/NQTe80ctz+CIzie1mLHIq7xE/egasLlc8YSDwCjo=; b=l6f38PKOOHG2hLdw+Z1yg+4iE72PMVbq5U9ZlXdOHXWnuO0ZdC58AOMvtQ67gUCkTr4gLUphuhBaRCQRfbJ1KHAhHLNGVcx+0LRO1SMSxsKA5PGGWs1VSTU5G0qbs5TK8rSl1ojdBpCDcEi+/AbXSVOK0bNJGJvTUCf+6Gee19Oy2AwsT/r2KVAF5Ju27khCc5k9J2Que31F5kyE8oLFjfWCOJH+z0tomXLsy7Kt0WhFCrWAN7EUk1/Ii/nwQqNrO1TJdslyQAlEcf1rvoHyiuipEUCLiYWHOMWphCtpyBCOLW9If2vaD0+UJDvArJANbrQcno1EpamvHGeFQ4LjBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bk/NQTe80ctz+CIzie1mLHIq7xE/egasLlc8YSDwCjo=; b=eOENRtCSodc6L02EWT6zyK2FBThhnMwx7gno2mHi/ZUcERJsBW3oCQc2R6pAqvdkkUTWnJJlqz6IiCwrvko0SgrLSRWgByxPJ2hJBthFRTfkZkDGVQ8M2sPTocfCImGhlA1ffq9uOWbkNa/tvagiqsFSXuHDwrB6lPMqtNXs0t0= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by CH2PR10MB4214.namprd10.prod.outlook.com (2603:10b6:610:a6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Wed, 4 May 2022 01:07:43 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::318c:d02:2280:c2c]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::318c:d02:2280:c2c%7]) with mapi id 15.20.5206.024; Wed, 4 May 2022 01:07:43 +0000 From: Liam Howlett To: "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton Subject: [PATCH v9 05/69] radix tree test suite: add support for slab bulk APIs Thread-Topic: [PATCH v9 05/69] radix tree test suite: add support for slab bulk APIs Thread-Index: AQHYX1NbZ3ZsHECzQ0O9jTdMwNDFsA== Date: Wed, 4 May 2022 01:07:43 +0000 Message-ID: <20220504010716.661115-7-Liam.Howlett@oracle.com> References: <20220504010716.661115-1-Liam.Howlett@oracle.com> In-Reply-To: <20220504010716.661115-1-Liam.Howlett@oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.35.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8d4e6e79-2253-40f5-8843-08da2d6a7e18 x-ms-traffictypediagnostic: CH2PR10MB4214:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: vaqiyQMzlds7zIZoO+4fqqM+gw/6oTwcT4sGB0SRRt2BFqBX0AAeBGhnFZdvTFMNJ0EiZbYYG1du0QHF7BuyVmkONWLpJIyixNJY66ztFUF4IFhz768LGYd5Wx38mQof21AjyFyauTHiJqdKS18EHg7H4j9eeZr+2+ZmFOT2C7FYY3OnG8KrW25vilmDqNnHSo+JNVMoPOvvEd8AY1cazDWVku10HUHmlyIJWCTTD4+G2ubEexpLPnG+2vyeoNwIFFidZSsZ1S+IM4ihFetOEiWs9SA4IZMuKxtL6Klf4marbuzu8kTj6CkQzUoJbX4FoRm0yDkVWzlcPHdXsq5znShTj6vbYqrMTYv+rFkzzqABHhc9pbp4ZL7dWZlTZcuve1mZ5sWqKsqJqXqrLNAKaFWX5pdz1wJXgAN/aCQARi7tslCM1XLzXT5rNECE3oI17IdGXxG6s0W25/PxzdlhmR8jkqEqRBiL9DNgtOQhaJ42DPe8ncK+Bg6B8X8aNQv9S26WZn2qL8Ba3zhsWuU5ks+tNtfzAcAlXNLqLXo9rM30oWxn9zv2KJLkZWuSR1scS92BH79KI20fAVTncKEnYPgKDDxCDLkG49820RzQ9Q6NXyvu5d7QRLBnqHFfg3264iTUN6rYJySRkX/kTIY2VpWuwh+MXBAFfUbikcruqlfJRa5BG8cdpkF3a7ueBdc0Bv4c2/x/x/b0y1l5EXh4MQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(66446008)(64756008)(66946007)(66556008)(66476007)(8676002)(76116006)(83380400001)(2616005)(110136005)(186003)(1076003)(316002)(6512007)(86362001)(26005)(2906002)(6506007)(71200400001)(36756003)(5660300002)(44832011)(38100700002)(508600001)(8936002)(38070700005)(122000001)(6486002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?rAW39i7f51EyOg1ksWwj8Rd?= =?iso-8859-1?q?IvnAV7c1LvjPxr60GffI81WR3rmZ9ntkQtuCswSz1Ajywii0p0u6dY0KsaTY?= =?iso-8859-1?q?0y1R/HZcK9X12m4ng7KhX3Lofy5NMCMv18L9Khfef7PpWPxX/v9M3fkTp4rg?= =?iso-8859-1?q?g3Gc2p71h/5DTi3UJM5/Qj9T1F8/MRFt6rQidUsORcLHKcI3qg7mp1pN+HfH?= =?iso-8859-1?q?1i2xCp2gQAmI49b9Z9uKSAZpegL1QBA3QASoZownOPuLzXVGhxBK/AAS+czh?= =?iso-8859-1?q?E/GAFVcQcM7+Sf8Sm/4UydptzR3NAN+/D/S231W7E0ECH7GztFRnrRk4MhwU?= =?iso-8859-1?q?bxqzhnHmjszKt8TOrnk0w4IGWwROOiVVM8SKEsR+zrH09H6Lc0sEkSuBX0/I?= =?iso-8859-1?q?JVVn6C50Pgx4MN9RIKktv0JrkR16LDdbm68ElOgVBcNDccGCuPJ/3gJHojql?= =?iso-8859-1?q?2MlG9VdJUFfHOOs8Q9bWl1OQTRp97ReC0yqeAudQjSXHQFNXl7rYwA7/q1H6?= =?iso-8859-1?q?XbN7xpkYK0q70j6FFnzA+S2VHOJLyw38P5uf//FPO6/WU0DnP6BHz4MXKdNi?= =?iso-8859-1?q?rxuQoheWvlLj5lFXeT5OK/8HdK6GrIU7eRsK8Tb/RO2nIxlb6yv5nrMjvUq8?= =?iso-8859-1?q?i7iTUq85WTwOHPsm8BmLH8/gnMKCxzrxfwf6vYtYW1fNYGPghWg4UJykcdPP?= =?iso-8859-1?q?HEjsERr6mIr+gsxgu/aY6V0dtSoFdrrU/rzb3+dzmmKlVqNHkX3tlXZbw2QU?= =?iso-8859-1?q?ua7aALUqobBtNB3oLLgh5GKqH35EBfYWcbgInBBfwoZwiExBx/PRY1jKVyGg?= =?iso-8859-1?q?ZqgFx8NEmppT4PwG0+KTl4Risv7f6AvqfXvyZxgQopvWO9fDJNB2eegl2IOV?= =?iso-8859-1?q?Sy/IRT1n0NLbNdt43IrEYgSfR+uEah51ODH+XfdVhJYXyLPIa2VC3LNdm/Qf?= =?iso-8859-1?q?7IHPmmR/mymAKX1pgwC8x2B2OFtIsI6BxTP0n9wQShcVxDymlg1dNfQCxiIn?= =?iso-8859-1?q?upSoPZjBxJLmCDsFXxPZSSKc34z+tBRy447NCV24rh0ysTsXsM+D21VxWWMh?= =?iso-8859-1?q?N1yQXdKUfzeW1AhQBA81VrIek0K/qGV41dBdWGHO+sgUpuipWSyzEX2H/s/h?= =?iso-8859-1?q?Mr3PI1zQ1m/Jch1BVeNhfNrfdJpADYvOKqnT8fH94WxaofZctzztxAxGJlHf?= =?iso-8859-1?q?DR1FqFV5DbgdhWNbDnFPPTKsP+PKEIMM5CojGCmckig6y/P448aSWrelqNoG?= =?iso-8859-1?q?pe9akRpq2VzKL5srUqQCF81zEr0XDJEF6Y+FiyBvkZ8cY5dRcp9mf7OI7rGr?= =?iso-8859-1?q?rTrI41R7892Y3r5ZOZrHxHLiIiUnbjTEPV4HJKK73OBIJvOycUrtWOmp3dmN?= =?iso-8859-1?q?hmMnuGe/AQbzjXKVHHx6nji1Acfz8xJHgkCfYRgqPjBsM77iZRQtIPqbWZdr?= =?iso-8859-1?q?lUnvtGyx7AFBWQgk00csm7zIU2Lr8VyHLC93n6Qn09QpSEKK+VliIJwf8BXl?= =?iso-8859-1?q?7T+PVihLd3eW04jwXM0pnp2p+/SIFLA4Kw47eCezpObwrHa55HvhWGvKh7sP?= =?iso-8859-1?q?agvcmMOhEKx5a0nr2tCSh7q48ifaYIHuc25wyzVja1MIsytStchRDfEkIMpr?= =?iso-8859-1?q?fAeVNXWdmGO66FDOz3HVKdo4h3m1EK+O6hjgc9LZecmN6pJ0ZD7OengW+bv7?= =?iso-8859-1?q?zqlTn1ksd8dPe22cSUqL4uyHGdGVHwVv9XTycPpWq+DukSaYKHYHYcKGi/EH?= =?iso-8859-1?q?U+3plVCVSdcyIZIx3SBQdcq3dbIgldUHRRH0CLN42fgjEUQOJwSppi88s5Qh?= =?iso-8859-1?q?qrQlJuwQ=3D?= MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d4e6e79-2253-40f5-8843-08da2d6a7e18 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 May 2022 01:07:43.0260 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ZYB+UnrHVrahbPYT1AHxE8YaXBLMo48k7UiPbUq1GGXw+OccDvBkqaBdxYsg3kSAxWJBwJ0z1doNqkvbxd8F/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4214 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486,18.0.858 definitions=2022-05-03_10:2022-05-02,2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205040005 X-Proofpoint-GUID: su5urL-hJTK4uHGPwA5-Qj8YkehqpW5R X-Proofpoint-ORIG-GUID: su5urL-hJTK4uHGPwA5-Qj8YkehqpW5R X-Rspamd-Queue-Id: 2036D120094 X-Stat-Signature: e8teh6aszcyxeerajqyxwpt87ktj3xja X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=tJ+5vs82; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=eOENRtCS; spf=none (imf29.hostedemail.com: domain of liam.howlett@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=liam.howlett@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspamd-Server: rspam09 X-HE-Tag: 1651626462-405175 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: From: "Liam R. Howlett" Add support for kmem_cache_free_bulk() and kmem_cache_alloc_bulk() to the radix tree test suite. Signed-off-by: Liam R. Howlett --- tools/include/linux/slab.h | 4 ++ tools/testing/radix-tree/linux.c | 118 ++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 2 deletions(-) diff --git a/tools/include/linux/slab.h b/tools/include/linux/slab.h index 0616409513eb..311759ea25e9 100644 --- a/tools/include/linux/slab.h +++ b/tools/include/linux/slab.h @@ -41,4 +41,8 @@ struct kmem_cache *kmem_cache_create(const char *name, unsigned int size, unsigned int align, unsigned int flags, void (*ctor)(void *)); +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); + #endif /* _TOOLS_SLAB_H */ diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c index f20529ae4dbe..2048d12c31df 100644 --- a/tools/testing/radix-tree/linux.c +++ b/tools/testing/radix-tree/linux.c @@ -93,14 +93,13 @@ void *kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru, return p; } -void kmem_cache_free(struct kmem_cache *cachep, void *objp) +void kmem_cache_free_locked(struct kmem_cache *cachep, void *objp) { assert(objp); uatomic_dec(&nr_allocated); uatomic_dec(&cachep->nr_allocated); if (kmalloc_verbose) printf("Freeing %p to slab\n", objp); - pthread_mutex_lock(&cachep->lock); if (cachep->nr_objs > 10 || cachep->align) { memset(objp, POISON_FREE, cachep->size); free(objp); @@ -110,9 +109,80 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp) node->parent = cachep->objs; cachep->objs = node; } +} + +void kmem_cache_free(struct kmem_cache *cachep, void *objp) +{ + pthread_mutex_lock(&cachep->lock); + kmem_cache_free_locked(cachep, objp); pthread_mutex_unlock(&cachep->lock); } +void kmem_cache_free_bulk(struct kmem_cache *cachep, size_t size, void **list) +{ + if (kmalloc_verbose) + pr_debug("Bulk free %p[0-%lu]\n", list, size - 1); + + pthread_mutex_lock(&cachep->lock); + for (int i = 0; i < size; i++) + kmem_cache_free_locked(cachep, list[i]); + pthread_mutex_unlock(&cachep->lock); +} + +int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size, + void **p) +{ + size_t i; + + if (kmalloc_verbose) + pr_debug("Bulk alloc %lu\n", size); + + if (!(gfp & __GFP_DIRECT_RECLAIM)) { + if (cachep->non_kernel < size) + return 0; + + cachep->non_kernel -= size; + } + + pthread_mutex_lock(&cachep->lock); + if (cachep->nr_objs >= size) { + struct radix_tree_node *node; + + for (i = 0; i < size; i++) { + node = cachep->objs; + cachep->nr_objs--; + cachep->objs = node->parent; + p[i] = node; + node->parent = NULL; + } + pthread_mutex_unlock(&cachep->lock); + } else { + pthread_mutex_unlock(&cachep->lock); + for (i = 0; i < size; i++) { + if (cachep->align) { + posix_memalign(&p[i], cachep->align, + cachep->size * size); + } else { + p[i] = malloc(cachep->size * size); + } + if (cachep->ctor) + cachep->ctor(p[i]); + else if (gfp & __GFP_ZERO) + memset(p[i], 0, cachep->size); + } + } + + for (i = 0; i < size; i++) { + uatomic_inc(&nr_allocated); + uatomic_inc(&cachep->nr_allocated); + uatomic_inc(&cachep->nr_tallocated); + if (kmalloc_verbose) + printf("Allocating %p from slab\n", p[i]); + } + + return size; +} + struct kmem_cache * kmem_cache_create(const char *name, unsigned int size, unsigned int align, unsigned int flags, void (*ctor)(void *)) @@ -130,3 +200,47 @@ kmem_cache_create(const char *name, unsigned int size, unsigned int align, ret->non_kernel = 0; return ret; } + +/* + * Test the test infrastructure for kem_cache_alloc/free and bulk counterparts. + */ +void test_kmem_cache_bulk(void) +{ + int i; + void *list[12]; + static struct kmem_cache *test_cache, *test_cache2; + + /* + * Testing the bulk allocators without aligned kmem_cache to force the + * bulk alloc/free to reuse + */ + test_cache = kmem_cache_create("test_cache", 256, 0, SLAB_PANIC, NULL); + + for (i = 0; i < 5; i++) + list[i] = kmem_cache_alloc(test_cache, __GFP_DIRECT_RECLAIM); + + for (i = 0; i < 5; i++) + kmem_cache_free(test_cache, list[i]); + assert(test_cache->nr_objs == 5); + + kmem_cache_alloc_bulk(test_cache, __GFP_DIRECT_RECLAIM, 5, list); + kmem_cache_free_bulk(test_cache, 5, list); + + for (i = 0; i < 12 ; i++) + list[i] = kmem_cache_alloc(test_cache, __GFP_DIRECT_RECLAIM); + + for (i = 0; i < 12; i++) + kmem_cache_free(test_cache, list[i]); + + /* The last free will not be kept around */ + assert(test_cache->nr_objs == 11); + + /* Aligned caches will immediately free */ + test_cache2 = kmem_cache_create("test_cache2", 128, 128, SLAB_PANIC, NULL); + + kmem_cache_alloc_bulk(test_cache2, __GFP_DIRECT_RECLAIM, 10, list); + kmem_cache_free_bulk(test_cache2, 10, list); + assert(!test_cache2->nr_objs); + + +}