Memory Management: Difference between revisions

From COMP15212 Wiki
gravatar Yuron [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (1 revision imported)
pc>Yuron
No edit summary
Line 3: Line 3:
-->{{#invoke:Dependencies|add|Memory,4}}
-->{{#invoke:Dependencies|add|Memory,4}}
<blockquote>
<blockquote>
This page looks at the software tasks involved in managing memory as
This page looks at the software tasks involved in managing memory as a <strong>resource</strong>; for an overview of the <em>hardware</em> used to support <strong>memory mapping</strong> and <strong>memory protection</strong>, see <strong>[[Memory Management Unit (MMU)|MMU]]</strong>.
a <strong>resource</strong>; for an overview of the <em>hardware</em> used to support
<strong>memory mapping</strong> and <strong>memory protection</strong>, see <strong>[[Memory Management Unit (MMU)|MMU]]</strong>.
</blockquote>
</blockquote>
For one reason or another, there is a limited memory resource in a
For one reason or another, there is a limited memory resource in a computer.  In a simple system, <em>without</em> [[Virtual_Memory|<strong>virtual memory</strong>]], it is perhaps most obvious that, as one process uses up some proportion of the memory it becomes unavailable for others.  With virtual memory and <strong>paging</strong> some of the restrictions can be bypassed (up to a point) but the problems still arise.
computer.  In a simple system, <em>without</em> [[Virtual_Memory|<strong>virtual
memory</strong>]], it is perhaps most obvious that, as one
process uses up some proportion of the memory it becomes unavailable
for others.  With virtual memory and <strong>paging</strong> some of the restrictions can be bypassed (up to a point) but the problems still arise.


Any process will require one or more logical memory
Any process will require one or more logical memory [[Memory Segmentation|segments]].  These are <em>contiguous</em> parts of the address space.  In some cases the memory can be allocated when the process starts – for example the program <strong>code</strong> is probably (but not always!) a known length and there is likely to be some <strong>static</strong> data.  In other cases, [[Dynamic_Memory_Allocation|memory is allocated <em>dynamically</em>]] so the exact memory needs cannot be determined in advance.
[[Memory Segmentation|segments]].  These are <em>contiguous</em> parts of the address
space.  In some cases the memory can be allocated when the process starts – for example the program <strong>code</strong> is probably (but not always!) a known length and there is likely to be some <strong>static</strong> data.  In other cases, [[Dynamic_Memory_Allocation|memory is allocated <em>dynamically</em>]] so the exact memory needs cannot be determined in advance.
<blockquote>
<blockquote>
Example: every time you create a <code>new()</code> instance in Java there
Example: every time you create a <code>new()</code> instance in Java there are some more variables created; the computer has to keep them somewhere.
are some more variables created; the computer has to keep them
somewhere.
</blockquote>
</blockquote>
Whilst the pattern of segments may vary there are some typical example
Whilst the pattern of segments may vary there are some typical example areas which occur in most processes.
areas which occur in most processes.
{|
{|
!Segment(s)
!Segment(s)
Line 50: Line 39:
[[Image:memory_map.png|link=|alt=Memory map]]
[[Image:memory_map.png|link=|alt=Memory map]]


Memory management can be done by both the application and the O.S.
Memory management can be done by both the application and the O.S. Sometimes an application will request &lsqou;large’ blocks of memory and then allocate from them, thus saving some (expensive) [[System_Calls|<strong>system calls</strong>]].  However in the end it is the OS which is responsible for the memory as a resource and the management principles are similar, even if the application takes on some of the responsibility.
Sometimes an application will request &lsqou;large’ blocks of
memory and then allocate from them, thus saving some (expensive)
[[System_Calls|<strong>system calls</strong>]].  However in the end it is the OS
which is responsible for the memory as a resource and the management
principles are similar, even if the application takes on some of the
responsibility.


The operating system can keep records of the memory in use and – in a
The operating system can keep records of the memory in use and – in a virtual memory environment – which <em>physical</em> pages are in use, and for what.
virtual memory environment – which <em>physical</em> pages are in use, and
for what.


The O.S. may need to:
The O.S. may need to:
Line 71: Line 52:


----
----
{{BookChapter|1.5.2|28-29}}
{{PageGraph}}
{{PageGraph}}
{{Category|Virtual Memory}}
{{Category|Virtual Memory}}
{{Category|Memory}}
{{Category|Memory}}

Revision as of 13:23, 2 August 2019

On path: Memory 1: Memory • 2: Memory Management • 3: Memory Sizes • 4: Memory Mapping • 5: Memory Segmentation • 6: Memory Protection • 7: Virtual Memory • 8: Paging • 9: Memory Management Unit (MMU) • 10: Caching • 11: Cache • 12: Translation Look-aside Buffer (TLB)
Depends on Memory

This page looks at the software tasks involved in managing memory as a resource; for an overview of the hardware used to support memory mapping and memory protection, see MMU.

For one reason or another, there is a limited memory resource in a computer. In a simple system, without virtual memory, it is perhaps most obvious that, as one process uses up some proportion of the memory it becomes unavailable for others. With virtual memory and paging some of the restrictions can be bypassed (up to a point) but the problems still arise.

Any process will require one or more logical memory segments. These are contiguous parts of the address space. In some cases the memory can be allocated when the process starts – for example the program code is probably (but not always!) a known length and there is likely to be some static data. In other cases, memory is allocated dynamically so the exact memory needs cannot be determined in advance.

Example: every time you create a new() instance in Java there are some more variables created; the computer has to keep them somewhere.

Whilst the pattern of segments may vary there are some typical example areas which occur in most processes.

Segment(s) Function Typical properties
Code Executable binary Fixed size; Read only
Read-only data   Stings, tables … Fixed size; Read only
Static data Global variables Fixed size; Read/write
Stack Local variables Dynamic; Read/write
Heap Run time structures   Dynamic; Read/write

Memory map

Memory management can be done by both the application and the O.S. Sometimes an application will request &lsqou;large’ blocks of memory and then allocate from them, thus saving some (expensive) system calls. However in the end it is the OS which is responsible for the memory as a resource and the management principles are similar, even if the application takes on some of the responsibility.

The operating system can keep records of the memory in use and – in a virtual memory environment – which physical pages are in use, and for what.

The O.S. may need to:

  • allocate spaces when a process is loaded
    • set up pages in a virtual memory system
  • manage access permissions
  • allocate additional space if the stack or heap overflow
  • keep track of a process’ use and recover the resource when the process terminates.

Also refer to: Operating System Concepts, 10th Edition: Chapter 1.5.2, pages 28-29