Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ep:labs:05 [2025/02/11 23:59]
cezar.craciunoiu
ep:labs:05 [2025/04/01 10:33] (current)
cezar.craciunoiu Move introduction to spoiler
Line 18: Line 18:
  
 ===== Introduction ===== ===== Introduction =====
 +
 +<​spoiler>​
  
 <note important>​Disk I/O subsystems are the slowest part of any Linux system. This is mainly due to their distance from the CPU and for the old HDD the fact that disk requires physics to work (rotation and seek). If the time taken to access disk as opposed to memory was converted into days and minutes, it is the difference between 7 days and 7 minutes. As a result, it is essential that the Linux kernel minimises the amount of I/O operations it generates on a disk. </​note>​ <note important>​Disk I/O subsystems are the slowest part of any Linux system. This is mainly due to their distance from the CPU and for the old HDD the fact that disk requires physics to work (rotation and seek). If the time taken to access disk as opposed to memory was converted into days and minutes, it is the difference between 7 days and 7 minutes. As a result, it is essential that the Linux kernel minimises the amount of I/O operations it generates on a disk. </​note>​
 The following subsections describe the different ways the kernel processes data I/O from disk to memory and back. The following subsections describe the different ways the kernel processes data I/O from disk to memory and back.
  
-==== 01. Reading and Writing Data - Memory Pages ====+**01. Reading and Writing Data - Memory Pages** 
 The Linux kernel breaks disk I/O into pages. The default page size on most Linux systems is **4K**. It reads and writes disk blocks in and out of memory in 4K page sizes. You can check the page size of your system by using the time command in verbose mode and searching for the page size:  The Linux kernel breaks disk I/O into pages. The default page size on most Linux systems is **4K**. It reads and writes disk blocks in and out of memory in 4K page sizes. You can check the page size of your system by using the time command in verbose mode and searching for the page size: 
  
 //# getconf PAGESIZE// //# getconf PAGESIZE//
  
-==== 02. Major and Minor Page Faults ​====+**02. Major and Minor Page Faults** 
 Linux, like most UNIX systems, uses a **virtual memory layer** that maps into physical address space. This mapping is **"​on-demand"​** in the sense that when a process starts, the kernel only maps what is required. When an application starts, the kernel searches the CPU caches and then physical memory. If the data does not exist in either, the kernel issues a **Major Page Fault** (MPF). A MPF is a request to the disk subsystem to retrieve pages of the disk and buffer them in RAM. Linux, like most UNIX systems, uses a **virtual memory layer** that maps into physical address space. This mapping is **"​on-demand"​** in the sense that when a process starts, the kernel only maps what is required. When an application starts, the kernel searches the CPU caches and then physical memory. If the data does not exist in either, the kernel issues a **Major Page Fault** (MPF). A MPF is a request to the disk subsystem to retrieve pages of the disk and buffer them in RAM.
  
Line 46: Line 50:
 </​note>​ </​note>​
  
-==== 03. The File Buffer Cache ====+**03. The File Buffer Cache**
  
 The **file buffer cache** is used by the kernel to** minimise MPFs and maximise MnPFs**. As a system generates I/O over time, this buffer cache will continue to grow as the system will leave these pages in memory until memory gets low and the kernel needs to "​**free**"​ some of these pages for other uses. The result is that many system administrators see low amounts of free memory and become concerned when in reality, the system is just making good use of its caches ;-) The **file buffer cache** is used by the kernel to** minimise MPFs and maximise MnPFs**. As a system generates I/O over time, this buffer cache will continue to grow as the system will leave these pages in memory until memory gets low and the kernel needs to "​**free**"​ some of these pages for other uses. The result is that many system administrators see low amounts of free memory and become concerned when in reality, the system is just making good use of its caches ;-)
  
  
-==== 04. Types of Memory Pages ====+**04. Types of Memory Pages**
  
 There are **3** types of memory pages in the Linux kernel: There are **3** types of memory pages in the Linux kernel:
Line 58: Line 62:
   * **Anonymous Pages** – Pages of data that do belong to a process, but do not have any file or backing store associated with them. They can't be synchronised back to disk. In the event of a memory shortage, kswapd writes these to the swap device as temporary storage until more RAM is free ("​swapping"​ pages).   * **Anonymous Pages** – Pages of data that do belong to a process, but do not have any file or backing store associated with them. They can't be synchronised back to disk. In the event of a memory shortage, kswapd writes these to the swap device as temporary storage until more RAM is free ("​swapping"​ pages).
  
-==== 05. Writing Data Pages Back to Disk ==== +**05. Writing Data Pages Back to Disk**
  
 Applications themselves may choose to write **dirty pages** back to disk immediately using the **fsync()** or **sync()** system calls. These system calls issue a direct request to the **I/O scheduler**. If an application does not invoke these system calls, the pdflush kernel daemon runs at periodic intervals and writes pages back to disk. Applications themselves may choose to write **dirty pages** back to disk immediately using the **fsync()** or **sync()** system calls. These system calls issue a direct request to the **I/O scheduler**. If an application does not invoke these system calls, the pdflush kernel daemon runs at periodic intervals and writes pages back to disk.
  
-===== Monitoring I/O =====+**Monitoring I/O**
  
 <note important>​Certain conditions occur on a system that may create I/O bottlenecks. These conditions may be identified by using a standard set of system monitoring tools. These tools include **top**, **vmstat**, **iostat**, and **sar**. There are some similarities between the outputs of these commands, but for the most part, each offers a unique set of output that provides a different aspect on performance. The following subsections describe conditions that cause **I/O bottlenecks**.</​note>​ <note important>​Certain conditions occur on a system that may create I/O bottlenecks. These conditions may be identified by using a standard set of system monitoring tools. These tools include **top**, **vmstat**, **iostat**, and **sar**. There are some similarities between the outputs of these commands, but for the most part, each offers a unique set of output that provides a different aspect on performance. The following subsections describe conditions that cause **I/O bottlenecks**.</​note>​
  
