€•ŠŒsphinx.addnodes”Œdocument”“”)�”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)�”}”(hhh]”(hŒ pending_xref”“”)�”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…”�”}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ,/translations/zh_CN/trace/ring-buffer-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)�”}”(hhh]”hŒChinese (Traditional)”…”�”}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/zh_TW/trace/ring-buffer-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒItalian”…”�”}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/it_IT/trace/ring-buffer-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒJapanese”…”�”}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/ja_JP/trace/ring-buffer-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒKorean”…”�”}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/ko_KR/trace/ring-buffer-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒPortuguese (Brazilian)”…”�”}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/pt_BR/trace/ring-buffer-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒSpanish”…”�”}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/sp_SP/trace/ring-buffer-design”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒcomment”“”)�”}”(hŒ?SPDX-License-Identifier: GPL-2.0 OR GFDL-1.2-no-invariants-only”h]”hŒ?SPDX-License-Identifier: GPL-2.0 OR GFDL-1.2-no-invariants-only”…”�”}”hh·sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1hµhhh²hh³ŒF/var/lib/git/docbuild/linux/Documentation/trace/ring-buffer-design.rst”h´KubhŒsection”“”)�”}”(hhh]”(hŒtitle”“”)�”}”(hŒLockless Ring Buffer Design”h]”hŒLockless Ring Buffer Design”…”�”}”(hhÏh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhhÊh²hh³hÇh´KubhŒ paragraph”“”)�”}”(hŒCopyright 2009 Red Hat Inc.”h]”hŒCopyright 2009 Red Hat Inc.”…”�”}”(hhßh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KhhÊh²hubhŒ field_list”“”)�”}”(hhh]”(hŒfield”“”)�”}”(hhh]”(hŒ field_name”“”)�”}”(hŒAuthor”h]”hŒAuthor”…”�”}”(hhùh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h÷hhôh³hÇh´KubhŒ field_body”“”)�”}”(hŒ$Steven Rostedt ”h]”hÞ)�”}”(hj h]”(hŒSteven Rostedt <”…”�”}”(hj h²hh³Nh´NubhŒ reference”“”)�”}”(hŒsrostedt@redhat.com”h]”hŒsrostedt@redhat.com”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:srostedt@redhat.com”uh1jhj ubhŒ>”…”�”}”(hj h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K hj ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhhôubeh}”(h]”h ]”h"]”h$]”h&]”uh1hòh³hÇh´K hhïh²hubhó)�”}”(hhh]”(hø)�”}”(hŒLicense”h]”hŒLicense”…”�”}”(hj?h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h÷hj<h³hÇh´Kubj)�”}”(hŒPThe GNU Free Documentation License, Version 1.2 (dual licensed under the GPL v2)”h]”hÞ)�”}”(hŒPThe GNU Free Documentation License, Version 1.2 (dual licensed under the GPL v2)”h]”hŒPThe GNU Free Documentation License, Version 1.2 (dual licensed under the GPL v2)”…”�”}”(hjQh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K hjMubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj<ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hòh³hÇh´K hhïh²hubhó)�”}”(hhh]”(hø)�”}”(hŒ Reviewers”h]”hŒ Reviewers”…”�”}”(hjnh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h÷hjkh³hÇh´Kubj)�”}”(hŒIMathieu Desnoyers, Huang Ying, Hidetoshi Seto, and Frederic Weisbecker. ”h]”hÞ)�”}”(hŒGMathieu Desnoyers, Huang Ying, Hidetoshi Seto, and Frederic Weisbecker.”h]”hŒGMathieu Desnoyers, Huang Ying, Hidetoshi Seto, and Frederic Weisbecker.”…”�”}”(hj€h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K hj|ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjkubeh}”(h]”h ]”h"]”h$]”h&]”uh1hòh³hÇh´K hhïh²hubeh}”(h]”h ]”h"]”h$]”h&]”uh1híhhÊh²hh³hÇh´K ubhÞ)�”}”(hŒWritten for: 2.6.31”h]”hŒWritten for: 2.6.31”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KhhÊh²hubhÉ)�”}”(hhh]”(hÎ)�”}”(hŒ!Terminology used in this Document”h]”hŒ!Terminology used in this Document”…”�”}”(hj±h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhj®h²hh³hÇh´KubhŒdefinition_list”“”)�”}”(hhh]”(hŒdefinition_list_item”“”)�”}”(hŒ3tail - where new writes happen in the ring buffer. ”h]”(hŒterm”“”)�”}”(hŒtail”h]”hŒtail”…”�”}”(hjÌh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´KhjÆubhŒ definition”“”)�”}”(hhh]”hŒ bullet_list”“”)�”}”(hhh]”hŒ list_item”“”)�”}”(hŒ,where new writes happen in the ring buffer. ”h]”hÞ)�”}”(hŒ+where new writes happen in the ring buffer.”h]”hŒ+where new writes happen in the ring buffer.”…”�”}”(hjêh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Khjæubah}”(h]”h ]”h"]”h$]”h&]”uh1jähjáubah}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1jßh³hÇh´KhjÜubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjÆubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´KhjÁubjÅ)�”}”(hŒ2head - where new reads happen in the ring buffer. ”h]”(jË)�”}”(hŒhead”h]”hŒhead”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´KhjubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒ+where new reads happen in the ring buffer. ”h]”hÞ)�”}”(hŒ*where new reads happen in the ring buffer.”h]”hŒ*where new reads happen in the ring buffer.”…”�”}”(hj.h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Khj*ubah}”(h]”h ]”h"]”h$]”h&]”uh1jähj'ubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´Khj$ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´KhjÁh²hubjÅ)�”}”(hŒFproducer - the task that writes into the ring buffer (same as writer) ”h]”(jË)�”}”(hŒproducer”h]”hŒproducer”…”�”}”(hjXh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´KhjTubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒ;the task that writes into the ring buffer (same as writer) ”h]”hÞ)�”}”(hŒ:the task that writes into the ring buffer (same as writer)”h]”hŒ:the task that writes into the ring buffer (same as writer)”…”�”}”(hjph²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Khjlubah}”(h]”h ]”h"]”h$]”h&]”uh1jähjiubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´Khjfubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjTubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´KhjÁh²hubjÅ)�”}”(hŒwriter - same as producer ”h]”(jË)�”}”(hŒwriter”h]”hŒwriter”…”�”}”(hjšh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´Khj–ubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒsame as producer ”h]”hÞ)�”}”(hŒsame as producer”h]”hŒsame as producer”…”�”}”(hj²h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Khj®ubah}”(h]”h ]”h"]”h$]”h&]”uh1jähj«ubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´Khj¨ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhj–ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´KhjÁh²hubjÅ)�”}”(hŒ@consumer - the task that reads from the buffer (same as reader) ”h]”(jË)�”}”(hŒconsumer”h]”hŒconsumer”…”�”}”(hjÜh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´K"hjØubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒ5the task that reads from the buffer (same as reader) ”h]”hÞ)�”}”(hŒ4the task that reads from the buffer (same as reader)”h]”hŒ4the task that reads from the buffer (same as reader)”…”�”}”(hjôh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K"hjðubah}”(h]”h ]”h"]”h$]”h&]”uh1jähjíubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´K"hjêubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjØubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´K"hjÁh²hubjÅ)�”}”(hŒreader - same as consumer. ”h]”(jË)�”}”(hŒreader”h]”hŒreader”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´K%hjubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒsame as consumer. ”h]”hÞ)�”}”(hŒsame as consumer.”h]”hŒsame as consumer.”…”�”}”(hj6h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K%hj2ubah}”(h]”h ]”h"]”h$]”h&]”uh1jähj/ubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´K%hj,ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´K%hjÁh²hubjÅ)�”}”(hŒ^reader_page - A page outside the ring buffer used solely (for the most part) by the reader. ”h]”(jË)�”}”(hŒ reader_page”h]”hŒ reader_page”…”�”}”(hj`h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´K)hj\ubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒNA page outside the ring buffer used solely (for the most part) by the reader. ”h]”hÞ)�”}”(hŒMA page outside the ring buffer used solely (for the most part) by the reader.”h]”hŒMA page outside the ring buffer used solely (for the most part) by the reader.”…”�”}”(hjxh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K(hjtubah}”(h]”h ]”h"]”h$]”h&]”uh1jähjqubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´K(hjnubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhj\ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´K)hjÁh²hubjÅ)�”}”(hŒ@head_page - a pointer to the page that the reader will use next ”h]”(jË)�”}”(hŒ head_page”h]”hŒ head_page”…”�”}”(hj¢h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´K,hjžubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒ4a pointer to the page that the reader will use next ”h]”hÞ)�”}”(hŒ3a pointer to the page that the reader will use next”h]”hŒ3a pointer to the page that the reader will use next”…”�”}”(hjºh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K,hj¶ubah}”(h]”h ]”h"]”h$]”h&]”uh1jähj³ubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´K,hj°ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjžubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´K,hjÁh²hubjÅ)�”}”(hŒ?tail_page - a pointer to the page that will be written to next ”h]”(jË)�”}”(hŒ tail_page”h]”hŒ tail_page”…”�”}”(hjäh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´K/hjàubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒ3a pointer to the page that will be written to next ”h]”hÞ)�”}”(hŒ2a pointer to the page that will be written to next”h]”hŒ2a pointer to the page that will be written to next”…”�”}”(hjüh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K/hjøubah}”(h]”h ]”h"]”h$]”h&]”uh1jähjõubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´K/hjòubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjàubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´K/hjÁh²hubjÅ)�”}”(hŒMcommit_page - a pointer to the page with the last finished non-nested write. ”h]”(jË)�”}”(hŒ commit_page”h]”hŒ commit_page”…”�”}”(hj&h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´K2hj"ubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒ?a pointer to the page with the last finished non-nested write. ”h]”hÞ)�”}”(hŒ>a pointer to the page with the last finished non-nested write.”h]”hŒ>a pointer to the page with the last finished non-nested write.”…”�”}”(hj>h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K2hj:ubah}”(h]”h ]”h"]”h$]”h&]”uh1jähj7ubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´K2hj4ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhj"ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´K2hjÁh²hubjÅ)�”}”(hX™cmpxchg - hardware-assisted atomic transaction that performs the following:: A = B if previous A == C R = cmpxchg(A, C, B) is saying that we replace A with B if and only if current A is equal to C, and we put the old (current) A into R R gets the previous A regardless if A is updated with B or not. To see if the update was successful a compare of ``R == C`` may be used. ”h]”(jË)�”}”(hŒcmpxchg”h]”hŒcmpxchg”…”�”}”(hjhh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´K@hjdubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hX�hardware-assisted atomic transaction that performs the following:: A = B if previous A == C R = cmpxchg(A, C, B) is saying that we replace A with B if and only if current A is equal to C, and we put the old (current) A into R R gets the previous A regardless if A is updated with B or not. To see if the update was successful a compare of ``R == C`` may be used. ”h]”(hÞ)�”}”(hŒBhardware-assisted atomic transaction that performs the following::”h]”hŒAhardware-assisted atomic transaction that performs the following:”…”�”}”(hj€h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K5hj|ubhŒ literal_block”“”)�”}”(hŒèA = B if previous A == C R = cmpxchg(A, C, B) is saying that we replace A with B if and only if current A is equal to C, and we put the old (current) A into R R gets the previous A regardless if A is updated with B or not.”h]”hŒèA = B if previous A == C R = cmpxchg(A, C, B) is saying that we replace A with B if and only if current A is equal to C, and we put the old (current) A into R R gets the previous A regardless if A is updated with B or not.”…”�”}”hj�sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´K7hj|ubhÞ)�”}”(hŒHTo see if the update was successful a compare of ``R == C`` may be used.”h]”(hŒ1To see if the update was successful a compare of ”…”�”}”(hjžh²hh³Nh´NubhŒliteral”“”)�”}”(hŒ ``R == C``”h]”hŒR == C”…”�”}”(hj¨h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¦hjžubhŒ may be used.”…”�”}”(hjžh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K?hj|ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jähjyubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´K5hjvubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjdubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´K@hjÁh²hubeh}”(h]”h ]”h"]”h$]”h&]”uh1j¿hj®h²hh³Nh´Nubeh}”(h]”Œ!terminology-used-in-this-document”ah ]”h"]”Œ!terminology used in this document”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´KubhÉ)�”}”(hhh]”(hÎ)�”}”(hŒThe Generic Ring Buffer”h]”hŒThe Generic Ring Buffer”…”�”}”(hjéh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhjæh²hh³hÇh´KCubhÞ)�”}”(hŒUThe ring buffer can be used in either an overwrite mode or in producer/consumer mode.”h]”hŒUThe ring buffer can be used in either an overwrite mode or in producer/consumer mode.”…”�”}”(hj÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KEhjæh²hubhÞ)�”}”(hŒÇProducer/consumer mode is where if the producer were to fill up the buffer before the consumer could free up anything, the producer will stop writing to the buffer. This will lose most recent events.”h]”hŒÇProducer/consumer mode is where if the producer were to fill up the buffer before the consumer could free up anything, the producer will stop writing to the buffer. This will lose most recent events.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KHhjæh²hubhÞ)�”}”(hŒ¼Overwrite mode is where if the producer were to fill up the buffer before the consumer could free up anything, the producer will overwrite the older data. This will lose the oldest events.”h]”hŒ¼Overwrite mode is where if the producer were to fill up the buffer before the consumer could free up anything, the producer will overwrite the older data. This will lose the oldest events.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KLhjæh²hubhÞ)�”}”(hX1No two writers can write at the same time (on the same per-cpu buffer), but a writer may interrupt another writer, but it must finish writing before the previous writer may continue. This is very important to the algorithm. The writers act like a "stack". The way interrupts works enforces this behavior::”h]”hX4No two writers can write at the same time (on the same per-cpu buffer), but a writer may interrupt another writer, but it must finish writing before the previous writer may continue. This is very important to the algorithm. The writers act like a “stackâ€�. The way interrupts works enforces this behavior:”…”�”}”(hj!h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KPhjæh²hubj�)�”}”(hŒ writer1 start writer2 start writer3 start writer3 finishes writer2 finishes writer1 finishes”h]”hŒ writer1 start writer2 start writer3 start writer3 finishes writer2 finishes writer1 finishes”…”�”}”hj/sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´KWhjæh²hubhÞ)�”}”(hŒhThis is very much like a writer being preempted by an interrupt and the interrupt doing a write as well.”h]”hŒhThis is very much like a writer being preempted by an interrupt and the interrupt doing a write as well.”…”�”}”(hj=h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K^hjæh²hubhÞ)�”}”(hX{Readers can happen at any time. But no two readers may run at the same time, nor can a reader preempt/interrupt another reader. A reader cannot preempt/interrupt a writer, but it may read/consume from the buffer at the same time as a writer is writing, but the reader must be on another processor to do so. A reader may read on its own processor and can be preempted by a writer.”h]”hX{Readers can happen at any time. But no two readers may run at the same time, nor can a reader preempt/interrupt another reader. A reader cannot preempt/interrupt a writer, but it may read/consume from the buffer at the same time as a writer is writing, but the reader must be on another processor to do so. A reader may read on its own processor and can be preempted by a writer.”…”�”}”(hjKh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kahjæh²hubhÞ)�”}”(hŒšA writer can preempt a reader, but a reader cannot preempt a writer. But a reader can read the buffer at the same time (on another processor) as a writer.”h]”hŒšA writer can preempt a reader, but a reader cannot preempt a writer. But a reader can read the buffer at the same time (on another processor) as a writer.”…”�”}”(hjYh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Khhjæh²hubhÞ)�”}”(hŒMThe ring buffer is made up of a list of pages held together by a linked list.”h]”hŒMThe ring buffer is made up of a list of pages held together by a linked list.”…”�”}”(hjgh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Klhjæh²hubhÞ)�”}”(hŒ`At initialization a reader page is allocated for the reader that is not part of the ring buffer.”h]”hŒ`At initialization a reader page is allocated for the reader that is not part of the ring buffer.”…”�”}”(hjuh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Knhjæh²hubhÞ)�”}”(hŒWThe head_page, tail_page and commit_page are all initialized to point to the same page.”h]”hŒWThe head_page, tail_page and commit_page are all initialized to point to the same page.”…”�”}”(hjƒh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kqhjæh²hubhÞ)�”}”(hŒ”The reader page is initialized to have its next pointer pointing to the head page, and its previous pointer pointing to a page before the head page.”h]”hŒ”The reader page is initialized to have its next pointer pointing to the head page, and its previous pointer pointing to a page before the head page.”…”�”}”(hj‘h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kthjæh²hubhÞ)�”}”(hX¢The reader has its own page to use. At start up time, this page is allocated but is not attached to the list. When the reader wants to read from the buffer, if its page is empty (like it is on start-up), it will swap its page with the head_page. The old reader page will become part of the ring buffer and the head_page will be removed. The page after the inserted page (old reader_page) will become the new head page.”h]”hX¢The reader has its own page to use. At start up time, this page is allocated but is not attached to the list. When the reader wants to read from the buffer, if its page is empty (like it is on start-up), it will swap its page with the head_page. The old reader page will become part of the ring buffer and the head_page will be removed. The page after the inserted page (old reader_page) will become the new head page.”…”�”}”(hjŸh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kxhjæh²hubhÞ)�”}”(hŒ|Once the new page is given to the reader, the reader could do what it wants with it, as long as a writer has left that page.”h]”hŒ|Once the new page is given to the reader, the reader could do what it wants with it, as long as a writer has left that page.”…”�”}”(hj­h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K€hjæh²hubhÞ)�”}”(hŒ…A sample of how the reader page is swapped: Note this does not show the head page in the buffer, it is for demonstrating a swap only.”h]”hŒ…A sample of how the reader page is swapped: Note this does not show the head page in the buffer, it is for demonstrating a swap only.”…”�”}”(hj»h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kƒhjæh²hubj�)�”}”(hX,+------+ |reader| RING BUFFER |page | +------+ +---+ +---+ +---+ | |-->| |-->| | | |<--| |<--| | +---+ +---+ +---+ ^ | ^ | | +-------------+ | +-----------------+ +------+ |reader| RING BUFFER |page |-------------------+ +------+ v | +---+ +---+ +---+ | | |-->| |-->| | | | |<--| |<--| |<-+ | +---+ +---+ +---+ | | ^ | ^ | | | | +-------------+ | | | +-----------------+ | +------------------------------------+ +------+ |reader| RING BUFFER |page |-------------------+ +------+ <---------------+ v | ^ +---+ +---+ +---+ | | | |-->| |-->| | | | | | | |<--| |<-+ | | +---+ +---+ +---+ | | | | ^ | | | | +-------------+ | | | +-----------------------------+ | +------------------------------------+ +------+ |buffer| RING BUFFER |page |-------------------+ +------+ <---------------+ v | ^ +---+ +---+ +---+ | | | | | |-->| | | | New | | | |<--| |<-+ | | Reader +---+ +---+ +---+ | | | page ----^ | | | | | | | +-----------------------------+ | +------------------------------------+”h]”hX,+------+ |reader| RING BUFFER |page | +------+ +---+ +---+ +---+ | |-->| |-->| | | |<--| |<--| | +---+ +---+ +---+ ^ | ^ | | +-------------+ | +-----------------+ +------+ |reader| RING BUFFER |page |-------------------+ +------+ v | +---+ +---+ +---+ | | |-->| |-->| | | | |<--| |<--| |<-+ | +---+ +---+ +---+ | | ^ | ^ | | | | +-------------+ | | | +-----------------+ | +------------------------------------+ +------+ |reader| RING BUFFER |page |-------------------+ +------+ <---------------+ v | ^ +---+ +---+ +---+ | | | |-->| |-->| | | | | | | |<--| |<-+ | | +---+ +---+ +---+ | | | | ^ | | | | +-------------+ | | | +-----------------------------+ | +------------------------------------+ +------+ |buffer| RING BUFFER |page |-------------------+ +------+ <---------------+ v | ^ +---+ +---+ +---+ | | | | | |-->| | | | New | | | |<--| |<-+ | | Reader +---+ +---+ +---+ | | | page ----^ | | | | | | | +-----------------------------+ | +------------------------------------+”…”�”}”hjÉsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´K‰hjæh²hubhÞ)�”}”(hŒ”It is possible that the page swapped is the commit page and the tail page, if what is in the ring buffer is less than what is held in a buffer page.”h]”hŒ”It is possible that the page swapped is the commit page and the tail page, if what is in the ring buffer is less than what is held in a buffer page.”…”�”}”(hj×h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K¿hjæh²hubj�)�”}”(hX reader page commit page tail page | | | v | | +---+ | | | |<----------+ | | |<------------------------+ | |------+ +---+ | | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX reader page commit page tail page | | | v | | +---+ | | | |<----------+ | | |<------------------------+ | |------+ +---+ | | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjåsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´KÄhjæh²hubhÞ)�”}”(hŒ½This case is still valid for this algorithm. When the writer leaves the page, it simply goes into the ring buffer since the reader page still points to the next location in the ring buffer.”h]”hŒ½This case is still valid for this algorithm. When the writer leaves the page, it simply goes into the ring buffer since the reader page still points to the next location in the ring buffer.”…”�”}”(hjóh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KÓhjæh²hubhÞ)�”}”(hŒThe main pointers:”h]”hŒThe main pointers:”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KÙhjæh²hubhŒ block_quote”“”)�”}”(hXqreader page - The page used solely by the reader and is not part of the ring buffer (may be swapped in) head page - the next page in the ring buffer that will be swapped with the reader page. tail page - the page where the next write will take place. commit page - the page that last finished a write. ”h]”jÀ)�”}”(hhh]”(jÅ)�”}”(hŒjreader page - The page used solely by the reader and is not part of the ring buffer (may be swapped in) ”h]”(jË)�”}”(hŒ reader page”h]”hŒ reader page”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´KÝhjubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒZThe page used solely by the reader and is not part of the ring buffer (may be swapped in) ”h]”hÞ)�”}”(hŒYThe page used solely by the reader and is not part of the ring buffer (may be swapped in)”h]”hŒYThe page used solely by the reader and is not part of the ring buffer (may be swapped in)”…”�”}”(hj4h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KÜhj0ubah}”(h]”h ]”h"]”h$]”h&]”uh1jähj-ubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´KÜhj*ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´KÝhjubjÅ)�”}”(hŒZhead page - the next page in the ring buffer that will be swapped with the reader page. ”h]”(jË)�”}”(hŒ head page”h]”hŒ head page”…”�”}”(hj^h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´KáhjZubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒLthe next page in the ring buffer that will be swapped with the reader page. ”h]”hÞ)�”}”(hŒKthe next page in the ring buffer that will be swapped with the reader page.”h]”hŒKthe next page in the ring buffer that will be swapped with the reader page.”…”�”}”(hjvh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kàhjrubah}”(h]”h ]”h"]”h$]”h&]”uh1jähjoubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´Kàhjlubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjZubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´KáhjubjÅ)�”}”(hŒ;tail page - the page where the next write will take place. ”h]”(jË)�”}”(hŒ tail page”h]”hŒ tail page”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´KähjœubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒ/the page where the next write will take place. ”h]”hÞ)�”}”(hŒ.the page where the next write will take place.”h]”hŒ.the page where the next write will take place.”…”�”}”(hj¸h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kähj´ubah}”(h]”h ]”h"]”h$]”h&]”uh1jähj±ubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´Kähj®ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjœubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´KähjubjÅ)�”}”(hŒ3commit page - the page that last finished a write. ”h]”(jË)�”}”(hŒ commit page”h]”hŒ commit page”…”�”}”(hjâh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´KçhjÞubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒ%the page that last finished a write. ”h]”hÞ)�”}”(hŒ$the page that last finished a write.”h]”hŒ$the page that last finished a write.”…”�”}”(hjúh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kçhjöubah}”(h]”h ]”h"]”h$]”h&]”uh1jähjóubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´Kçhjðubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjÞubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´Kçhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1j¿hjubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÇh´KÛhjæh²hubhÞ)�”}”(hŒ‘The commit page only is updated by the outermost writer in the writer stack. A writer that preempts another writer will not move the commit page.”h]”hŒ‘The commit page only is updated by the outermost writer in the writer stack. A writer that preempts another writer will not move the commit page.”…”�”}”(hj,h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kéhjæh²hubhÞ)�”}”(hŒÆWhen data is written into the ring buffer, a position is reserved in the ring buffer and passed back to the writer. When the writer is finished writing data into that position, it commits the write.”h]”hŒÆWhen data is written into the ring buffer, a position is reserved in the ring buffer and passed back to the writer. When the writer is finished writing data into that position, it commits the write.”…”�”}”(hj:h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kíhjæh²hubhÞ)�”}”(hŒŸAnother write (or a read) may take place at anytime during this transaction. If another write happens it must finish before continuing with the previous write.”h]”hŒŸAnother write (or a read) may take place at anytime during this transaction. If another write happens it must finish before continuing with the previous write.”…”�”}”(hjHh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kñhjæh²hubj)�”}”(hX` Write reserve:: Buffer page +---------+ |written | +---------+ <--- given back to writer (current commit) |reserved | +---------+ <--- tail pointer | empty | +---------+ Write commit:: Buffer page +---------+ |written | +---------+ |written | +---------+ <--- next position for write (current commit) | empty | +---------+ If a write happens after the first reserve:: Buffer page +---------+ |written | +---------+ <-- current commit |reserved | +---------+ <--- given back to second writer |reserved | +---------+ <--- tail pointer After second writer commits:: Buffer page +---------+ |written | +---------+ <--(last full commit) |reserved | +---------+ |pending | |commit | +---------+ <--- tail pointer When the first writer commits:: Buffer page +---------+ |written | +---------+ |written | +---------+ |written | +---------+ <--(last full commit and tail pointer) ”h]”(j)�”}”(hX‚Write reserve:: Buffer page +---------+ |written | +---------+ <--- given back to writer (current commit) |reserved | +---------+ <--- tail pointer | empty | +---------+ Write commit:: Buffer page +---------+ |written | +---------+ |written | +---------+ <--- next position for write (current commit) | empty | +---------+ ”h]”(hÞ)�”}”(hŒWrite reserve::”h]”hŒWrite reserve:”…”�”}”(hj^h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KöhjZubj�)�”}”(hŒž Buffer page +---------+ |written | +---------+ <--- given back to writer (current commit) |reserved | +---------+ <--- tail pointer | empty | +---------+”h]”hŒž Buffer page +---------+ |written | +---------+ <--- given back to writer (current commit) |reserved | +---------+ <--- tail pointer | empty | +---------+”…”�”}”hjlsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´KøhjZubhÞ)�”}”(hŒWrite commit::”h]”hŒ Write commit:”…”�”}”(hjzh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MhjZubj�)�”}”(hŒ� Buffer page +---------+ |written | +---------+ |written | +---------+ <--- next position for write (current commit) | empty | +---------+”h]”hŒ� Buffer page +---------+ |written | +---------+ |written | +---------+ <--- next position for write (current commit) | empty | +---------+”…”�”}”hjˆsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MhjZubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÇh´KöhjVubhÞ)�”}”(hŒ,If a write happens after the first reserve::”h]”hŒ+If a write happens after the first reserve:”…”�”}”(hjœh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M hjVubj�)�”}”(hXn Buffer page +---------+ |written | +---------+ <-- current commit |reserved | +---------+ <--- given back to second writer |reserved | +---------+ <--- tail pointer After second writer commits:: Buffer page +---------+ |written | +---------+ <--(last full commit) |reserved | +---------+ |pending | |commit | +---------+ <--- tail pointer When the first writer commits:: Buffer page +---------+ |written | +---------+ |written | +---------+ |written | +---------+ <--(last full commit and tail pointer)”h]”hXn Buffer page +---------+ |written | +---------+ <-- current commit |reserved | +---------+ <--- given back to second writer |reserved | +---------+ <--- tail pointer After second writer commits:: Buffer page +---------+ |written | +---------+ <--(last full commit) |reserved | +---------+ |pending | |commit | +---------+ <--- tail pointer When the first writer commits:: Buffer page +---------+ |written | +---------+ |written | +---------+ |written | +---------+ <--(last full commit and tail pointer)”…”�”}”hjªsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MhjVubeh}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÇh´Köhjæh²hubhÞ)�”}”(hXThe commit pointer points to the last write location that was committed without preempting another write. When a write that preempted another write is committed, it only becomes a pending commit and will not be a full commit until all writes have been committed.”h]”hXThe commit pointer points to the last write location that was committed without preempting another write. When a write that preempted another write is committed, it only becomes a pending commit and will not be a full commit until all writes have been committed.”…”�”}”(hj¾h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M1hjæh²hubhÞ)�”}”(hŒ‹The commit page points to the page that has the last full commit. The tail page points to the page with the last write (before committing).”h]”hŒ‹The commit page points to the page that has the last full commit. The tail page points to the page with the last write (before committing).”…”�”}”(hjÌh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M6hjæh²hubhÞ)�”}”(hŒøThe tail page is always equal to or after the commit page. It may be several pages ahead. If the tail page catches up to the commit page then no more writes may take place (regardless of the mode of the ring buffer: overwrite and produce/consumer).”h]”hŒøThe tail page is always equal to or after the commit page. It may be several pages ahead. If the tail page catches up to the commit page then no more writes may take place (regardless of the mode of the ring buffer: overwrite and produce/consumer).”…”�”}”(hjÚh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M:hjæh²hubhÞ)�”}”(hŒThe order of pages is::”h]”hŒThe order of pages is:”…”�”}”(hjèh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M?hjæh²hubj�)�”}”(hŒhead page commit page tail page”h]”hŒhead page commit page tail page”…”�”}”hjösbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MAhjæh²hubhÞ)�”}”(hŒPossible scenario::”h]”hŒPossible scenario:”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MEhjæh²hubj�)�”}”(hX+ tail page head page commit page | | | | v v v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX+ tail page head page commit page | | | | v v v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MGhjæh²hubhÞ)�”}”(hX¸There is a special case that the head page is after either the commit page and possibly the tail page. That is when the commit (and tail) page has been swapped with the reader page. This is because the head page is always part of the ring buffer, but the reader page is not. Whenever there has been less than a full page that has been committed inside the ring buffer, and a reader swaps out a page, it will be swapping out the commit page.”h]”hX¸There is a special case that the head page is after either the commit page and possibly the tail page. That is when the commit (and tail) page has been swapped with the reader page. This is because the head page is always part of the ring buffer, but the reader page is not. Whenever there has been less than a full page that has been committed inside the ring buffer, and a reader swaps out a page, it will be swapping out the commit page.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MPhjæh²hubj�)�”}”(hXg reader page commit page tail page | | | v | | +---+ | | | |<----------+ | | |<------------------------+ | |------+ +---+ | | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ ^ | head page”h]”hXg reader page commit page tail page | | | v | | +---+ | | | |<----------+ | | |<------------------------+ | |------+ +---+ | | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ ^ | head page”…”�”}”hj.sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MYhjæh²hubhÞ)�”}”(hŒbIn this case, the head page will not move when the tail and commit move back into the ring buffer.”h]”hŒbIn this case, the head page will not move when the tail and commit move back into the ring buffer.”…”�”}”(hj<h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mlhjæh²hubhÞ)�”}”(hX The reader cannot swap a page into the ring buffer if the commit page is still on that page. If the read meets the last commit (real commit not pending or reserved), then there is nothing more to read. The buffer is considered empty until another full commit finishes.”h]”hX The reader cannot swap a page into the ring buffer if the commit page is still on that page. If the read meets the last commit (real commit not pending or reserved), then there is nothing more to read. The buffer is considered empty until another full commit finishes.”…”�”}”(hjJh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mohjæh²hubhÞ)�”}”(hŒ¯When the tail meets the head page, if the buffer is in overwrite mode, the head page will be pushed ahead one. If the buffer is in producer/consumer mode, the write will fail.”h]”hŒ¯When the tail meets the head page, if the buffer is in overwrite mode, the head page will be pushed ahead one. If the buffer is in producer/consumer mode, the write will fail.”…”�”}”(hjXh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mthjæh²hubhÞ)�”}”(hŒOverwrite mode::”h]”hŒOverwrite mode:”…”�”}”(hjfh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mxhjæh²hubj�)�”}”(hXÅ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ ^ | head page tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ ^ | head page tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ ^ | head page”h]”hXÅ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ ^ | head page tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ ^ | head page tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ ^ | head page”…”�”}”hjtsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´Mzhjæh²hubhÞ)�”}”(hŒ…Note, the reader page will still point to the previous head page. But when a swap takes place, it will use the most recent head page.”h]”hŒ…Note, the reader page will still point to the previous head page. But when a swap takes place, it will use the most recent head page.”…”�”}”(hj‚h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M�hjæh²hubeh}”(h]”Œthe-generic-ring-buffer”ah ]”h"]”Œthe generic ring buffer”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´KCubhÉ)�”}”(hhh]”(hÎ)�”}”(hŒ Making the Ring Buffer Lockless:”h]”hŒ Making the Ring Buffer Lockless:”…”�”}”(hj›h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhj˜h²hh³hÇh´M¢ubhÞ)�”}”(hX­The main idea behind the lockless algorithm is to combine the moving of the head_page pointer with the swapping of pages with the reader. State flags are placed inside the pointer to the page. To do this, each page must be aligned in memory by 4 bytes. This will allow the 2 least significant bits of the address to be used as flags, since they will always be zero for the address. To get the address, simply mask out the flags::”h]”hX¬The main idea behind the lockless algorithm is to combine the moving of the head_page pointer with the swapping of pages with the reader. State flags are placed inside the pointer to the page. To do this, each page must be aligned in memory by 4 bytes. This will allow the 2 least significant bits of the address to be used as flags, since they will always be zero for the address. To get the address, simply mask out the flags:”…”�”}”(hj©h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M¤hj˜h²hubj�)�”}”(hŒMASK = ~3 address & MASK”h]”hŒMASK = ~3 address & MASK”…”�”}”hj·sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M¬hj˜h²hubhÞ)�”}”(hŒ)Two flags will be kept by these two bits:”h]”hŒ)Two flags will be kept by these two bits:”…”�”}”(hjÅh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M°hj˜h²hubj)�”}”(hŒ«HEADER - the page being pointed to is a head page UPDATE - the page being pointed to is being updated by a writer and was or is about to be a head page. ”h]”jÀ)�”}”(hhh]”(jÅ)�”}”(hŒ2HEADER - the page being pointed to is a head page ”h]”(jË)�”}”(hŒHEADER”h]”hŒHEADER”…”�”}”(hjÞh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´M³hjÚubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒ)the page being pointed to is a head page ”h]”hÞ)�”}”(hŒ(the page being pointed to is a head page”h]”hŒ(the page being pointed to is a head page”…”�”}”(hjöh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M³hjòubah}”(h]”h ]”h"]”h$]”h&]”uh1jähjïubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´M³hjìubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhjÚubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´M³hj×ubjÅ)�”}”(hŒiUPDATE - the page being pointed to is being updated by a writer and was or is about to be a head page. ”h]”(jË)�”}”(hŒUPDATE”h]”hŒUPDATE”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jÊh³hÇh´M·hj ubjÛ)�”}”(hhh]”jà)�”}”(hhh]”jå)�”}”(hŒ^the page being pointed to is being updated by a writer and was or is about to be a head page. ”h]”hÞ)�”}”(hŒ]the page being pointed to is being updated by a writer and was or is about to be a head page.”h]”hŒ]the page being pointed to is being updated by a writer and was or is about to be a head page.”…”�”}”(hj8 h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M¶hj4 ubah}”(h]”h ]”h"]”h$]”h&]”uh1jähj1 ubah}”(h]”h ]”h"]”h$]”h&]”jjuh1jßh³hÇh´M¶hj. ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÚhj ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jÄh³hÇh´M·hj×ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j¿hjÓubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÇh´M²hj˜h²hubj�)�”}”(hXI reader page | v +---+ | |------+ +---+ | | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hXI reader page | v +---+ | |------+ +---+ | | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjj sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M»hj˜h²hubhÞ)�”}”(hŒ³The above pointer "-H->" would have the HEADER flag set. That is the next page is the next page to be swapped out by the reader. This pointer means the next page is the head page.”h]”hŒ·The above pointer “-H->â€� would have the HEADER flag set. That is the next page is the next page to be swapped out by the reader. This pointer means the next page is the head page.”…”�”}”(hjx h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MÉhj˜h²hubhÞ)�”}”(hŒjWhen the tail page meets the head pointer, it will use cmpxchg to change the pointer to the UPDATE state::”h]”hŒiWhen the tail page meets the head pointer, it will use cmpxchg to change the pointer to the UPDATE state:”…”�”}”(hj† h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MÍhj˜h²hubj�)�”}”(hX¨ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX¨ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj” sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MÑhj˜h²hubhÞ)�”}”(hŒ0"-U->" represents a pointer in the UPDATE state.”h]”hŒ4“-U->â€� represents a pointer in the UPDATE state.”…”�”}”(hj¢ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Máhj˜h²hubhÞ)�”}”(hXAny access to the reader will need to take some sort of lock to serialize the readers. But the writers will never take a lock to write to the ring buffer. This means we only need to worry about a single reader, and writes only preempt in "stack" formation.”h]”hXAny access to the reader will need to take some sort of lock to serialize the readers. But the writers will never take a lock to write to the ring buffer. This means we only need to worry about a single reader, and writes only preempt in “stackâ€� formation.”…”�”}”(hj° h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mãhj˜h²hubhÞ)�”}”(hXGWhen the reader tries to swap the page with the ring buffer, it will also use cmpxchg. If the flag bit in the pointer to the head page does not have the HEADER flag set, the compare will fail and the reader will need to look for the new head page and try again. Note, the flags UPDATE and HEADER are never set at the same time.”h]”hXGWhen the reader tries to swap the page with the ring buffer, it will also use cmpxchg. If the flag bit in the pointer to the head page does not have the HEADER flag set, the compare will fail and the reader will need to look for the new head page and try again. Note, the flags UPDATE and HEADER are never set at the same time.”…”�”}”(hj¾ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mèhj˜h²hubhÞ)�”}”(hŒ-The reader swaps the reader page as follows::”h]”hŒ,The reader swaps the reader page as follows:”…”�”}”(hjÌ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mîhj˜h²hubj�)�”}”(hXM+------+ |reader| RING BUFFER |page | +------+ +---+ +---+ +---+ | |--->| |--->| | | |<---| |<---| | +---+ +---+ +---+ ^ | ^ | | +---------------+ | +-----H-------------+”h]”hXM+------+ |reader| RING BUFFER |page | +------+ +---+ +---+ +---+ | |--->| |--->| | | |<---| |<---| | +---+ +---+ +---+ ^ | ^ | | +---------------+ | +-----H-------------+”…”�”}”hjÚ sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´Mðhj˜h²hubhÞ)�”}”(hŒXThe reader sets the reader page next pointer as HEADER to the page after the head page::”h]”hŒWThe reader sets the reader page next pointer as HEADER to the page after the head page:”…”�”}”(hjè h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mühj˜h²hubj�)�”}”(hX²+------+ |reader| RING BUFFER |page |-------H-----------+ +------+ v | +---+ +---+ +---+ | | |--->| |--->| | | | |<---| |<---| |<-+ | +---+ +---+ +---+ | | ^ | ^ | | | | +---------------+ | | | +-----H-------------+ | +--------------------------------------+”h]”hX²+------+ |reader| RING BUFFER |page |-------H-----------+ +------+ v | +---+ +---+ +---+ | | |--->| |--->| | | | |<---| |<---| |<-+ | +---+ +---+ +---+ | | ^ | ^ | | | | +---------------+ | | | +-----H-------------+ | +--------------------------------------+”…”�”}”hjö sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´Mhj˜h²hubhÞ)�”}”(hŒÔIt does a cmpxchg with the pointer to the previous head page to make it point to the reader page. Note that the new pointer does not have the HEADER flag set. This action atomically moves the head page forward::”h]”hŒÓIt does a cmpxchg with the pointer to the previous head page to make it point to the reader page. Note that the new pointer does not have the HEADER flag set. This action atomically moves the head page forward:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M hj˜h²hubj�)�”}”(hX¢+------+ |reader| RING BUFFER |page |-------H-----------+ +------+ v | ^ +---+ +---+ +---+ | | | |-->| |-->| | | | | |<--| |<--| |<-+ | | +---+ +---+ +---+ | | | | ^ | | | | +-------------+ | | | +-----------------------------+ | +------------------------------------+”h]”hX¢+------+ |reader| RING BUFFER |page |-------H-----------+ +------+ v | ^ +---+ +---+ +---+ | | | |-->| |-->| | | | | |<--| |<--| |<-+ | | +---+ +---+ +---+ | | | | ^ | | | | +-------------+ | | | +-----------------------------+ | +------------------------------------+”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´Mhj˜h²hubhÞ)�”}”(hŒeAfter the new head page is set, the previous pointer of the head page is updated to the reader page::”h]”hŒdAfter the new head page is set, the previous pointer of the head page is updated to the reader page:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mhj˜h²hubj�)�”}”(hXZ+------+ |reader| RING BUFFER |page |-------H-----------+ +------+ <---------------+ v | ^ +---+ +---+ +---+ | | | |-->| |-->| | | | | | | |<--| |<-+ | | +---+ +---+ +---+ | | | | ^ | | | | +-------------+ | | | +-----------------------------+ | +------------------------------------+ +------+ |buffer| RING BUFFER |page |-------H-----------+ <--- New head page +------+ <---------------+ v | ^ +---+ +---+ +---+ | | | | | |-->| | | | New | | | |<--| |<-+ | | Reader +---+ +---+ +---+ | | | page ----^ | | | | | | | +-----------------------------+ | +------------------------------------+”h]”hXZ+------+ |reader| RING BUFFER |page |-------H-----------+ +------+ <---------------+ v | ^ +---+ +---+ +---+ | | | |-->| |-->| | | | | | | |<--| |<-+ | | +---+ +---+ +---+ | | | | ^ | | | | +-------------+ | | | +-----------------------------+ | +------------------------------------+ +------+ |buffer| RING BUFFER |page |-------H-----------+ <--- New head page +------+ <---------------+ v | ^ +---+ +---+ +---+ | | | | | |-->| | | | New | | | |<--| |<-+ | | Reader +---+ +---+ +---+ | | | page ----^ | | | | | | | +-----------------------------+ | +------------------------------------+”…”�”}”hj. sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M!hj˜h²hubhÞ)�”}”(hX‚Another important point: The page that the reader page points back to by its previous pointer (the one that now points to the new head page) never points back to the reader page. That is because the reader page is not part of the ring buffer. Traversing the ring buffer via the next pointers will always stay in the ring buffer. Traversing the ring buffer via the prev pointers may not.”h]”hX‚Another important point: The page that the reader page points back to by its previous pointer (the one that now points to the new head page) never points back to the reader page. That is because the reader page is not part of the ring buffer. Traversing the ring buffer via the next pointers will always stay in the ring buffer. Traversing the ring buffer via the prev pointers may not.”…”�”}”(hj< h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M;hj˜h²hubhÞ)�”}”(hŒÞNote, the way to determine a reader page is simply by examining the previous pointer of the page. If the next pointer of the previous page does not point back to the original page, then the original page is a reader page::”h]”hŒÝNote, the way to determine a reader page is simply by examining the previous pointer of the page. If the next pointer of the previous page does not point back to the original page, then the original page is a reader page:”…”�”}”(hjJ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MBhj˜h²hubj�)�”}”(hŒû +--------+ | reader | next +----+ | page |-------->| |<====== (buffer page) +--------+ +----+ | | ^ | v | next prev | +----+ +------------->| | +----+”h]”hŒû +--------+ | reader | next +----+ | page |-------->| |<====== (buffer page) +--------+ +----+ | | ^ | v | next prev | +----+ +------------->| | +----+”…”�”}”hjX sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MGhj˜h²hubhÞ)�”}”(hŒ$The way the head page moves forward:”h]”hŒ$The way the head page moves forward:”…”�”}”(hjf h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MQhj˜h²hubhÞ)�”}”(hXöWhen the tail page meets the head page and the buffer is in overwrite mode and more writes take place, the head page must be moved forward before the writer may move the tail page. The way this is done is that the writer performs a cmpxchg to convert the pointer to the head page from the HEADER flag to have the UPDATE flag set. Once this is done, the reader will not be able to swap the head page from the buffer, nor will it be able to move the head page, until the writer is finished with the move.”h]”hXöWhen the tail page meets the head page and the buffer is in overwrite mode and more writes take place, the head page must be moved forward before the writer may move the tail page. The way this is done is that the writer performs a cmpxchg to convert the pointer to the head page from the HEADER flag to have the UPDATE flag set. Once this is done, the reader will not be able to swap the head page from the buffer, nor will it be able to move the head page, until the writer is finished with the move.”…”�”}”(hjt h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MShj˜h²hubhÞ)�”}”(hŒŽThis eliminates any races that the reader can have on the writer. The reader must spin, and this is why the reader cannot preempt the writer::”h]”hŒ�This eliminates any races that the reader can have on the writer. The reader must spin, and this is why the reader cannot preempt the writer:”…”�”}”(hj‚ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M[hj˜h²hubj�)�”}”(hX¨ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX¨ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj� sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M^hj˜h²hubhÞ)�”}”(hŒ8The following page will be made into the new head page::”h]”hŒ7The following page will be made into the new head page:”…”�”}”(hjž h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mnhj˜h²hubj�)�”}”(hŒÒ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒÒ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj¬ sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´Mphj˜h²hubhÞ)�”}”(hŒ[After the new head page has been set, we can set the old head page pointer back to NORMAL::”h]”hŒZAfter the new head page has been set, we can set the old head page pointer back to NORMAL:”…”�”}”(hjº h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mxhj˜h²hubj�)�”}”(hŒÒ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒÒ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjÈ sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M{hj˜h²hubhÞ)�”}”(hŒHAfter the head page has been moved, the tail page may now move forward::”h]”hŒGAfter the head page has been moved, the tail page may now move forward:”…”�”}”(hjÖ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Mƒhj˜h²hubj�)�”}”(hŒí tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒí tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjä sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M…hj˜h²hubhÞ)�”}”(hŒFThe above are the trivial updates. Now for the more complex scenarios.”h]”hŒFThe above are the trivial updates. Now for the more complex scenarios.”…”�”}”(hjò h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MŽhj˜h²hubhÞ)�”}”(hX}As stated before, if enough writes preempt the first write, the tail page may make it all the way around the buffer and meet the commit page. At this time, we must start dropping writes (usually with some kind of warning to the user). But what happens if the commit was still on the reader page? The commit page is not part of the ring buffer. The tail page must account for this::”•—ih]”hX|As stated before, if enough writes preempt the first write, the tail page may make it all the way around the buffer and meet the commit page. At this time, we must start dropping writes (usually with some kind of warning to the user). But what happens if the commit was still on the reader page? The commit page is not part of the ring buffer. The tail page must account for this:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M‘hj˜h²hubj�)�”}”(hXî reader page commit page | | v | +---+ | | |<----------+ | | | |------+ +---+ | | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ ^ | tail page”h]”hXî reader page commit page | | v | +---+ | | |<----------+ | | | |------+ +---+ | | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+ ^ | tail page”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M™hj˜h²hubhÞ)�”}”(hŒŽIf the tail page were to simply push the head page forward, the commit when leaving the reader page would not be pointing to the correct page.”h]”hŒŽIf the tail page were to simply push the head page forward, the commit when leaving the reader page would not be pointing to the correct page.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M«hj˜h²hubhÞ)�”}”(hŒËThe solution to this is to test if the commit page is on the reader page before pushing the head page. If it is, then it can be assumed that the tail page wrapped the buffer, and we must drop new writes.”h]”hŒËThe solution to this is to test if the commit page is on the reader page before pushing the head page. If it is, then it can be assumed that the tail page wrapped the buffer, and we must drop new writes.”…”�”}”(hj* h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M®hj˜h²hubhÞ)�”}”(hXThis is not a race condition, because the commit page can only be moved by the outermost writer (the writer that was preempted). This means that the commit will not move while a writer is moving the tail page. The reader cannot swap the reader page if it is also being used as the commit page. The reader can simply check that the commit is off the reader page. Once the commit page leaves the reader page it will never go back on it unless a reader does another swap with the buffer page that is also the commit page.”h]”hXThis is not a race condition, because the commit page can only be moved by the outermost writer (the writer that was preempted). This means that the commit will not move while a writer is moving the tail page. The reader cannot swap the reader page if it is also being used as the commit page. The reader can simply check that the commit is off the reader page. Once the commit page leaves the reader page it will never go back on it unless a reader does another swap with the buffer page that is also the commit page.”…”�”}”(hj8 h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M²hj˜h²hubeh}”(h]”Œmaking-the-ring-buffer-lockless”ah ]”h"]”Œ making the ring buffer lockless:”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´M¢ubhÉ)�”}”(hhh]”(hÎ)�”}”(hŒ Nested writes”h]”hŒ Nested writes”…”�”}”(hjQ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhjN h²hh³hÇh´M½ubhÞ)�”}”(hŒÊIn the pushing forward of the tail page we must first push forward the head page if the head page is the next page. If the head page is not the next page, the tail page is simply updated with a cmpxchg.”h]”hŒÊIn the pushing forward of the tail page we must first push forward the head page if the head page is the next page. If the head page is not the next page, the tail page is simply updated with a cmpxchg.”…”�”}”(hj_ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M¿hjN h²hubhÞ)�”}”(hŒaOnly writers move the tail page. This must be done atomically to protect against nested writers::”h]”hŒ`Only writers move the tail page. This must be done atomically to protect against nested writers:”…”�”}”(hjm h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MÃhjN h²hubj�)�”}”(hŒZtemp_page = tail_page next_page = temp_page->next cmpxchg(tail_page, temp_page, next_page)”h]”hŒZtemp_page = tail_page next_page = temp_page->next cmpxchg(tail_page, temp_page, next_page)”…”�”}”hj{ sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MÆhjN h²hubhÞ)�”}”(hŒ¯The above will update the tail page if it is still pointing to the expected page. If this fails, a nested write pushed it forward, the current write does not need to push it::”h]”hŒ®The above will update the tail page if it is still pointing to the expected page. If this fails, a nested write pushed it forward, the current write does not need to push it:”…”�”}”(hj‰ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MÊhjN h²hubj�)�”}”(hX  temp page | v tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX  temp page | v tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj— sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MÏhjN h²hubhÞ)�”}”(hŒ7Nested write comes in and moves the tail page forward::”h]”hŒ6Nested write comes in and moves the tail page forward:”…”�”}”(hj¥ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MÚhjN h²hubj�)�”}”(hX  tail page (moved by nested writer) temp page | | | v v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX  tail page (moved by nested writer) temp page | | | v v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj³ sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MÜhjN h²hubhÞ)�”}”(hŒ¡The above would fail the cmpxchg, but since the tail page has already been moved forward, the writer will just try again to reserve storage on the new tail page.”h]”hŒ¡The above would fail the cmpxchg, but since the tail page has already been moved forward, the writer will just try again to reserve storage on the new tail page.”…”�”}”(hjÁ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MåhjN h²hubhÞ)�”}”(hŒ7But the moving of the head page is a bit more complex::”h]”hŒ6But the moving of the head page is a bit more complex:”…”�”}”(hjÏ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MéhjN h²hubj�)�”}”(hŒÓ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒÓ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjÝ sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MëhjN h²hubhÞ)�”}”(hŒ4The write converts the head page pointer to UPDATE::”h]”hŒ3The write converts the head page pointer to UPDATE:”…”�”}”(hjë h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MóhjN h²hubj�)�”}”(hŒÓ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒÓ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjù sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MõhjN h²hubhÞ)�”}”(hX But if a nested writer preempts here, it will see that the next page is a head page, but it is also nested. It will detect that it is nested and will save that information. The detection is the fact that it sees the UPDATE flag instead of a HEADER or NORMAL pointer.”h]”hX But if a nested writer preempts here, it will see that the next page is a head page, but it is also nested. It will detect that it is nested and will save that information. The detection is the fact that it sees the UPDATE flag instead of a HEADER or NORMAL pointer.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MýhjN h²hubhÞ)�”}”(hŒ6The nested writer will set the new head page pointer::”h]”hŒ5The nested writer will set the new head page pointer:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MhjN h²hubj�)�”}”(hŒÒ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒÒ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj# sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MhjN h²hubhÞ)�”}”(hŒŽBut it will not reset the update back to normal. Only the writer that converted a pointer from HEAD to UPDATE will convert it back to NORMAL::”h]”hŒ�But it will not reset the update back to normal. Only the writer that converted a pointer from HEAD to UPDATE will convert it back to NORMAL:”…”�”}”(hj1 h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M hjN h²hubj�)�”}”(hŒí tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒí tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj? sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MhjN h²hubhÞ)�”}”(hŒbAfter the nested writer finishes, the outermost writer will convert the UPDATE pointer to NORMAL::”h]”hŒaAfter the nested writer finishes, the outermost writer will convert the UPDATE pointer to NORMAL:”…”�”}”(hjM h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MhjN h²hubj�)�”}”(hŒí tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒí tail page | v +---+ +---+ +---+ +---+ <---| |--->| |--->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj[ sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MhjN h²hubhÞ)�”}”(hŒjIt can be even more complex if several nested writes came in and moved the tail page ahead several pages::”h]”hŒiIt can be even more complex if several nested writes came in and moved the tail page ahead several pages:”…”�”}”(hji h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M&hjN h²hubj�)�”}”(hŒã(first writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒã(first writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-H->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjw sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M*hjN h²hubhÞ)�”}”(hŒ4The write converts the head page pointer to UPDATE::”h]”hŒ3The write converts the head page pointer to UPDATE:”…”�”}”(hj… h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M4hjN h²hubj�)�”}”(hŒÓ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒÓ tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj“ sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M6hjN h²hubhÞ)�”}”(hŒINext writer comes in, and sees the update and sets up the new head page::”h]”hŒHNext writer comes in, and sees the update and sets up the new head page:”…”�”}”(hj¡ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M>hjN h²hubj�)�”}”(hŒã(second writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒã(second writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj¯ sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MAhjN h²hubhÞ)�”}”(hŒ†The nested writer moves the tail page forward. But does not set the old update page to NORMAL because it is not the outermost writer::”h]”hŒ…The nested writer moves the tail page forward. But does not set the old update page to NORMAL because it is not the outermost writer:”…”�”}”(hj½ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MKhjN h²hubj�)�”}”(hŒí tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒí tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjË sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MNhjN h²hubhÞ)�”}”(hŒqAnother writer preempts and sees the page after the tail page is a head page. It changes it from HEAD to UPDATE::”h]”hŒpAnother writer preempts and sees the page after the tail page is a head page. It changes it from HEAD to UPDATE:”…”�”}”(hjÙ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MVhjN h²hubj�)�”}”(hŒý(third writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-U->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒý(third writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-U->| |---> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjç sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MYhjN h²hubhÞ)�”}”(hŒ,The writer will move the head page forward::”h]”hŒ+The writer will move the head page forward:”…”�”}”(hjõ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MchjN h²hubj�)�”}”(hŒý(third writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-U->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒý(third writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-U->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MfhjN h²hubhÞ)�”}”(hŒ_But now that the third writer did change the HEAD flag to UPDATE it will convert it to normal::”h]”hŒ^But now that the third writer did change the HEAD flag to UPDATE it will convert it to normal:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MphjN h²hubj�)�”}”(hŒý(third writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hŒý(third writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MthjN h²hubhÞ)�”}”(hŒGThen it will move the tail page, and return back to the second writer::”h]”hŒFThen it will move the tail page, and return back to the second writer:”…”�”}”(hj- h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MhjN h²hubj�)�”}”(hX(second writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX(second writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj; sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M‚hjN h²hubhÞ)�”}”(hŒ°The second writer will fail to move the tail page because it was already moved, so it will try again and add its data to the new tail page. It will return to the first writer::”h]”hŒ¯The second writer will fail to move the tail page because it was already moved, so it will try again and add its data to the new tail page. It will return to the first writer:”…”�”}”(hjI h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M�hjN h²hubj�)�”}”(hX(first writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX(first writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjW sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M’hjN h²hubhÞ)�”}”(hŒ©The first writer cannot know atomically if the tail page moved while it updates the HEAD page. It will then update the head page to what it thinks is the new head page::”h]”hŒ¨The first writer cannot know atomically if the tail page moved while it updates the HEAD page. It will then update the head page to what it thinks is the new head page:”…”�”}”(hje h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MœhjN h²hubj�)�”}”(hX(first writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX(first writer) tail page | v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjs sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M¡hjN h²hubhÞ)�”}”(hXSince the cmpxchg returns the old value of the pointer the first writer will see it succeeded in updating the pointer from NORMAL to HEAD. But as we can see, this is not good enough. It must also check to see if the tail page is either where it use to be or on the next page::”h]”hXSince the cmpxchg returns the old value of the pointer the first writer will see it succeeded in updating the pointer from NORMAL to HEAD. But as we can see, this is not good enough. It must also check to see if the tail page is either where it use to be or on the next page:”…”�”}”(hj� h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M«hjN h²hubj�)�”}”(hX(first writer) A B tail page | | | v v v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX(first writer) A B tail page | | | v v v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |-H->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj� sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´M±hjN h²hubhÞ)�”}”(hŒÓIf tail page != A and tail page != B, then it must reset the pointer back to NORMAL. The fact that it only needs to worry about nested writers means that it only needs to check this after setting the HEAD page::”h]”hŒÒIf tail page != A and tail page != B, then it must reset the pointer back to NORMAL. The fact that it only needs to worry about nested writers means that it only needs to check this after setting the HEAD page:”…”�”}”(hj� h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´M»hjN h²hubj�)�”}”(hX(first writer) A B tail page | | | v v v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX(first writer) A B tail page | | | v v v +---+ +---+ +---+ +---+ <---| |--->| |-U->| |--->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hj« sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MÀhjN h²hubhÞ)�”}”(hŒÄNow the writer can update the head page. This is also why the head page must remain in UPDATE and only reset by the outermost writer. This prevents the reader from seeing the incorrect head page::”h]”hŒÃNow the writer can update the head page. This is also why the head page must remain in UPDATE and only reset by the outermost writer. This prevents the reader from seeing the incorrect head page:”…”�”}”(hj¹ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´MÊhjN h²hubj�)�”}”(hX(first writer) A B tail page | | | v v v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”h]”hX(first writer) A B tail page | | | v v v +---+ +---+ +---+ +---+ <---| |--->| |--->| |--->| |-H-> --->| |<---| |<---| |<---| |<--- +---+ +---+ +---+ +---+”…”�”}”hjÇ sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jŽh³hÇh´MÏhjN h²hubeh}”(h]”Œ nested-writes”ah ]”h"]”Œ nested writes”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´M½ubeh}”(h]”Œlockless-ring-buffer-design”ah ]”h"]”Œlockless ring buffer design”ah$]”h&]”uh1hÈhhh²hh³hÇh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÇuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)�”}”(hÍNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÇŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jâ jß jãjàj•j’jK jH jÚ j× uŒ nametypes”}”(jâ ‰jã‰j•‰jK ‰jÚ ‰uh}”(jß hÊjàj®j’jæjH j˜j× jN uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.