2008-05-26 08:38:26 +04:00
|
|
|
/*
|
|
|
|
* This file is part of the SPL: Solaris Porting Layer.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Lawrence Livermore National Security, LLC.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory
|
|
|
|
* Written by:
|
|
|
|
* Brian Behlendorf <behlendorf1@llnl.gov>,
|
|
|
|
* Herb Wartens <wartens2@llnl.gov>,
|
|
|
|
* Jim Garlick <garlick@llnl.gov>
|
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
#include "splat-internal.h"
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
#define SPLAT_SUBSYSTEM_KMEM 0x0100
|
|
|
|
#define SPLAT_KMEM_NAME "kmem"
|
|
|
|
#define SPLAT_KMEM_DESC "Kernel Malloc/Slab Tests"
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
#define SPLAT_KMEM_TEST1_ID 0x0101
|
|
|
|
#define SPLAT_KMEM_TEST1_NAME "kmem_alloc"
|
|
|
|
#define SPLAT_KMEM_TEST1_DESC "Memory allocation test (kmem_alloc)"
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
#define SPLAT_KMEM_TEST2_ID 0x0102
|
|
|
|
#define SPLAT_KMEM_TEST2_NAME "kmem_zalloc"
|
|
|
|
#define SPLAT_KMEM_TEST2_DESC "Memory allocation test (kmem_zalloc)"
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
#define SPLAT_KMEM_TEST3_ID 0x0103
|
|
|
|
#define SPLAT_KMEM_TEST3_NAME "slab_alloc"
|
|
|
|
#define SPLAT_KMEM_TEST3_DESC "Slab constructor/destructor test"
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
#define SPLAT_KMEM_TEST4_ID 0x0104
|
|
|
|
#define SPLAT_KMEM_TEST4_NAME "slab_reap"
|
|
|
|
#define SPLAT_KMEM_TEST4_DESC "Slab reaping test"
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-03-14 22:04:41 +03:00
|
|
|
#define SPLAT_KMEM_TEST5_ID 0x0105
|
|
|
|
#define SPLAT_KMEM_TEST5_NAME "vmem_alloc"
|
|
|
|
#define SPLAT_KMEM_TEST5_DESC "Memory allocation test (vmem_alloc)"
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
#define SPLAT_KMEM_ALLOC_COUNT 10
|
2008-03-14 22:04:41 +03:00
|
|
|
#define SPLAT_VMEM_ALLOC_COUNT 10
|
|
|
|
|
2008-02-26 23:36:04 +03:00
|
|
|
/* XXX - This test may fail under tight memory conditions */
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_kmem_test1(struct file *file, void *arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
void *ptr[SPLAT_KMEM_ALLOC_COUNT];
|
2008-02-26 23:36:04 +03:00
|
|
|
int size = PAGE_SIZE;
|
|
|
|
int i, count, rc = 0;
|
|
|
|
|
2008-03-14 23:56:26 +03:00
|
|
|
/* We are intentionally going to push kmem_alloc to its max
|
|
|
|
* allocation size, so suppress the console warnings for now */
|
|
|
|
kmem_set_warning(0);
|
|
|
|
|
2008-03-14 22:04:41 +03:00
|
|
|
while ((!rc) && (size <= (PAGE_SIZE * 32))) {
|
2008-02-26 23:36:04 +03:00
|
|
|
count = 0;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
for (i = 0; i < SPLAT_KMEM_ALLOC_COUNT; i++) {
|
2008-02-26 23:36:04 +03:00
|
|
|
ptr[i] = kmem_alloc(size, KM_SLEEP);
|
|
|
|
if (ptr[i])
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
for (i = 0; i < SPLAT_KMEM_ALLOC_COUNT; i++)
|
2008-02-26 23:36:04 +03:00
|
|
|
if (ptr[i])
|
|
|
|
kmem_free(ptr[i], size);
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST1_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
"%d byte allocations, %d/%d successful\n",
|
2008-02-28 02:42:31 +03:00
|
|
|
size, count, SPLAT_KMEM_ALLOC_COUNT);
|
|
|
|
if (count != SPLAT_KMEM_ALLOC_COUNT)
|
2008-02-26 23:36:04 +03:00
|
|
|
rc = -ENOMEM;
|
|
|
|
|
|
|
|
size *= 2;
|
|
|
|
}
|
|
|
|
|
2008-03-14 23:56:26 +03:00
|
|
|
kmem_set_warning(1);
|
|
|
|
|
2008-02-26 23:36:04 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_kmem_test2(struct file *file, void *arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
void *ptr[SPLAT_KMEM_ALLOC_COUNT];
|
2008-02-26 23:36:04 +03:00
|
|
|
int size = PAGE_SIZE;
|
|
|
|
int i, j, count, rc = 0;
|
|
|
|
|
2008-03-14 23:56:26 +03:00
|
|
|
/* We are intentionally going to push kmem_alloc to its max
|
|
|
|
* allocation size, so suppress the console warnings for now */
|
|
|
|
kmem_set_warning(0);
|
|
|
|
|
2008-03-14 22:04:41 +03:00
|
|
|
while ((!rc) && (size <= (PAGE_SIZE * 32))) {
|
2008-02-26 23:36:04 +03:00
|
|
|
count = 0;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
for (i = 0; i < SPLAT_KMEM_ALLOC_COUNT; i++) {
|
2008-02-26 23:36:04 +03:00
|
|
|
ptr[i] = kmem_zalloc(size, KM_SLEEP);
|
|
|
|
if (ptr[i])
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure buffer has been zero filled */
|
2008-02-28 02:42:31 +03:00
|
|
|
for (i = 0; i < SPLAT_KMEM_ALLOC_COUNT; i++) {
|
2008-02-26 23:36:04 +03:00
|
|
|
for (j = 0; j < size; j++) {
|
|
|
|
if (((char *)ptr[i])[j] != '\0') {
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST2_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
"%d-byte allocation was "
|
|
|
|
"not zeroed\n", size);
|
|
|
|
rc = -EFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
for (i = 0; i < SPLAT_KMEM_ALLOC_COUNT; i++)
|
2008-02-26 23:36:04 +03:00
|
|
|
if (ptr[i])
|
|
|
|
kmem_free(ptr[i], size);
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST2_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
"%d byte allocations, %d/%d successful\n",
|
2008-02-28 02:42:31 +03:00
|
|
|
size, count, SPLAT_KMEM_ALLOC_COUNT);
|
|
|
|
if (count != SPLAT_KMEM_ALLOC_COUNT)
|
2008-02-26 23:36:04 +03:00
|
|
|
rc = -ENOMEM;
|
|
|
|
|
|
|
|
size *= 2;
|
|
|
|
}
|
|
|
|
|
2008-03-14 23:56:26 +03:00
|
|
|
kmem_set_warning(1);
|
|
|
|
|
2008-02-26 23:36:04 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
#define SPLAT_KMEM_TEST_MAGIC 0x004488CCUL
|
|
|
|
#define SPLAT_KMEM_CACHE_NAME "kmem_test"
|
|
|
|
#define SPLAT_KMEM_CACHE_SIZE 256
|
|
|
|
#define SPLAT_KMEM_OBJ_COUNT 128
|
|
|
|
#define SPLAT_KMEM_OBJ_RECLAIM 64
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
typedef struct kmem_cache_data {
|
2008-02-28 02:42:31 +03:00
|
|
|
char kcd_buf[SPLAT_KMEM_CACHE_SIZE];
|
2008-02-26 23:36:04 +03:00
|
|
|
unsigned long kcd_magic;
|
|
|
|
int kcd_flag;
|
|
|
|
} kmem_cache_data_t;
|
|
|
|
|
|
|
|
typedef struct kmem_cache_priv {
|
|
|
|
unsigned long kcp_magic;
|
|
|
|
struct file *kcp_file;
|
|
|
|
kmem_cache_t *kcp_cache;
|
2008-02-28 02:42:31 +03:00
|
|
|
kmem_cache_data_t *kcp_kcd[SPLAT_KMEM_OBJ_COUNT];
|
2008-02-26 23:36:04 +03:00
|
|
|
int kcp_count;
|
|
|
|
int kcp_rc;
|
|
|
|
} kmem_cache_priv_t;
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_kmem_test34_constructor(void *ptr, void *priv, int flags)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
|
|
|
kmem_cache_data_t *kcd = (kmem_cache_data_t *)ptr;
|
|
|
|
kmem_cache_priv_t *kcp = (kmem_cache_priv_t *)priv;
|
|
|
|
|
|
|
|
if (kcd) {
|
2008-02-28 02:42:31 +03:00
|
|
|
memset(kcd->kcd_buf, 0xaa, SPLAT_KMEM_CACHE_SIZE);
|
2008-02-26 23:36:04 +03:00
|
|
|
kcd->kcd_flag = 1;
|
|
|
|
|
|
|
|
if (kcp) {
|
2008-05-07 00:38:28 +04:00
|
|
|
kcd->kcd_magic = kcp->kcp_magic;
|
2008-02-26 23:36:04 +03:00
|
|
|
kcp->kcp_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_kmem_test34_destructor(void *ptr, void *priv)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
|
|
|
kmem_cache_data_t *kcd = (kmem_cache_data_t *)ptr;
|
|
|
|
kmem_cache_priv_t *kcp = (kmem_cache_priv_t *)priv;
|
|
|
|
|
|
|
|
if (kcd) {
|
2008-02-28 02:42:31 +03:00
|
|
|
memset(kcd->kcd_buf, 0xbb, SPLAT_KMEM_CACHE_SIZE);
|
2008-02-26 23:36:04 +03:00
|
|
|
kcd->kcd_flag = 0;
|
|
|
|
|
|
|
|
if (kcp)
|
|
|
|
kcp->kcp_count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_kmem_test3(struct file *file, void *arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
|
|
|
kmem_cache_t *cache = NULL;
|
|
|
|
kmem_cache_data_t *kcd = NULL;
|
|
|
|
kmem_cache_priv_t kcp;
|
|
|
|
int rc = 0, max;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
kcp.kcp_magic = SPLAT_KMEM_TEST_MAGIC;
|
2008-02-26 23:36:04 +03:00
|
|
|
kcp.kcp_file = file;
|
|
|
|
kcp.kcp_count = 0;
|
|
|
|
kcp.kcp_rc = 0;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
cache = kmem_cache_create(SPLAT_KMEM_CACHE_NAME, sizeof(*kcd), 0,
|
|
|
|
splat_kmem_test34_constructor,
|
|
|
|
splat_kmem_test34_destructor,
|
2008-02-26 23:36:04 +03:00
|
|
|
NULL, &kcp, NULL, 0);
|
|
|
|
if (!cache) {
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST3_NAME,
|
|
|
|
"Unable to create '%s'\n", SPLAT_KMEM_CACHE_NAME);
|
2008-02-26 23:36:04 +03:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
kcd = kmem_cache_alloc(cache, 0);
|
|
|
|
if (!kcd) {
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST3_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
"Unable to allocate from '%s'\n",
|
2008-02-28 02:42:31 +03:00
|
|
|
SPLAT_KMEM_CACHE_NAME);
|
2008-02-26 23:36:04 +03:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!kcd->kcd_flag) {
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST3_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
"Failed to run contructor for '%s'\n",
|
2008-02-28 02:42:31 +03:00
|
|
|
SPLAT_KMEM_CACHE_NAME);
|
2008-02-26 23:36:04 +03:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kcd->kcd_magic != kcp.kcp_magic) {
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST3_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
"Failed to pass private data to constructor "
|
2008-02-28 02:42:31 +03:00
|
|
|
"for '%s'\n", SPLAT_KMEM_CACHE_NAME);
|
2008-02-26 23:36:04 +03:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
max = kcp.kcp_count;
|
|
|
|
|
|
|
|
/* Destructor's run lazily so it hard to check correctness here.
|
|
|
|
* We assume if it doesn't crash the free worked properly */
|
|
|
|
kmem_cache_free(cache, kcd);
|
|
|
|
|
|
|
|
/* Destroy the entire cache which will force destructors to
|
|
|
|
* run and we can verify one was called for every object */
|
|
|
|
kmem_cache_destroy(cache);
|
|
|
|
if (kcp.kcp_count) {
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST3_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
"Failed to run destructor on all slab objects "
|
2008-02-28 02:42:31 +03:00
|
|
|
"for '%s'\n", SPLAT_KMEM_CACHE_NAME);
|
2008-02-26 23:36:04 +03:00
|
|
|
rc = -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST3_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
"%d allocated/destroyed objects for '%s'\n",
|
2008-02-28 02:42:31 +03:00
|
|
|
max, SPLAT_KMEM_CACHE_NAME);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
if (kcd)
|
|
|
|
kmem_cache_free(cache, kcd);
|
2008-02-27 22:09:51 +03:00
|
|
|
|
2008-02-26 23:36:04 +03:00
|
|
|
kmem_cache_destroy(cache);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_kmem_test4_reclaim(void *priv)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
|
|
|
kmem_cache_priv_t *kcp = (kmem_cache_priv_t *)priv;
|
|
|
|
int i;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(kcp->kcp_file, SPLAT_KMEM_TEST4_NAME,
|
2008-05-07 00:38:28 +04:00
|
|
|
"Reaping %d objects from '%s'\n",
|
|
|
|
SPLAT_KMEM_OBJ_RECLAIM, SPLAT_KMEM_CACHE_NAME);
|
2008-02-28 02:42:31 +03:00
|
|
|
for (i = 0; i < SPLAT_KMEM_OBJ_RECLAIM; i++) {
|
2008-02-26 23:36:04 +03:00
|
|
|
if (kcp->kcp_kcd[i]) {
|
|
|
|
kmem_cache_free(kcp->kcp_cache, kcp->kcp_kcd[i]);
|
|
|
|
kcp->kcp_kcd[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_kmem_test4(struct file *file, void *arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
|
|
|
kmem_cache_t *cache;
|
|
|
|
kmem_cache_priv_t kcp;
|
|
|
|
int i, rc = 0, max, reclaim_percent, target_percent;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
kcp.kcp_magic = SPLAT_KMEM_TEST_MAGIC;
|
2008-02-26 23:36:04 +03:00
|
|
|
kcp.kcp_file = file;
|
|
|
|
kcp.kcp_count = 0;
|
|
|
|
kcp.kcp_rc = 0;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
cache = kmem_cache_create(SPLAT_KMEM_CACHE_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
sizeof(kmem_cache_data_t), 0,
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_kmem_test34_constructor,
|
|
|
|
splat_kmem_test34_destructor,
|
|
|
|
splat_kmem_test4_reclaim, &kcp, NULL, 0);
|
2008-02-26 23:36:04 +03:00
|
|
|
if (!cache) {
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST4_NAME,
|
|
|
|
"Unable to create '%s'\n", SPLAT_KMEM_CACHE_NAME);
|
2008-02-26 23:36:04 +03:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
kcp.kcp_cache = cache;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
for (i = 0; i < SPLAT_KMEM_OBJ_COUNT; i++) {
|
2008-02-27 22:09:51 +03:00
|
|
|
/* All allocations need not succeed */
|
2008-02-26 23:36:04 +03:00
|
|
|
kcp.kcp_kcd[i] = kmem_cache_alloc(cache, 0);
|
|
|
|
if (!kcp.kcp_kcd[i]) {
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST4_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
"Unable to allocate from '%s'\n",
|
2008-02-28 02:42:31 +03:00
|
|
|
SPLAT_KMEM_CACHE_NAME);
|
2008-02-26 23:36:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
max = kcp.kcp_count;
|
2008-05-07 00:38:28 +04:00
|
|
|
ASSERT(max > 0);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
/* Force shrinker to run */
|
|
|
|
kmem_reap();
|
|
|
|
|
|
|
|
/* Reclaim reclaimed objects, this ensure the destructors are run */
|
|
|
|
kmem_cache_reap_now(cache);
|
|
|
|
|
|
|
|
reclaim_percent = ((kcp.kcp_count * 100) / max);
|
2008-02-28 02:42:31 +03:00
|
|
|
target_percent = (((SPLAT_KMEM_OBJ_COUNT - SPLAT_KMEM_OBJ_RECLAIM) * 100) /
|
|
|
|
SPLAT_KMEM_OBJ_COUNT);
|
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST4_NAME,
|
2008-02-26 23:36:04 +03:00
|
|
|
"%d%% (%d/%d) of previous size, target of "
|
|
|
|
"%d%%-%d%% for '%s'\n", reclaim_percent, kcp.kcp_count,
|
|
|
|
max, target_percent - 10, target_percent + 10,
|
2008-02-28 02:42:31 +03:00
|
|
|
SPLAT_KMEM_CACHE_NAME);
|
2008-02-26 23:36:04 +03:00
|
|
|
if ((reclaim_percent < target_percent - 10) ||
|
|
|
|
(reclaim_percent > target_percent + 10))
|
|
|
|
rc = -EINVAL;
|
|
|
|
|
|
|
|
/* Cleanup our mess */
|
2008-02-28 02:42:31 +03:00
|
|
|
for (i = 0; i < SPLAT_KMEM_OBJ_COUNT; i++)
|
2008-02-26 23:36:04 +03:00
|
|
|
if (kcp.kcp_kcd[i])
|
|
|
|
kmem_cache_free(cache, kcp.kcp_kcd[i]);
|
|
|
|
|
|
|
|
kmem_cache_destroy(cache);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-03-14 22:04:41 +03:00
|
|
|
static int
|
|
|
|
splat_kmem_test5(struct file *file, void *arg)
|
|
|
|
{
|
|
|
|
void *ptr[SPLAT_VMEM_ALLOC_COUNT];
|
|
|
|
int size = PAGE_SIZE;
|
|
|
|
int i, count, rc = 0;
|
|
|
|
|
|
|
|
while ((!rc) && (size <= (PAGE_SIZE * 1024))) {
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < SPLAT_VMEM_ALLOC_COUNT; i++) {
|
|
|
|
ptr[i] = vmem_alloc(size, KM_SLEEP);
|
|
|
|
if (ptr[i])
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < SPLAT_VMEM_ALLOC_COUNT; i++)
|
|
|
|
if (ptr[i])
|
|
|
|
vmem_free(ptr[i], size);
|
|
|
|
|
|
|
|
splat_vprint(file, SPLAT_KMEM_TEST5_NAME,
|
|
|
|
"%d byte allocations, %d/%d successful\n",
|
|
|
|
size, count, SPLAT_VMEM_ALLOC_COUNT);
|
|
|
|
if (count != SPLAT_VMEM_ALLOC_COUNT)
|
|
|
|
rc = -ENOMEM;
|
|
|
|
|
|
|
|
size *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_subsystem_t *
|
|
|
|
splat_kmem_init(void)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_subsystem_t *sub;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
sub = kmalloc(sizeof(*sub), GFP_KERNEL);
|
|
|
|
if (sub == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(sub, 0, sizeof(*sub));
|
2008-02-28 02:42:31 +03:00
|
|
|
strncpy(sub->desc.name, SPLAT_KMEM_NAME, SPLAT_NAME_SIZE);
|
|
|
|
strncpy(sub->desc.desc, SPLAT_KMEM_DESC, SPLAT_DESC_SIZE);
|
2008-02-26 23:36:04 +03:00
|
|
|
INIT_LIST_HEAD(&sub->subsystem_list);
|
|
|
|
INIT_LIST_HEAD(&sub->test_list);
|
|
|
|
spin_lock_init(&sub->test_lock);
|
2008-02-28 02:42:31 +03:00
|
|
|
sub->desc.id = SPLAT_SUBSYSTEM_KMEM;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST1_NAME, SPLAT_KMEM_TEST1_DESC,
|
|
|
|
SPLAT_KMEM_TEST1_ID, splat_kmem_test1);
|
|
|
|
SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST2_NAME, SPLAT_KMEM_TEST2_DESC,
|
|
|
|
SPLAT_KMEM_TEST2_ID, splat_kmem_test2);
|
|
|
|
SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST3_NAME, SPLAT_KMEM_TEST3_DESC,
|
|
|
|
SPLAT_KMEM_TEST3_ID, splat_kmem_test3);
|
|
|
|
SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST4_NAME, SPLAT_KMEM_TEST4_DESC,
|
|
|
|
SPLAT_KMEM_TEST4_ID, splat_kmem_test4);
|
2008-03-14 22:04:41 +03:00
|
|
|
SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST5_NAME, SPLAT_KMEM_TEST5_DESC,
|
|
|
|
SPLAT_KMEM_TEST5_ID, splat_kmem_test5);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_kmem_fini(splat_subsystem_t *sub)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
|
|
|
ASSERT(sub);
|
2008-03-14 22:04:41 +03:00
|
|
|
SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST5_ID);
|
2008-02-28 02:42:31 +03:00
|
|
|
SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST4_ID);
|
|
|
|
SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST3_ID);
|
|
|
|
SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST2_ID);
|
|
|
|
SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST1_ID);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
kfree(sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_kmem_id(void) {
|
|
|
|
return SPLAT_SUBSYSTEM_KMEM;
|
2008-02-26 23:36:04 +03:00
|
|
|
}
|