StudentShare
Contact Us
Sign In / Sign Up for FREE
Search
Go to advanced search...
Free

Memory Management - Lab Report Example

Cite this document
Summary
The paper "Memory Management" explains the programmer needs to address memory space where various variables will be stored and the intermediate results of execution. A system there has to be developed that will define a standard way in which a programmer accesses memory for storage purposes…
Download full paper File format: .doc, available for editing
GRAB THE BEST PAPER95.4% of users find it useful
Memory Management
Read Text Preview

Extract of sample "Memory Management"

? The memory model The computer memory is an essential component without which a computer would not be able to execute any instructions/processes. It provides space for loading the instructions to be followed in execution of various processes (Tanenbaum, 1992). It also provides storage space for results of various executions. In writing various programs, a programmer needs to address memory space where various variables will be stored and the intermediate results of execution (Stallings, 2001). A system there has to be developed that will define a standard way in which a programmer accesses memory for storage purposes. The memory model is an abstraction that allows the programmer access to memory. In execution of programs, the operating system sees instructions as either processes or threads. The programmer has the task of defining how many processes or threads his/her program will have, and what each of them will do. The memory model also defines the valid values of operations such as read, the time it takes for other threads to see changes in values of variables, and other parameters (Stallings, 1995). The memory model is therefore very crucial when it comes to qualities such as performance and portability of programs. Programmers could use several memory models. These include the single thread model, where memory accesses are executed sequentially. The strict consistency model where any read operations to a particular memory location returns the most recent value stored at that location. Another model is the sequential consistency model which emphasizes atomicity of all memory operations (Tanenbaum, 1992). The last model is the weak ordering model. Generally, the main objective of a memory model is to control the allowable actions from the system’s hardware. Some of the relaxed models make the system more flexible but also bring about complexity in the programming effort (Stallings, 1995). The figure below shows computer memory model and C++ code for referencing the memory. Source: Stallings, W. (2001). Operating systems: Internals and design principles. Global and local memory When writing a program in any programming language, the programmer has the choice of declaring both local and global variables. Being global means that a variable can be accessed by all functions in that program while local variables can only be accessed within the functions in which they are declared. The same applies to memory. Below is an illustration of global and local variables in C++ code: Source: Stallings, W. (2001). Operating systems: Internals and design principles. The architecture of computers has greatly shifted towards designing computers with multiple processors. They mainly operate in parallel with each other enabling the computers to process faster. Various techniques have also come up allowing the processors to access the common address space. Some of these techniques include Uniform memory access and non-uniform memory access (Stallings, 2001). In implementations of memory management such as in windows operating systems, the OS maintains a page of memory to be designated as general purpose global memory. Just like any function within a program can access and modify a global variable, any process in a system can use the global memory for whatever it wants. However, the programmer has to explicitly write global memory functions to be able to access a computer’s global memory. Any program in the system can access data stored in global memory and modify it. Local memory is restricted to one program. The program does not manage this memory since the operating system has this task. However, no other program can access local memory of another one. It is mutually exclusive. Virtual memory Sometimes, the available physical memory is not enough for all the processing needs of a computer. The installed physical memory has to be shared between system programs and user applications. The system needs address space to be able to conduct various routine operations and provide a favorable execution environment for user applications. The increased multiprocessing capability of computers being built today made it necessary to come up with a technique of extending the installed physical memory in a computer. The solution was virtual memory. This is where the computer’s physical memory is extended from RAM to include a mass storage device, the hard disk. In virtual memory, part of the hard disk storage capacity is designated to be used as RAM would be used (Tanenbaum, 1992). Each program is assigned an address space and this is split between physical memory and virtual memory. Initially, when a program starts execution, all of its memory pages are in virtual memory. When it makes its first memory reference, a page fault occurs and the page fault handler reads in the page from virtual memory into main memory. As execution continues, the physical memory will fill up and an algorithm has to be invoked to remove a page from main memory and replace it with a required page. There are different implementations of page replacement algorithms that can be used to select a victim to be evicted (Tsichritzis, 1974). To aid the algorithms in locating the page in virtual memory and map it to main memory, there is a page table. This is a structure with pointers of the location of a page in virtual memory so that it can be swapped to main memory. Below is C++ code to show virtual memory management in a computer. Source: Stallings, W. (2001). Operating systems: Internals and design principles. Heap memory and allocating a memory block During execution of programs, each program has to be provided with a default execution heap. As it executes, the program’s address space will increase because its processes are continually producing results of execution. Therefore, a process may request allocation of more heap as it executes (Tsichritzis, 1974). Heap functions manage their own allocations of virtual memory and the paging mechanisms. Therefore, as the heaps grow with data, they can be set to grow as execution progresses. When a heap has been set to increase its size automatically, then it will allocate its pages as need be. In order to use heap memory, a handle to the default heap has to be obtained. Once the handle has been obtained, it is passed to the functions used for memory allocation and memory is allocated to the heap. In a programming language like C++, functions such as malloc(), free() and calloc() are used in allocation of memory. They are very similar to heap functions such as HeapCreate(), HeapDestroy(), HeapAlloc(), etc. The HeapCreate() function creates a heap and returns a handle used for that heap. The HeapDestroy() function closes the heap’s handle and returns its memory space to a pool of available memory (Tanenbaum, 1992). Managing process specific memory Each process has its own address space. Processes do not share address space and therefore, there is need for mechanisms to enforce mutual exclusion in the way processes access their address space. If there was an occurrence where more than one process accesses the same memory space, then one process’s data would be overwritten causing it to fail execution. Each process is allocated a set of pages, which are used during its execution. In systems implementing virtual memory, the program’s pages are kept in the virtual address space while the ones holding instructions being executed are loaded in main memory. Whenever the program references a page that is not currently in main memory, a page fault occurs invoking the page fault handler to bring in the page from virtual memory. Once the page is in main memory, execution resumes. Besides main and virtual memory, computer systems also have a cache memory. Fetching a page from virtual memory into main memory takes considerable length of time, considering the fast execution speed of processors today. Therefore, designers include a fast speed memory called the cache memory. In most systems, this cache is located on the processor chip. The processor accesses the main memory through the memory bus (Tsichritzis, 1974). The process is made even slower by having to swap in pages from virtual memory. Including the cache memory on the processor significantly increases the speed of execution of the processor. Designers also have to come up with algorithms to manage the address space that is maintained on the cache memory. Efficient use of the cache improves the overall efficiency of the system (Davis, 1987). Below is C++ code for managing process specific memory Source: Deitel, H. M. (1984). An introduction to operating systems. Allocating and managing virtual memory block One of the most important aspects of virtual memory management is the page table. This is usually at the top of the hierarchy of virtual memory management. Any time that a page needs to be swapped out and a new one brought in, the pager looks up the memory map in the page table. A good approach to managing the memory is to have all pages in virtual memory as a program starts up. Each time a new page is referenced, it should be brought into main memory. However, as execution progresses, the memory requirements of all processes will exceed the available physical memory (Peterson, 1985). At this stage, a page in main memory has to be swapped out and the required page brought in. several algorithms have been created for this process. The most basic algorithm is the first in- first out (FIFO) algorithm. This chooses the page that has been in memory the longest for eviction. It is however not very efficient since the oldest page could be heavily used and cause many page faults, which slow down the process. Some of the solutions to this problem include an algorithm that marks pages with a dirty bit. Here, pages in main memory that have been recently referenced are marked as dirty and therefore more likely to be referenced in the next instruction (Peterson, 1985). Pages that are not dirty are less likely to be referenced and therefore are evicted. Choosing a page for eviction is a highly complex process and relies heavily on speculation. Below is C++ code for allocating and managing virtual memory Source: Deitel, H. M. (1984). An introduction to operating systems. Creating a process Processes are the main execution units in any program. The operating system is responsible of managing processes and it can also create its own processes. There are four main events that lead to creation of processes. They are: Initialization of the system Execution of a system call to create a process User requesting creation of a new process When a batch job is initialized When a user logs on to a system, a new process is created to provide the user with the basic user interface. This is a system process since the user is not even aware of it. Several background processes have to be run on a system in order to provide a good execution environment for the user to take run his/her own processes (Peterson, 1985). As the user continues using the system, he/she may need to use a particular application. As the application starts, it creates its own processes, which may in turn create child processes. The OS also periodically caries out basic utility functions which require their own processes to manage them, therefore new processes will be created. Programs may call functions that create new processes. An example is a call to the fork() function. After creation, the process enters the ready queue awaiting to allocation to the processor for execution. During execution, a process may be preempted from the processor entering either a waiting or blocked state (Deitel, 1984). It moves between the ready, blocked and waiting states in a cycle until it completes the task it was created for. At this stage, the process is terminated. Below is C++ code for process creation Source: http://stackoverflow.com/questions/1067789/how-to-create-a-process-in-c-on-windows Creating threads A process is single continuous execution stream. Threads are easy to manage since they do not require as many resources as processes do. Unlike processes, threads can share address space reducing the complexity involved in inter process communication. The process of switching between different threads is much simpler because they do not have very many resources (Deitel, 1984). Creating a thread is much like a process. The main difference is that threads belong to a particular process while processes belong to programs (Lorin, 1981). They can be created in user space or in kernel space. In kernel space, the operating system creates threads to manage the tasks of processes created for maintenance of basic utility of the system. The kernel is a privileged execution environment and the user has no control over the threads created in kernel space (Lorin, 1981). There is also the option of creating threads in user space. Here, they execute normally as they would on other occasions. User processes to do various tasks usually create user space threads. Like processes, the thread goes through the states of ready, waiting, blocked and executing (Davis, 1987). They have to share the processor. On completion, a thread terminates. However, the operating system may terminate a thread on special occasions. Below is C++ code that creates a thread Source: http://stackoverflow.com/questions/266168/simple-example-of-threading-in-c References ACM Special Interest Group in Operating Systems., Symposium on Operating Systems Principles., International Conference on Architectural Support for Programming Languages and Operating Systems., & Symposium on Operating Systems Design and Implementation (OSDI). (1969). Operating systems review. New York, N.Y: ACM Special Interest Group on Operating Systems. Davis, W. S. (1987). Operating systems: A systematic view. Reading, Mass: Addison-Wesley Pub. Co. Deitel, H. M. (1984). An introduction to operating systems. Reading, Mass: Addison-Wesley Pub. Co. Lorin, H., & Deitel, H. M. (1981). Operating systems. Reading, Mass: Addison Wesley. Madnick, S. E., & Donovan, J. J. (1974). Operating systems. New York: McGraw-Hill. Peterson, J. L., & Silberschatz, A. (1985). Operating system concepts. Reading, Mass: Addison- Wesley. Stallings, W. (2001). Operating systems: Internals and design principles. Upper Saddle River, N.J: Prentice Hall. Stallings, W. (1995). Operating systems. Englewood Cliffs, NJ: Prentice Hall. Tanenbaum, A. S. (1992). Modern operating systems. Englewood Cliffs, N.J: Prentice Hall. Tsichritzis, D. C., & Bernstein, P. A. (1974). Operating systems. New York: Academic Press. Read More
Cite this document
  • APA
  • MLA
  • CHICAGO
