What is Swap Memory?
Memory Introduction -:
- Memory references are dynamically translated into physical addresses at run time
- A process may be broken up into pieces that do not need to located contiguously in main memory
- All pieces of a process do not need to be loaded in main memory during execution
- Operating system brings into main memory a few pieces of the program
- Resident set - portion of process that is in main memory
- An interrupt is generated when an address is needed that is not in main memory
- Operating system places the process in a blocking state
- Piece of process that contains the logical address is brought into main memory
- Operating system issues a disk I/O Read request
- Another process is dispatched to run while the disk I/O takes place
- An interrupt is issued when disk I/O complete which causes the operating system to place the affected process in the Ready state
- More processes may be maintained in main memory
- Only load in some of the pieces of each process
- With so many processes in main memory, it is very likely a process will be in the Ready state at any particular time
- A process may be larger than all of main memory.
Swap Memory -:
Linux divides its physical RAM
(random access memory) into chucks of memory called pages.The operating system
divides physical memory into units called frames. The virtual memory is
similarly divided into pages, Imagine that all the physical memory also as a
long byte-wide tape. We cut it up into page size rectangles from the
beginning to the end. These cut up rectangles are known as frames
Initially, the pages are slices of program or data files stored on the HDD. As the OS loads and unloads, several pages of different processes will be in the frames. It is possible that no process has all its pages in frames. Recently referenced pages are located in the frames. The OS loads pages into frames as needed, and unloads a page either because it is no longer need to be in a frame (i.e., RAM), or because a fresh page needs to be loaded into a frame and all frames are already occupied.
Swapping is the process whereby a page of memory is copied to the preconfigured space on the hard disk, called swap space, to free up that page of memory. The combined sizes of the physical memory and the swap space is the amount of virtual memory available.
Swapping is necessary for two important reasons-:
First, when the system requires more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately.
Second, a significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache.
In Another Way , The operating system creates a swap volume, or a pagefile on the hard disk. If a page is not used ("referenced") for a while, it is written to the pagefile, marking the frame it occupied until then as now vacant. This is called "swapping" or "paging out" memory. If that piece of memory is then later referenced by a program, the operating system reads the memory page back from the pagefile into physical memory, also called "swapping" or "paging in" memory.
Initially, the pages are slices of program or data files stored on the HDD. As the OS loads and unloads, several pages of different processes will be in the frames. It is possible that no process has all its pages in frames. Recently referenced pages are located in the frames. The OS loads pages into frames as needed, and unloads a page either because it is no longer need to be in a frame (i.e., RAM), or because a fresh page needs to be loaded into a frame and all frames are already occupied.
Swapping is the process whereby a page of memory is copied to the preconfigured space on the hard disk, called swap space, to free up that page of memory. The combined sizes of the physical memory and the swap space is the amount of virtual memory available.
Swapping is necessary for two important reasons-:
First, when the system requires more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately.
Second, a significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache.
In Another Way , The operating system creates a swap volume, or a pagefile on the hard disk. If a page is not used ("referenced") for a while, it is written to the pagefile, marking the frame it occupied until then as now vacant. This is called "swapping" or "paging out" memory. If that piece of memory is then later referenced by a program, the operating system reads the memory page back from the pagefile into physical memory, also called "swapping" or "paging in" memory.
What is Journaling?
A file system in which the hard disk maintains data integrity in the event of a system crash or if the system is otherwise halted abnormally. The journaled file system (JFS) maintains a log, or journal, of what activity has taken place in the main data areas of the disk; if a crash occurs, any lost data can be recreated because updates to the metadata in directories and bit maps have been written to a serial log. The JFS not only returns the data to the pre-crash configuration but also recovers unsaved data and stores it in the location it would have been stored in if the system had not been unexpectedly interrupted.
What occurs during the journaling process is that a user submits a change to a file. The first thing the file system does is to mark the changes in a 'journal', or a separate file used specifically for journaling. The size of the journal file is a set size which when full, older entries are overwritten (often called a circular file).
Three events can cause the journal entries to be written to the specified files:
1. File system buffer is low
2. Timed setting has expired
3. Journal is getting full and could start overwriting itself
If a crash occurs, the journal entries and files are compared. Data is written to the files that are in the journal, but not yet on the disk. The process recovers the data to its wanted state.
There are three types of Journaling: writeback, ordered and data.
1. writeback
Here, only the metadata is journaled and data is written to the file on the disk. In a crash, the file system is recoverable, but the physical data can be corrupted. Corruption can occur if a crash happens after the journal is made of the metadata, but before the writing of the physical data. File system recovery is the worst, but the performance is the best.
2. ordered (default)
This mode is the reverse of writeback. The physical data is written first before the metadata is journaled. The ordered mode allows the data and file system to be uncorrupted if a system crashes before the journal is written. File system recovery is medial.
3. data
In the data mode, the metadata and file contents are journaled. System performancecan be poorer than the other two modes, but the fault tolerance is much better.
What is Inode?
The
“inode” is sometimes referred to as an index node. But what is it? Basically,
it is a file structure on a file system. More easily, it is a “database” of all
file information except the file contents and the file name.
In a
file system, inodes consist roughly of 1% of the total disk space, whether it
is a whole storage unit (hard disk,thumb drive, etc.) or a partition on a
storage unit. The inode space is used to “track” the files stored on the hard
disk. The inode entries store metadata about each file, directory or object,
but only points to these structures rather than storing the data. Each entry is
128 bytes in size. The metadata contained about each structure can include the
following:
Inode number
- Access Control List (ACL)
- Extended attribute
- Direct/indirect disk blocks
- Number of blocks
- File access, change and modification time
- File deletion time
- File generation number
- File size
- File type
- Group
- Number of links
- Owner
- Permissions
- Status flags
NOTE:
- The metadata does not include the file’s name.
- An inode number can only change if the file is moved.
Rather
than the name, the inode of each file uses a pointer to point to the specific
file, directory or object. The pointer is a unique number which usually is
referred to as the inode number.
This is best feature of operating system.
ReplyDeleteThank you
Thank you Sir it is very help full information
ReplyDeletekya blog hai ..wow dil bagh bagh ho gaya
ReplyDelete