#ident "$Id$" /* ----------------------------------------------------------------------- * * * Copyright 2000-2001 H. Peter Anvin - All Rights Reserved * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, Inc., * 59 Temple Place Ste 330, Boston MA 02111-1307, USA, version 2.1, * incorporated herein by reference. * * ----------------------------------------------------------------------- */ /* * internals.h * * Internals for LPSM. Not to be used by applications. */ #ifndef LPSM_INTERNALS_H #define LPSM_INTERNALS_H #include "lpsm.h" /* Main include file */ #include "system.h" /* System-specific constants */ /* Debugging print statements */ #ifdef PRINT_DEBUG_INFO #include #define DPRINTF(X) printf X #else #define DPRINTF(X) #endif /* Arena definitions */ struct lpsm_arena { int main_fd; /* Primary file descriptor */ int log_fd; /* Log file descriptor */ int pagesize; /* Page size */ int pageshift; /* log2(pagesize) */ void *arena; /* Mapped memory zone */ size_t arena_len; /* Length of arena */ char *pageinfo; /* Page info pointer */ size_t loaded_count; /* Loaded pages count (accounting) */ size_t dirty_count; /* Dirty pages count (accounting) */ struct sigaction oldact; /* Previous signal action */ size_t fork_seq; /* Sequence number of forked processes */ }; enum lpsm_recordtype { osrec_page, /* Page data */ osrec_commit, /* Commit record */ }; #define LOGRECORD_MAGIC 0x9247746e struct lpsm_logrecord { unsigned int magic; /* Magic number; for verification */ unsigned int record_type; /* Record */ size_t size; /* Data byte count (sequence # for commit) */ off_t offset; /* Offset of data */ }; extern struct lpsm_arena *lpsm_memory_info; #define PM lpsm_memory_info /* Shorthand */ /* This might end up being a bitmask eventually */ enum page_status { page_clean = 0, page_dirty = 1, }; /* Memory management definitions */ #define SLAB_MAGIC 0xec2062ae struct slab_info { int size; /* Size of SLAB */ int count; /* SLABs per page */ int data_offset; /* Start of data area */ int total_pages; /* Count of pages allocaed to this size SLAB */ int alloc_slabs; /* Count of SLABs currently in use */ struct slab_header *list; }; /* This is 16 bytes on 32-bit and 24 bytes on 64-bit architectures */ /* This header must end aligned to a bitscan_t datum */ struct slab_header { uint32_t magic; uint16_t free_count; uint16_t index; /* Index into slab_info array */ struct slab_header *next, **rev; }; #define SLAB_INFO_COUNT 32 struct arena_header { unsigned char arena_magic[16]; uint32_t arena_byteorder; uint16_t arena_bytesize; uint16_t arena_ptrsize; void *arena_base; /* Base of allocation */ void *free_bitmap; /* The free bitmap */ void *alloc_bitmap; /* The allocated (buddy) bitmap */ void *data_start; /* Beginning of data area */ int buddy_order_min; /* Minimum size of buddy allocation */ int arena_size_lg2; /* Current arena allocation size */ int header_size; /* Size of this header+padding */ struct slab_info slab[SLAB_INFO_COUNT]; void *root_data_ptrs[LPSM_ROOT_POINTERS]; /* Root data pointers - for the user */ }; extern struct arena_header *lpsm_arena_header; #define AH lpsm_arena_header /* Shorthand */ /* This is the minimal order before going to SLAB allocation. */ #define BUDDY_ORDER_MIN 12 #define BUDDY_SIZE_MIN (1U << BUDDY_ORDER_MIN) /* Align allocations at least this large (2^n) to this boundary */ #define MINIMUM_ALIGN_LG2 4 #define MINIMUM_ALIGN (1 << MINIMUM_ALIGN_LG2) #define MINIMUM_ALIGN_MASK (MINIMUM_ALIGN-1) /* This is the size (2^n) allocated for a brand new arena. This allocation will be sparse, so don't freak out too much! */ #define ARENA_START_SIZE_LG2 17 /* 128K */ #define ARENA_START_SIZE (1UL << ARENA_START_SIZE_LG2) /* Function definitions used across modules */ struct buddy_params { int xbit; int rorder; }; struct buddy_params lpsm_find_alloc_buddy(void *ptr); int lpsm_extend_arena(int logsize); int lpsm_malloc_buddy_xbit(int order); void *lpsm_malloc_buddy(size_t size); void *lpsm_malloc_slab(size_t size); void lpsm_free_buddy(void *ptr); void lpsm_free_slab(void *ptr); #ifdef PRINT_DEBUG_INFO void lpsm_print_statistics(void); #else #define lpsm_print_statistics() ((void)0) #endif #endif