(Memory Management Lab Report Example | Topics and Well Written Essays - 2000 words, n.d.)
Memory Management Lab Report Example | Topics and Well Written Essays - 2000 words. https://studentshare.org/logic-programming/1479438-technical-paper-memory-management
(Memory Management Lab Report Example | Topics and Well Written Essays - 2000 Words)
Memory Management Lab Report Example | Topics and Well Written Essays - 2000 Words. https://studentshare.org/logic-programming/1479438-technical-paper-memory-management.
“Memory Management Lab Report Example | Topics and Well Written Essays - 2000 Words”. https://studentshare.org/logic-programming/1479438-technical-paper-memory-management.
  • Cited: 0 times

CHECK THESE SAMPLES OF Memory Management

Operating System Memory Management

hellip; Here the concept of Memory Management starts. The memory basically consists of a large array of words or bytes.... Also there is a unit MMU(Memory Management unit) that performs the following tasks: Sometimes there may be a shortage of main memory due to the size of various applications and also in some cases several active processes may need to share memory at the same time.... Fixed partition Memory Management: This is the simplest Memory Management scheme for multiprogrammed system....
8 Pages (2000 words) Essay

Windows Operating System

It also supports the application programs and serves as a mediator between the computer hardware and the computer user (Silberschatz, Galvin and Gagne 3).... In this scenario, Microsoft… This paper presents the history and development of Windows operating system.... This paper will also discuss the main ideas of this operating Microsoft Windows or simply Windows is an operating system family of personal computer operating systems that is developed by Microsoft to make use of the computer through graphical user interface (GUI)....
5 Pages (1250 words) Research Paper

