Memory Management Lab
Introduction
This lab provides hands-on experience with understanding the memory management in a modern operating system.
Linux Memory Commands
The free command provides information regarding the usage of memory in a Linux system.
1) Read the manual pages for the free command: $ man free 2) Using the free command, answer the following questions.
a) What version of the command should you type to display memory in MB?
b) How much total memory does the system have?
c) How much of the total memory is the system using?
d) How much of the total memory is free?
e) How much swap is available on the system?
f) How much of the available swap is being used?
The vmstat command provides information regarding virtual memory usage in the Linux system.
1) Read the manual pages for vmstat: $ man vmstat 2) Using the vmstat command, answer the following questions.
a) What number of processes are in the ready state?
b) What number of processes are in the blocked state?
c) What is the number of context switches per second?
d) What is the amount of virtual memory used in the system?
e) What is the amount of memory swapped in from disk?
f) What is the amount of memory swapped out to disk?
Linux Internals: /proc directory
The /proc directory serves an important function in the Linux operating system. The /proc directory essentially stores information related to running processes on the system.
1) Review the man pages for the ls, ps, cd, and cat commands.
2) Use these commands to answer the questions below.
a) What do the numbered directories represent?
b) What types of files and folders are inside the numbered directories? What do these do?
c) What other types of information are stored in the /proc directory? Search for items you recognize from our discussion of Operating Systems. Write down what you find. If you are not sure, what you are looking at, research the file on the Internet.
Windows Memory Commands
Memory Management information in a Windows System can be viewed with the Task Manager. In addition to this application, other applications exist that allow a user to view this information. In particular, some resources available on http://technet.microsoft.com/en-us/sysinternals/default.aspx provide helpful insights into the function of memory on Windows Operating Systems.
Task Manager
Configure the task manager to display the following additional items:
Memory usage, memory usage delta, peak memory usage, page faults, page faults delta, virtual memory size, paged pool, and non-paged pool.
Use the additional information in the task manager to answer the following questions.
1) Which process has the highest peak memory usage?
2) Which process has the highest number of page faults?
3) Which process has the highest virtual memory size?
4) Find a process with a memory delta greater than 0. Watch the statistics for a moment. What numbers do you see for memory delta? What do they have in common?
5) What is the difference between memory usage and peak memory usage?
6) What are the paged pool and non-paged pool?
Hint: http://blogs.technet.com/askperf/archive/2007/03/07/memory-management-understanding- pool-resources.aspx
VMMap
The Process Explorer displays the process table and its entries in a tree-like structure. The Process Explorer exposes many details of processes and threads as handled in the Windows System.
Use the VMMap application to profile the memory usage of several different processes on your system.
Use the VMMap help documentation if necessary.
1) Select a process to profile. Firefox.exe will work well.
2) How much committed memory has the process been allocated?
3) How much total working set memory does the process have?
4) What is the difference between committed and working set memory?
5) Empty the working set for the process.
6) Look at the processes statistics in Task Manager.
What happens to the page fault and page fault delta characteristics? Why is this happening?
7) Find a memory location that contains a printable string. What are you looking at? What type of memory is more likely to have a printable string?
Windows Memory Command Line
The mem command and its variants provides some view of the available memory and memory layout of a Windows system.
Experiment with this command.
Process and Memory Management Wrapup
1) Compare and contrast Windows and Linux approaches to process and memory management.
2) Why are process management and memory management so closely linked?
3) Are a Linux daemon and a Windows service the same thing?
4) Are a daemon, service, and a process all the same thing?
5) How do Windows and Linux differ with respect to the monitoring tools related to process and memory management? What are strengths and weaknesses of these different approaches?
Recursion
Copy the following code into notepad. Save the file as an html file. Open the file in Firefox. Experiment with recursion.
<!-- For full description of recursion, review the
Website: http://www.c-point.com/javascript_tutorial/recursion.htm -->
<html>
<head>
<title>Recursion</title>
</head>
<body>
<h1>I love recursion!</h1>
<script type="text/javascript">
function factorial(aNumber) {
// If the number is not an integer, round it down.
aNumber = Math.floor(aNumber);
// The number must be equal to or bigger than zero if (aNumber < 0)
{
return "undefined";
}
//base case
if ((aNumber == 0) || (aNumber == 1))
{ // If the number is 0 or 1, its factorial is 1.
return 1;
}
//recursive case else
{ // Make a recursive call
return (aNumber * factorial(aNumber - 1));
} }
number = prompt("Enter a number:", "5") document.write(factorial(number));
</script>
</body>
</html>
What happens if you put in a very large number?
Hint: search the error console in Firefox if nothing appears to happen.
Why does Firefox behave in this manner?
What happens in the stack when a recursive call is made?
Why is recursion so powerful and yet dangerous in a computer program?