1 /* 2 * Copyright (c) 2010 Kip Macy All rights reserved. 3 * Copyright (C) 2017 THL A29 Limited, a Tencent company. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice, this 10 * list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 */ 27 28 29 #ifndef _FSTACK_VM_UMA_INT_H_ 30 #define _FSTACK_VM_UMA_INT_H_ 31 32 #include <sys/mutex.h> 33 #include <sys/sx.h> 34 35 #define vtoslab vtoslab_native 36 #define vtozoneslab vtozoneslab_native 37 #define vsetzoneslab vsetzoneslab_native 38 #include_next <vm/uma_int.h> 39 #undef vtoslab 40 #undef vtozoneslab 41 #undef vsetzoneslab 42 43 #undef UMA_MD_SMALL_ALLOC 44 45 #define critical_enter() do {} while(0) 46 #define critical_exit() do {} while(0) 47 48 #define sleepq_lock(w) do {} while(0) 49 #define sleepq_release(w) do {} while(0) 50 #define sleepq_add(a, b, c, d, e) do {} while(0) 51 #define sleepq_wait(w, p) do {} while(0) 52 53 #define _vm_map_unlock(sx, arg) do {} while(0) 54 55 extern int uma_page_mask; 56 57 extern int __read_mostly vm_ndomains; 58 59 #define UMA_PAGE_HASH(va) (((va) >> PAGE_SHIFT) & uma_page_mask) 60 61 typedef struct uma_page { 62 LIST_ENTRY(uma_page) list_entry; 63 vm_offset_t up_va; 64 uma_slab_t up_slab; 65 uma_zone_t up_zone; 66 } *uma_page_t; 67 68 LIST_HEAD(uma_page_head, uma_page); 69 extern struct uma_page_head *uma_page_slab_hash; 70 71 static __inline uma_slab_t 72 vtoslab(vm_offset_t va) 73 { 74 struct uma_page_head *hash_list; 75 uma_page_t up; 76 77 hash_list = &uma_page_slab_hash[UMA_PAGE_HASH(va)]; 78 LIST_FOREACH(up, hash_list, list_entry) 79 if (up->up_va == va) 80 return (up->up_slab); 81 return (NULL); 82 } 83 84 static __inline void 85 vtozoneslab(vm_offset_t va, uma_zone_t *zone, uma_slab_t *slab) 86 { 87 struct uma_page_head *hash_list; 88 uma_page_t up; 89 90 hash_list = &uma_page_slab_hash[UMA_PAGE_HASH(va)]; 91 LIST_FOREACH(up, hash_list, list_entry) 92 if (up->up_va == va) 93 break; 94 95 *slab = up->up_slab; 96 *zone = up->up_zone; 97 } 98 99 static __inline void 100 vsetzoneslab(vm_offset_t va, uma_zone_t zone, uma_slab_t slab) 101 { 102 struct uma_page_head *hash_list; 103 uma_page_t up; 104 hash_list = &uma_page_slab_hash[UMA_PAGE_HASH(va)]; 105 LIST_FOREACH(up, hash_list, list_entry) 106 if (up->up_va == va) 107 break; 108 109 if (up != NULL) { 110 up->up_slab = slab; 111 up->up_zone = zone; 112 return; 113 } 114 115 up = malloc(sizeof(*up), M_DEVBUF, M_WAITOK); 116 up->up_va = va; 117 up->up_slab = slab; 118 up->up_zone = zone; 119 LIST_INSERT_HEAD(hash_list, up, list_entry); 120 } 121 122 #endif /* _FSTACK_VM_UMA_INT_H_ */ 123