From 6b957f167e59782f2342e692ac1fd749e2adf025 Mon Sep 17 00:00:00 2001 From: kcwu Date: Sun, 27 May 2007 14:08:38 +0000 Subject: * hack dietlibc's allocator. release small block to OS. * allocation behavior dirty hack for dietlibc. Avoid allocate 64byte slot, use 128byte slot instead. Thus, they share same memory block. * save about 400mb for ptt. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3519 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/alloc.c | 18 ++++++++++++++++++ mbbsd/fav.c | 5 +++++ mbbsd/pmore.c | 9 +++++++++ 3 files changed, 32 insertions(+) (limited to 'mbbsd') diff --git a/mbbsd/alloc.c b/mbbsd/alloc.c index 06b84177..de676ce4 100644 --- a/mbbsd/alloc.c +++ b/mbbsd/alloc.c @@ -56,6 +56,9 @@ static void REGPARM(1) *do_mmap(size_t size) { static __alloc_t* __small_mem[8]; +static int smallalloc[8]; +static int smallalloc_max[8]; + #define __SMALL_NR(i) (MEM_BLOCK_SIZE/(i)) #define __MIN_SMALL_SIZE __SMALL_NR(256) /* 16 / 32 */ @@ -88,6 +91,17 @@ static void REGPARM(2) __small_free(void*_ptr,size_t _size) { ptr->next=__small_mem[idx]; __small_mem[idx]=ptr; + + smallalloc[idx]--; + + if (MEM_BLOCK_SIZE == PAGE_SIZE && + smallalloc[idx] == 0 && + smallalloc_max[idx] < __SMALL_NR(size)) { + __alloc_t* p = __small_mem[idx]; + __alloc_t* ph = p - (size_t)p%PAGE_SIZE; + munmap(ph, MEM_BLOCK_SIZE); + __small_mem[idx] = 0; + } } static void* REGPARM(1) __small_malloc(size_t _size) { @@ -119,6 +133,10 @@ static void* REGPARM(1) __small_malloc(size_t _size) { __small_mem[idx]=ptr->next; ptr->next=0; + smallalloc[idx]++; + if(smallalloc[idx] > smallalloc_max[idx]) + smallalloc_max[idx] = smallalloc[idx]; + return ptr; } diff --git a/mbbsd/fav.c b/mbbsd/fav.c index eb9a40dc..e4b0e74e 100644 --- a/mbbsd/fav.c +++ b/mbbsd/fav.c @@ -524,7 +524,12 @@ int fav_load(void) if ((frp = fopen(buf, "r")) == NULL) return -1; +#ifdef CRITICAL_MEMORY + // kcwu: dirty hack, avoid 64byte slot. use 128 instead. + fp = (fav_t *)fav_malloc(sizeof(fav_t)+64); +#else fp = (fav_t *)fav_malloc(sizeof(fav_t)); +#endif fav_number = 0; fread(&version, sizeof(version), 1, frp); // if (version != FAV_VERSION) { ... } diff --git a/mbbsd/pmore.c b/mbbsd/pmore.c index 26f73a38..dd22ed60 100644 --- a/mbbsd/pmore.c +++ b/mbbsd/pmore.c @@ -809,7 +809,16 @@ mf_parseHeaders() // p is pointing at a new line. (\n) l = (int)(p - pb); +#ifdef CRITICAL_MEMORY + // kcwu: dirty hack, avoid 64byte slot. use 128byte slot instead. + if (l<100) { + p = (unsigned char*) malloc (100+1); + } else { + p = (unsigned char*) malloc (l+1); + } +#else p = (unsigned char*) malloc (l+1); +#endif fh.headers[i] = p; memcpy(p, pb, l); p[l] = 0; -- cgit v1.2.3