1997-08-05 22:24:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1997 John S. Dyson
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice immediately at the beginning of the file, without modification,
|
|
|
|
* this list of conditions, and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Absolutely no warranty of function or purpose is made by the author
|
|
|
|
* John S. Dyson.
|
|
|
|
* 4. This work was done expressly for inclusion into FreeBSD. Other use
|
|
|
|
* is allowed if this notation is included.
|
|
|
|
* 5. Modifications may be freely made to this file if the above conditions
|
|
|
|
* are met.
|
|
|
|
*
|
1997-12-14 05:17:44 +00:00
|
|
|
* $Id: vm_zone.h,v 1.8 1997/12/05 19:55:52 bde Exp $
|
1997-08-05 22:24:31 +00:00
|
|
|
*/
|
|
|
|
|
1997-08-05 00:07:31 +00:00
|
|
|
#if !defined(_SYS_ZONE_H)
|
|
|
|
|
|
|
|
#define _SYS_ZONE_H
|
|
|
|
|
1997-09-21 11:41:12 +00:00
|
|
|
#define ZONE_INTERRUPT 1 /* Use this if you need to allocate at int time */
|
|
|
|
#define ZONE_BOOT 16 /* This is an internal flag used by zbootinit */
|
1997-08-05 00:07:31 +00:00
|
|
|
|
1997-12-05 19:55:52 +00:00
|
|
|
#include <machine/lock.h>
|
1997-08-05 00:07:31 +00:00
|
|
|
|
|
|
|
typedef struct vm_zone {
|
1997-09-21 11:41:12 +00:00
|
|
|
struct simplelock zlock; /* lock for data structure */
|
|
|
|
void *zitems; /* linked list of items */
|
|
|
|
int zfreecnt; /* free entries */
|
|
|
|
int zfreemin; /* minimum number of free entries */
|
|
|
|
int znalloc; /* number of allocations */
|
|
|
|
vm_offset_t zkva; /* Base kva of zone */
|
|
|
|
int zpagecount; /* Total # of allocated pages */
|
|
|
|
int zpagemax; /* Max address space */
|
|
|
|
int zmax; /* Max number of entries allocated */
|
|
|
|
int ztotal; /* Total entries allocated now */
|
|
|
|
int zsize; /* size of each entry */
|
|
|
|
int zalloc; /* hint for # of pages to alloc */
|
|
|
|
int zflags; /* flags for zone */
|
|
|
|
int zallocflag; /* flag for allocation */
|
|
|
|
struct vm_object *zobj; /* object to hold zone */
|
|
|
|
char *zname; /* name for diags */
|
|
|
|
struct vm_zone *znext; /* list of zones for sysctl */
|
1997-08-05 00:07:31 +00:00
|
|
|
} *vm_zone_t;
|
|
|
|
|
|
|
|
|
1997-09-21 11:41:12 +00:00
|
|
|
void zerror __P((int)) __dead2;
|
|
|
|
vm_zone_t zinit __P((char *name, int size, int nentries, int flags,
|
|
|
|
int zalloc));
|
|
|
|
int zinitna __P((vm_zone_t z, struct vm_object *obj, char *name,
|
|
|
|
int size, int nentries, int flags, int zalloc));
|
|
|
|
static void * zalloc __P((vm_zone_t z));
|
|
|
|
static void zfree __P((vm_zone_t z, void *item));
|
|
|
|
void * zalloci __P((vm_zone_t z));
|
|
|
|
void zfreei __P((vm_zone_t z, void *item));
|
|
|
|
void zbootinit __P((vm_zone_t z, char *name, int size, void *item,
|
|
|
|
int nitems));
|
|
|
|
void * _zget __P((vm_zone_t z));
|
1997-08-05 22:24:31 +00:00
|
|
|
|
1997-09-21 04:24:27 +00:00
|
|
|
#define ZONE_ERROR_INVALID 0
|
|
|
|
#define ZONE_ERROR_NOTFREE 1
|
|
|
|
#define ZONE_ERROR_ALREADYFREE 2
|
|
|
|
|
1997-12-14 05:17:44 +00:00
|
|
|
#define ZONE_ROUNDING 32
|
1997-09-21 04:24:27 +00:00
|
|
|
|
|
|
|
#define ZENTRY_FREE 0x12342378
|
1997-08-05 22:24:31 +00:00
|
|
|
/*
|
|
|
|
* void *zalloc(vm_zone_t zone) --
|
|
|
|
* Returns an item from a specified zone.
|
|
|
|
*
|
|
|
|
* void zfree(vm_zone_t zone, void *item) --
|
|
|
|
* Frees an item back to a specified zone.
|
|
|
|
*/
|
1997-08-05 00:07:31 +00:00
|
|
|
static __inline__ void *
|
1997-09-21 11:41:12 +00:00
|
|
|
_zalloc(vm_zone_t z)
|
|
|
|
{
|
1997-08-05 00:07:31 +00:00
|
|
|
void *item;
|
|
|
|
|
1997-09-21 04:24:27 +00:00
|
|
|
#if defined(DIAGNOSTIC)
|
|
|
|
if (z == 0)
|
|
|
|
zerror(ZONE_ERROR_INVALID);
|
|
|
|
#endif
|
|
|
|
|
1997-09-21 11:41:12 +00:00
|
|
|
if (z->zfreecnt <= z->zfreemin)
|
1997-08-05 22:24:31 +00:00
|
|
|
return _zget(z);
|
1997-09-21 11:41:12 +00:00
|
|
|
|
1997-08-05 00:07:31 +00:00
|
|
|
item = z->zitems;
|
1997-09-21 04:24:27 +00:00
|
|
|
z->zitems = ((void **) item)[0];
|
|
|
|
#if defined(DIAGNOSTIC)
|
|
|
|
if (((void **) item)[1] != (void *) ZENTRY_FREE)
|
|
|
|
zerror(ZONE_ERROR_NOTFREE);
|
|
|
|
((void **) item)[1] = 0;
|
|
|
|
#endif
|
1997-09-21 11:41:12 +00:00
|
|
|
|
1997-08-05 22:24:31 +00:00
|
|
|
z->zfreecnt--;
|
1997-08-07 03:52:55 +00:00
|
|
|
z->znalloc++;
|
1997-08-05 00:07:31 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ void
|
1997-09-21 11:41:12 +00:00
|
|
|
_zfree(vm_zone_t z, void *item)
|
|
|
|
{
|
1997-09-21 04:24:27 +00:00
|
|
|
((void **) item)[0] = z->zitems;
|
|
|
|
#if defined(DIAGNOSTIC)
|
1997-09-21 11:41:12 +00:00
|
|
|
if (((void **) item)[1] == (void *) ZENTRY_FREE)
|
1997-09-21 04:24:27 +00:00
|
|
|
zerror(ZONE_ERROR_ALREADYFREE);
|
|
|
|
((void **) item)[1] = (void *) ZENTRY_FREE;
|
|
|
|
#endif
|
1997-08-05 00:07:31 +00:00
|
|
|
z->zitems = item;
|
1997-08-05 22:24:31 +00:00
|
|
|
z->zfreecnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ void *
|
1997-09-21 11:41:12 +00:00
|
|
|
zalloc(vm_zone_t z)
|
|
|
|
{
|
1997-09-21 04:24:27 +00:00
|
|
|
#if defined(SMP)
|
1997-08-05 22:24:31 +00:00
|
|
|
return zalloci(z);
|
|
|
|
#else
|
|
|
|
return _zalloc(z);
|
|
|
|
#endif
|
1997-08-05 00:07:31 +00:00
|
|
|
}
|
1997-08-05 22:24:31 +00:00
|
|
|
|
|
|
|
static __inline__ void
|
1997-09-21 11:41:12 +00:00
|
|
|
zfree(vm_zone_t z, void *item)
|
|
|
|
{
|
1997-09-21 04:24:27 +00:00
|
|
|
#if defined(SMP)
|
1997-08-05 22:24:31 +00:00
|
|
|
zfreei(z, item);
|
|
|
|
#else
|
|
|
|
_zfree(z, item);
|
1997-08-05 00:07:31 +00:00
|
|
|
#endif
|
1997-08-05 22:24:31 +00:00
|
|
|
}
|
1997-08-05 00:07:31 +00:00
|
|
|
|
|
|
|
#endif
|