1MALLOC(9) 386BSD Kernel Programmer's Manual MALLOC(9) 2 3NNAAMMEE 4 mmaalllloocc - kernel dynamic memory allocator 5 6SSYYNNOOPPSSIISS 7 ##iinncclluuddee ""mmaalllloocc..hh"" 8 9 _v_o_i_d * 10 mmaalllloocc(_u__l_o_n_g _s_i_z_e, _i_n_t _t_y_p_e, _i_n_t _f_l_a_g_s) 11 12 _v_o_i_d 13 ffrreeee(_v_o_i_d *_a_d_d_r, _i_n_t _t_y_p_e) 14 15DDEESSCCRRIIPPTTIIOONN 16 Most shared resources in the 386BSD kernel are dynamically allocated on 17 demand to serve need (with administrative bounds present to avoid system 18 overrun). The mmaalllloocc() function is used to allocate small (<= 64KB) 19 portions of memory in the kernel, and is especially useful in sub-page 20 sized allocations, since it maintains a free pool of page fragments to 21 allocate from. 22 23 While this function superfically resembles the user mode malloc(3) 24 function, it has two additional arguments. Associated with each 25 allocation is a _t_y_p_e which tags allocations of a given kind for use in 26 statistics and run-away allocation prevention. In addition, mmaalllloocc() has 27 a _f_l_a_g_s argument to select optional handling (M_NOWAIT is the most common 28 option, allowing the function to be used from interrupt level by 29 disallowing a block if no space available). 30 31 The mmaalllloocc() function obtains memory for its pool from the virtual memory 32 system via the kmem(9) facility. 33 34 The ffrreeee() function returns used memory to the memory pool. If a surplus 35 of memory is present in the allocator's pool, it will attempt to return 36 whole pages back to the kmem(9) facility. As such, it defers to the 37 virtual memory system as the primary location where memory resource 38 resides. 39 40 Since the virtual memory system itself makes use of mmaalllloocc() for its 41 operation, care is taken to avoid recursion. 42 43RREETTUURRNN VVAALLUUEESS 44 The mmaalllloocc() function returns a address of the allocated resource if 45 successful; otherwise a null address is returned. 46 47SSEEEE AALLSSOO 48 kmem(9) 49 50386BSD Release 1.0 August 29, 1994 1 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67