From da0a7d7b8f896bc2117ce488c4e245d626ef8aba Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 19 Dec 2008 03:13:39 -0800 Subject: malloc bug fixes. use malloc by default. free stacks. R=r DELTA=424 (333 added, 29 deleted, 62 changed) OCL=21553 CL=21584 --- src/runtime/malloc.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/runtime/malloc.h') diff --git a/src/runtime/malloc.h b/src/runtime/malloc.h index e2a4af9ef8..9c71e631ac 100644 --- a/src/runtime/malloc.h +++ b/src/runtime/malloc.h @@ -62,7 +62,7 @@ // 4. If the heap has too much memory, return some to the // operating system. // -// TODO(rsc): Steps 2, 3, 4 are not implemented. +// TODO(rsc): Step 4 is not implemented. // // Allocating and freeing a large object uses the page heap // directly, bypassing the MCache and MCentral free lists. @@ -79,6 +79,7 @@ typedef struct MHeapMap MHeapMap; typedef struct MHeapMapCache MHeapMapCache; typedef struct MSpan MSpan; typedef struct MStats MStats; +typedef struct MLink MLink; enum { @@ -102,6 +103,12 @@ enum }; +// A generic linked list of blocks. (Typically the block is bigger than sizeof(MLink).) +struct MLink +{ + MLink *next; +}; + // SysAlloc obtains a large chunk of memory from the operating system, // typically on the order of a hundred kilobytes or a megabyte. // @@ -129,7 +136,7 @@ struct FixAlloc { uintptr size; void *(*alloc)(uintptr); - void *list; + MLink *list; byte *chunk; uint32 nchunk; }; @@ -146,6 +153,7 @@ struct MStats { uint64 alloc; uint64 sys; + uint64 stacks; }; extern MStats mstats; @@ -175,8 +183,9 @@ extern void InitSizes(void); typedef struct MCacheList MCacheList; struct MCacheList { - void *list; + MLink *list; uint32 nlist; + uint32 nlistmin; }; struct MCache @@ -230,8 +239,8 @@ struct MCentral }; void MCentral_Init(MCentral *c, int32 sizeclass); -int32 MCentral_AllocList(MCentral *c, int32 n, void **start, void **end); -void MCentral_FreeList(MCentral *c, int32 n, void *start, void *end); +int32 MCentral_AllocList(MCentral *c, int32 n, MLink **first); +void MCentral_FreeList(MCentral *c, int32 n, MLink *first); // Free(v) must be able to determine the MSpan containing v. -- cgit v1.3