Share to: share facebook share twitter share wa share telegram print page

Copy-on-write

Copy-on-write (COW), sometimes referred to as implicit sharing[1] or shadowing,[2] is a resource-management technique used in computer programming to efficiently implement a "duplicate" or "copy" operation on modifiable resources[3] (most commonly memory pages, storage sectors, files, and data structures).

In virtual memory management

Copy-on-write finds its main use in operating systems, sharing the physical memory of computers running multiple processes, in the implementation of the fork() system call. Typically, the new process does not modify any memory and immediately executes a new process, replacing the address space entirely. It would waste processor time and memory to copy all of the old process's memory during the fork only to immediately discard the copy.[4]

Copy-on-write can be implemented efficiently using the page table by marking certain pages of memory as read-only and keeping a count of the number of references to the page. When data is written to these pages, the operating-system kernel intercepts the write attempt and allocates a new physical page, initialized with the copy-on-write data, although the allocation can be skipped if there is only one reference. The kernel then updates the page table with the new (writable) page, decrements the number of references, and performs the write. The new allocation ensures that a change in the memory of one process is not visible in another's.[citation needed]

The copy-on-write technique can be extended to support efficient memory allocation by keeping one page of physical memory filled with zeros. When the memory is allocated, all the pages returned refer to the page of zeros and are all marked copy-on-write. This way, physical memory is not allocated for the process until data is written, allowing processes to reserve more virtual memory than physical memory and use memory sparsely, at the risk of running out of virtual address space. The combined algorithm is similar to demand paging.[3]

Copy-on-write pages are also used in the Linux kernel's same-page merging feature.[5]

In software

COW is also used in library, application, and system code.

Examples

The string class provided by the C++ standard library was specifically designed to allow copy-on-write implementations in the initial C++98 standard,[6] but not in the newer C++11 standard:[7]

std::string x("Hello");

std::string y = x;  // x and y use the same buffer.

y += ", World!";    // Now y uses a different buffer; x still uses the same old buffer.

In the PHP programming language, all types except references are implemented as copy-on-write. For example, strings and arrays are passed by reference, but when modified, they are duplicated if they have non-zero reference counts. This allows them to act as value types without the performance problems of copying on assignment or making them immutable.[8]

