Digital UNIX Internals II4 - 1Buffer Caches Chapter Four.

Slides:



Advertisements
Similar presentations
Chapter 12: File System Implementation
Advertisements

Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Paging: Design Issues. Readings r Silbershatz et al: ,
Tutorial 8 March 9, 2012 TA: Europa Shang
More on File Management
Chapter 12. Kernel Memory Allocation
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 9: Virtual Memory Background Demand Paging.
Virtual-Memory Management
File System Implementation 1 Chapter 9. File System Implementation Introduction System V File System Berkeley Fast File System Temporary File System Special-purpose.
Chapter 11: File System Implementation
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
File System Implementation
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
Chapter 12: File System Implementation
CS 333 Introduction to Operating Systems Class 18 - File System Performance Jonathan Walpole Computer Science Portland State University.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
File System Implementation
1 I/O Management in Representative Operating Systems.
Chapter 3 Buffer Cache TOPICS UNIX system Architecture Buffer Cache
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
Disk Access. DISK STRUCTURE Sector: Smallest unit of data transfer from/to disk; 512B 2/4/8 adjacent sectors transferred together: Blocks Read/write heads.
Operating Systems CMPSC 473 I/O Management (4) December 09, Lecture 25 Instructor: Bhuvan Urgaonkar.
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
Chapter 4. INTERNAL REPRESENTATION OF FILES
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials– 8 th Edition Chapter 10: File System Implementation.
Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations.
Free Space Management.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 12: File System Implementation File System Structure File System Implementation.
File System Implementation
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 11: File System Implementation.
Chapter 4. INTERNAL REPRESENTATION OF FILES
A summary by Nick Rayner for PSU CS533, Spring 2006
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
Lecture 11 Page 1 CS 111 Online Working Sets Give each running process an allocation of page frames matched to its needs How do we know what its needs.
12.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 12: File System Implementation Chapter 12: File System Implementation.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 12: File System Implementation File System Structure File System Implementation.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition File System Implementation.
CS333 Intro to Operating Systems Jonathan Walpole.
UNIX File System (UFS) Chapter Five.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 12: File System Implementation.
File Systems cs550 Operating Systems David Monismith.
4P13 Week 12 Talking Points Device Drivers 1.Auto-configuration and initialization routines 2.Routines for servicing I/O requests (the top half)
11.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 11.5 Free-Space Management Bit vector (n blocks) … 012n-1 bit[i] =  1  block[i]
4P13 Week 9 Talking Points
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 7 – Buffer Management.
FILE SYSTEM IMPLEMENTATION 1. 2 File-System Structure File structure Logical storage unit Collection of related information File system resides on secondary.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
1 The File System. 2 Linux File System Linux supports 15 file systems –ext, ext2, xia, minix, umsdos, msdos, vfat, proc, smb, ncp, iso9660, sysv, hpfs,
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
Introduction to Kernel
Chapter 3 Buffer Cache TOPICS UNIX system Architecture Buffer Cache
Chapter 2: The Linux System Part 4
Jonathan Walpole Computer Science Portland State University
Module 11: File Structure
Chapter 11: File System Implementation
Chapter 12: File System Implementation
Chapter 9: Virtual Memory
Buffer Cache.
Lecture 10: Buffer Manager and File Organization
Chapter 9: Virtual-Memory Management
Overview Continuation from Monday (File system implementation)
Overview: File system implementation (cont)
Internal Representation of Files
Structure of Processes
Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps
Virtual Memory.
Mr. M. D. Jamadar Assistant Professor
CSE 542: Operating Systems
Presentation transcript:

Digital UNIX Internals II4 - 1Buffer Caches Chapter Four

Digital UNIX Internals II4 - 2Buffer Caches File System I/O Using a Cache buffer user process buffer kernel in memory cache On-disk Data read/write buffer user process mmap

Digital UNIX Internals II4 - 3Buffer Caches Process Reading One Byte read (...,1) user process kernel A Buffer

Digital UNIX Internals II4 - 4Buffer Caches File System Caches and I/O Read-ahead –When a file system notices a file being read sequentially, it can order the physical read of the next block(s) before the application actually requests them. Write-behind –Data blocks do not have to be immediately written to disk. File systems can cluster together writes to contiguous disk blocks to improve performance.

Digital UNIX Internals II4 - 5Buffer Caches File System Caches in Digital UNIX (Traditional BSD UNIX) Buffer Cache –From BSD –Fixed pool of physical memory Unified Buffer Cache –Similar to SunOS and SVR4 –Flexible pool of physical memory –Supports memory mapping

Digital UNIX Internals II4 - 6Buffer Caches Example: UFS uses both v_type = VDIR v_object v_cleanblkhd v_dirtyblkhd vnode v_type = VREG v_object v_cleanblkhd v_dirtyblkhd vnode vm_object vo_vp vo_cleanpl vo_cleanwpl vo_dirtywpl ob_memq vm_page vm_vp_object buf

