In this machine problem, we need to implement frame pool manager to allocate and release the memory.
Design rule is kernel space is within 0-4 MB, process memory from 4MB to 32MB. So we have kernel frame pool below 4MB, process memory pool above 4MB. there are 3 stages to record the usage of memory pool. we use two bit 00 available, 01 head of sequence allocated, 10 allocated. Each bytes contains 8 bits, so we could store 4 frames usage status in 1 byte.
In the head file, in the class contFramePool, we define two ContFramePool objects, kernel memory pool and process memory pool. base frame no and nframes to record frame pool start in the physical memory, size of frame pool. info_frame_no and ninfo_frame where do we start to management information.
There are mainly 4 functions
first one is initialized function
bitmap could fit in a single frame?
infoframno = 0, we keep managemnt info in first frame. else we use provided frame to store information.
innitialize bitmap to zero.
mark the first frame which is being used already.
get function we want a frame which could allocate the memory and return its index, also mark the frame as being used in bitmap.
frame_no initialized as base_frame_no
mark inaccessible,
mark all the frames in the range as being used.
first we check the range
update bitmap
Release function, here we have create a conframepool object temp.check if the _first_frame_no is the within the kernel pool.
first we release the first frame in these allocated frames and remove continuous part
Since 1 frame with 4096 bytes storage, we could store 4096 * 8 / 2 roughly 16000 frames information,up to manage 64MB memory