How to Get More Value from Your File System Directory Cache

How to Get More Value from Your File System Directory Cache

How to Get More Value From Your File System Directory Cache Chia-Che Tsai, Yang Zhan, Jayashree Reddy, Yizheng Jiao, Tao Zhang, and Donald E. Porter Stony Brook University fchitsai, yazhan, jdivakared, yjiao, zhtao, [email protected] Abstract 80% access/stat Applications frequently request file system operations that 60% open traverse the file system directory tree, such as opening a file 40% chmod/chown or reading a file’s metadata. As a result, caching file system unlink directory structure and metadata in memory is an important Time 20% performance optimization for an OS kernel. This paper identifies several design principles that can 0% substantially improve hit rate and reduce hit cost transpar- Execution Total % ently to applications and file systems. Specifically, our di- rectory cache design can look up a directory in a constant Figure 1: Fraction of execution time in several common util- number of hash table operations, separates finding paths from ities spent executing path-based system calls with a warm permission checking, memoizes the results of access con- cache, as measured with ftrace. trol checks, uses signatures to accelerate lookup, and re- duces miss rates through caching directory completeness. This design can meet a range of idiosyncratic requirements Directory caches are essential for good application per- imposed by POSIX, Linux Security Modules, namespaces, formance. Many common system calls must operate on file and mount aliases. These optimizations are a significant net paths, which require a directory cache lookup. For instance, improvement for real-world applications, such as improving between 10–20% of all system calls in the iBench system the throughput of the Dovecot IMAP server by up to 12% and call traces do a path lookup [17]. Figure 1 lists the fraction the updatedb utility by up to 29%. of total execution time several common command-line appli- cations spend executing path-based system calls (more de- tails on these applications and the test machine in x6). We 1. Introduction note that these system calls include work other than path Operating System kernels commonly cache file system data lookup, and that these numbers include some instrumenta- and metadata in a virtual file system (VFS) layer, which ab- tion overhead; nonetheless, in all cases except rm, the system stracts low-level file systems into a common API, such as call times and counts are dominated by stat and open, for POSIX. This caching layer has become a ubiquitous opti- which path lookup is a significant component of execution mization to hide access latency for persistent storage tech- time. For these applications, path-based system calls account nologies, such as a local disk. The directory cache is not ex- for 6–54% of total execution time. This implies that lowering clusively a performance optimization; it also simplifies the path lookup latency is one of the biggest opportunities for a implementation of mount-ing multiple file systems, consis- kernel to improve these applications’ execution time. tent file handle behavior, and advanced security models, such Unfortunately, even directory cache hits are costly—0.3– as SELinux [24]. 1.1 µs for a stat on our test Linux system, compared to only .04 µs for a getppid and 0.3 µs for a 4 KB pread. This issue is taken particularly seriously in the Linux ker- Permission to make digital or hard copies of all or part of this work for personal or nel community, which has made substantial revisions and in- classroom use is granted without fee provided that copies are not made or distributed creasingly elaborate optimizations to reduce the hit cost of for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the its directory cache, such as removing locks from the read author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or path or replacing lock ordering with deadlock avoidance in a republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]. retry loop [11, 12]. Figure 2 plots directory cache hit latency SOSP’15, October 4–7, 2015, Monterey, CA. against lines of directory cache code changed over several Copyright is held by the owner/author(s). Publication rights licensed to ACM. ACM 978-1-4503-3834-9/15/10. $15.00. versions of Linux, using a path-to-inode lookup microbench- http://dx.doi.org/10.1145/2815400.2815405 mark on the test system described in Section 6. These efforts 1.2 stat Syscall Latency (µs) 3000 slow down infrequent modifications to the directory hierar- v2.6.36 1.0 Changed LoC 2500 chy, such as rename, chmod, and chown of a directory. v3.14 0.8 2000 However, these slower operations account for less than .01% v3.0 0.6005 v4.0 of the system calls in the iBench traces [17]. Second, the 0.6 v3.14 1500 (µs) opt memory overheads of the dcache are increased. Third, lookup 0.4 1000 0.4438 has a probability of error from signature collisions that can 0.2 500 Kernel Previous LoC Changed from LoC Changed be adjusted to be negligible and within acceptable thresholds stat Callstat Latency System 0.0 0 widely used by data deduplication systems [13, 34, 40, 50]. 2010 2011 2012 2013 2014 2015 2016 In the micro-benchmark of Figure 2, our directory cache op- Release Year of Linux Kernel Versions timizations improve lookup latency by 26% over unmodified Figure 2: Latency of stat system call with a long Linux. path XXX/YYY/ZZZ/AAA/BBB/CCC/DDD/FFF on Linux This paper demonstrates that these techniques improve over four years (lower is better), as well as the churn performance for applications that use the directory cache within the directory cache code (all insertions in dcache.c, heavily, and the harm is minimal to applications that do dcache.h, namei.c, namei.h and namespace.c). not benefit. These changes are encapsulated in the VFS— Our optimized 3.14 kernel further reduces stat system call individual file systems do not have to change their code. This latency by 26%. paper describes a prototype of these improvements imple- mented in Linux 3.14. Section 2 explains that the directory cache structure of Mac OS X, FreeBSD, and Solaris are suf- ficiently similar that these principles should generalize. have improved hit latency by 47% from 2011 to 2013, but The contributions of this paper are as follows: have plateaued for the last three years. • A performance analysis of the costs of path lookup and The root of the problem is that the POSIX path permis- the opportunities to improve cache hit latency. sion semantics seemingly require work that is linear in the • A directory cache design that improves path lookup la- number of path components, and severely limit the kernel de- tency with a combination of techniques, including: veloper’s implementation options. For instance, in order to Indexing the directory cache by full path, reducing open file /X/Y/Z one must have search permission to parent average-case lookup from linear to constant in the directories /, /X, and /X/Y, as well as permission to access number of path components. file Z. The Linux implementation simply walks the directory A Prefix Check Cache (PCC) that separates permission tree top-down to check permissions. Unfortunately, when the checking from path caching. The PCC memoizes per- critical path is dominated by walking a pointer-based data mission checks, and is compatible with LSMs [47]. structure, including memory barriers on some architectures Reducing the cost of checking for hash bucket colli- for multi-core consistency, modern CPUs end up stalling on sions with path signatures. hard-to-prefetch loads. Moreover, because so many Linux • Identifying opportunities to leverage metadata the kernel features are built around this behavior, such as Linux Security already has to reduce miss rates, such as tracking whether Modules (LSMs) [47], namespaces, and mount aliases, it is a directory is completely in cache. not clear that any data-structural enhancements are possible • Carefully addressing numerous, subtle edge cases that without breaking backward-compatibility with other Linux would frustrate rote application of these techniques, such kernel features. A priori, it is not obvious that a faster lookup as integration with symbolic links and Linux namespaces. algorithm, such as a single hash table lookup, can meet these • A thorough evaluation of these optimizations. For in- API specifications and kernel-internal requirements; to our stance, our optimizations improve throughput of the knowledge, no one has tried previously. Dovecot IMAP server by up to 12% and latency of up- This paper proposes a decomposition of the directory datedb by up to 29%. cache, which allows most lookup operations to execute with a single hash table lookup (x3), as well as optimizations to reduce the miss rate based on information that is already in 2. Background the cache, but not used effectively (x5). Our design maintains This section first reviews the Unix directory semantics which compatibility (x4) through several essential insights, includ- a directory cache must support; and then explains how di- ing how to separate the indexing of paths from checking par- rectory caches are implemented in modern OSes, including ent permissions, and how to effectively and safely memoize Linux, FreeBSD, Solaris, Mac OS X, and Windows. the results of access control checks. Our optimizations improve the performance of frequent 2.1 Unix Directory Hierarchy Semantics lookup operations, but introduce several costs, described in The most common operation a directory cache performs is a x3 and measured in x6, which we believe are acceptable and lookup, which maps a path string onto an in-memory inode a net improvement for applications.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    16 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us