Figure 54 Levels of mapping from user allocation to physical memory 519 Page

Figure 54 levels of mapping from user allocation to

This preview shows page 59 - 61 out of 102 pages.

Figure 5.4: Levels of mapping from user allocation to physical memory. 5.1.9 Page size, fragmentation and alignment The process of allocating memory is really only half the story of memory management. We must also be able to de-allocate or free memory. When memory is freed from a segment, it leaves a hole of a certain size, which is added to the free-list . Eventually, the number of these holes grows quite large and the memory is said to become fragmented . Fragmentation can lead to wasted resources. We would clearly like to re-use freed memory as far as possible, but if the holes are not big enough to fit the data we need to allocate then this is not possible. Another technical problem which leads to fragmentation and wastage is alignment . Alignment is a technical problem associated with the word- size and design of the CPU. Certain memory objects (variables) have to be stored starting from a particular (usually even ) address. This is because the multiple-byte registers of the CPU need to align their ``footprints'' to the addresses of the memory. Or, by virtue of the word-size of the system, the CPU regards the addresses as being effectively multiples of the word-size. In order to meet this requirement, memory sometimes has to be `padded' out with empty bytes - which are therefore wasted. Fragmentation occurs at two levels:
Image of page 59
Internal fragmentation. This is space wasted by malloc in trying to fit data into a segment (logical memory). External fragmentation. This is space lying between segments in the physical memory. (There are never holes between segments in logical memory since we can always just renumber the logical addresses to remove them - they are not real anyway.) See the figure below. Figure 5.5: Fragmentation occurs because we allocate memory in blocks of different sizes and then free the blocks. Fragments are show as the white gaps between allocated objects. Internal fragmentation happens inside segments of logical memory when programs like malloc divide up the segment space. External fragmentation occurs in the mapping of logical segments to physical segments when there are gaps between the segments in physical memory. External fragmentation is cured by only mapping pages as in figure 5.4. Note that external fragmentation is formally eliminated by the page concept. With pages, every object in physical memory is always the size of a page or frame, every hole must also be the size of a page and thus one is guaranteed to be able to fit a page block into a page hole. To some extent this is a cheat though, because the problem is only transferred from external to internal fragmentation - but such is the nature of definitions. Internal fragmentation can be minimized by choosing a smaller page size for the system. That means that, on average, fewer bytes will be wasted per page. Of course, the system overhead grows larger as the page size is reduced, so as usual the size of pages is a tradeoff between two competing requirements.
Image of page 60
Image of page 61

You've reached the end of your free preview.

Want to read all 102 pages?

  • One '20

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors