[srvx-commits] commit: Rearrange slab allocation header; minor slab fixes.
Brought to you by:
entrope
|
From: Michael P. <md...@tr...> - 2005-02-05 13:04:05
|
Revision: srvx--devo--1.3--patch-15
Archive: sr...@sr...--2005-srvx
Creator: Michael Poole <md...@tr...>
Date: Sat Feb 5 08:03:21 EST 2005
Standard-date: 2005-02-05 13:03:21 GMT
Modified-files: ChangeLog src/alloc-slab.c
New-patches: sr...@sr...--2005-srvx/srvx--devo--1.3--patch-15
Summary: Rearrange slab allocation header; minor slab fixes.
Keywords:
src/alloc-slab.c (ALLOC_MAGIC, FREE_MAGIC): Replace with single-byte values.
(struct alloc_header): Move file_id and line into second 32-bit word
of header.
(slab_alloc): Remove commented-out debug statements.
(slab_unalloc): Remove memset() of freed block and commented-out debug
statements.
(slab_free): memset() freed blocks here instead. Try to fix
*_alloc_size counting errors (use the originally requested length
rather than rounded-up length)
* added files
{arch}/srvx/srvx--devo/srvx--devo--1.3/sr...@sr...--2005-srvx/patch-log/patch-15
* modified files
--- orig/ChangeLog
+++ mod/ChangeLog
@@ -2,6 +2,27 @@
# arch-tag: aut...@sr...--2005-srvx/srvx--devo--1.3
#
+2005-02-05 13:03:21 GMT Michael Poole <md...@tr...> patch-15
+
+ Summary:
+ Rearrange slab allocation header; minor slab fixes.
+ Revision:
+ srvx--devo--1.3--patch-15
+
+ src/alloc-slab.c (ALLOC_MAGIC, FREE_MAGIC): Replace with single-byte values.
+ (struct alloc_header): Move file_id and line into second 32-bit word
+ of header.
+ (slab_alloc): Remove commented-out debug statements.
+ (slab_unalloc): Remove memset() of freed block and commented-out debug
+ statements.
+ (slab_free): memset() freed blocks here instead. Try to fix
+ *_alloc_size counting errors (use the originally requested length
+ rather than rounded-up length)
+
+ modified files:
+ ChangeLog src/alloc-slab.c
+
+
2005-02-05 03:52:51 GMT Michael Poole <md...@tr...> patch-14
Summary:
--- orig/src/alloc-slab.c
+++ mod/src/alloc-slab.c
@@ -30,14 +30,14 @@
#if SLAB_DEBUG
-#define ALLOC_MAGIC 0x1acf
-#define FREE_MAGIC 0xfc1d
+#define ALLOC_MAGIC 0x1a
+#define FREE_MAGIC 0xcf
struct alloc_header {
- unsigned int file_id : 8;
unsigned int size : 24;
+ unsigned int magic : 8;
+ unsigned int file_id : 8;
unsigned int line : 16;
- unsigned int magic : 16;
};
static const char *file_ids[256];
@@ -226,7 +226,6 @@
assert(!slab->prev || slab == slab->prev->next);
sset->child = slab;
sset->nslabs++;
- /* log_module(MAIN_LOG, LOG_DEBUG, "Allocated new %u-slab %p.", sset->size, slab); */
}
slab = sset->child;
@@ -235,7 +234,6 @@
<= (slab_pagesize() - sizeof(*slab) - sset->size));
slab->free = *item;
if (++slab->used == sset->items_per_slab) {
- /* log_module(MAIN_LOG, LOG_DEBUG, "%u-slab %p is empty.", sset->size, item); */
if (sset->child != slab) {
/* Unlink slab and reinsert before sset->child. */
if (slab->prev)
@@ -261,15 +259,12 @@
static void
slab_unalloc(void *ptr, size_t size)
{
- void **item;
struct slab *slab, *new_next;
- item = ptr;
assert(size < SMALL_CUTOFF);
slab = (struct slab*)((((unsigned long)ptr | (slab_pagesize() - 1)) + 1) - sizeof(*slab));
- *item = slab->free;
- memset(item + 1, 0xde, size - sizeof(*item));
- slab->free = item;
+ *(void**)ptr = slab->free;
+ slab->free = ptr;
slab->parent->nallocs--;
if (slab->used-- == slab->parent->items_per_slab
@@ -288,9 +283,7 @@
slab->parent->child = slab;
assert(!slab->next || slab == slab->next->prev);
assert(!slab->prev || slab == slab->prev->next);
- /* log_module(MAIN_LOG, LOG_DEBUG, "%u-slab %p became partial.", slab->parent->size, slab); */
} else if (!slab->used) {
- /* log_module(MAIN_LOG, LOG_DEBUG, "%u-slab %p became full.", slab->parent->size, slab); */
/* Unlink slab from its parent. */
slab->parent->nslabs--;
if (slab->prev)
@@ -310,6 +303,8 @@
/* Make sure we have enough free slab pages. */
while (free_slab_count < SLAB_RESERVE) {
struct slab *tslab;
+ void *item;
+
item = slab_map(slab_pagesize());
tslab = (struct slab*)((char*)item + slab_pagesize() - sizeof(*slab));
tslab->base = item;
@@ -408,7 +403,7 @@
slab_free(const char *file, unsigned int line, void *ptr)
{
alloc_header_t *hdr;
- size_t real;
+ size_t user, real;
if (!ptr)
return;
@@ -418,20 +413,21 @@
hdr->file_id = get_file_id(file);
hdr->line = line;
hdr->magic = FREE_MAGIC;
- real = hdr->size + sizeof(*hdr);
+ user = hdr->size;
#else
- real = *hdr + sizeof(*hdr);
+ user = *hdr;
(void)file; (void)line;
#endif
- real = (real + SLAB_GRAIN - 1) & ~(SLAB_GRAIN - 1);
+ real = (user + sizeof(*hdr) + SLAB_GRAIN - 1) & ~(SLAB_GRAIN - 1);
if (real < SMALL_CUTOFF) {
+ memset(hdr + 1, 0xde, real - sizeof(*hdr));
slab_unalloc(hdr, real);
slab_alloc_count--;
- slab_alloc_size -= real - sizeof(*hdr);
+ slab_alloc_size -= user;
} else {
munmap(hdr, slab_round_up(real));
big_alloc_count--;
- big_alloc_size -= real - sizeof(*hdr);
+ big_alloc_size -= user;
}
}
|