2 * xvmalloc memory allocator
4 * Copyright (C) 2008, 2009, 2010 Nitin Gupta
6 * This code is released using a dual license strategy: BSD/GPL
7 * You can choose the licence that better fits your requirements.
9 * Released under the terms of 3-clause BSD License
10 * Released under the terms of GNU General Public License Version 2.0
13 #ifndef _XV_MALLOC_INT_H_
14 #define _XV_MALLOC_INT_H_
16 #include <linux/kernel.h>
17 #include <linux/types.h>
19 /* User configurable params */
21 /* Must be power of two */
23 #define XV_ALIGN_SHIFT 3
25 #define XV_ALIGN_SHIFT 2
27 #define XV_ALIGN (1 << XV_ALIGN_SHIFT)
28 #define XV_ALIGN_MASK (XV_ALIGN - 1)
30 /* This must be greater than sizeof(link_free) */
31 #define XV_MIN_ALLOC_SIZE 32
32 #define XV_MAX_ALLOC_SIZE (PAGE_SIZE - XV_ALIGN)
35 * Free lists are separated by FL_DELTA bytes
36 * This value is 3 for 4k pages and 4 for 64k pages, for any
37 * other page size, a conservative (PAGE_SHIFT - 9) is used.
40 #define FL_DELTA_SHIFT 4
42 #define FL_DELTA_SHIFT (PAGE_SHIFT - 9)
44 #define FL_DELTA (1 << FL_DELTA_SHIFT)
45 #define FL_DELTA_MASK (FL_DELTA - 1)
46 #define NUM_FREE_LISTS ((XV_MAX_ALLOC_SIZE - XV_MIN_ALLOC_SIZE) \
49 #define MAX_FLI DIV_ROUND_UP(NUM_FREE_LISTS, BITS_PER_LONG)
51 /* End of user params */
59 #define FLAGS_MASK XV_ALIGN_MASK
60 #define PREV_MASK (~FLAGS_MASK)
62 struct freelist_entry
{
69 struct page
*prev_page
;
70 struct page
*next_page
;
77 /* This common header must be XV_ALIGN bytes */
84 struct link_free link
;
89 ulong slbitmap
[MAX_FLI
];
90 u64 total_pages
; /* stats */
91 struct freelist_entry freelist
[NUM_FREE_LISTS
];