The virtual memory system (vmm) is driven off the following two structures:
typedef struct vmem{ unsigned signature; unsigned dirty; unsigned ele_size; unsigned ele_per_blk; long num_ele; unsigned cblock; char *buf; } vmem; typedef struct hdr { int active; int nrefs; unsigned nblocks; unsigned offset; union { struct hdr *h; //if hdr is in freelist (active=0) struct vmem *v; //virt. mem. element (active = 1) } next; } hdr;
It helps to think of the virtual memory file as a long array of unsigned chars. The hdr structure points to a region in the file. The region may be used or free for use. The used regions of the file are referenced by a vmem structure. The unused regions are kept in a circular linked list of headers. These structures are described in Kernighan and Ritchie. The elements of the hdr structure are:
The vmem structure contains the information for an active hdr. The vmm file is organized in blocks of size BLK_SIZE. 3.2 The elements of the vmem are:
The function vmalloc() creates a hdr and a vmem. The function vfree() frees the vmem and places the hdr in the freelist. Freed space in the file is coalesced with neighboring free blocks.