|
|
In this FAQ: Virtual memory, Scheduler,
Commands to check memory usage, |
|||||||||||||||||||||||||||||||||||||
|
Unix FAQ Menu |
Question: Could you please describe for me how the: For example, could you tell me how the memory manager handles memory using the memory manager. Does it use Demand Paging? Segmented Paging? If it does use paging, does it handle pages on a first come first served basis? Thank you, Answer;The Linux virtual memory handler, in common with most modern Unix variants
uses demand paging in most situations. In very extreme memory shortfall
situations the handler may revert to process swapping, this is where an
entire process is swapped out of main memory. Segmented paging - where segments of a program are replaced under the control of that same program is not used in Unix. How memory is managed under UnixWhen talking about Unix, 'memory' generally refers to virtual memory ("VM") and not simple physical memory (RAM/Random Access Memory). An explanation of a few terms is in order;
One cannot describe the virtual memory system as a working on a first-come,
first-served basis. Just after boot when most physical RAM is free then
this statement is generally true, however in normal operation the algorithm
is a considerably more sophisticated.
At system startup the free memory pool will steadily fall as new programs are started as part of the boot process. What happens next will vary with the functions being performed by the system. The algorithm used by the VM handler when the free memory pool drops below desfree is complex, varies enormously by platform and the reader should refer to their system documentation for specifics. Generally when the VM handler is called on by the kernel to free memory, each page of memory is analysed using several criteria, including usage count and whether the page contains code or data, and in the later case whether it private to one process or shared amongst several. Virtual Memory in the Real World Servers (e.g. fileservers, database servers, web servers) have
a generally static process load. As such their free memory pool should
normally remain above desfree. If a server consistently shows high VM
handler activity during normal operation then it is short of physical
memory. The commands "vmstat" and "sar" can be used to observe virtual memory activity. Typically you would run vmstat with an interval - i.e. "vmstat 5". Bear in mind that Unix uses physical memory for many things other than just programs and data. For example many filesystem and network related structures are cached for performance. Unix uses all physical memory all
the time The SchedulerI don't fully understand what you need by the term "Processor Manager", I suspect you probably mean the process scheduler. The scheduler is responsible for allocating CPU time to those processes on the runqueue. The runqueue is simply a list of processes that currently require CPU time, as opposed to those waiting for some external event, such as a data I/O operation to complete, a user prompt, etc.. Normally the scheduler evenly allocates CPU time amongst those processes that require it, however issues like priority, and the real-time status of a process are also factored into this calculation. Commands to observe scheduler activity are "vmstat", "sar", "top", and "ps". Process priority can be modified using the the 'nice' and 'renice' commands. Commands to Check memory.Two commands to check memory usage on a system wide basis are 'vmstat' and 'sar'. My favourite being vmstat. The vmstat command below shows the amount of swap and physical memory free - in Kb. The columns 're','mf','pi','po',and 'fr' indicate the level of paging activity. Note the first line shows averages since the system booted, subsequent lines the activity over the last 5 seconds. sun (ksh) % vmstat 5 procs memory page disk faults cpu r b w swap free re mf pi po fr de sr s1 s3 s6 -- in sy cs us sy id 0 0 0 134848 41988 0 4 20 4 6 0 0 9 2 0 0 54 145 58 5 4 92 0 0 0 132448 29632 0 2 0 0 0 0 0 0 0 0 0 22 56 41 0 1 99 0 0 0 132448 29632 0 0 0 0 0 0 0 0 0 0 0 11 48 31 0 0 100 0 0 0 132440 29624 0 0 0 0 0 0 0 0 0 0 0 22 56 43 0 1 99 0 0 0 132440 29624 0 0 0 0 0 0 0 1 6 0 0 54 47 34 0 1 99 <Ctrl-C> sun (ksh) % Process memory usage can be examined using the '-l' option of ps - 'SZ' column; sun (ksh) % ps -l Here our shell is occupying 430 pages of virtual memory. On this system
1 page = 4096 bytes, so 430 pages is about 1.7MB. Note - page size varies
between platforms Footnotes; thrashing is where the system is spending considerably more time and effort performing memory management functions than it is running applications. The term is overused, and frequently misused. desperation swapping is where the virtual memory handler cannot identify pages to shift to the swap space and instead resorts, as a desperate last measure, to swapping an entire program out. Very rarely witnessed in normal operation.
Reference; Good complete works for Linux are thin on the ground, such is the nature
of open source development. One of the best works is a thesis by Mel Gorman,
available from the University of Limerick; FeedbackI hope you found this FAQ to be of some use. It would be most helpful if you
could rate it below. All fields are optional...
|
|||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||