提交 83ec84ee 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

avoid scoped_gc_epoch in kmalloc and a faster bucket() to speed up kmalloc/kmfree

上级 4143f26a
...@@ -10,9 +10,8 @@ ...@@ -10,9 +10,8 @@
#include "mtrace.h" #include "mtrace.h"
#include "cpu.hh" #include "cpu.hh"
// allocate in power-of-two sizes up to 2^KMMAX // allocate in power-of-two sizes up to 2^KMMAX (PGSIZE)
// must be < 12 #define KMMAX 12
#define KMMAX 11
struct header { struct header {
struct header *next; struct header *next;
...@@ -60,17 +59,20 @@ morecore(int c, int b) ...@@ -60,17 +59,20 @@ morecore(int c, int b)
static int static int
bucket(u64 nbytes) bucket(u64 nbytes)
{ {
u64 nn = 8, b = 3; static int bucketmap[] = {
6,
while(nn < nbytes) { 7,
nn *= 2; 8, 8,
b++; 9, 9, 9, 9,
} 10, 10, 10, 10, 10, 10, 10, 10,
if(nn != (1 << b)) 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
panic("kmalloc oops"); 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
if(b > KMMAX) 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
panic("kmalloc too big %ld", nbytes); };
assert(nbytes <= PGSIZE);
int b = bucketmap[nbytes >> 6];
assert((1<<b) >= nbytes);
return b; return b;
} }
...@@ -79,7 +81,6 @@ kmalloc(u64 nbytes) ...@@ -79,7 +81,6 @@ kmalloc(u64 nbytes)
{ {
int b = bucket(nbytes); int b = bucket(nbytes);
scoped_gc_epoch gc;
struct header *h; struct header *h;
int c = mycpu()->id; int c = mycpu()->id;
...@@ -112,8 +113,6 @@ void ...@@ -112,8 +113,6 @@ void
kmfree(void *ap, u64 nbytes) kmfree(void *ap, u64 nbytes)
{ {
int b = bucket(nbytes); int b = bucket(nbytes);
if(b < 0 || b > KMMAX)
panic("kmfree bad bucket");
struct header *h = (struct header *) ap; struct header *h = (struct header *) ap;
verifyfree((char *) ap, (1<<b)); verifyfree((char *) ap, (1<<b));
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论