Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Programming Threads > Re: sup****ting...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 28 Topic 4066 of 4146
Post > Topic >>

Re: sup****ting header-less blocks in memory allocators...

by "Chris M. Thomasson" <no@[EMAIL PROTECTED] > Oct 2, 2008 at 09:29 AM

"Dmitriy V'jukov" <dvyukov@[EMAIL PROTECTED]
> wrote in message 
news:280c8b35-0fe0-403a-9a71-288ae5fd0bdd@[EMAIL PROTECTED]
> Chris M. Thomasson wrote:
>
>> There is a way to minimize the GUID scheme, but it requires two
sections 
>> of
>> virtual memory which can be wasteful. It involves block sizes <= chunk 
>> size
>> to be allocated from a separate memory pool than block sizes that are >
>> chunk size. The former can use the normal scheme of simple rounding up 
>> and
>> subtracting to get chunk header... However, the latter would need to
use 
>> the
>> GUID search algorithm.
>
> If object is bigger than 16 pages, I think it's perfectly Ok to spent
> 16 bytes on header.
> What is the point of huge headerless blocks?


But how could I efficiently intermingle large blocks and small blocks from
a 
single reserved memory pool? Anyway, I don't think I was thinking clearly 
when I wrote the following ****tion of my original message


"There is a way to minimize the GUID scheme, but it requires two sections
of
virtual memory which can be wasteful. It involves block sizes <= chunk
size
to be allocated from a separate memory pool than block sizes that are >
chunk size. The former can use the normal scheme of simple rounding up and
subtracting to get chunk header... However, the latter would need to use
the
GUID search algorithm."


I would not need to use the GUID search algorithm at all if I split the 
reserved virtual memory address space into 2 sections and _strictly_ 
enforced it. For instance, I reserve 4 gigs of memory, and split it into
two 
sections; one for allocations <= chunk size, and one for allocations >
chunk 
size. But that wastes memory. What if the application only made small 
allocations and wanted to use more than 2 gigs? Or if the application only

did large allocations and wanted to use more than 2 gigs? This scheme
would 
allow me to get around the search algorithm by using the following 
algorithm; pseudo-code:
__________________________________________________________________________
#define CACHE_LINE 128UL
#define PAGE_SIZE 4096UL
#define CHUNK_SIZE (PAGE_SIZE * 16UL)
#define RESERVE_SIZE 0xFFFFFFFFUL
#define LARGE_SIZE (RESERVE_SIZE / 2UL)


static unsigned char* reserved_mem = VirtualAlloc(RESERVE_SIZE);
static unsigned char* small_mem = reserved_mem;
static unsigned char* large_mem = small_mem + LARGE_SIZE;


struct header {
  struct header* next;
  struct header* prev;
  per_thread* thread;
  size_t size;
};


/* small chunks aligned on CHUNK_SIZE boundary! */
union chunk {
  struct header header;
  unsigned char pad[CACHE_LINE];
};


bool
is_mem_large(unsigned char* mem) {
  if (mem < large_mem) {
    return false;
  }
  return true;
}


union chunk*
chunk_from_mem(unsigned char* mem) {
  union chunk* chunk;
  if (! is_mem_large(mem)) {
    chunk = (union chunk*)
      ((ALIGN(mem, CHUNK_SIZE) - sizeof(union chunk))
  } else {
    chunk = (union chunk*)(mem - sizeof(union chunk);
  }
  return chunk;
}


void free(void* mem) {
  per_thread* const this_thread = pthread_getspecific(...);
  union chunk* const chunk = chunk_from_mem(mem);
  if (chunk->header.this.thread) {
    if (chunk->header.this.thread == this_thread) {
      per_thread_local_free(chunk, mem);
    } else {
      per_thread_remote_free(chunk, mem);
    }
  } else {
    global_free(chunk);
  }
}
__________________________________________________________________________



That would work fine, but it has limitations in that small chunks could
not 
be allocated from the large chunk pool and vise-versa. However, if I used 
the GUID search thing, then the entire reserved memory could be organized 
into adjacent chunks and both small and large allocations could use the
same 
pool. What am I missing here? I hope its not something ridiculously
simple!


Humm... Perhaps splitting the pool is not so bad. Humm...

;^/
 




 28 Posts in Topic:
supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 07:28:39 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 07:30:14 
Re: supporting header-less blocks in memory allocators...
Eric Sosman <Eric.Sosm  2008-10-02 10:55:36 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 10:17:04 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 14:47:48 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-02 08:41:31 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 09:29:16 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-02 11:00:02 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 11:50:57 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 11:55:02 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:20:25 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:30:51 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-02 12:00:46 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:30:09 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:38:26 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:48:45 
Re: supporting header-less blocks in memory allocators...
Michel Decima <michel.  2008-10-03 13:56:34 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-02 12:07:41 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-03 22:41:41 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-02 12:24:01 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:32:18 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:35:16 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-03 03:40:04 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-03 03:42:50 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-03 05:52:20 
Re: supporting header-less blocks in memory allocators...
Michel Decima <michel.  2008-10-03 15:28:13 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-03 22:19:59 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-06 00:02:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 9:42:36 CST 2008.