VISOPSYS’ MEMORY MANAGER
Visopsys contains a memory manager that is capable of controlling basically arbitrary quantities of RAM memory. Suffice to say that your PC hardware is not capable of supporting more memory than Visopsys can handle.
The quantity of memory in your system is determined at boot time by Visopsys’ Operating System Loader. The amount of memory detected is then passed to the kernel at startup. This is the “safest” way to detect your memory — there are other possible methods*, but the consensus among hardware programmers is that asking the 16- bit system BIOS (before the 32-bit Visopsys kernel is invoked) is the most appropriate technique.
In Visopsys, memory is organized as a 32-bit flat memory space. From the application program’s point of view, memory is arranged as one large space which starts at address 0 and continues uninterrupted all the way to the end. All of this means that Visopsys does not use the x86’s famously complicated segmented memory scheme. While segmented memory is easy to “protect” (i.e. to protect applications from interfering with memory that doesn’t belong to them), it introduces unnecessary complication. In Visopsys, memory protection is achieved via the “paging” or “virtual memory” mechanism. An application may only access memory pages that belong to it.
“Real” or “linear” (as opposed to paged or virtual) memory is allocated in 4 kilobyte pages. Thus, any allocation of memory can be no smaller than 4Kb, and can theoretically be as large as the maximum number supported by the 32- bit x86 CPU — 4 gigabytes.
This 4Kb minimum allocation was chosen for a couple of reasons: not coincidentally, it corresponds with the size of a virtual memory page in the x86. Also, 4Kb is relatively small compared to the large quantities of memory shipped with most modern PCs. Any potential wastage as a result of multiple small memory allocation requests is kept reasonably low in relation to the available memory in most systems. Computer Science theory tells us that on average, for each memory allocation request, ½ of the minimum block size (2 Kb) will go unused. Generally speaking, good “heap” memory management will reduce the number of small allocation requests; instead, one larger allocation is performed by the application libraries and pieces of that memory are parceled out when necessary.
Shortly, I will be documenting the Visopsys kernel’s external interface to the memory management routines, for use by libraries and application programs. In its current form, it is only available for internal use by the kernel itself.
* The original IBM PC couldn’t support even a single megabyte of RAM. Even today, detecting memory beyond 64 megabytes is slightly tricky. A technique exists to test the presence memory whereby the programmer attempts to use memory in increasing increments — at the point where such an attempt fails, the programmer assumes that no real memory exists beyond that point. This is not generally considered a “safe” technique.