• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 #ifndef MM_SLAB_H
13 #define MM_SLAB_H
14 
15 #include <common/list.h>
16 
17 /*
18  * order range: [SLAB_MIN_ORDER, SLAB_MAX_ORDER]
19  * ChCore prepares the slab for each order in the range.
20  */
21 #define SLAB_MIN_ORDER (5)
22 #define SLAB_MAX_ORDER (11)
23 
24 /* The size of one slab is 256K. */
25 #define SIZE_OF_ONE_SLAB (256 * 1024)
26 
27 /* slab_header resides in the beginning of each slab (i.e., occupies the first slot). */
28 struct slab_header {
29     /* The list of free slots, which can be converted to struct slab_slot_list. */
30     void *free_list_head;
31     /* Partial slab list. */
32     struct list_head node;
33 
34     int order;
35     unsigned short total_free_cnt; /* MAX: 65536 */
36     unsigned short current_free_cnt;
37 };
38 
39 /* Each free slot in one slab is regarded as slab_slot_list. */
40 struct slab_slot_list {
41     void *next_free;
42 };
43 
44 struct slab_pointer {
45     struct slab_header *current_slab;
46     struct list_head partial_slab_list;
47 };
48 
49 /* All interfaces are kernel/mm module internal interfaces. */
50 void init_slab(void);
51 void *alloc_in_slab(unsigned long, size_t *);
52 void free_in_slab(void *addr);
53 unsigned long get_free_mem_size_from_slab(void);
54 
55 #endif /* MM_SLAB_H */