xref: /dragonfly/sys/vm/vm_zone.h (revision 3d33658b)
1 /*
2  * Copyright (c) 1997, 1998 John S. Dyson
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *	notice immediately at the beginning of the file, without modification,
10  *	this list of conditions, and the following disclaimer.
11  * 2. Absolutely no warranty of function or purpose is made by the author
12  *	John S. Dyson.
13  *
14  * $FreeBSD: src/sys/vm/vm_zone.h,v 1.13.2.2 2002/10/10 19:50:16 dillon Exp $
15  * $DragonFly: src/sys/vm/vm_zone.h,v 1.10 2008/01/21 20:21:19 nth Exp $
16  */
17 
18 #ifndef _VM_VM_ZONE_H_
19 #define _VM_VM_ZONE_H_
20 
21 #define ZONE_INTERRUPT 0x0001	/* If you need to allocate at int time */
22 #define ZONE_PANICFAIL 0x0002	/* panic if the zalloc fails */
23 #define ZONE_SPECIAL   0x0004	/* special vm_map_entry zone, see zget() */
24 #define ZONE_BOOT      0x0010	/* Internal flag used by zbootinit */
25 #define ZONE_USE_RESERVE 0x0020	/* use reserve memory if necessary */
26 #define ZONE_DESTROYABLE 0x0040 /* can be zdestroy()'ed */
27 
28 #define ZONE_MAXPGLOAD	32	/* max VM pages burst in zget() */
29 
30 #include <sys/spinlock.h>
31 #include <sys/thread.h>
32 
33 /*
34  * Zone allocator.
35  * Zones are deprecated, use <sys/objcache.h> instead for new developments.
36  * Zones are not thread-safe; the mp lock must be held while calling
37  * zone functions.
38  */
39 struct vm_zpcpu {
40 	void	*zitems;
41 	long	zfreecnt;
42 	long	znalloc;		/* allocations from pcpu */
43 } __cachealign;
44 
45 typedef struct vm_zpcpu vm_zpcpu_t;
46 
47 typedef struct vm_zone {
48 	vm_zpcpu_t	zpcpu[SMP_MAXCPU];
49 	struct spinlock zspin;		/* lock for global portion */
50 	void		*zitems;	/* linked list of items */
51 	long		zfreecnt;	/* free entries */
52 	long		zfreemin;	/* minimum number of free entries */
53 	long		znalloc;	/* allocations from global */
54 	vm_offset_t	zkva;		/* Base kva of zone */
55 	vm_pindex_t	zpagecount;	/* Total # of allocated pages */
56 	vm_pindex_t	zpagemax;	/* Max address space */
57 	long		zmax;		/* Max number of entries allocated */
58 	long		zmax_pcpu;	/* Max pcpu cache */
59 	long		ztotal;		/* Total entries allocated now */
60 	long		zsize;		/* size of each entry */
61 	long		zalloc;		/* hint for # of pages to alloc */
62 	long		zflags;		/* flags for zone */
63 	uint32_t	zallocflag;	/* flag for allocation */
64 	char		*zname;		/* name for diags */
65 	LIST_ENTRY(vm_zone) zlink;	/* link in zlist */
66 
67  	/*
68  	 * The following fields track kmem_alloc()'ed blocks when
69  	 * ZONE_DESTROYABLE set and normal zone (i.e. not ZONE_INTERRUPT nor
70  	 * ZONE_SPECIAL).
71  	 */
72  	vm_offset_t	*zkmvec;	/* krealloc()'ed array */
73 	long		zkmcur;		/* next free slot in zkmvec */
74 	long		zkmmax;		/* # of slots in zkmvec */
75 } *vm_zone_t;
76 
77 
78 void		zerror (int) __dead2;
79 vm_zone_t	zinit (char *name, size_t size, long nentries, uint32_t flags);
80 int		zinitna (vm_zone_t z, char *name,
81 			     size_t size, long nentries, uint32_t flags);
82 void *		zalloc (vm_zone_t z);
83 void		zfree (vm_zone_t z, void *item);
84 void		zbootinit (vm_zone_t z, char *name, size_t size, void *item,
85 			       long nitems);
86 void		zdestroy(vm_zone_t z);
87 
88 #endif	/* _VM_VM_ZONE_H_ */
89