13.07.2015 Views

iAPX 286 Operating System Writers Guide 1983

iAPX 286 Operating System Writers Guide 1983

iAPX 286 Operating System Writers Guide 1983

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 3REAL MEMORY MANAGEMENTIn dynamic applications, when tasks begin and end frequently, the operating system is responsible forallocating memory to tasks. Without the control that an operating system provides, independent taskscannot be trusted to share the system's memory harmoniously. The <strong>iAPX</strong> <strong>286</strong>, through the descriptormechanism, gives the operating system the power to control memory usage. For static systems, you canuse the Builder to allocate memory. This chapter presents an example of how to manage real memorydynamically, using dynamically created descriptors.MEMORY MANAGEMENT FUNCTIONSProcedures at various levels in a system have a need to get memory for their use. Some of the functionsthat use memory dynamically include• Loading the code and data segments for a new task• Creating the TSS and LDT of a new task• Expanding an application data structure• Expanding system stack segments when stacks grow too large• Allocating buffers for a newly opened fileIn allocating memory statically using the Builder, you or the Builder must keep account of what memorylocations are available and what locations are used. A dynamic memory allocation module must do thesame, but, in addition, it needs to reuse the space vacated by tasks that have finished. Even tasks thatare still executing may no longer need all of the memory they once were using, so you need to providesome means for them to return that space dynamically. The need to reclaim formerly used memoryspace provides considerable challenge to operating system designers.Protection usuaily requires that segments not overlap. The operating system should accurately keeptrack of allocated memory to prevent new segments from overlapping current segments.Allocation of memory to tasks in a dynamic environment is complicated by the facts that segmentshave differing lengths and that the order of creation and deletion is unpredictable. Consequently, aftera number of tasks have come and gone, memory becomes fragmented, as illustrated in figure 3-1. Itbecomes increasingly difficult to find free areas large enough to accomodate requests for space. It mayhappen that no single free area in all of memory is large enough to fill a request for memory eventhough the total of all smaller available areas is larger than the amount needed. Knuth (see "ExternalLiterature" in the Preface) discusses how various memory-management mechanisms can minimize ormagnify this problem.Memory management on the <strong>iAPX</strong> <strong>286</strong> differs from memory management on other processors in thatdescriptors must be constructed to access any region of physical memory.EXAMPLE OF A MEMORY MANAGERAs an example of how a memory manager can manipulate descriptors and segments, consider a memorymanagement module that implements a version of the "first fit" algorithm (as described by Knuth)and combines adjacent free segments as a way to reduce fragmentation. This example employs the3-1 121960·001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!