| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: subr_vmem.c,v 1.115 2023/12/03 19:34:08 thorpej Exp $ */ | | 1 | /* $NetBSD: subr_vmem.c,v 1.116 2024/04/24 02:08:03 thorpej Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c)2006,2007,2008,2009 YAMAMOTO Takashi, | | 4 | * Copyright (c)2006,2007,2008,2009 YAMAMOTO Takashi, |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -36,27 +36,27 @@ | | | @@ -36,27 +36,27 @@ |
36 | * - A pool(9) is used for vmem boundary tags | | 36 | * - A pool(9) is used for vmem boundary tags |
37 | * - During a pool get call the global vmem_btag_refill_lock is taken, | | 37 | * - During a pool get call the global vmem_btag_refill_lock is taken, |
38 | * to serialize access to the allocation reserve, but no other | | 38 | * to serialize access to the allocation reserve, but no other |
39 | * vmem arena locks. | | 39 | * vmem arena locks. |
40 | * - During pool_put calls no vmem mutexes are locked. | | 40 | * - During pool_put calls no vmem mutexes are locked. |
41 | * - pool_drain doesn't hold the pool's mutex while releasing memory to | | 41 | * - pool_drain doesn't hold the pool's mutex while releasing memory to |
42 | * its backing therefore no interference with any vmem mutexes. | | 42 | * its backing therefore no interference with any vmem mutexes. |
43 | * - The boundary tag pool is forced to put page headers into pool pages | | 43 | * - The boundary tag pool is forced to put page headers into pool pages |
44 | * (PR_PHINPAGE) and not off page to avoid pool recursion. | | 44 | * (PR_PHINPAGE) and not off page to avoid pool recursion. |
45 | * (due to sizeof(bt_t) it should be the case anyway) | | 45 | * (due to sizeof(bt_t) it should be the case anyway) |
46 | */ | | 46 | */ |
47 | | | 47 | |
48 | #include <sys/cdefs.h> | | 48 | #include <sys/cdefs.h> |
49 | __KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.115 2023/12/03 19:34:08 thorpej Exp $"); | | 49 | __KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.116 2024/04/24 02:08:03 thorpej Exp $"); |
50 | | | 50 | |
51 | #if defined(_KERNEL) && defined(_KERNEL_OPT) | | 51 | #if defined(_KERNEL) && defined(_KERNEL_OPT) |
52 | #include "opt_ddb.h" | | 52 | #include "opt_ddb.h" |
53 | #endif /* defined(_KERNEL) && defined(_KERNEL_OPT) */ | | 53 | #endif /* defined(_KERNEL) && defined(_KERNEL_OPT) */ |
54 | | | 54 | |
55 | #include <sys/param.h> | | 55 | #include <sys/param.h> |
56 | #include <sys/hash.h> | | 56 | #include <sys/hash.h> |
57 | #include <sys/queue.h> | | 57 | #include <sys/queue.h> |
58 | #include <sys/bitops.h> | | 58 | #include <sys/bitops.h> |
59 | | | 59 | |
60 | #if defined(_KERNEL) | | 60 | #if defined(_KERNEL) |
61 | #include <sys/systm.h> | | 61 | #include <sys/systm.h> |
62 | #include <sys/kernel.h> /* hz */ | | 62 | #include <sys/kernel.h> /* hz */ |
| @@ -961,26 +961,34 @@ vmem_fit(const bt_t *bt, vmem_size_t siz | | | @@ -961,26 +961,34 @@ vmem_fit(const bt_t *bt, vmem_size_t siz |
961 | */ | | 961 | */ |
962 | | | 962 | |
963 | vmem_t * | | 963 | vmem_t * |
964 | vmem_init(vmem_t *vm, const char *name, | | 964 | vmem_init(vmem_t *vm, const char *name, |
965 | vmem_addr_t base, vmem_size_t size, vmem_size_t quantum, | | 965 | vmem_addr_t base, vmem_size_t size, vmem_size_t quantum, |
966 | vmem_import_t *importfn, vmem_release_t *releasefn, | | 966 | vmem_import_t *importfn, vmem_release_t *releasefn, |
967 | vmem_t *arg, vmem_size_t qcache_max, vm_flag_t flags, int ipl) | | 967 | vmem_t *arg, vmem_size_t qcache_max, vm_flag_t flags, int ipl) |
968 | { | | 968 | { |
969 | int i; | | 969 | int i; |
970 | | | 970 | |
971 | KASSERT((flags & (VM_SLEEP|VM_NOSLEEP)) != 0); | | 971 | KASSERT((flags & (VM_SLEEP|VM_NOSLEEP)) != 0); |
972 | KASSERT((~flags & (VM_SLEEP|VM_NOSLEEP)) != 0); | | 972 | KASSERT((~flags & (VM_SLEEP|VM_NOSLEEP)) != 0); |
973 | KASSERT(quantum > 0); | | 973 | KASSERT(quantum > 0); |
| | | 974 | KASSERT(powerof2(quantum)); |
| | | 975 | |
| | | 976 | /* |
| | | 977 | * If private tags are going to be used, they must |
| | | 978 | * be added to the arena before the first span is |
| | | 979 | * added. |
| | | 980 | */ |
| | | 981 | KASSERT((flags & VM_PRIVTAGS) == 0 || size == 0); |
974 | | | 982 | |
975 | #if defined(_KERNEL) | | 983 | #if defined(_KERNEL) |
976 | /* XXX: SMP, we get called early... */ | | 984 | /* XXX: SMP, we get called early... */ |
977 | if (!vmem_bootstrapped) { | | 985 | if (!vmem_bootstrapped) { |
978 | vmem_bootstrap(); | | 986 | vmem_bootstrap(); |
979 | } | | 987 | } |
980 | #endif /* defined(_KERNEL) */ | | 988 | #endif /* defined(_KERNEL) */ |
981 | | | 989 | |
982 | if (vm == NULL) { | | 990 | if (vm == NULL) { |
983 | vm = xmalloc(sizeof(*vm), flags); | | 991 | vm = xmalloc(sizeof(*vm), flags); |
984 | } | | 992 | } |
985 | if (vm == NULL) { | | 993 | if (vm == NULL) { |
986 | return NULL; | | 994 | return NULL; |