-=== Calculating IOs Per Second ​===+**Calculating IOs Per Second**
  
 Every I/O __request__ to a disk takes a certain amount of time. This is due primarily to the fact that a //disk must spin// and //a head must seek//. The spinning of a disk is often referred to as "​**rotational delay**"​ (RD 8-))  and the moving of the head as a "​**disk seek**"​ (DS). The time it takes for each I/O request is calculated by __adding__ DS and RD. A disk's RD is fixed based on the RPM of the drive. An RD is considered half a revolution around a disk. Every I/O __request__ to a disk takes a certain amount of time. This is due primarily to the fact that a //disk must spin// and //a head must seek//. The spinning of a disk is often referred to as "​**rotational delay**"​ (RD 8-))  and the moving of the head as a "​**disk seek**"​ (DS). The time it takes for each I/O request is calculated by __adding__ DS and RD. A disk's RD is fixed based on the RPM of the drive. An RD is considered half a revolution around a disk.
Line 73: Line 76:
 Each time an application issues an I/O, it takes an average of 8MS to service that I/O on a 10K RPM disk. Since this is a fixed time, it is imperative that the disk be as efficient as possible with the time it will spend reading and writing to the disk. The amount of I/O requests is often measured in I/Os Per Second (IOPS). The 10K RPM disk has the ability to push 120 to 150 (burst) IOPS. To measure the effectiveness of IOPS, divide the amount of IOPS by the amount of data read or written for each I/O. Each time an application issues an I/O, it takes an average of 8MS to service that I/O on a 10K RPM disk. Since this is a fixed time, it is imperative that the disk be as efficient as possible with the time it will spend reading and writing to the disk. The amount of I/O requests is often measured in I/Os Per Second (IOPS). The 10K RPM disk has the ability to push 120 to 150 (burst) IOPS. To measure the effectiveness of IOPS, divide the amount of IOPS by the amount of data read or written for each I/O.
  
-=== Random vs Sequential I/O ===+**Random vs Sequential I/O**
 The relevance of KB per I/O depends on the __workload__ of the system. There are two different types of workload categories on a system: sequential and random. The relevance of KB per I/O depends on the __workload__ of the system. There are two different types of workload categories on a system: sequential and random.
  
Line 80: Line 83:
 **Random I/O** - Random access workloads do not depend as much on size of data. They depend primarily on the amount of IOPS a disk can push. Web and mail servers are examples of random access workloads. The I/O requests are rather small. Random access workload relies on how many requests can be processed at once. Therefore, the amount of IOPS the disk can push becomes crucial. **Random I/O** - Random access workloads do not depend as much on size of data. They depend primarily on the amount of IOPS a disk can push. Web and mail servers are examples of random access workloads. The I/O requests are rather small. Random access workload relies on how many requests can be processed at once. Therefore, the amount of IOPS the disk can push becomes crucial.
  
-=== When Virtual Memory Kills I/O ===+**When Virtual Memory Kills I/O**
  
 If the system does not have enough **RAM** to accommodate all requests, it must start to use the **SWAP** device. As file system I/Os, writes to the SWAP device are just as costly. If the system is extremely deprived of RAM, it is possible that it will create a __paging storm__ to the SWAP disk. If the SWAP device is on the same file system as the data trying to be accessed, the system will enter into contention for the I/O paths. This will cause a complete **performance breakdown** on the system. If pages can't be read or written to disk, they will stay in RAM longer. If they stay in RAM longer, the kernel will need to free the RAM. The problem is that the __I/O channels__ are so __clogged__ that nothing can be done. This inevitably leads to a __kernel panic and crash of the system__. If the system does not have enough **RAM** to accommodate all requests, it must start to use the **SWAP** device. As file system I/Os, writes to the SWAP device are just as costly. If the system is extremely deprived of RAM, it is possible that it will create a __paging storm__ to the SWAP disk. If the SWAP device is on the same file system as the data trying to be accessed, the system will enter into contention for the I/O paths. This will cause a complete **performance breakdown** on the system. If pages can't be read or written to disk, they will stay in RAM longer. If they stay in RAM longer, the kernel will need to free the RAM. The problem is that the __I/O channels__ are so __clogged__ that nothing can be done. This inevitably leads to a __kernel panic and crash of the system__.
Line 96: Line 99:
 <note tip>Both the swap device (///​dev/​sda1//​) and the file system device (///​dev/​sda3//​) are contending for I/O. Both have __high amounts of write requests per second__ (//w/s//) and __high wait time__ (//await//) to __low service time ratios__ (//​svctm//​). This indicates that there is **contention** between the two partitions, causing both to **underperform**.</​note>​ <note tip>Both the swap device (///​dev/​sda1//​) and the file system device (///​dev/​sda3//​) are contending for I/O. Both have __high amounts of write requests per second__ (//w/s//) and __high wait time__ (//await//) to __low service time ratios__ (//​svctm//​). This indicates that there is **contention** between the two partitions, causing both to **underperform**.</​note>​
  
-==== Takeaways ​====+**Takeaways**
  
 <note important>​ <note important>​
Line 105: Line 108:
   * Monitor the swap and file system partitions to make sure that **virtual memory** is not contending for **filesystem I/O**.   * Monitor the swap and file system partitions to make sure that **virtual memory** is not contending for **filesystem I/O**.
 </​note>​ </​note>​
 +
 +</​spoiler>​
  
 ===== Tasks ===== ===== Tasks =====
ep/labs/05.1739311157.txt.gz · Last modified: 2025/02/11 23:59 by cezar.craciunoiu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0