FreeBSD/sys/kern/subr_pcpu.c
/*
 * First-fit extent based allocator for allocating space in the per-cpu
 * region reserved for modules.  This is only intended for use by the
 * kernel linkers to place module linker sets.
 */
First-fit extent based allocator for allocating space in the per-cpu
region reserved for modules.  This is only intended for use by the
kernel linkers to place module linker sets.
First - fit extent based allocator for allocating space in the per - cpu region reserved for modules . This is only intended for use by the kernel linkers to place module linker sets .
void *
dpcpu_alloc(int size)
{
	struct dpcpu_free *df;
	void *s;
	s = NULL;
	size = roundup2(size, sizeof(void *));
	sx_xlock(&dpcpu_lock);
	TAILQ_FOREACH(df, &dpcpu_head, df_link) {
		if (df->df_len < size)
			continue;
		if (df->df_len == size) {
			s = (void *)df->df_start;
			TAILQ_REMOVE(&dpcpu_head, df, df_link);
			free(df, M_PCPU);
			break;
		}
		s = (void *)df->df_start;
		df->df_len -= size;
		df->df_start = df->df_start + size;
		break;
	}
	sx_xunlock(&dpcpu_lock);
	return (s);
}
void * dpcpu_alloc ( int size ) { struct dpcpu_free * df ; void * s ; s = NULL ; size = roundup2 ( size , sizeof ( void * ) ) ; sx_xlock ( & dpcpu_lock ) ; TAILQ_FOREACH ( df , & dpcpu_head , df_link ) { if ( df -> df_len < size ) continue ; if ( df -> df_len == size ) { s = ( void * ) df -> df_start ; TAILQ_REMOVE ( & dpcpu_head , df , df_link ) ; free ( df , M_PCPU ) ; break ; } s = ( void * ) df -> df_start ; df -> df_len -= size ; df -> df_start = df -> df_start + size ; break ; } sx_xunlock ( & dpcpu_lock ) ; return ( s ) ; }
First-fit extent based allocator for allocating space in the per-cpu
 region reserved for modules.
First - fit extent based allocator for allocating space in the per - cpu region reserved for modules .