Presentation is loading. Please wait.

Presentation is loading. Please wait.

File and Page Caching CSE451 Andrew Whitaker. Oh, The Many Caches of CSE451 Virtual memory  OS maintains a cache of recently used memory pages File system.

Similar presentations


Presentation on theme: "File and Page Caching CSE451 Andrew Whitaker. Oh, The Many Caches of CSE451 Virtual memory  OS maintains a cache of recently used memory pages File system."— Presentation transcript:

1 File and Page Caching CSE451 Andrew Whitaker

2 Oh, The Many Caches of CSE451 Virtual memory  OS maintains a cache of recently used memory pages File system  OS maintains a cache of recently used file blocks

3 Unified Caching OS maintains a single pool of buffers for disk blocks and memory pages  Linux: page cache Advantages  Flexibility: Can adjust memory allocation to meet changing demands  Efficiency: Avoid storing multiple copies of data Page cache provides backing for other services:  Memory-mapped files  Pipes

4 Memory-Mapped Files Basic Idea: Access files like memory  Use load/store instead of read/write Process Address Space foo.txt

5 Memory Map Implementation Normal pages are stored in a generic swap area  Either a dedicated partition or a file Memory-mapped files are simply swapped out to the appropriate file Everything is done lazily  Pages are demand loaded (on a load)  The OS uses asynchronous write-back The msync call flushes dirty pages

6 cat -v foo.txt | grep ‘hello’ Pipes Pipes implement unidirectional communication between threads/processes A pipe consists of two file descriptors  A read end  A write end

7 1.// ls | wc -l 2.int main() { 3. int pfds[2]; 4. // create a pair of file descriptors (read,write) 5. pipe(pfds); 6. if (!fork()) { 7. close(1); /* close normal stdout */ 8. dup(pfds[1]); // make stdout same as pfds[1] 9. close(pfds[0]); /* we don't need this */ 10. execlp("ls", "ls", NULL); 11. } else { 12. close(0); /* close normal stdin */ 13. dup(pfds[0]); /* make stdin same as pfds[0] */ 14. close(pfds[1]); /* we don't need this */ 15. execlp("wc", "wc", "-l", NULL); 16. } 17.}

8 Pipe Implementation Pipes are implemented by a special “file system”  Linux: pipefs Pipe data is a bounded buffer  Allocated from the page cache  No on disk-representation Size of the pipe is bounded  One page in <= Linux 2.6.10  16 pages starting with Linux 2.6.11


Download ppt "File and Page Caching CSE451 Andrew Whitaker. Oh, The Many Caches of CSE451 Virtual memory  OS maintains a cache of recently used memory pages File system."

Similar presentations


Ads by Google