4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
35 #include <fmd_alloc.h>
37 #include <fmd_module.h>
38 #include <fmd_scheme.h>
42 fmd_alloc(size_t size
, int flags
)
44 void *data
= umem_alloc(size
, UMEM_DEFAULT
);
45 uint_t
try, lim
, msecs
;
47 if (data
!= NULL
|| size
== 0 || !(flags
& FMD_SLEEP
))
48 return (data
); /* in common cases just return result */
50 lim
= fmd
.d_alloc_tries
;
51 msecs
= fmd
.d_alloc_msecs
;
53 for (try = 0; data
== NULL
&& try < lim
; try++) {
54 (void) poll(NULL
, 0, msecs
);
56 data
= umem_alloc(size
, UMEM_DEFAULT
);
60 fmd_modhash_tryapply(fmd
.d_mod_hash
, fmd_module_trygc
);
61 fmd_scheme_hash_trygc(fmd
.d_schemes
);
62 data
= umem_alloc(size
, UMEM_DEFAULT
);
66 fmd_panic("insufficient memory (%u bytes needed)\n", size
);
72 fmd_zalloc(size_t size
, int flags
)
74 void *data
= fmd_alloc(size
, flags
);
83 fmd_free(void *data
, size_t size
)
85 umem_free(data
, size
);