author | Joshua M. Clulow <jmc@joyent.com> |
Mon, 04 Mar 2013 23:52:56 +0000 | |
changeset 14188 | afe390b9f1e0 |
parent 14028 | bcbb822da4dd |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
6712
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
5 |
* Common Development and Distribution License (the "License"). |
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
6 |
* You may not use this file except in compliance with the License. |
0 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
6712
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
21 |
|
0 | 22 |
/* |
12093
fa0c0f5bf466
6538954 kmem_cache_alloc() doesn't scale for anon structure allocations when cache magazines are empty
David Valin <David.Valin@Sun.COM>
parents:
11178
diff
changeset
|
23 |
* Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. |
14028
bcbb822da4dd
3630 NFS server should not allocate oversized buffers
Sebastien Roy <seb@delphix.com>
parents:
12684
diff
changeset
|
24 |
* Copyright (c) 2012 by Delphix. All rights reserved. |
0 | 25 |
*/ |
26 |
||
27 |
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ |
|
28 |
/* All Rights Reserved */ |
|
29 |
||
30 |
#ifndef _SYS_KMEM_H |
|
31 |
#define _SYS_KMEM_H |
|
32 |
||
33 |
#include <sys/types.h> |
|
34 |
#include <sys/vmem.h> |
|
35 |
||
36 |
#ifdef __cplusplus |
|
37 |
extern "C" { |
|
38 |
#endif |
|
39 |
||
40 |
/* |
|
41 |
* Kernel memory allocator: DDI interfaces. |
|
42 |
* See kmem_alloc(9F) for details. |
|
43 |
*/ |
|
44 |
||
45 |
#define KM_SLEEP 0x0000 /* can block for memory; success guaranteed */ |
|
46 |
#define KM_NOSLEEP 0x0001 /* cannot block for memory; may fail */ |
|
47 |
#define KM_PANIC 0x0002 /* if memory cannot be allocated, panic */ |
|
48 |
#define KM_PUSHPAGE 0x0004 /* can block for memory; may use reserve */ |
|
12156
3c537b2a7425
6675738 KM_NOSLEEP may still try too hard for some allocations
Stan Studzinski <Stan.Studzinski@Sun.COM>
parents:
12093
diff
changeset
|
49 |
#define KM_NORMALPRI 0x0008 /* with KM_NOSLEEP, lower priority allocation */ |
0 | 50 |
#define KM_VMFLAGS 0x00ff /* flags that must match VM_* flags */ |
51 |
||
52 |
#define KM_FLAGS 0xffff /* all settable kmem flags */ |
|
53 |
||
54 |
#ifdef _KERNEL |
|
55 |
||
56 |
extern void *kmem_alloc(size_t size, int kmflags); |
|
57 |
extern void *kmem_zalloc(size_t size, int kmflags); |
|
58 |
extern void kmem_free(void *buf, size_t size); |
|
59 |
extern void *kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags); |
|
11178
d671c0911ce4
6898505 kmem_verify oddities around Fast Crash Dump integration
Dave Plauger <Dave.Plauger@Sun.COM>
parents:
6712
diff
changeset
|
60 |
extern void kmem_dump_init(size_t); |
d671c0911ce4
6898505 kmem_verify oddities around Fast Crash Dump integration
Dave Plauger <Dave.Plauger@Sun.COM>
parents:
6712
diff
changeset
|
61 |
extern void kmem_dump_begin(void); |
d671c0911ce4
6898505 kmem_verify oddities around Fast Crash Dump integration
Dave Plauger <Dave.Plauger@Sun.COM>
parents:
6712
diff
changeset
|
62 |
extern size_t kmem_dump_finish(char *buf, size_t size); |
0 | 63 |
|
64 |
#endif /* _KERNEL */ |
|
65 |
||
66 |
/* |
|
67 |
* Kernel memory allocator: private interfaces. |
|
68 |
* These interfaces are still evolving. |
|
69 |
* Do not use them in unbundled drivers. |
|
70 |
*/ |
|
71 |
||
72 |
/* |
|
73 |
* Flags for kmem_cache_create() |
|
74 |
*/ |
|
75 |
#define KMC_NOTOUCH 0x00010000 |
|
76 |
#define KMC_NODEBUG 0x00020000 |
|
77 |
#define KMC_NOMAGAZINE 0x00040000 |
|
78 |
#define KMC_NOHASH 0x00080000 |
|
79 |
#define KMC_QCACHE 0x00100000 |
|
80 |
#define KMC_KMEM_ALLOC 0x00200000 /* internal use only */ |
|
81 |
#define KMC_IDENTIFIER 0x00400000 /* internal use only */ |
|
12093
fa0c0f5bf466
6538954 kmem_cache_alloc() doesn't scale for anon structure allocations when cache magazines are empty
David Valin <David.Valin@Sun.COM>
parents:
11178
diff
changeset
|
82 |
#define KMC_PREFILL 0x00800000 |
0 | 83 |
|
84 |
struct kmem_cache; /* cache structure is opaque to kmem clients */ |
|
85 |
||
86 |
typedef struct kmem_cache kmem_cache_t; |
|
87 |
||
6712
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
88 |
/* Client response to kmem move callback */ |
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
89 |
typedef enum kmem_cbrc { |
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
90 |
KMEM_CBRC_YES, |
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
91 |
KMEM_CBRC_NO, |
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
92 |
KMEM_CBRC_LATER, |
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
93 |
KMEM_CBRC_DONT_NEED, |
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
94 |
KMEM_CBRC_DONT_KNOW |
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
95 |
} kmem_cbrc_t; |
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
96 |
|
0 | 97 |
#ifdef _KERNEL |
98 |
||
12684
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12156
diff
changeset
|
99 |
/* |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12156
diff
changeset
|
100 |
* Helps clients implementing the move() callback to recognize known objects by |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12156
diff
changeset
|
101 |
* testing a client-designated pointer member. Takes advantage of the fact that |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12156
diff
changeset
|
102 |
* any scribbling to freed memory done by kmem is guaranteed to set one of the |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12156
diff
changeset
|
103 |
* two low order bits. |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12156
diff
changeset
|
104 |
*/ |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12156
diff
changeset
|
105 |
#define POINTER_IS_VALID(p) (!((uintptr_t)(p) & 0x3)) |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12156
diff
changeset
|
106 |
#define POINTER_INVALIDATE(pp) (*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1)) |
397e44ebb8a9
6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12156
diff
changeset
|
107 |
|
0 | 108 |
extern int kmem_ready; |
109 |
extern pgcnt_t kmem_reapahead; |
|
14028
bcbb822da4dd
3630 NFS server should not allocate oversized buffers
Sebastien Roy <seb@delphix.com>
parents:
12684
diff
changeset
|
110 |
extern size_t kmem_max_cached; |
0 | 111 |
|
112 |
extern void kmem_init(void); |
|
113 |
extern void kmem_thread_init(void); |
|
114 |
extern void kmem_mp_init(void); |
|
115 |
extern void kmem_reap(void); |
|
116 |
extern void kmem_reap_idspace(void); |
|
789 | 117 |
extern int kmem_debugging(void); |
0 | 118 |
extern size_t kmem_avail(void); |
119 |
extern size_t kmem_maxavail(void); |
|
120 |
||
121 |
extern kmem_cache_t *kmem_cache_create(char *, size_t, size_t, |
|
122 |
int (*)(void *, void *, int), void (*)(void *, void *), |
|
123 |
void (*)(void *), void *, vmem_t *, int); |
|
6712
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
124 |
extern void kmem_cache_set_move(kmem_cache_t *, |
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
125 |
kmem_cbrc_t (*)(void *, void *, size_t, void *)); |
0 | 126 |
extern void kmem_cache_destroy(kmem_cache_t *); |
127 |
extern void *kmem_cache_alloc(kmem_cache_t *, int); |
|
128 |
extern void kmem_cache_free(kmem_cache_t *, void *); |
|
129 |
extern uint64_t kmem_cache_stat(kmem_cache_t *, char *); |
|
789 | 130 |
extern void kmem_cache_reap_now(kmem_cache_t *); |
6712
79afecec3f3c
6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents:
789
diff
changeset
|
131 |
extern void kmem_cache_move_notify(kmem_cache_t *, void *); |
0 | 132 |
|
133 |
#endif /* _KERNEL */ |
|
134 |
||
135 |
#ifdef __cplusplus |
|
136 |
} |
|
137 |
#endif |
|
138 |
||
139 |
#endif /* _SYS_KMEM_H */ |