码迷,mamicode.com
首页 > 系统相关 > 详细

Linux page cache

时间:2015-02-13 10:13:07      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:linux page cache vs direct io

Overview

Block device layer
page cache
IO scheduer


Page cache contains all file I/O data, direct I/O bypasses the page cache.


Page cache helps Linux to economize I/O

– Read requests can be made faster by adding a read ahead quantity, depending on the

historical behavior of file system accesses by applications

– Write requests are delayed and data in the page cache can have multiple updates before

being written to disk.

– Write requests in the page cache can be merged into larger I/O requests

But page cache...

    – Requires Linux memory pages

    – Is not useful when cached data is not exploited

Data just only needed once

Application buffers data itself

    – In Linux does not know which data the application really needs next. It makes only a guess

No alternatives if application cannot handle direct I/O


Consider to use...

direct I/O:
    – bypasses the page cache
    – is a good choice in all cases where the application does not want Linux to economize I/O and/or where the application buffers larger amount of file contents
async I/O:
    – prevents the application from being blocked in the I/O system call until the I/O completes
    – allows read merging by Linux in case of using page cache
    – can be combined with direct I/O

temporary files:
    – should not reside on real disks, a ram disk or tmpfs allows fastest access to these files
    – they don‘t need to survive a crash, don‘t place them on a journaling file system
file system:
    – use ext3 and select the appropriate journaling mode (journal, ordered, writeback)
    – turning off atime is only suitable if no application makes decisions on "last read" time,consider relatime instead

Direct I/O versus Page cache


Direct I/O

    – Preferable if application caches itself

Application knows best which data is needed again

Application knows which data is most likely needed next

    Example database base management systems DBMS

    – Preferable if caching makes no sense

Data only needed once

Backup and restore

Page cache

    – Optimizes re-read / write but can be critical

Data written to the page cache but not to disk yet can get lost if data loss cannot easily be handled

    – If application cannot handle direct I/O

Typical example is a file server


Linux page cache

标签:linux page cache vs direct io

原文地址:http://xmwang.blog.51cto.com/9889672/1614204

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!