In the Qt framework, many types are copy-on-write ("implicitly shared" in Qt's terms). Qt uses atomic compare-and-swap operations to increment or decrement the internal reference counter. Since the copies are cheap, Qt types can often be safely used by multiple threads without the need of locking mechanisms such as mutexes. The benefits of COW are thus valid in both single- and multithreaded systems.[9]

In computer storage

COW may also be used as the underlying mechanism for snapshots, such as those provided by logical volume management, file systems such as Btrfs, ZFS, ReFS and Bcachefs,[10] and database servers such as Microsoft SQL Server. Typically, the snapshots store only the modified data, and are stored close to the original, so they are only a weak form of incremental backup and cannot substitute for a full backup.[11]

See also

References

  1. ^ "Implicit Sharing". Qt Project. Archived from the original on 8 February 2024. Retrieved 10 November 2023.
  2. ^ Rodeh, Ohad (1 February 2008). "B-Trees, Shadowing, and Clones" (PDF). ACM Transactions on Storage. 3 (4): 1. CiteSeerX 10.1.1.161.6863. doi:10.1145/1326542.1326544. S2CID 207166167. Archived from the original (PDF) on 2 January 2017. Retrieved 10 November 2023.
  3. ^ a b Bovet, Daniel Pierre; Cesati, Marco (1 January 2002). Understanding the Linux Kernel. O'Reilly Media. p. 295. ISBN 9780596002138. Archived from the original on 15 September 2024. Retrieved 10 November 2023.
  4. ^ Silberschatz, Abraham; Galvin, Peter B.; Gagne, Greg (2018). Operating System Concepts (10th ed.). Wiley. pp. 120–123. ISBN 978-1119456339.
  5. ^ Abbas, Ali. "The Kernel Samepage Merging Process". alouche.net. Archived from the original on 8 August 2016. Retrieved 10 November 2023.{{cite web}}: CS1 maint: unfit URL (link)
  6. ^ Meyers, Scott (2012). Effective STL. Addison-Wesley. pp. 64–65. ISBN 9780132979184.
  7. ^ "Concurrency Modifications to Basic String". Open Standards. Archived from the original on 10 November 2023. Retrieved 10 November 2023.
  8. ^ Pauli, Julien; Ferrara, Anthony; Popov, Nikita (2013). "Memory management". PhpInternalsBook.com. Archived from the original on 10 November 2023. Retrieved 10 November 2023.
  9. ^ "Threads and Implicitly Shared Classes". Qt Project. Archived from the original on 3 December 2023. Retrieved 10 November 2023.
  10. ^ Kasampalis, Sakis (2010). "Copy-on-Write Based File Systems Performance Analysis and Implementation" (PDF). p. 19. Archived (PDF) from the original on 5 May 2024. Retrieved 10 November 2023.
  11. ^ Chien, Tim. "Snapshots Are NOT Backups". Oracle.com. Oracle. Archived from the original on 10 November 2023. Retrieved 10 November 2023.

Read other articles:

Parus Gelatik-batu kelabu (Parus major) Klasifikasi ilmiah Kerajaan: Animalia Filum: Chordata Kelas: Aves Ordo: Passeriformes Famili: Paridae Genus: ParusLinnaeus, 1758 Spesies lihat teks Parus adalah genus burung dari familia Paridae. Spesies yang termasuk dalam genus ini diantaranya: Parus guineensis Parus leucomelas Parus niger Parus carpi Parus albiventris Parus leuconotus Parus funereus Parus rufiventris Parus fringillinus Parus fasciiventer Parus thruppi Parus griseiventris Parus cinera...

В Википедии есть статьи о других людях с именем Георгий III. В Википедии есть статьи о других людях с фамилией Багратион. Георгий IIIгруз. გიორგი III Царь Имеретии 1605 — 1639 Предшественник Ростом Преемник Александр III Рождение XVI век Смерть 1639(1639) Род Багратионы Отец цареви...

Neighborhood of St. Louis in Missouri, United StatesMark Twain/I-70 IndustrialNeighborhood of St. LouisMark Twain/I-70 Industrial in May 2018. View from Union Boulevard and Brown intersection facing south.Location (red) of Mark Twain I-70 Industrial within St. LouisCountryUnited StatesStateMissouriCitySt. LouisWards22Area • Total1.21 sq mi (3.1 km2)Population (2020)[1] • Total902 • Density750/sq mi (290/km2)ZIP code(s)Part o...

Forum der Freien Völker Post-Russlands Das Forum der Freien Völker Post-Russlands (früher Forum der Freien Völker Russlands) ist eine Diskussionsplattform, deren Teilnehmer den Zerfall Russlands in mehrere unabhängigen Staaten anstreben. An dem Forum nehmen nicht nur Vertreter der russischen politischen Opposition teil, die aus dem Land ausgewandert sind, aber auch ausländische Persönlichkeiten. Inhaltsverzeichnis 1 Ziel 2 Aktivitäten 2.1 Forum I / 8.–9. Mai 2022 – Warschau, Polen...

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (نوفمبر 2020) التنمية المنهجية عملية التفكير في التنمية التي تستخدم نهج التفكير المنهجي، لخلق حل للضغوط الاجتماعية والبيئية والاقتصادية التي يعاني منها العالم. نظرة عا...

Stasiun Ichishiro市城駅Stasiun Ichishiro pada Agustus 2007LokasiIchishiro 442, Nakanojō-machi, Agatsuma-gun, Gunma-ken 377-0421JepangKoordinat36°34′15″N 138°52′56″E / 36.5709°N 138.8823°E / 36.5709; 138.8823Koordinat: 36°34′15″N 138°52′56″E / 36.5709°N 138.8823°E / 36.5709; 138.8823Pengelola JR EastJalur■ Jalur AgatsumaLetak dari pangkal16.4 km dari ShibukawaJumlah peron1 peron sampingInformasi lainStatusTanpa stafS...

La Unión Comuna BanderaEscudo Coordenadas 40°17′43″S 73°04′56″O / -40.2952, -73.0822Idioma oficial EspañolEntidad Comuna • País Chile • Región Los Ríos • Provincia Ranco • Comuna La Unión • Distrito N.º 54Alcalde Juan Andrés Reinoso CarrilloEventos históricos   • Fundación 1821 • Nombre Villa de San José de La UniónSuperficie   • Total 2.137 km²Altitud   • Media 26 m s. n. m.Po...

2000 Oklahoma Sooners softballNational ChampionNCAA Norman Regional championBig 12 regular season championConferenceBig 12 ConferenceRecord66–8 (17–1 Big 12)Head coachPatty Gasso (6th season)Home stadiumOU Softball ComplexSeasons← 19992001 → 2000 Big 12 Conference softball standings vte Conf Overall Team W   L   T   PCT W   L   T   PCT No. 1 Oklahoma ‍†‍‍y 17 – 1 – 0   .944 66 – 8...

2011 Russian filmSiberia, MonamourFilm posterRussian: Сибирь. МонамурDirected byVyacheslav RossWritten byVyacheslav RossProduced by Igor Chekalin Julia Leonova Vyacheslav Ross Andrey Skurikhin Pavel Skurikhin Vadim Zhuk Starring Pyotr Zaychenko Mikhail Protsko Sergey Novikov Lidiya Bayrashevskaya Sonya Ross CinematographyYury RayskiyEdited byIgor LitoninskiyMusic byAidar GainullinRelease date 20 April 2011 (2011-04-20)[1] CountryRussiaLanguageRussian Siberi...

العلاقات البليزية المولدوفية بليز مولدوفا   بليز   مولدوفا تعديل مصدري - تعديل   العلاقات البليزية المولدوفية هي العلاقات الثنائية التي تجمع بين بليز ومولدوفا.[1][2][3][4][5] مقارنة بين البلدين هذه مقارنة عامة ومرجعية للدولتين: وجه المقارنة بلي...

King of France from 1322 to 1328 Charles IVGisant of Charles IV by Jean de Liège, c. 1372King of France (more...) Reign3 January 1322 – 1 February 1328Coronation21 February 1322PredecessorPhilip VSuccessorPhilip VIKing of NavarreReign3 January 1322 – 1 February 1328PredecessorPhilip IISuccessorJoan IIBorn18/19 June 1294Clermont, Oise, FranceDied1 February 1328 (aged 33)Vincennes, FranceBurialSaint Denis BasilicaSpouses Blanche of Burgundy ​ ​(m. 1307;&#...

Series of travel guide books Harper's Hand-Book for Travellers in Europe and the East, 1862 Harper's Hand-Book for Travellers (est.1862) was a series of travel guide books published by Harper & Brothers of New York. Each annual edition contained information for tourists in Europe and parts of the Middle East. The indefatigable William Pembroke Fetridge[1] wrote most of the guides from 1862 until at least 1885.[2] In its day the Harper's Hand-Book competed with popular guid...

Piano Trio in D minorNo. 1by Robert SchumannThe composer in 1850KeyD minorOpus63Composed1847 (1847)Movementsfour The Piano Trio No. 1 in D minor, Op. 63, by Robert Schumann was written in 1847. It has four movements: Mit Energie und Leidenschaft Lebhaft, doch nicht zu rasch Langsam, mit inniger Empfindung Mit Feuer The first piano trio (first of three works with this title plus the Fantasiestücke Op. 88 for the same forces) is in an intensely romantic style, and is the most celebrated o...

Country in Central America This article is about the country in Central America. For other uses, see El Salvador (disambiguation). Republic of El SalvadorRepública de El Salvador (Spanish) Flag Coat of arms Motto: Dios, Unión, LibertadGod, Union, LibertyAnthem: Himno Nacional de El SalvadorNational Anthem of El SalvadorCapitaland largest citySan Salvador13°41′56″N 89°11′29″W / 13.69889°N 89.19139°W / 13.69889; -89.19139Official languag...

مطار جاكسونز الدولي Jacksons International Airport   إياتا: POM – ايكاو: AYPY موجز نوع المطار عام يخدم بورت مورسبي البلد بابوا غينيا الجديدة  الموقع بورت مورسبي، بابوا غينيا الجديدة الارتفاع 38 م؛ 124 قدم إحداثيات 9°26′36″S 147°13′12″E / 9.4433333333333°S 147.22°E / -9.4433333333333; 147.22  الموقع ال...

State park in Niagara County, New York This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Wilson-Tuscarora State Park – news · newspapers · books · scholar · JSTOR (February 2021) (Learn how and when to remove this template message) Wilson-Tuscarora State ParkWilson-Tuscarora State Park, July 2006Location of Wi...

Software agent For the human occupation, see Virtual assistant (occupation). Not to be confused with Personal digital assistant. Google Assistant running on a Pixel XL smartphone A virtual assistant (VA) is a software agent that can perform a range of tasks or services for a user based on user input such as commands or questions, including verbal ones. Such technologies often incorporate chatbot capabilities to simulate human conversation, such as via online chat, to facilitate interaction wi...

Heritage railway in Shropshire, England Telford Steam RailwayLocaleHorsehay, Shropshire, EnglandTerminusSpring Village, Horsehay & DawleyCommercial operationsNameWellington & Severn Junction RailwayOriginal gauge4 ft 8+1⁄2 in (1,435 mm) standard gaugePreserved operationsOperated byTelford Horsehay Steam TrustStations3Length1.0 mile (1.6 km)Preserved gauge4 ft 8+1⁄2 in (1,435 mm) standard gaugeCommercial historyOpened1859Closed19...

Perahu gaya pajala Bugis-Makassar berujung ganda dengan tiang tripod dan layar miring persegi (beberapa di antaranya diturunkan dan disimpan di geladak), serta kemudi quarter yang digantung. Gambar ini dibuat tahun 1803 oleh seniman William Westall tentang perahu Bugis di pesisir pantai Arnhem, Australia. Kesempatan itu datang ketika Flinders bertemu dengan armada perahu Bugis yang datang dari Makassar ketika mereka mengumpulkan teripang. Perahu ini memiliki bobot 25 ton dan dipersenjatai den...

Statue at the University of Southern California This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Tommy Trojan – news · newspapers · books · scholar · JSTOR (October 2009) (Learn how and when to remove this template message) Tommy TrojanArtistRoger Noble BurnhamMediumBronze sculpture statueLocationLos Angeles,...

Kembali kehalaman sebelumnya