1/*- 2 * Copyright (c) 2013 Antti Kantee. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 14 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26#ifndef _BMK_CORE_MEMALLOC_H_ 27#define _BMK_CORE_MEMALLOC_H_ 28 29/* 30 * Allocator levels/priorities/somethinglikethat: 31 * 32 * BMK_MEMWHO_WIREDBMK: 33 * This level is the most critical one. Everything runs on top of 34 * it, and usually if a WIREDBMK allocation fails, everything fails. 35 * 36 * BMK_MEMWHO_RUMPKERN: 37 * This level is used by "pageable" (and/or non-critical) memory 38 * allocated by the rump kernel hypercalls. The memory is not 39 * really pageable (no VM!), but since the rump kernel a) attempts 40 * to cache until it has consumed all memory b) will release said 41 * caches if we ask it to, the memory is not "wired" in the same 42 * sense as WIREDBMK is. 43 * 44 * BMK_MEMWHO_USER: 45 * This level is used by user-level memory allocation. User level 46 * memory is "worse" that the RUMPKERN level since generally speaking 47 * applications do not have a way to respond to memory backpressure. 48 * 49 * 50 * The approximate memory flow is (or as of writing this, "will be") the 51 * following: 52 * 1) WIREDBMK used is predictable and it will be handed a fixed size 53 * chunk of pages. This pool should never run out of pages. 54 * 2) RUMPKERN will try to allocate all available memory, or up to a 55 * dynamically configurable limit, but still at least up to a 56 * hardcoded low watermark (hardcoded = decided a boot time). 57 * 3) USER will allocate as much memory as it needs. In case USER is 58 * out of memory, it will notify the rump kernel to free up some 59 * memory. 60 * 61 * TODO: figure out if we want to support the case where USER allocates 62 * and then frees a lot of memory (will require changes to the allocator) 63 */ 64 65enum bmk_memwho { 66 BMK_MEMWHO_WIREDBMK, 67 BMK_MEMWHO_RUMPKERN, 68 BMK_MEMWHO_USER 69}; 70 71void bmk_memalloc_init(void); 72 73void * bmk_memalloc(unsigned long, unsigned long, enum bmk_memwho); 74void * bmk_memcalloc(unsigned long, unsigned long, enum bmk_memwho); 75void bmk_memfree(void *, enum bmk_memwho); 76 77void * bmk_memrealloc_user(void *, unsigned long); 78 79void * bmk_xmalloc_bmk(unsigned long); 80 81/* diagnostic */ 82void bmk_memalloc_printstats(void); 83 84#endif /* _BMK_CORE_MEMALLOC_H_ */ 85