|
@@ -42,12 +42,10 @@ static void *__early_alloc(int size) {
|
|
|
return early_kmalloc(size, 1);
|
|
return early_kmalloc(size, 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
static void *__pool_alloc(int size) {
|
|
static void *__pool_alloc(int size) {
|
|
|
return early_kmalloc(size, CACHE_SIZE);
|
|
return early_kmalloc(size, CACHE_SIZE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
struct mempool_dir mempools[] = {
|
|
struct mempool_dir mempools[] = {
|
|
|
/* you can join a structure in here too */
|
|
/* you can join a structure in here too */
|
|
|
|
|
|
|
@@ -64,8 +62,6 @@ struct mempool_dir mempools[] = {
|
|
|
{ 0, NULL }
|
|
{ 0, NULL }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
int early_mempool_init(void) {
|
|
int early_mempool_init(void) {
|
|
|
struct mempool_dir *dir;
|
|
struct mempool_dir *dir;
|
|
|
|
|
|
|
@@ -75,7 +71,6 @@ int early_mempool_init(void) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
struct mempool *mempool_create(int size, void *(* alloc) (int size), void *(* pool_alloc) (int)) {
|
|
struct mempool *mempool_create(int size, void *(* alloc) (int size), void *(* pool_alloc) (int)) {
|
|
|
struct mempool *pool;
|
|
struct mempool *pool;
|
|
|
struct bucket_entry *e;
|
|
struct bucket_entry *e;
|
|
@@ -89,7 +84,6 @@ struct mempool *mempool_create(int size, void *(* alloc) (int size), void *(* po
|
|
|
/* this printk is not safe, as you know */
|
|
/* this printk is not safe, as you know */
|
|
|
panic("mempool_create: Out of memory\n");
|
|
panic("mempool_create: Out of memory\n");
|
|
|
|
|
|
|
|
-
|
|
|
|
|
pool->size = size;
|
|
pool->size = size;
|
|
|
|
|
|
|
|
/* we'll not free this */
|
|
/* we'll not free this */
|
|
@@ -112,7 +106,6 @@ struct mempool *mempool_create(int size, void *(* alloc) (int size), void *(* po
|
|
|
return pool;
|
|
return pool;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
void *__mempool_alloc(struct mempool *pool) {
|
|
void *__mempool_alloc(struct mempool *pool) {
|
|
|
struct bucket_entry *e = pool->freeptr;
|
|
struct bucket_entry *e = pool->freeptr;
|
|
|
struct mempool *p = pool;
|
|
struct mempool *p = pool;
|
|
@@ -129,7 +122,6 @@ void *__mempool_alloc(struct mempool *pool) {
|
|
|
return (void *) e;
|
|
return (void *) e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
int __mempool_free(struct mempool *pool, void *p) {
|
|
int __mempool_free(struct mempool *pool, void *p) {
|
|
|
struct bucket_entry *old, *e;
|
|
struct bucket_entry *old, *e;
|
|
|
|
|
|
|
@@ -144,8 +136,6 @@ int __mempool_free(struct mempool *pool, void *p) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
void *kmalloc(int size) {
|
|
void *kmalloc(int size) {
|
|
|
struct mempool_dir *d;
|
|
struct mempool_dir *d;
|
|
|
|
|
|
|
@@ -154,12 +144,11 @@ void *kmalloc(int size) {
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
if (!d->size)
|
|
if (!d->size)
|
|
|
- panic("WARNING: kmalloc: size is too big\n");
|
|
|
|
|
|
|
+ panic("kmalloc: size is too big\n");
|
|
|
|
|
|
|
|
return __mempool_alloc(d->pools);
|
|
return __mempool_alloc(d->pools);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
int free_s(void *p, int size) {
|
|
int free_s(void *p, int size) {
|
|
|
struct mempool_dir *d;
|
|
struct mempool_dir *d;
|
|
|
struct mempool *pool;
|
|
struct mempool *pool;
|
|
@@ -176,16 +165,15 @@ int free_s(void *p, int size) {
|
|
|
pool = pool->next_pool;
|
|
pool = pool->next_pool;
|
|
|
|
|
|
|
|
if (!pool && size)
|
|
if (!pool && size)
|
|
|
- panic("WARNING: free_s: object is not in any mempool\n");
|
|
|
|
|
|
|
+ panic("free_s: object is not in any mempool\n");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!d->size)
|
|
if (!d->size)
|
|
|
- panic("WARNING: free_s: object is not in any mempool\n");
|
|
|
|
|
|
|
+ panic("free_s: object is not in any mempool\n");
|
|
|
|
|
|
|
|
return __mempool_free(pool, p);
|
|
return __mempool_free(pool, p);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
int dump_pool(struct mempool_dir *d) {
|
|
int dump_pool(struct mempool_dir *d) {
|
|
|
struct mempool *p;
|
|
struct mempool *p;
|
|
|
int total;
|
|
int total;
|
|
@@ -198,8 +186,6 @@ int dump_pool(struct mempool_dir *d) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
int kmalloc_report(void) {
|
|
int kmalloc_report(void) {
|
|
|
struct mempool_dir *d;
|
|
struct mempool_dir *d;
|
|
|
|
|
|
|
@@ -209,4 +195,3 @@ int kmalloc_report(void) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|