Uploaded by ugyenwgyeltshen.ug

VIRTUAL MEMORY in mac OS

advertisement
VIRTUAL MEMORY IN mac OS
The macOS operating system has a feature called virtual memory that enables it to emulate
RAM by using hard drive space. Using hard disk space as extra RAM enables the system to
execute more and bigger apps. Data is moved in and out of RAM and the hard drive as
necessary to do this. Demand paging is a feature of macOS that allows it to page out pages that
haven't been used in a while to the disk and bring pages into memory when needed. In the
System Preferences, the virtual memory size may be changed, and macOS takes care of
managing the virtual memory automatically. However, excessive usage of the virtual memory
might result in thrashing, which drastically slows down the system.
Using demand paging or demand segmentation, virtual memory enables on-demand loading of
necessary pages or segments into memory without necessitating the presence of all pages in
main memory at the same time.
Demand Paging
Operating systems employ demand paging as a memory management strategy to optimize
memory use. Demand paging is another tool used by Mac OS X, now known as macOS, to
effectively manage its processes.
Demand paging delays loading memory pages into physical memory until a process really need
them. This is different from the conventional method, which requires loading the complete
program into memory before it can be used.
Each process in macOS has an own virtual address space. A page fault happens when a process
tries to access memory that isn't currently in physical memory. When the necessary page has
been loaded into physical memory, the operating system adjusts the process's page table to
reflect the new position of the page.
MacOS also uses a method known as "copy-on-write" (COW) to further minimize the utilization
of memory. The operating system may create a new page and designate it as a copy-on-write
page when a process requests a new page of memory. This implies that unless the process tries
to edit the page, it hasn't truly been duplicated. Until then, it is possible for numerous processes
to share the same physical memory page, which lowers memory utilization and boosts system
speed.
1
Advantages:



The ability to sustain many processes in main memory enables more effective CPU
usage.
Demand paging allows for the execution of processes that are bigger than the main
memory, eliminating a basic programming limitation.
Reduces the amount of main memory needed for each task, enabling higher degrees of
multiprogramming.
Disadvantages:



Can reduce system performance since the hard drive and physical memory are
constantly exchanging data.
Increases the likelihood of data loss or corruption if a hard drive failure or power outage
happens while data is being transferred.
Manages both physical and virtual memory, which makes the memory management
system more complicated.
Page Fault Service Time: Time refers to the time taken by an operating system to service a page
fault when a process accesses a page that is not currently in physical memory. A shorter Page
Fault Service Time is desirable for better performance, and techniques such as pre-fetching
frequently accessed pages and using faster storage systems can be used to improve it.
2
Swapping:
Operating systems employ the memory management method known as swapping to
temporarily move memory pages to disk or swap space in order to free up physical memory.
Like the majority of contemporary operating systems, macOS employs swapping as a
component of its memory management scheme.
When the operating system in macOS wants to release physical memory for use by other
processes or to prevent memory exhaustion, swapping takes place. The operating system may
decide to move part of a process's memory pages to disk or swap space when it detects that the
process is not actively using its allotted memory.
The operating system will swap a page that has been removed from physical memory back in
when it is required. Due to the operating system's need to read the page from disk and update
the process's page table, this may result in a page fault delay.
To effectively manage memory, macOS combines demand paging and swapping. MacOS may
replace entire processes or sections of processes that are not actively being used when physical
memory is running low. This keeps the system from running out of memory and helps free up
memory for other programs that require it.
MacOS also uses a method known as "copy-on-write" (COW) to further minimize the utilization
of memory. The operating system may create a new page and designate it as a copy-on-write
page when a process requests a new page of memory. This implies that unless the process tries
to edit the page, it hasn't truly been duplicated. Until then, it is possible for numerous processes
to share the same physical memory page, which lowers memory utilization and boosts system
speed.
3
Thrashing
More processes can be kept in memory since only a small portion of any particular process is
ever present in the main memory. Additionally, time is saved by avoiding swapping out and in
unneeded pages of memory. The OS must, however, handle this system in a sensible manner. So
that the CPU and OS have direct access to as many processes as feasible, almost all of the main
memory will be taken up by process pages in the steady-state. As a result, the OS must discard a
page whenever it loads a new one. If it discards a page right before it is utilized, it will simply
need to acquire that page once more nearly immediately.
Thrashing is a disorder that develops when this happens frequently. Instead of carrying out
instructions, the system wastes the majority of its time switching pages. So it's necessary to use
a decent page replacement method.
4
The graphic demonstrates how, due to excessive page replacement, raising the level of
multiprogramming over a particular threshold (lambda), can result in lower CPU usage and
longer processing times. Thrashing is the term for this.
Causes of Thrashing:
A lack of physical memory is the main reason for thrashing in macOS and any other operating
system. Insufficient physical memory forces the system to frequently swap pages of memory
between physical memory and the disk, which can result in high CPU and disk I/O utilization,
slowing the system and making programs unresponsive.
Other elements that may cause macOS to thrash include:



Running too many programs or processes at once: The system may employ paging or
swapping to satisfy the demand when too many applications are executing at once and
end up needing more memory than is available.
Memory leaks: Some applications have a tendency to accumulate memory usage over
time without releasing it, which leaves the system with insufficient memory.
Insufficient virtual memory settings: The efficiency with which the macOS system
manages memory needs can be affected by the virtual memory settings. The system may
thrash if the virtual memory settings are not optimized.
5




Memory fragmentation: When memory is fragmented, there may not be enough
contiguous free memory to allot to new processes, which forces the system to use
swapping or paging.
Lack of memory compression: If macOS is unable to adequately compress memory, it
may be forced to use excessive paging or swapping.
High degree of multiprogramming : If the number of processes keeps on increasing in
the memory then the number of frames allocated to each process will be decreased. So,
fewer frames will be available for each process. Due to this, a page fault will occur more
frequently and more CPU time will be wasted in just swapping in and out of pages and
the utilization will keep on decreasing.
Lacks of Frames: If a process has fewer frames then fewer pages of that process will be
able to reside in memory and hence more frequent swapping in and out will be required.
This may lead to thrashing. Hence sufficient amount of frames must be allocated to each
process in order to prevent thrashing.
Reduction of Thrashing


Tell the long-term scheduler not to put the processes into memory after the threshold in
order to prevent the system from thrashing.
Instruct the mid-term scheduler to suspend some of the processes if the system is
already thrashing so that we can stop it from thrashing.
Other elements that avoids cause macOS to thrash include:






Add more RAM to your system to reduce reliance on swapping and paging.
Adjust virtual memory settings, like increasing the swap file size, to optimize memory
usage.
Close unnecessary programs to reduce memory usage and prevent thrashing.
Address memory leaks in programs by closing and reopening them or updating to a
newer version.
Defragment memory by restarting your system or using a third-party tool.
Choose memory-efficient software with features that reduce memory usage.
The performance of a virtual memory management system depends on the total number of
page faults, which depend on “paging policies” and “frame allocation”
Frame Allocation:
6
Number of frames allocating to each process in either static or dynamic.
 Static Allocation: The number of frame allocation to a process is fixed.
 Dynamic Allocation: The number of frames allocated to a process changes.
Paging Policies:



Fetch Policy: It decides when a page should be loaded into memory.
Replacement Policy: It decides which page in memory should be replaced.
Placement Policy: It decides where in memory should a page be loaded.
demand paging in mac os - Bing images
Virtual Memory in Operating System - GeeksforGeeks
Swapping in Operating System - GeeksforGeeks
Techniques to handle Thrashing - GeeksforGeeks
7
Download