Digital UNIX Internals II4 - 7Buffer Caches Traditional Buffer Cache Pool of Memory –Allocated at boot time –Shared with no other subsystem or allocator Buffer Structures –Links into access hash chain, LRU and same vnode lists –Device containing buffer –Pointer to vnode –Logical block in vnode –Pointer to routine called when I/O is done Linked lists of Buffers –Hash chain bucket, LOCKED, LRU, AGE and EMPTY lists

Digital UNIX Internals II4 - 8Buffer Caches struct buf b_flags b_forw, b_back av_forw, av_back b_blockf, b_blockb b_bufsize b_bcount b_devb_error b_un b_lblkno, b_blkno b_resid b_proc b_hash_chain b_iodone() b_pagelist b_vp, b_rvp b_rcred, b_wcred b_dirtyoff, b_dirtyend b_iocomplete b_lock driver fields buf Hash list buf Queue buf Vnode buffer list Buffer proc buf vm_page vnode ucred Credentials Head of hash lst

Digital UNIX Internals II4 - 9Buffer Caches Buffer Cache Lists bufhd bufhash buf bfreelist[0] LOCKED bfreelist[1] LRU bfreelist[2] AGE bfreelist[3] EMPTY Buffer Memory Pages

Digital UNIX Internals II4 - 10Buffer Caches To Find a Buffer 1.Calculate hash index using disk block number (b_blkno) and vnode (b_vp) (see BUFHASH macro in /sys/include/sys/buf.h). 2.Index into the hash list. 3.Follow hash pointer to buf structure in queue. 4.Identify the correct buf structure using vnode and block numbers. 5.If no match, follow hash pointer (b_forw) to next buf structure in queue. 6. If you get to the end of the list (wraps back to beginning) without finding the buf structure, it does not exist; allocate a new one from the free list.

Digital UNIX Internals II4 - 11Buffer Caches Getting a Buffer bread() getnewbuf() getblk() VOP_STRATEGY() allocbuf()

Digital UNIX Internals II4 - 12Buffer Caches UBC - Unified Buffer Cache(1) Motivation –File Systems and Virtual Memory (Process Management) compete for physical memory. –UBC unifies previously separate pools of physical memory. –Available Memory can be used by File Systems (UBC) or VM on a first come first serve basis. –VM can memory map a file using same memory object as UBC. Utilizes memory from the available pool –vm_page_queue_free –vm_page_array

Digital UNIX Internals II4 - 13Buffer Caches Unified Buffer Cache (2) Uses memory objects of type OT_UBC –includes a pointer to a vnode –associates cached pages with a specific file –accessed by a file system looking for cached data memory management on pagefault for an mmap’d file Utilizes lists; –vm_page_buckets to find vm_pages belonging to an object –ubc_lru to time order when pages were cached

Digital UNIX Internals II4 - 14Buffer Caches UBC Memory Object (OT_UBC) struct vm_ubc_object ob_ref_count ob_res_count ob_size ob_resident_pages ob_flags ob_memq ob_ops = u_anon_oop vm_object_ops ob_type vm_page vu_cleanpl vu_cleanwpl vu_dirtywpl vu_ops vu_vfp vu_wirecnt vu_object vu_nsequential vu_loffset vu_stamp vu_seglock vu_seglist vfs_ubcops vu_pshared vu_freelists

Digital UNIX Internals II4 - 15Buffer Caches UBC LRU Page Queue Least recently used list of UBC pages –One per memory affinity domain vm_mads[N].md_ubc.ubc_lru Each is a struct vm_page –vm_page -> vm_ubc_object -> vnode For each vnode's VM object, –clean page list –clean wired page list –dirty page list –dirty wired page list

Digital UNIX Internals II4 - 16Buffer Caches UBC Routines (1) RoutineFunction ubc_object_allocate() Allocates a vm_ubc_object if the vnode is a regular type and one has not already been allocated. ubc_object_free() Frees the vm_ubc_object when the vnode is about to be reused. ubc_page_lookup() Looks up the page at the specified offset and specified vm_vp_object. ubc_incore() Looks for resident pages in the specified range. ubc_page_alloc() Allocates a page or returns a found page in the page hash list. ubc_page_release() Releases a page to the UBC LRU list or system memory if possible.

Digital UNIX Internals II4 - 17Buffer Caches UBC Routines (2) RoutineFunction ubc_lookup() Performs a hash search lookup on the page at the specified offset. If found, removes the page from the ubc_lru list and holds it. ubc_page_dirty() Transitions a page from the vnode's clean page list to its dirty page list. ubc_msync() Calls for mmap to free all clean pages and writes all dirty pages. ubc_invalidate() Invalidates some (or all) resident pages for a vnode. ubc_flush_dirty() Starts I/O on all dirty pages for a vnode. Does not wait for I/O completion if flag B_ASYNC is used.

Digital UNIX Internals II4 - 18Buffer Caches UBC Routines (3) RoutineFunction ubc_dirty_kluster() Creates a list of sorted pages for a vnode. Assumes pages are scheduled for writing. ubc_bufalloc() Allocates a buf structure. ubc_sync_iodone() Waits for synchronous I/O transfer to complete, then frees buf and pages. ubc_async_iodone_lwc() Called as LWC when asyncronous I/O transfer completes.

