summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-03-09 09:10:44 +0100
committerMaria Matejka <mq@ucw.cz>2022-03-09 09:10:44 +0100
commitc78247f9b97802d6fe76d9b7cddf2c1940134d33 (patch)
tree42c178b7c4dbb19223e07540a4ba06ef60e7e42f /lib
parent06ece3265e222f218224bb394c250cb414e44ab4 (diff)
Single-threaded version of sark-branch memory page management
Diffstat (limited to 'lib')
-rw-r--r--lib/resource.c2
-rw-r--r--lib/resource.h5
-rw-r--r--lib/slab.c13
3 files changed, 11 insertions, 9 deletions
diff --git a/lib/resource.c b/lib/resource.c
index 5636872c..a179afe3 100644
--- a/lib/resource.c
+++ b/lib/resource.c
@@ -270,6 +270,8 @@ rlookup(unsigned long a)
void
resource_init(void)
{
+ resource_sys_init();
+
root_pool.r.class = &pool_class;
root_pool.name = "Root";
init_list(&root_pool.inside);
diff --git a/lib/resource.h b/lib/resource.h
index 0e4c44d8..992fa5b2 100644
--- a/lib/resource.h
+++ b/lib/resource.h
@@ -110,10 +110,11 @@ void sl_free(slab *, void *);
void buffer_realloc(void **buf, unsigned *size, unsigned need, unsigned item_size);
/* Allocator of whole pages; for use in slabs and other high-level allocators. */
-u64 get_page_size(void);
+extern long page_size;
void *alloc_page(void);
void free_page(void *);
-extern uint pages_kept;
+
+void resource_sys_init(void);
#ifdef HAVE_LIBDMALLOC
/*
diff --git a/lib/slab.c b/lib/slab.c
index 9a4c3ee2..9be9844d 100644
--- a/lib/slab.c
+++ b/lib/slab.c
@@ -180,7 +180,7 @@ struct sl_alignment { /* Magic structure for testing of alignment */
int x[0];
};
-#define SL_GET_HEAD(x) ((struct sl_head *) (((uintptr_t) (x)) & ~(get_page_size()-1)))
+#define SL_GET_HEAD(x) ((struct sl_head *) (((uintptr_t) (x)) & ~(page_size-1)))
/**
* sl_new - create a new Slab
@@ -202,7 +202,6 @@ sl_new(pool *p, uint size)
s->obj_size = size;
s->head_size = sizeof(struct sl_head);
- u64 page_size = get_page_size();
do {
s->objs_per_slab = (page_size - s->head_size) / size;
@@ -273,7 +272,7 @@ no_partial:
}
h = alloc_page();
#ifdef POISON
- memset(h, 0xba, get_page_size());
+ memset(h, 0xba, page_size);
#endif
ASSERT_DIE(SL_GET_HEAD(h) == h);
memset(h, 0, s->head_size);
@@ -332,7 +331,7 @@ sl_free(slab *s, void *oo)
if (s->num_empty_heads >= MAX_EMPTY_HEADS)
{
#ifdef POISON
- memset(h, 0xde, get_page_size());
+ memset(h, 0xde, page_size);
#endif
free_page(h);
}
@@ -399,7 +398,7 @@ slab_memsize(resource *r)
return (struct resmem) {
.effective = eff,
- .overhead = ALLOC_OVERHEAD + sizeof(struct slab) + heads * get_page_size() - eff,
+ .overhead = ALLOC_OVERHEAD + sizeof(struct slab) + heads * page_size - eff,
};
}
@@ -410,10 +409,10 @@ slab_lookup(resource *r, unsigned long a)
struct sl_head *h;
WALK_LIST(h, s->partial_heads)
- if ((unsigned long) h < a && (unsigned long) h + get_page_size() < a)
+ if ((unsigned long) h < a && (unsigned long) h + page_size < a)
return r;
WALK_LIST(h, s->full_heads)
- if ((unsigned long) h < a && (unsigned long) h + get_page_size() < a)
+ if ((unsigned long) h < a && (unsigned long) h + page_size < a)
return r;
return NULL;
}