xref: /f-stack/lib/include/vm/uma_int.h (revision a9643ea8)
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 
34 #define vtoslab   vtoslab_native
35 #define vsetslab  vsetslab_native
36 #include_next <vm/uma_int.h>
37 #undef vtoslab
38 #undef vsetslab
39 
40 #undef UMA_MD_SMALL_ALLOC
41 
42 #define critical_enter() do {} while(0)
43 #define critical_exit()  do {} while(0)
44 
45 extern int uma_page_mask;
46 
47 #define UMA_PAGE_HASH(va) (((va) >> PAGE_SHIFT) & uma_page_mask)
48 
49 typedef struct uma_page {
50     LIST_ENTRY(uma_page) list_entry;
51     vm_offset_t up_va;
52     uma_slab_t up_slab;
53 } *uma_page_t;
54 
55 LIST_HEAD(uma_page_head, uma_page);
56 extern struct uma_page_head *uma_page_slab_hash;
57 
58 static __inline uma_slab_t
59 vtoslab(vm_offset_t va)
60 {
61     struct uma_page_head *hash_list;
62     uma_page_t up;
63 
64     hash_list = &uma_page_slab_hash[UMA_PAGE_HASH(va)];
65     LIST_FOREACH(up, hash_list, list_entry)
66             if (up->up_va == va)
67                     return (up->up_slab);
68     return (NULL);
69 }
70 
71 static __inline void
72 vsetslab(vm_offset_t va, uma_slab_t slab)
73 {
74     struct uma_page_head *hash_list;
75     uma_page_t up;
76     hash_list = &uma_page_slab_hash[UMA_PAGE_HASH(va)];
77     LIST_FOREACH(up, hash_list, list_entry)
78         if (up->up_va == va)
79             break;
80 
81     if (up != NULL) {
82         up->up_slab = slab;
83         return;
84     }
85 
86     up = malloc(sizeof(*up), M_DEVBUF, M_WAITOK);
87     up->up_va = va;
88     up->up_slab = slab;
89     LIST_INSERT_HEAD(hash_list, up, list_entry);
90 }
91 
92 #endif    /* _FSTACK_VM_UMA_INT_H_ */
93