/** * HIPPO, the HOS In-place Physical Page Organizer. * * HIPPO maintains a list of free physical pages "in place", meaning that the * available page itself is used as the linked list entry so separate memory * is not needed to keep track of the available pages. */ module hulk.hippo; struct Hippo { /** * Linked list node entry for a physical page. */ private static struct PhysicalPage { PhysicalPage * next; } /** * Linked list of free physical pages. */ private static __gshared PhysicalPage * free_pages; /** * Number of free physical pages. */ private static __gshared size_t m_n_free_pages; /** * Free a physical page. * * @param phys Physical page address. */ public static void free_page(T)(T phys) { PhysicalPage * pp = cast(PhysicalPage *)phys; pp.next = free_pages; free_pages = pp; m_n_free_pages++; } /** * Allocate a physical page. * * @return Page address, or null if no pages are available. */ public static void * allocate_page() { PhysicalPage * pp; if (free_pages != null) { pp = free_pages; free_pages = free_pages.next; m_n_free_pages--; } return cast(void *)pp; } /** * Get the number of free pages. * * @return The number of free pages. */ public @property size_t n_free_pages() const { return m_n_free_pages; } }