Digital UNIX Internals II4 - 19Buffer Caches File System and VM Routines System Call read() write() VFS VOP_READ VOP_WRITE File System ufs_read() ufs_write() uiomove() UBC Resident Page Management ufs_getpage() returns VM page mmap Page Fault Handler I/O

Digital UNIX Internals II4 - 20Buffer Caches Finding a UBC page from a file system VOP_READ(vnode,...) ufs_read(vnode,...) ufs_getpage(vnode,...) ufs_getapage(vnode,...) ubc_lookup(vnode,...) vm_page_lookup(mem_obj,..)

Digital UNIX Internals II4 - 21Buffer Caches Limiting UBC ubc_dirty_thread –Calls ubc_memory_flushdirty Launders excessive dirty pages via calls to FSOP_PUTPAGE() vm_pageout thread (pageout daemon) –Runs vm_pageout_loop() –When number of free pages is low and UBC has borrowed to many pages, UBC pages are reclaimed off ubc_lru If no free pages, vm_page_alloc() may also come to ubc_lru.

Digital UNIX Internals II4 - 22Buffer Caches ubc_memory_purge() Flow Start Get ubc_lru page Free the page Referenced bit on? Yes No Yes No Freed enough? Yes Dirty? Move page from vm_vp_obect dirty list to clean list Write the page out (VOP_PUTPAGE()) asynchronously No Turn off and move to tail of bc_lru Stop

Digital UNIX Internals II4 - 23Buffer Caches Limiting the Amount of Dirty Data in UBC UBC limits the percent of its cached data that is modified –improves performance by spreading out IO load –minimizes loss of data if system crash Managed by separate kernel daemon thread

Digital UNIX Internals II4 - 24Buffer Caches ubc_dirty_thread_loop() Flow Start Sleep on timer Remove page from ubc_lru Too many dirty pages Yes No Get ubc_lru_page Yes No Too many dirty pages Yes Dirty Move page from vm_vp_obect dirty list to clean list Write the page out (VOP_PUTPAGE()) asynchronously No

Digital UNIX Internals II4 - 25Buffer Caches UBC Parameters and Thresholds (1) FieldDescription ubc_pages Count of UBC pages. ubc_minpages Smallest number of pages UBC will shrink to. ubc_minpages = (vm_managed_pages * ubc_minpercent)/100 where ubc_minpercent is tunable (Default =10). ubc_maxpages Upper limit of size of UBC. ubc_maxpages = (vm_managed_pages * ubc_maxpercent)/100 where ubc_maxpercent is tunable (Default = 100). ubc_lru_count Number of pages on the UBC LRU queue. ubc_dirty_limit Determines if UBC should flush and free dirty pages. ubc_dirty_limit=MAX(ubc_min_dirtypages, ((vm_tune_value(ubcdirtypercent) * ubc_pages)/100)) where ubcdirtypercent is tunable (Default =10).

Digital UNIX Internals II4 - 26Buffer Caches UBC Parameters and Thresholds (2) FieldDescription ubc_dirty_pages UBC page currently dirty; tracked by system. ubc_borrowlimit Number of pages UBC can have. If ubc_pages>ubc_borrowlimt then UBC is asked to free pages. ubc_borrowlimit=(ubc_borrowpercent * vm_managed_pages)/100 where ubc_borrowpercent is 10 by default. vm_perf.vpf_ubchit Rate of UBC pages transitioning to the tail of the UBC LRU list because a pmap_is_referenced returned TRUE. vm_perf.vpf_ubcalloc Rate of UBC page allocation vm_perf.vpf_ubcpagepushes Rate of pages being evicted from the UBC because of memory reclamation activity. vm_free_count Current count of free pages.

Digital UNIX Internals II4 - 27Buffer Caches Source Reference (1 of 4) Buf Cache kernel/sys/buf.h –definition of struct buf kernel/vfs/vfs_bio.c –bfreelist[], bufhash and buf routines (bread() etc.)

Digital UNIX Internals II4 - 28Buffer Caches Source Reference (2 of 4) UBC kernel/vm/vm_page.h –definitions of vm_page, vm_page_array kernel/vm/vm_resident.c –definition of vm_page_bucket hashing array kernel/vfs/vfs_ubc.c –definition of ubc lru list kernel/vm/vm_ubc.h –definition of vm_ubc_object kernel/vfs/vfs_ubc.c –implementation of ubc routines interface routines.

Digital UNIX Internals II4 - 29Buffer Caches Source Reference (3 of 4) Reading Data From a UBC Cached UFS File kernel/ufs/ufs_vnops.cufs_read() ufs_getpage() ufs_getapage() kernel/vfs/vfs_ubc.cubc_lookup() kernel/vm/vm_resident.cvm_page_lookup()

Digital UNIX Internals II4 - 30Buffer Caches Source Reference (4 of 4) Pagefaulting on a UBC MMAPed Page kernel/arch/alpha/locore.sXentMM kernel/arch/alpha/trap.ctrap() kernel/vm/vm_fault.cvm_fault() kernel/vm/vm_umap.cu_map_fault() kernel/vm/u_mape_vp.cu_vp_fault()