Memory Management Paper

Once allocated, a process cannot hold memory indefinitely Memory Management refers to how a computer's memory is allocated between the… Memory Management is essential for the proper resource allocation and functioning of a computer and it must essentially satisfy the following four requirements (Ramesh, 2010; Isrd, 2006); As a number of programs are usually present in the Memory Management Requirements By Introduction In order for a program to execute, it is brought into the main memory (swap in)....
2 Pages (500 words) Essay

Comparison of Operating System Kernels

Computer itself is a large entity, and has many components such as memory unit, processing unit, operating system, cache, and many more parts.... The modern day digital colored screened computers that we see around us in form of laptops, desktops, mobile phone (operating system enabled), and tablets, all have a complete set of body inside them....
11 Pages (2750 words) Essay

What Are Some of the Basic Components of an Operating System

ain Memory Management:Apart from the internal components, and the operating system consists of a set of components, which include the controlling unit, the service support programs unit and the utility programs support systemsWhat is the resource allocation process?... Ensuring that the data so used is in use by the authentic users is also the main Memory Management function.... Memory spaces adjustment on the hard disk and the Ram is another function performed during the main Memory Management process....
2 Pages (500 words) Essay

Windows XP Vs Linux Ubuntu

This paper "Windows XP Vs Linux Ubuntu" will undertake the exercise of comparing the Memory Management of two operating systems, namely, windows XP and Ubuntu Linux.... These two are very popular operating systems but uses a different type of Memory Management techniques.... Memory Management is one of the core part of the operating system.... Virtual memory is an important concept in the context of the Memory Management system....
9 Pages (2250 words) Case Study

The Operation of Java Applications in the Context of Operating Systems

Java is widely accepted as its Memory Management model enables programmers to evade the time-consuming job of physical Memory Management by implementing “automatic garbage collection.... The OS acts as an intermediary between programs and the computer hardware and hardware functions like the input and output and memory allocation, although the application code is generally directly executed by the hardware and will commonly make a system call to an OS function....
6 Pages (1500 words) Term Paper

Memory Management - Virtual Memory with Paging and Segmentation

This paper "Memory Management - Virtual Memory with Paging and Segmentation" examines memory paging as a management method for memory for managing how resources of virtual machines or computer memory are shared.... Basically, a PC can address memory above the amount set up on the computer.... hellip; Dhamdhere affirms that the memory that is nonphysical, commonly regarded as virtual memory, is in fact a hard disk's portion that is installed to emulate the RAM of the computer....
12 Pages (3000 words) Literature review
sponsored ads
We use cookies to create the best experience for you. Keep on browsing if you are OK with that, or find out how to manage cookies.
Contact Us