projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
smalloc: only clear the bitmap, not the whole pool
[fio.git]
/
smalloc.c
diff --git
a/smalloc.c
b/smalloc.c
index 67cb7cc11d475b81aef3d53a7eb896eee31504bb..5047cda5e3438c8215a3bb549577f5a81e5b0a29 100644
(file)
--- a/
smalloc.c
+++ b/
smalloc.c
@@
-26,13
+26,15
@@
#define SMALLOC_BPL (SMALLOC_BPB * SMALLOC_BPI)
#define INITIAL_SIZE 16*1024*1024 /* new pool size */
#define SMALLOC_BPL (SMALLOC_BPB * SMALLOC_BPI)
#define INITIAL_SIZE 16*1024*1024 /* new pool size */
-#define MAX_POOLS
1
/* maximum number of pools to setup */
+#define MAX_POOLS
8
/* maximum number of pools to setup */
#define SMALLOC_PRE_RED 0xdeadbeefU
#define SMALLOC_POST_RED 0x5aa55aa5U
unsigned int smalloc_pool_size = INITIAL_SIZE;
#define SMALLOC_PRE_RED 0xdeadbeefU
#define SMALLOC_POST_RED 0x5aa55aa5U
unsigned int smalloc_pool_size = INITIAL_SIZE;
+#ifdef SMALLOC_REDZONE
static const int int_mask = sizeof(int) - 1;
static const int int_mask = sizeof(int) - 1;
+#endif
struct pool {
struct fio_mutex *lock; /* protects this pool */
struct pool {
struct fio_mutex *lock; /* protects this pool */
@@
-211,9
+213,9
@@
static int add_pool(struct pool *pool, unsigned int alloc_size)
if (ptr == MAP_FAILED)
goto out_fail;
if (ptr == MAP_FAILED)
goto out_fail;
- memset(ptr, 0, alloc_size);
pool->map = ptr;
pool->bitmap = (void *) ptr + (pool->nr_blocks * SMALLOC_BPL);
pool->map = ptr;
pool->bitmap = (void *) ptr + (pool->nr_blocks * SMALLOC_BPL);
+ memset(pool->bitmap, 0, bitmap_blocks * sizeof(unsigned int));
pool->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
if (!pool->lock)
pool->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
if (!pool->lock)
@@
-230,11
+232,21
@@
out_fail:
void sinit(void)
{
void sinit(void)
{
- int ret;
+ int
i,
ret;
lock = fio_rwlock_init();
lock = fio_rwlock_init();
- ret = add_pool(&mp[0], INITIAL_SIZE);
- assert(!ret);
+
+ for (i = 0; i < MAX_POOLS; i++) {
+ ret = add_pool(&mp[i], INITIAL_SIZE);
+ if (ret)
+ break;
+ }
+
+ /*
+ * If we added at least one pool, we should be OK for most
+ * cases.
+ */
+ assert(i);
}
static void cleanup_pool(struct pool *pool)
}
static void cleanup_pool(struct pool *pool)
@@
-353,8
+365,12
@@
void sfree(void *ptr)
global_read_unlock();
global_read_unlock();
- assert(pool);
- sfree_pool(pool, ptr);
+ if (pool) {
+ sfree_pool(pool, ptr);
+ return;
+ }
+
+ log_err("smalloc: ptr %p not from smalloc pool\n", ptr);
}
static void *__smalloc_pool(struct pool *pool, size_t size)
}
static void *__smalloc_pool(struct pool *pool, size_t size)
@@
-442,16
+458,17
@@
static void *smalloc_pool(struct pool *pool, size_t size)
void *smalloc(size_t size)
{
void *smalloc(size_t size)
{
- unsigned int i;
+ unsigned int i
, end_pool
;
if (size != (unsigned int) size)
return NULL;
global_write_lock();
i = last_pool;
if (size != (unsigned int) size)
return NULL;
global_write_lock();
i = last_pool;
+ end_pool = nr_pools;
do {
do {
- for (; i <
nr_pools
; i++) {
+ for (; i <
end_pool
; i++) {
void *ptr = smalloc_pool(&mp[i], size);
if (ptr) {
void *ptr = smalloc_pool(&mp[i], size);
if (ptr) {
@@
-461,40
+478,29
@@
void *smalloc(size_t size)
}
}
if (last_pool) {
}
}
if (last_pool) {
- last_pool = 0;
+ end_pool = last_pool;
+ last_pool = i = 0;
continue;
}
continue;
}
- if (nr_pools + 1 > MAX_POOLS)
- break;
- else {
- i = nr_pools;
- if (add_pool(&mp[nr_pools], size))
- goto out;
- }
+ break;
} while (1);
} while (1);
-out:
global_write_unlock();
return NULL;
}
void *scalloc(size_t nmemb, size_t size)
{
global_write_unlock();
return NULL;
}
void *scalloc(size_t nmemb, size_t size)
{
- void *ret;
-
- ret = smalloc(nmemb * size);
- if (ret)
- memset(ret, 0, nmemb * size);
-
- return ret;
+ return smalloc(nmemb * size);
}
char *smalloc_strdup(const char *str)
{
}
char *smalloc_strdup(const char *str)
{
- char *ptr;
+ char *ptr
= NULL
;
ptr = smalloc(strlen(str) + 1);
ptr = smalloc(strlen(str) + 1);
- strcpy(ptr, str);
+ if (ptr)
+ strcpy(ptr, str);
return ptr;
}
return ptr;
}