plan 9 kernel history: overview | file list | diff list

1992/0621/port/alloc.c (diff list | history)

1992/0620/sys/src/9/port/alloc.c:4,121992/0621/sys/src/9/port/alloc.c:4,21 (short | long | prev | next)
1992/0618    
#include	"dat.h" 
#include	"fns.h" 
 
1992/0621    
/* 
 * Plan 9 has two kernel allocators, the x... routines provide a first 
 * fit hole allocator which should be used for permanent or large structures. 
 * Routines are provided to allocate aligned memory which does not cross 
 * arbitrary 2^n boundaries. A second allocator malloc, smalloc, free is 
 * a 2n bucket allocator which steals from the x routines. This should 
 * be used for small frequently used structures. 
 */ 
 
1992/0619    
#define	nil		((void*)0) 
#define datoff		((ulong)&((Xhdr*)0)->data) 
#define bdatoff		((ulong)&((Bucket*)0)->data) 
1992/0621    
#define datoff		((ulong)((Xhdr*)0)->data) 
#define bdatoff		((ulong)((Bucket*)0)->data) 
1992/0619    
 
1992/0618    
enum 
{ 
1992/0620/sys/src/9/port/alloc.c:14,191992/0621/sys/src/9/port/alloc.c:23,29
1992/0619    
	Nhole		= 128, 
	Magichole	= 0xDeadBabe, 
1992/0620    
	Magic2n		= 0xFeedBeef, 
1992/0621    
	Spanlist	= 64, 
1992/0618    
}; 
 
typedef struct Hole Hole; 
1992/0620/sys/src/9/port/alloc.c:75,901992/0621/sys/src/9/port/alloc.c:85,93
1992/0619    
		p &= ~(BY2PG-1); 
		return (void*)p; 
	} 
                 
	return xalloc(size); 
1992/0621    
	return xalloc(size);; 
1992/0619    
} 
 
void* 
iallocspan(ulong size, int quanta, ulong span) 
{ 
	return ialloc(size, quanta); 
} 
                 
1992/0618    
void 
xinit(void) 
{ 
1992/0620/sys/src/9/port/alloc.c:125,1301992/0621/sys/src/9/port/alloc.c:128,163
1992/0619    
 
	palloc.np0 = np0; 
	palloc.np1 = np1; 
1992/0621    
} 
 
/* 
 * NB. spanalloc memory will cause a panic if free'd 
 */ 
void* 
xspanalloc(ulong size, int align, ulong span) 
{ 
	int i, j; 
	ulong a, p; 
	ulong ptr[Spanlist]; 
 
	span = ~(span-1); 
	for(i = 0; i < Spanlist; i++) { 
		p = (ulong)xalloc(size+align); 
		if(p == 0) 
			panic("xspanalloc: size %d align %d span %d", size, align, span); 
 
		a = p+align; 
		a &= ~(align-1); 
		if((a&span) == ((a+size)&span)) { 
			for(j = 0; j < i; j++) 
				xfree((void*)ptr[j]); 
 
			return (void*)a; 
		} 
		ptr[i] = p; 
	} 
	panic("xspanalloc: spanlist");		 
	return 0; 
1992/0618    
} 
 
void* 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)