Bcache: Difference between revisions

Content deleted Content added
m →‎History: ref link update
 
(22 intermediate revisions by 15 users not shown)
Line 1:
{{Lowercase title}}
{{Use mdy dates|date=August 2014}}
{{short description|Cache in the Linux kernel's block layer}}
{{Infobox software
| name = bcache
| title = bcache
| logo = <!-- Image name is enough -->
| logo caption = =
| logo_size = =
| logo_alt = =
| screenshot = <!-- Image name is enough -->
| caption = =
| screenshot_size = =
| screenshot_alt = =
| collapsible = =
| author = =
| developer = Kent Overstreet and others
| released = <!-- {{Start date and age|YYYY2013|MM06|DD30|df=yes/no}} -->(Linux 3.10)
| discontinued = =
| latest release version =
| latest release date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} -->
| latest preview version =
| latest preview date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} -->
| status = =
| programming language = [[C (programming language)|C]]
| operating system = [[Linux]]
| platform = =
| size = =
| language = =
| language count = <!-- DO NOT include this parameter unless you know what it does -->
| language footnote = =
| genre = [[:Category:Linux kernel features|Linux kernel features]]
| license = [[GNU GPL]]
| website = {{URL|http://bcache.evilpiepirate.org/}}
}}
 
'''bcache''' (abbreviated from ''block cache'') is a [[Cache (computing)|cache]] in the [[Linux kernel]]'s block layer, which is used for accessing [[secondary storage]] devices. It allows one or more fast storage devices, such as flash-based [[solid-state drive]]s (SSDs), to act as a cache for one or more slower storage devices, such as [[hard disk drive]]s (HDDs); this effectively creates [[hybrid volume]]s and provides performance improvements.
 
Designed around the nature and performance characteristics of SSDs, bcache also minimizes [[write amplification]] by avoiding [[random write]]s and turning them into [[sequential write]]s instead. This merging of [[I/O operation]]s is performed for both the cache and the primary storage, helping in extending the lifetime of flash-based devices used as caches, and in improving the performance of write-sensitive primary storages, such as [[RAID 5]] sets.
 
bcache is licensed under the [[GNU General Public License]] (GPL), and Kent Overstreet is its primary developer. Overstreet considers bcache as a "prototype" for the development of [[bcachefs]], a filesystem with significant improvements over bcache.<ref>{{cite web
| title = bcache FAQ
| url = https://bcache.evilpiepirate.org/FAQ/
| access-date = 2021-05-07
| website = kernelnewbiesbcache.evilpiepirate.org
}}</ref>
 
== Overview ==
Using bcache makes it possible to have SSDs as another level of indirection within the data storage access paths, resulting in improved overall performance by using fast [[Flash memory|flash]]-based SSDs as caches for slower mechanical hard disk drives (HDDs) with rotational [[Magnetic storage|magnetic media]]. That way, the gap between SSDs and HDDs can be bridged{{snd}} the costly speed of SSDs gets combined with the cheap storage capacity of traditional HDDs.<ref>{{cite web
| url = http://www.linuxjournal.com/content/advanced-hard-drive-caching-techniques
| title = Advanced Hard Drive Caching Techniques
| date = {{date|2013-11-November 25|mdy}}, 2013 | accessdateaccess-date = {{date|December 2, 2013-12-02|mdy}}
| author = Petros Koutoupis | publisher = [[Linux Journal]]
}}</ref>
 
Caching is implemented by using SSDs for storing data associated with performed [[random read]]s and random writes, using near-zero [[seek time]]s as the most prominent feature of SSDs. [[Sequential I/O]] is not cached, to avoid rapid SSD [[cache invalidation]] on such operations that are already suitable enough for HDDs; going around the cache for big sequential writes is known as the [[write-around]] policy. Not caching the sequential [[Input/output|I/O]] also helps in extending the lifetime of SSDs used as caches.<ref name="kernel-docs">{{Cite web
| url = https://www.kernel.org/doc/Documentation/bcache.txt
| title = Linux kernel documentation: Documentation/bcache.txt
| date = {{date|2013-08-August 12|mdy}}, 2013 | accessdateaccess-date = {{date|January 24, 2014-01-24|mdy}}
| publisher = [[kernel.org]]
}}</ref> [[Write amplification]] is avoided by not performing random writes to SSDs; instead, all random writes to SSD caches are always combined into block-level writes, ending up with rewriting only the complete [[erase block]]s on SSDs.<ref name="bcache">{{cite web
| url = http://bcache.evilpiepirate.org/
| title = bcache: Linux kernel block layer cache
| accessdateaccess-date = {{date|December 2, 2013-12-02|mdy}}
| author = Kent Overstreet | website = bcache.evilpiepirate.org
}}</ref><ref name="lwn-497024">{{cite web
| url = https://lwn.net/Articles/497024/
| title = A bcache update
| date = {{date|2012-05-May 12|mdy}}, 2012 | accessdateaccess-date = {{date|October 4, 2013-10-04|mdy}}
| author = Jonathan Corbet | publisher = [[LWN.net]]
}}</ref>
 
Both ''[[write-back]]'' and ''[[write-through]]'' (which is the default) policies are supported for caching write operations. In case of the write-back policy, written data is stored inside the SSD caches first, and propagated to the HDDs later in a batched way while performing seek-friendly operations{{snd}} making bcache to act also as an [[I/O scheduler]]. For the write-through policy, which ensures that no write operation is marked as finished until the data requested to be written has reached both SSDs and HDDs, performance improvements are reduced by effectively performing only caching of the written data.<ref name="bcache" /><ref name="lwn-497024" />
 
Write-back policy with batched writes to HDDs provides additional benefits to write-sensitive [[redundant array of independent disks]] (RAID) layouts such as [[RAID&nbsp;5]] and [[RAID&nbsp;6]], which perform actual write operations as [[Atomic operation|atomic]] [[read-modify-write]] sequences. That way, performance penalties<ref>{{cite web
| url = http://www.ecs.umass.edu/ece/koren/architecture/Raid/basicRAID.html
| title = Basic RAID Organizations
| accessdateaccess-date = {{date|October 4, 2013-10-04|mdy}}
| website = ecs.umass.edu
}}</ref> of small random writes are reduced or avoided for such RAID layouts, by grouping them together and performing as batched sequential writes.<ref name="bcache" /><ref name="lwn-497024" />
 
Caching performed by bcache operates at the [[block device]] level, making itself [[file system]]&ndash;agnostic as long as the file system provides an embedded [[universally unique identifier]] (UUID); this requirement is satisfied by virtually all standard [[Linux file systems]], as well as by [[Linux swap|swap partitions]]. Sizes of the logical blocks used internally by bcache as caching extents can go down to the size of a single HDD sector.<ref>{{cite web
| url = https://lwn.net/Articles/394672/
| title = Bcachebcache: Caching beyond just RAM
| date = {{date|July 2, 2010-07-02|mdy}} | accessdateaccess-date = {{date|October 4, 2013-10-04|mdy}}
| author1 = William Stearns | author2 = Kent Overstreet
| publisher = [[LWN.net]]
Line 85 ⟶ 91:
bcache was first announced by Kent Overstreet in July 2010, as a completely working Linux kernel module, though at its early beta stage.<ref>{{cite web
| url = https://lwn.net/Articles/394905/
| title = Bcachebcache: Version 6
| date = {{date|July 4, 2010-07-04|mdy}} | accessdateaccess-date = {{date|October 4, 2013-10-04|mdy}}
| author = Kent Overstreet | publisher = [[LWN.net]]
}}</ref> The development continued for almost two years, until May 2012, at which point bcache reached its production-ready state.<ref name="lwn-497024" />
 
It was merged into the [[Linux kernel mainline]] in kernel version 3.10, released on June 30, 2013.<ref>{{cite web |date=June 30, 2013 |title=Linux kernel 3.10, Section 1.2. bcache, a block layer cache for SSD caching |url=https://kernelnewbies.org/Linux_3.10#Bcache.2C_a_block_layer_cache_for_SSD_caching |access-date=October 4, 2013 |website=kernelnewbies.org}}</ref><ref name="bcache-kent">{{cite web
| url = http://kernelnewbies.org/Linux_3.10#head-a0ad787f2e030b53bdabbb4b6e22e7ed16803bb1
| title = Linux kernel 3.10, Section 1.2. Bcache, a block layer cache for SSD caching
| date = {{date|2013-06-30|mdy}} | accessdate = {{date|2013-10-04|mdy}}
| website = kernelnewbies.org
}}</ref><ref name="bcache-kent">{{cite web
| url = http://www.linux.com/news/featured-blogs/200-libby-clark/728209-about-the-linux-kernel-bcache
| title = All About the Linux Kernel: Bcachebcache
| date = {{date|2013-06-June 11|mdy}} | accessdate =, {{date|2013-10-09|mdy}}
| access-date = October 9, 2013
| author = Libby Clark | website = linux.com
| website = linux.com
| archive-url = https://web.archive.org/web/20130929230638/http://www.linux.com/news/featured-blogs/200-libby-clark/728209-about-the-linux-kernel-bcache/
| archive-date = September 29, 2013
}}</ref> Overstreet has since been developing the [[file system]] [[bcachefs]], based on ideas first developed in bcache that he said began "evolving&nbsp;... into a full blown, general-purpose [[POSIX]] filesystem".<ref>{{cite web
| last = Larabel |first = Michael
| title = A New Linux File-System Aims For Speed While Having ZFS/Btrfs-Like Features
| url = https://www.phoronix.com/scan.php?page=article&item=bcache-fs-linux&num=1
| date = 2015-08-21 | access-date = 2018-11-22
| work = [[Phoronix]]
}}</ref> He describes bcache as a "prototype" for the ideas that became bcachefs and intends bcachefs to replace bcache.<ref>{{cite web
| last = Edge | first = Jake
| title = An update on bcachefs
| url = https://lwn.net/Articles/755276/
| date = 2018-05-23 | access-date = 2018-11-22
| work = [[LWN.net]]
}}</ref> He officially announced bcachefs in 2015 and got it merged into the mainline Linux kernel in October 2023.<ref>{{cite web
| last = Larabel | first = Michael
| title = Bcachefs Merged Into The Linux 6.7 Kernel
| url = https://www.phoronix.com/news/Bcachefs-Merged-Linux-6.7
| date = 2023-10-31 | access-date = 2023-11-20
| work = [[Phoronix]]
| language = en
}}</ref>
 
Line 107 ⟶ 131:
* The same cache device can be used for caching an arbitrary number of the primary storage devices
* Runtime attaching and detaching of primary storage devices from their caches, while mounted and in use (running in passthrough mode when not cached)
* Automated recovery from unclean shutdowns{{snd}} writes are not completed until the cache is consistent with respect to the primary storage device; internally, bcache makes no differencesdistinction between clean and unclean shutdowns
* Transparent handling of I/O errors generated by the cache devices<ref name="kernel-docs" />
* [[Write barrier]]s and associated cache flushes are properly handled
Line 127 ⟶ 151:
 
== See also ==
{{Portal|Free and open-source software|Linux}}
 
* [[dm-cache]]{{snd}} a Linux kernel's device mapper target that allows creation of hybrid volumes
* [[EnhanceIO]]{{snd}} a disk cache module for the Linux kernel.
* [[Flashcache]]{{snd}} a disk cache component for the Linux kernel, initially developed by Facebook
* [[Hybrid drive]]{{snd}} a storage device that combines flash-based and spinning magnetic media storage technologies
Line 139 ⟶ 163:
 
== External links ==
{{Commons category|Linux kernel}}
 
* {{Official website|http://bcache.evilpiepirate.org/}}
* [https://lwn.net/Articles/548348/ LSFMM: Caching{{snd}} dm-cache and bcache], [[LWN.net]], May 1, 2013, by Jake Edge
* [http://en.community.dell.com/techcenter/extras/m/white_papers/20438199/download Linux Block Caching Choices in Stable Upstream Kernel] (PDF), [[Dell]], December 2013
* Testing bcache series: {{usurped|1=[https://web.archive.org/web/20100829082801/http://www.linux-mag.com/id/7843/ Throughput]}}, {{usurped|1=[https://web.archive.org/web/20100911085025/http://www.linux-mag.com/id/7847 IOPS]}}, {{usurped|1=[https://web.archive.org/web/20100920062520/http://www.linux-mag.com/id/7852 Metadata]}}, and {{usurped|1=[https://web.archive.org/web/20101002103446/http://www.linux-mag.com/id/7858/ Large Files and a Wrap-Up]}}, ''[[Linux Magazine]]'', August&ndash;September 2010, by Jeffrey B. Layton
* [http://lkml.indiana.edu/hypermail/linux/kernel/1306.1/01246.html Performance Comparison among EnhanceIO, bcache and dm-cache], [[LKML]], June 11, 2013
* [https://www.phoronix.com/scan.php?page=news_item&px=MTM4ODA EnhanceIO, Bcache & DM-Cache Benchmarked], [[Phoronix]], June 11, 2013, by Michael Larabel