github.com/moontrade/nogc@v0.1.7/alloc/rpmalloc/model.go (about)

     1  package rpmalloc
     2  
     3  // #include "rpmalloc.h"
     4  import "C"
     5  
     6  type ()
     7  
     8  type Config struct {
     9  	//! Map memory pages for the given number of bytes. The returned address MUST be
    10  	//  aligned to the rpmalloc span size, which will always be a power of two.
    11  	//  Optionally the function can store an alignment offset in the offset variable
    12  	//  in case it performs alignment and the returned pointer is offset from the
    13  	//  actual start of the memory region due to this alignment. The alignment offset
    14  	//  will be passed to the memory unmap function. The alignment offset MUST NOT be
    15  	//  larger than 65535 (storable in an uint16_t), if it is you must use natural
    16  	//  alignment to shift it into 16 bits. If you set a memory_map function, you
    17  	//  must also set a memory_unmap function or else the default implementation will
    18  	//  be used for both.
    19  	MemoryMap uintptr
    20  	//! Unmap the memory pages starting at address and spanning the given number of bytes.
    21  	//  If release is set to non-zero, the unmap is for an entire span range as returned by
    22  	//  a previous libfuzzerCall to memory_map and that the entire range should be released. The
    23  	//  release argument holds the size of the entire span range. If release is set to 0,
    24  	//  the unmap is a partial decommit of a subset of the mapped memory range.
    25  	//  If you set a memory_unmap function, you must also set a memory_map function or
    26  	//  else the default implementation will be used for both.
    27  	MemoryUnmap uintptr
    28  	//! Called when an assert fails, if asserts are enabled. Will use the standard assert()
    29  	//  if this is not set.
    30  	ErrorCallback uintptr
    31  	//! Called when a libfuzzerCall to map memory pages fails (out of memory). If this callback is
    32  	//  not set or returns zero the library will return a null pointer in the allocation
    33  	//  libfuzzerCall. If this callback returns non-zero the map libfuzzerCall will be retried. The argument
    34  	//  passed is the number of bytes that was requested in the map libfuzzerCall. Only used if
    35  	//  the default system memory map function is used (memory_map callback is not set).
    36  	MapFailCallback uintptr
    37  	//! Size of memory pages. The page size MUST be a power of two. All memory mapping
    38  	//  requests to memory_map will be made with size set to a multiple of the page size.
    39  	//  Used if RPMALLOC_CONFIGURABLE is defined to 1, otherwise system page size is used.
    40  	PageSize uintptr
    41  	//! Size of a span of memory blocks. MUST be a power of two, and in [4096,262144]
    42  	//  range (unless 0 - set to 0 to use the default span size). Used if RPMALLOC_CONFIGURABLE
    43  	//  is defined to 1.
    44  	SpanSize uintptr
    45  	//! Number of spans to map at each request to map new virtual memory blocks. This can
    46  	//  be used to minimize the system libfuzzerCall overhead at the cost of virtual memory address
    47  	//  space. The extra mapped pages will not be written until actually used, so physical
    48  	//  committed memory should not be affected in the default implementation. Will be
    49  	//  aligned to a multiple of spans that match memory page size in case of huge pages.
    50  	SpanMapCount uintptr
    51  	//! Enable use of large/huge pages. If this flag is set to non-zero and page size is
    52  	//  zero, the allocator will try to enable huge pages and auto detect the configuration.
    53  	//  If this is set to non-zero and page_size is also non-zero, the allocator will
    54  	//  assume huge pages have been configured and enabled prior to initializing the
    55  	//  allocator.
    56  	//  For Windows, see https://docs.microsoft.com/en-us/windows/desktop/memory/large-page-support
    57  	//  For Linux, see https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
    58  	EnableHugePages int32
    59  	Unused          int32
    60  }
    61  
    62  type GlobalStats struct {
    63  	//! Current amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STATISTICS=1)
    64  	Mapped uintptr
    65  	//! Peak amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STATISTICS=1)
    66  	MappedPeak uintptr
    67  	//! Current amount of memory in global caches for small and medium sizes (<32KiB)
    68  	Cached uintptr
    69  	//! Current amount of memory allocated in huge allocations, i.e larger than LARGE_SIZE_LIMIT which is 2MiB by default (only if ENABLE_STATISTICS=1)
    70  	HugeAlloc uintptr
    71  	//! Peak amount of memory allocated in huge allocations, i.e larger than LARGE_SIZE_LIMIT which is 2MiB by default (only if ENABLE_STATISTICS=1)
    72  	HugeAllocPeak uintptr
    73  	//! Total amount of memory mapped since initialization (only if ENABLE_STATISTICS=1)
    74  	MappedTotal uintptr
    75  	//! Total amount of memory unmapped since initialization  (only if ENABLE_STATISTICS=1)
    76  	UnmappedTotal uintptr
    77  }
    78  
    79  type ThreadStats struct {
    80  	//! Current number of bytes available in thread size class caches for small and medium sizes (<32KiB)
    81  	SizeCache uintptr
    82  	//! Current number of bytes available in thread span caches for small and medium sizes (<32KiB)
    83  	SpanCache uintptr
    84  	//! Total number of bytes transitioned from thread cache to global cache (only if ENABLE_STATISTICS=1)
    85  	ThreadToGlobal uintptr
    86  	//! Total number of bytes transitioned from global cache to thread cache (only if ENABLE_STATISTICS=1)
    87  	GlobalToThread uintptr
    88  	//! Per span count statistics (only if ENABLE_STATISTICS=1)
    89  	SpanUse [64]SpanStats
    90  	//! Per size class statistics (only if ENABLE_STATISTICS=1)
    91  	SizeUse [128]SizeUse
    92  }
    93  
    94  type SpanStats struct {
    95  	//! Currently used number of spans
    96  	Current uintptr
    97  	//! High water mark of spans used
    98  	Peak uintptr
    99  	//! Number of spans transitioned to global cache
   100  	ToGlobal uintptr
   101  	//! Number of spans transitioned from global cache
   102  	FromGlobal uintptr
   103  	//! Number of spans transitioned to thread cache
   104  	ToCache uintptr
   105  	//! Number of spans transitioned from thread cache
   106  	FromCache uintptr
   107  	//! Number of spans transitioned to reserved state
   108  	ToReserved uintptr
   109  	//! Number of spans transitioned from reserved state
   110  	FromReserved uintptr
   111  	//! Number of raw memory map calls (not hitting the reserve spans but resulting in actual OS mmap calls)
   112  	MapCalls uintptr
   113  }
   114  
   115  type SizeUse struct {
   116  	//! Current number of allocations
   117  	AllocCurrent uintptr
   118  	//! Peak number of allocations
   119  	AllocPeak uintptr
   120  	//! Total number of allocations
   121  	AllocTotal uintptr
   122  	//! Total number of frees
   123  	FreeTotal uintptr
   124  	//! Number of spans transitioned to cache
   125  	SpansToCache uintptr
   126  	//! Number of spans transitioned from cache
   127  	SpansFromCache uintptr
   128  	//! Number of spans transitioned from reserved state
   129  	SpansFromReserved uintptr
   130  	//! Number of raw memory map calls (not hitting the reserve spans but resulting in actual OS mmap calls)
   131  	MapCalls uintptr
   132  }