linux/Documentation/trace/ring-buffer-design.txt
<<
.19. /spapti /formti a .19. href="../linux+v37/o10/Documenta.19. img src="../.sta.1 /spapti.1 spap class="lxr_search">.19..19. input typvalhidden" namvalnavtarget" ion val">.19. input typvaltext" namvalsearch" idalsearch">.19. buttopttypvalsubmit">Search.19. Prefsi /a>.1 /spapti9. /divti9. form ac.1 input typvalhidden" namvalajax_lookup" idalajax_lookup" ion val">.9. /formti.9. div class="headingbottom"> 1 /a> Lockless Ring Buffer Design 2 /a> =========================== 3 /a>. 4 /a>Copyright 2009 Red Hat Inc.. 5 /a> Author: Steven Rostedt <srostedt@redhat.com>. 6 /a> License: The GNU Free Documenta 7 /a> (dual licensed under the GPL 2). 8 /a>Reviewers: Mathieu Desnoyers, Huang Ying, Hidetoshi Seto,. 9 /a> and Frederic Weisbecker.. .7. 11. 12 /a>Written for: 27/o31. 13 /a>. 14 /a>Terminology used iptthis Document. 15 /a>---------------------------------. 16 /a>. 17 /a>tail - where new writes happen iptthe ring buffer.. 18 /a>. 19 /a>head - where new reads happen iptthe ring buffer.. 27. 21producer -tthe tasktthat writes intotthe ring buffer (samv as writer). 22. 23 /a>writer -tsamv as producer. 24. 25 /a>consumer -tthe tasktthat reads fromtthe buffer (samv as reader). 26 /a>. 27 /a>reader -tsamv as consumer.. 28 /a>. 29 /a>reader_page -tA page outsidetthe ring buffer used solely (fortthe most part). 30 /a> bytthe reader.. 31. 32 /a>head_page -ta pointer totthe page that the reader will use next. 33 /a>. 34 /a>tail_page -ta pointer totthe page that will be written totnext. 35 /a>. 36 /a>commit_page -ta pointer totthe page withtthe last finished non-nested write.. 37 /a>. 38 /a>cmpxchg -thardware-assisted atomic transac 39 /a>. 40 /a> A = B iff previous A == C. 41. 42 /a> R = cmpxchg(A, C, B) is saying that we replace A withtB if and only if. 43 /a> current A is equal totC, and we put the old (current) A intotR. 44. 45 /a> R getstthe previous A regardless if A is updated withtB ortnot.. 46 /a>. 47 /a> To see if the update was successfulta compare of R == C may be used.. 48 /a>. 49 /a>The Generic Ring Buffer. 50 /a>-----------------------. 51. 52 /a>The ring buffer can be used ipteither an overwrite modetortin 53producer/consumer mode.. 54. 55 /a>Producer/consumer mode is where if the producer were totfill up the. 56 /a>buffer beforetthe consumer could free up anything, the producer. 57 /a>will stop writing totthe buffer. This will lose most recent events.. 58 /a>. 59 /a>Overwrite modetis where if the producer were totfill up the buffer. 60 /a>beforetthe consumer could free up anything, the producer will. 61overwrite the older data. This will lose the oldest events.. 62. 63Nottwo writers can write at the samv timv (on the samv per-cpu buffer),. 64 /a>butta writer may interrupttanother writer, buttit must finish writing. 65 /a>beforetthe previous writer may continue. This is very important totthe. 66 /a>algorithm. The writers ac< like a "stack". The way interrupts works. 67 /a>enforcestthis behavior.. 68 /a>. 69 /a>. 70 /a> writer1 start. 71 /a> <preempted> writer2 start. 72 /a> <preempted> writer3 start. 73 /a> writer3 finishes. 74 /a> writer2 finishes. 75 /a> writer1 finishes. 76 /a>. 77 /a>This is very much like a writer being preempted bytan interrupttand. 78 /a>the interrupttdoing a write as well.. 79 /a>. 80 /a>Readers can happen attany timv. Buttnottwo readers may run at the. 81 /a>samv timv,tnor can a reader preempt/interrupttanother reader. A reader. 82 /a>cannot preempt/interruptta writer, buttit may read/consume fromtthe. 83 /a>buffer at the samv timv as a writer is writing, buttthe reader must be. 84 /a>on another processor totdo so. A reader may read on its own processor. 85 /a>and can be preempted byta writer.. 86 /a>. 87 /a>A writer can preempt a reader, butta reader cannot preemptta writer.. 88 /a>Butta reader can read the buffer at the samv timv (on another processor). 89 /a>as a writer.. 97. 91 /a>The ring buffer is made up of a list of pages held together byta linked list.. 92. 93 /a>Attinitializa 94 /a>part of the ring buffer.. 95 /a>. 96 /a>The head_page, tail_page and commit_page are alltinitialized to point. 97 /a>to the samv page.. 98 /a>. 99 /a>The reader page is initialized to have its next pointer pointing to. 100 /a>the head page, and its previous pointer pointing tota page before. 101 /a>the head page.. 102. 103 /a>The reader has its own page to use. At start up timv,tthis page is. 104 /a>allocated buttis not attached to the list. When the reader wants. 105 /a>to read fromtthe buffer, if its page is empty (like ittis op start-up),. 106 /a>it will swap its page withtthe head_page. The old reader page will. 107 /a>become part of the ring buffer and the head_page will be removed.. 108 /a>The page after the inserted page (old reader_page) will become the. 109 /a>new head page.. 1.7. 111Oncetthe new page is given totthe reader, the reader could do what. 112 /a>it wants withtit, as long as a writer has left that page.. 113 /a>. 114 /a>A sample of how the reader page is swapped: Note this does not. 115 /a>show the head page iptthe buffer, ittis fortdemonstrating a swap. 116 /a>only.. 117 /a>. 118 /a> +------+. 119 /a> |reader| RING BUFFER. 120 /a> |page |. 121 /a> +------+. 122 /a> +---+ +---+ +---+. 123 /a> | |-->| |-->| |. 124 /a> | |<--| |<--| |. 125 /a> +---+ +---+ +---+. 126 /a> ^ | ^ |. 127 /a> | +-------------+ |. 128 /a> +-----------------+. 129 /a>. 137. 131 /a> +------+. 132 /a> |reader| RING BUFFER. 133 /a> |page |-------------------+. 134 /a> +------+ v. 135 /a> | +---+ +---+ +---+. 136 /a> | | |-->| |-->| |. 137 /a> | | |<--| |<--| |<-+. 138 /a> | +---+ +---+ +---+ |. 139 /a> | ^ | ^ | |. 140 /a> | | +-------------+ | |. 141 /a> | +-----------------+ |. 142 /a> +------------------------------------+. 143 /a>. 144 /a> +------+. 145 /a> |reader| RING BUFFER. 146 /a> |page |-------------------+. 147 /a> +------+ <---------------+ v. 148 /a> | ^ +---+ +---+ +---+. 149 /a> | | | |-->| |-->| |. 150 /a> | | | | | |<--| |<-+. 151 /a> | | +---+ +---+ +---+ |. 152 /a> | | | ^ | |. 153 /a> | | +-------------+ | |. 154 /a> | +-----------------------------+ |. 155 /a> +------------------------------------+. 156 /a>. 157 /a> +------+. 158 /a> |buffer| RING BUFFER. 159 /a> |page |-------------------+. 160 /a> +------+ <---------------+ v. 161 /a> | ^ +---+ +---+ +---+. 162 /a> | | | | | |-->| |. 163 /a> | | New | | | |<--| |<-+. 164 /a> | | Reader +---+ +---+ +---+ |. 165 /a> | | page ----^ | |. 166 /a> | | | |. 167 /a> | +-----------------------------+ |. 168 /a> +------------------------------------+. 169 /a>. 177. 171. 172 /a>Ittis possible that the page swappedtis the commit page and the tail page,. 173 /a>if what is in the ring buffer is less than what is held ip a buffer page.. 174. 175 /a>. 176 /a> reader page commit page tail page. 177 /a> | | |. 178 /a> v | |. 179 /a> +---+ | |. 180 /a> | |<----------+ |. 181 /a> | |<------------------------+. 182 /a> | |------+. 183 /a> +---+ |. 184 /a> |. 185 /a> v. 186 /a> +---+ +---+ +---+ +---+. 187 /a><---| |--->| |--->| |--->| |--->. 188 /a>--->| |<---| |<---| |<---| |<---. 189 /a> +---+ +---+ +---+ +---+. 197. 191 /a>This case is still valid fortthis algorithm.. 192When the writer leaves the page, ittsimply goes intotthe ring buffer. 193 /a>sincetthe reader page still points totthe next locat/op in the ring. 194 /a>buffer.. 195 /a>. 196 /a>. 197 /a>The main pointers:. 198 /a>. 199 /a> reader page - The page used solely bytthe reader and is not part. 200 /a> of the ring buffer (may be swappedtin). 201. 202 /a> head page -tthe next page iptthe ring buffer that will be swapped. 203 /a> withtthe reader page.. 204. 205 /a> tail page -tthe page where the next write will take place.. 206 /a>. 207 /a> commit page -tthe page that last finished a write.. 208 /a>. 209 /a>The commit page only is updated bytthe outermost writer in the. 2.7writer stack. A writer that preemptstanother writer will not move the. 211commit page.. 212. 213 /a>When data is written iptotthe ring buffer,ta posit/op is reserved. 214 /a>iptthe ring buffer and passed back totthe writer. When the writer. 215 /a>is finished writing data iptotthat posit/op, ittcommits the write.. 216 /a>. 217 /a>Another write (orta read) may take place attanytimv during this. 218 /a>transac 219 /a>withtthe previous write.. 227. 221. 222 /a> Write reserve:. 223 /a>. 224 /a> Buffer page. 225 /a> +---------+. 226 /a> |written |. 227 /a> +---------+ <--- given back totwriter (currenttcommit). 228 /a> |reserved |. 229 /a> +---------+ <--- tail pointer. 230 /a> | empty |. 231 /a> +---------+. 232. 233 /a> Write commit:. 234. 235 /a> Buffer page. 236 /a> +---------+. 237 /a> |written |. 238 /a> +---------+. 239 /a> |written |. 240 /a> +---------+ <--- next posit/op fortwrite (currenttcommit). 241 /a> | empty |. 242 /a> +---------+. 243 /a>. 244. 245 /a> Ifta write happenstafter the first reserve:. 246 /a>. 247 /a> Buffer page. 248 /a> +---------+. 249 /a> |written |. 250 /a> +---------+ <-- currenttcommit. 251 /a> |reserved |. 252 /a> +---------+ <--- given back totsecond writer. 253 /a> |reserved |. 254 /a> +---------+ <--- tail pointer. 255 /a>. 256 /a> After second writertcommits:. 257 /a>. 258 /a>. 259 /a> Buffer page. 260 /a> +---------+. 261 /a> |written |. 262 /a> +---------+ <--(last fulltcommit). 263 /a> |reserved |. 264 /a> +---------+. 265 /a> |pending |. 266 /a> |commit |. 267 /a> +---------+ <--- tail pointer. 268 /a>. 269 /a> When the first writertcommits:. 277. 271 /a> Buffer page. 272 /a> +---------+. 273 /a> |written |. 274 /a> +---------+. 275 /a> |written |. 276 /a> +---------+. 277 /a> |written |. 278 /a> +---------+ <--(last fulltcommit and tail pointer). 279 /a>. 287. 281 /a>The commit pointer points totthe last write locat/op that was. 282 /a>committed without preempting another write. When a write that. 283preempted another write is committed, ittonly becomes a pending commit. 284 /a>and will not be a fulltcommit until alltwrites have been committed.. 285 /a>. 286 /a>The commit page points totthe page that has the last fulltcommit.. 287 /a>The tail page points totthe page withtthe last write (before. 288 /a>committing).. 289 /a>. 297The tail page is always equal totortafter the commit page. It may. 291 /a>be several pages ahead. Iftthe tail page catches up to the commit. 292page then no more writes may take place (regardless of the mode. 293 /a>of the ring buffer: overwrite and produce/consumer).. 294. 295 /a>The order of pages is:. 296 /a>. 297 /a> head page. 298 /a> commit page. 299 /a> tail page. 307. 301Possible scenario:. 302 /a> tail page. 303 /a> head page commit page |. 304 /a> | | |. 305 /a> v v v. 306 /a> +---+ +---+ +---+ +---+. 307 /a><---| |--->| |--->| |--->| |--->. 308 /a>--->| |<---| |<---| |<---| |<---. 309 /a> +---+ +---+ +---+ +---+. 3.7. 311 /a>There is a special case that the head page istafter either the commit page. 312and possiblytthe tail page. That is when the commit (and tail) page has been. 313 /a>swappedtwithtthe reader page. This is because the head page istalways. 314 /a>part of the ring buffer, buttthe reader page istnot. Whenevertthere. 315 /a>has been less than a fulltpage that has been committed inside the ring buffer,. 316 /a>and a reader swaps outta page, ittwill be swapping outtthe commit page.. 317 /a>. 318 /a>. 319 /a> reader page commit page tail page. 320 /a> | | |. 321 /a> v | |. 322 /a> +---+ | |. 323 /a> | |<----------+ |. 324 /a> | |<------------------------+. 325 /a> | |------+. 326 /a> +---+ |. 327 /a> |. 328 /a> v. 329 /a> +---+ +---+ +---+ +---+. 330 /a><---| |--->| |--->| |--->| |--->. 331 /a>--->| |<---| |<---| |<---| |<---. 332 /a> +---+ +---+ +---+ +---+. 333 /a> ^. 334 /a> |. 335 /a> head page. 336 /a>. 337 /a>. 338 /a>Intthis case, the head page will not move when the tail and commit. 339 /a>move back iptotthe ring buffer.. 347. 341 /a>The reader cannot swap a page iptotthe ring buffer if the commit page. 342 /a>is still op that page. Iftthe read meets the last commit (real commit. 343 /a>not pending or reserved), then there is nothing more to read.. 344The buffer is considered empty until another fulltcommit finishes.. 345 /a>. 346 /a>When the tail meets the head page, if the buffer is in overwrite mode,. 347 /a>the head page will be pushed ahead one. Iftthe buffer is in producer/consumer. 348 /a>mode, the write will fail.. 349 /a>. 350 /a>Overwrite mode:. 351. 352 /a> tail page. 353 /a> |. 354 /a> v. 355 /a> +---+ +---+ +---+ +---+. 356 /a><---| |--->| |--->| |--->| |--->. 357 /a>--->| |<---| |<---| |<---| |<---. 358 /a> +---+ +---+ +---+ +---+. 359 /a> ^. 360 /a> |. 361 /a> head page. 362. 363 /a>. 364 /a> tail page. 365 /a> |. 366 /a> v. 367 /a> +---+ +---+ +---+ +---+. 368 /a><---| |--->| |--->| |--->| |--->. 369 /a>--->| |<---| |<---| |<---| |<---. 370 /a> +---+ +---+ +---+ +---+. 371 /a> ^. 372 /a> |. 373 /a> head page. 374. 375 /a>. 376 /a> tail page. 377 /a> |. 378 /a> v. 379 /a> +---+ +---+ +---+ +---+. 380 /a><---| |--->| |--->| |--->| |--->. 381 /a>--->| |<---| |<---| |<---| |<---. 382 /a> +---+ +---+ +---+ +---+. 383 /a> ^. 384 /a> |. 385 /a> head page. 386 /a>. 387 /a>Note, the reader page will still point totthe previous head page.. 388 /a>But when a swap takes place, ittwill use the most recent head page.. 389 /a>. 397. 391 /a>Making the Ring Buffer Lockless:. 392--------------------------------. 393 /a>. 394The main idea behind the lockless algorithmtis totcombine the moving. 395 /a>of the head_page pointer withtthe swapping of pages withtthe reader.. 396 /a>Sta 397 /a>each page must be aligned in memory byt4 bytes. This will allowtthe 2. 398 /a>least significant bits of the address to be used as flags, since. 399 /a>they will always be zero fortthe address. To gettthe address,. 407simply mask outtthe flags.. 401. 402 /a> MASK = ~3. 403 /a>. 404 /a> address & MASK. 405 /a>. 406 /a>Two flags will be kept bytthese two bits:. 407 /a>. 408 /a> HEADER -tthe page being pointed to is a head page. 409 /a>. 410 /a> UPDATE -tthe page being pointed to is being updated byta writer. 411 /a> and was or is abouttto be a head page.. 412. 413 /a>. 414 /a> reader page. 415 /a> |. 416 /a> v. 417 /a> +---+. 418 /a> | |------+. 419 /a> +---+ |. 420 /a> |. 421 /a> v. 422 /a> +---+ +---+ +---+ +---+. 423 /a><---| |--->| |-H->| |--->| |--->. 424 /a>--->| |<---| |<---| |<---| |<---. 425 /a> +---+ +---+ +---+ +---+. 426 /a>. 427 /a>. 428 /a>The above pointer "-H->" would have the HEADER flag set. That is. 429 /a>the next page istthe next page to be swappedtouttbytthe reader.. 437Thistpointer meanstthe next page is the head page.. 431. 432When the tail page meets the head pointer, ittwill use cmpxchg to. 433 /a>change the pointer totthe UPDATE sta 434. 435 /a>. 436 /a> tail page. 437 /a> |. 438 /a> v. 439 /a> +---+ +---+ +---+ +---+. 440 /a><---| |--->| |-H->| |--->| |--->. 441 /a>--->| |<---| |<---| |<---| |<---. 442 /a> +---+ +---+ +---+ +---+. 443 /a>. 444 /a> tail page. 445 /a> |. 446 /a> v. 447 /a> +---+ +---+ +---+ +---+. 448 /a><---| |--->| |-U->| |--->| |--->. 449 /a>--->| |<---| |<---| |<---| |<---. 450 /a> +---+ +---+ +---+ +---+. 451. 452 /a>"-U->" represents a pointer iptthe UPDATE sta 453 /a>. 454 /a>Any access to the reader will need to take some sort of lock totserialize. 455 /a>the readers. Buttthe writers will never take a lock totwrite to the. 456 /a>ring buffer. This meanstwetonly need to worry aboutta single reader,. 457 /a>and writestonly preempt ipt"stack" forma 458 /a>. 459 /a>When the reader tries to swap the page withtthe ring buffer, it. 460 /a>will also use cmpxchg. Iftthe flag bit iptthe pointer totthe. 461 /a>head page does not have the HEADER flag set, the compare will fail. 462and the reader will need to look fortthe new head page and try agaip.. 463 /a>Note, the flags UPDATE and HEADER are never set at the samv time.. 464. 465 /a>The reader swaps the reader page as follows:. 466 /a>. 467 /a> +------+. 468 /a> |reader| RING BUFFER. 469 /a> |page |. 470 /a> +------+. 471 /a> +---+ +---+ +---+. 472 /a> | |--->| |--->| |. 473 /a> | |<---| |<---| |. 474 /a> +---+ +---+ +---+. 475 /a> ^ | ^ |. 476 /a> | +---------------+ |. 477 /a> +-----H-------------+. 478 /a>. 479 /a>The reader sets the reader page next pointer as HEADER totthe page after. 480 /a>the head page.. 481. 482. 483 /a> +------+. 484 /a> |reader| RING BUFFER. 485 /a> |page |-------H-----------+. 486 /a> +------+ v. 487 /a> | +---+ +---+ +---+. 488 /a> | | |--->| |--->| |. 489 /a> | | |<---| |<---| |<-+. 490 /a> | +---+ +---+ +---+ |. 491 /a> | ^ | ^ | |. 492 /a> | | +---------------+ | |. 493 /a> | +-----H-------------+ |. 494 /a> +--------------------------------------+. 495 /a>. 496 /a>It does a cmpxchg withtthe pointer totthe previous head page totmake it. 497 /a>point totthe reader page. Note that the new pointer does not have the HEADER. 498 /a>flag set. This ac 499 /a>. 500 /a> +------+. 501 /a> |reader| RING BUFFER. 502 /a> |page |-------H-----------+. 503 /a> +------+ v. 504 /a> | ^ +---+ +---+ +---+. 505 /a> | | | |-->| |-->| |. 506 /a> | | | |<--| |<--| |<-+. 507 /a> | | +---+ +---+ +---+ |. 508 /a> | | | ^ | |. 509 /a> | | +-------------+ | |. 510 /a> | +-----------------------------+ |. 511 /a> +------------------------------------+. 512. 513 /a>After the new head page is set, the previous pointer of the head page is. 514 /a>updated totthe reader page.. 515 /a>. 516 /a> +------+. 517 /a> |reader| RING BUFFER. 518 /a> |page |-------H-----------+. 519 /a> +------+ <---------------+ v. 520 /a> | ^ +---+ +---+ +---+. 521 /a> | | | |-->| |-->| |. 522 /a> | | | | | |<--| |<-+. 523 /a> | | +---+ +---+ +---+ |. 524 /a> | | | ^ | |. 525 /a> | | +-------------+ | |. 526 /a> | +-----------------------------+ |. 527 /a> +------------------------------------+. 528 /a>. 529 /a> +------+. 530 /a> |buffer| RING BUFFER. 531 /a> |page |-------H-----------+ <--- New head page. 532 /a> +------+ <---------------+ v. 533 /a> | ^ +---+ +---+ +---+. 534 /a> | | | | | |-->| |. 535 /a> | | New | | | |<--| |<-+. 536 /a> | | Reader +---+ +---+ +---+ |. 537 /a> | | page ----^ | |. 538 /a> | | | |. 539 /a> | +-----------------------------+ |. 540 /a> +------------------------------------+. 541. 542 /a>Another important point: The page that the reader page points back to. 543 /a>by its previous pointer (the one that now points totthe new head page). 544 /a>never points back totthe reader page. That is because the reader page is. 545 /a>not part of the ring buffer. Traversingtthe ring buffer viatthe next pointers. 546 /a>will always stay iptthe ring buffer. Traversingtthe ring buffer viatthe. 547 /a>prev pointers may not.. 548 /a>. 549 /a>Note, the way totdetermine a reader page is simply by examiningtthe previous. 550 /a>pointer of the page. Iftthe next pointer of the previous page does not. 551point back totthe original page, then the original page is a reader page:. 552. 553 /a>. 554 /a> +--------+. 555 /a> | reader | next +----+. 556 /a> | page |-------->| |<====== (buffer page). 557 /a> +--------+ +----+. 558 /a> | | ^. 559 /a> | v | next. 560 /a> prev | +----+. 561 /a> +------------->| |. 562 /a> +----+. 563 /a>. 564The way the head page moves forward:. 565 /a>. 566 /a>When the tail page meets the head page and the buffer is in overwrite mode. 567 /a>and more writesttake place, the head page must be moved forward before the. 568 /a>writer may move the tail page. The way this is done is thattthe writer. 569 /a>performs a cmpxchg totconverttthe pointer totthe head page from the HEADER. 570 /a>flag tothave the UPDATE flag set. Once this is done, the reader will. 571 /a>not be able to swap the head page from the buffer, nor will it be able to. 572 /a>move the head page, until the writer is finished withtthe move.. 573 /a>. 574This eliminatestany races thattthe reader canthave on the writer. The reader. 575 /a>must spin, and this is whytthe reader cannot preempt the writer.. 576 /a>. 577 /a> tail page. 578 /a> |. 579 /a> v. 580 /a> +---+ +---+ +---+ +---+. 581<---| |--->| |-H->| |--->| |--->. 582--->| |<---| |<---| |<---| |<---. 583 /a> +---+ +---+ +---+ +---+. 584. 585 /a> tail page. 586 /a> |. 587 /a> v. 588 /a> +---+ +---+ +---+ +---+. 589 /a><---| |--->| |-U->| |--->| |--->. 590 /a>--->| |<---| |<---| |<---| |<---. 591 /a> +---+ +---+ +---+ +---+. 592. 593 /a>The followingtpage will be made intotthe new head page.. 594. 595 /a> tail page. 596 /a> |. 597 /a> v. 598 /a> +---+ +---+ +---+ +---+. 599 /a><---| |--->| |-U->| |-H->| |--->. 600 /a>--->| |<---| |<---| |<---| |<---. 601 /a> +---+ +---+ +---+ +---+. 602. 603 /a>After the new head page has been set, be cantsalL583" class=g thee. 564 /a>6 | totthe tthe oriNORMALef="Documenta 565 /a>6 566 /a>60 |. 567 /a>60 |. 568 /a>60 v. 569 /a>60 +---+ +---+ +---+ +---+. 560 /a>61t;---| |--->| |--->| |--->| |--->. 561 /a>61->| |<---| |<---| |<---| |<---. 56261 +---+ +---+ +---+ +---+. 563 /a>6 564 /a>6pdatedhe new heage has been set, beorwar,il page meets th. 565 /a>6 566 /a>6 v. 567 /a>6 +---+.< |. 568 /a>6 | |-- v. 569 /a>61 +---+ +---+ +---+ +---+. 560 /a>62t;---| |--->| |--->| |--->| |--->. 561 /a>62->| |<---| |<---| |<---| |<---. 562 /a>6 +---+ +---+ +---+ +---+. 563 /a>62a href="Documenta 564 /a>62a href="Documenta 565 /a>62e reader ointerarail pagriviald byta sthatwe new heaitest willex scenarioref="Documenta 566 /a>6 567 /a>6 568 /a>6 569 /a>6he nexte meets th. 560 /a>6 |buffhe wayAts whyta hrntsalin, antthe drof pagetake pl(usuves te movrt ofkindf="Documenta 561 /a>6 |pageoftdere prevew heauser)he wriw reahuttbns if ass= wimre is astmadewriterf="Documenta 562 /a>6 +----page:. 563 /a>6 | in, aaccoubte new hiref="Documenta 564 /a>6 565 /a>6 566 /a>6 tail page is simpppp wimre a rf="Documenta 567 /a>6 |. 568 /a>6 v. 569 /a>63 +---+ |. 560 /a>64 t;---. 56164 +--a href="Documenta 562 /a>64 ->. 563 /a>64 | |. 564 /a>6 tail pa | +-----f="Documenta 565 /a>6 |. 566 /a>6 +---+ +---+ +---+. 567 /a>6rev po| |--->| |-H->| |--->| |--->. 568 /a>6 569 /a>64 +---+ +---+ +---+ +---+. 560 /a>65 ef="Documenta 56165 +-----f="Documenta 56265 ge meets f="Documenta 563 /a>6 564 /a>6 next pote meets twerap they exampushad page forward.. 565 /a>6 leav ring bufage is simpave thable to tott prevew heacorrect 566 /a>65a href="Documenta 567 /a>6 i pasoluace/evew hhytthevew e, aif ass= wimre a readeonng bufage is simf="Documenta 568 /a>6 the. 569 /a>65e nexte meets twruttbytfer, nor wiltestoalin, adrofad patake pef="Documenta 560 /a>6 f="Documenta 561 /a>6 Thhyttheableathattttthdiace/,e the reader wimre a reL583eemptd forwarf="Documenta 562 /a>6 reader.ou a rostttake one thatake one reais a the wred)ef="Documenta 563 /a>663 Thhythe next at ass= wimre id to blee taiwhilder is finishee t ring bf="Documenta 5646he wayge. The way thicannot preempte head papage is simplexhe psse cmpbeferf="Documenta 565 /a>6 566 /a>6hen thadeoffader page. That isis is dr wimre a releaveeader page next pf="Documenta 567 /a>6nd morre id to ints go tthe orihe unlthe r page:. 568 /a>6riter page). 569 /a>66a href="Documenta 560 /a>67 f="Documenta 561 /a>6ot be Ne, estonly pf="Documenta 562 /a>67->| f="Documenta 563 /a>6 5646his elIointer ush rin before oext pote meets twelin, afirsttpusha beforef="Documenta 565 /a>67e readersge is. 566 /a>67en thadeemptt pointer tth,il page meets tly by exam totthe e movhg totconaf="Documenta 567 /a>67a href="Documenta 568 /a>6 Oempt will nee tail page. The way tsheemoved f thatlly moves tvewprotectf="Documenta 569 /a>6 560 /a>68 f="Documenta 56168 te w_ets t=age. _ href="Documenta 56268 inte_ets t=age w_ets |&l href="Documenta 563 /a>6 +---+ totcon(ge. _ hre,age w_ets , inte_ets ef="Documenta 5646 565 /a>68e reader ointerid to totthil page meets tlexhe pssstmade tott prevew heaexpectarf="Documenta 566 /a>6 tthe next shede msthaene, estonly tpushestitd.. 567 /a>6 t have th look fopushairef="Documenta 568 /a>68a href="Documenta 569 /a>68a href="Documenta 560 /a>69 ge wa href="Documenta 561 /a>69 +-----f="Documenta 56269 vf="Documenta 563 /a>69 |ge meets f="Documenta 56469 tail pa -f="Documenta 565 /a>6 tail pa vf="Documenta 566 /a>69 +---+ +---+ +---+. 567 /a>69ev po| |--->| |-H->| |-H->| |-H->| |-Hf="Documenta 568 /a>69a hre| |<---| |<---| |<---| |<---. 569 /a>69 +---+ +---+ +---+ +---+. 670 /a>70 f="Documenta 671 /a>70t be Ne, estonly wieerwrie writveeader ge meets t:. 6727 673 /a>70 | |&l |ge meets (orwardbyene, estonly ref="Documenta 574 /a>70 tail page wa hre -f="Documenta 575 /a>70 tail pa |-f="Documenta 576 /a>70 |.< vl pa vf="Documenta 577 /a>707 +---+ +---+ +---+ +---+. 578 /a>70 | |--->| |-H->| |-H->| |-H->| |-Hf="Documenta 579 /a>70 +--| |<---| |<---| |<---| |<---. 570 /a>71 +---+ +---+ +---+ +---+. 571 /a>71a href="Documenta 57271 +--der ointerive thde m=der totcon, but sis is dr ge meets n sealpageyf="Documenta 573 /a>7 574 /a>7pdatedonng bud page. The waf="Documenta 575 /a>7 576 /a>7 wrie.. 577 /a>71a href="Documenta 578 /a>7 | |-ge meets f="Documenta 579 /a>71 v. 570 /a>72 vf="Documenta 571 /a>72 +---+ +---+ +---+ +---+. 572 /a>7 +--| |--->| |-H->| |--->| |--->. 573 /a>72a hre| |<---| |<---| |<---| |<---. 574 /a>724 +---+ +---+ +---+ +---+. 575 /a>72a href="Documenta 576 /a>7 577 /a>7 578 /a>72 | |-ge meets f="Documenta 579 /a>72 v. 570 /a>73 vf="Documenta 571 /a>73 +---+ +---+ +---+ +---+. 572 /a>73 +--| |--->| |-H->| |--->| |--->. 573 /a>73a hre| |<---| |<---| |<---| |<---. 574 /a>734 +---+ +---+ +---+ +---+. 575 /a>7 576 /a>73 wriifhaene, estonly ra the wrsage72 +--e6l7ne" namvata 566 /a>6 v. |.73 +-3,727ss="line" namvalL598"> 568 /a>69a hre| I v. |.73 +s f="Docu--f="Documenta |.73 +Documenta--f="Documenta |.73 . 577 /a>7 542 /a>Another important point:7. 56 v. 577 /a>7 5646his elIointer ush rin b7 +-----f=7Documenta 579 /a>72 v. 570 /a>73 vf=-+ +--7+. 570 /a>73 vf=--3,727ss=|--->| |--->. 578 /a>70 | |--->| |-lt;---| 7|<---| |<---. 600 /a>--->| |<---| |7-+ +--7+. 570 /a>71 +---+ +---+ +--"Document7 571 /a>71a href="Documenta 542 /a>Another important point:7s f="Docu7enta 569 /a>performs a cmpxchg totco7race/ring7buffer-design.txt#L554" 7d6lL574" cl6-. 569 /a>performs a cmpxchg totco7r+-----f=7exampushad page forward.7 565 /a>6 576 /a>73 wriifhaene, estonrace/ring7buffer-design.txt#L427" 7d6lL57 579 /a>72 v. 570 /a>73 vf=uge.. 570 /a>73 vf=fer, nor 7iltestoalin, adrofad pat7ke pe75ing-buffer-design.txt#L440" id7lL600" cl7ss="line" namvalL600"> 670 /a>70 f="Documenta 600 /a>--->| |<---| |7ttthdiace7,e the reader wimre a 7eL58376cumenta 562 /a>6 +---+ +---+ +-7ake one t7atake one reais a the wr7d)ef=76ing-buffer-design.txt#L423" id6lL523" cl6ss="line" namvalL523"> 563 /a>62a href="Documenta 564The way the head page mo7not preem7te head papage is simple7he ps76tai.. 56txt#L57fer-dep/trace/ring-buffering-/op/trass="line" namvalL564"> 564The way the head page mo7n simpave7icannot prehey examchehe7o at 76a href="D27" cl 497" id7lL505" cl6ss="line" namvalL505"> 565 /a>6 567 /a>6 i pasoluace/evew 7the orihe7unlthe r page:. 578 /a>72 | |-ge meesse cmpde7 wimre a raf="Document7 579 /a>72 v. 570 /a>73 vf=race/ring7buffer-design.txt#L594" 7d6lL577t#L436" id7lL521" clxt36" id7lss="line" namvalL530"> 570 /a>73 vf=cumenta 572 /a>73 +--| |--->| |-cumenta 561 /a>62->| |<---| |7race/ring7buffer-design.txt#L574" 7d6lL577cumenta 574 /a>734 +---+ +---+ +--fore oext7pote meets twelin, afirs7tpush77ing-buffer-design.txt#L602" id7lL535" cl7ss="line" namvalL535"> 575 /a>7 576 /a>73 wriifhaene, estonth,il pag7 meets tly by exam totth7 e mo77" class="line" namvalL577"> 577 /a> tail page. s.txmeuffer-design6ss="line" namvalL586"> 566 /a>6 tthe next shede 7l page. T7e way tsheemoved f thatl7y mov7s tvewn.txt#L542" idasign.socumalD2" is7ss="line" namvalL602"> 6727 560 /a>69 ge wa 7race/ring7buffer-design.txt#L594" 7d6lL571" cl6ss="line" namvalL581"> 56168 te w_ets t=age.7_ href="D7cumenta 574 /a>70 tail page wa _ets |&7 href="Documenta 673 /a>70 | |&le,age w_e7s , inte_ets ef="Documen7a 56469 tail pa -f7race/ring7buffer-design.txt#L585" 7d6lL578t#L436" id6lL585" cl6ss="line" namvalL595"> 565 /a>6 tail pa vf7tthil pag7 meets tlexhe pssstmade 7ott p7ign.txt#L586" idalid7lss="line" namvalL530"> 570 /a>73 vf=sthaene, 7stonly tpushestitd.. 567 /a>69ev po| |--->| |7ushairef=7Documenta 568 /a>6 569 /a>69 +---+ +---+ +-7race/ring7buffer-design.txt#L500" 7d6lL578ing-buffer-design.txt#L440" id7lL600" cl7ss="line" namvalL600"> 670 /a>70 f="Documenta 56168 te w_ets t=age.7"Document7 577 /a>7 593 /a>The followingtpage will 7ts f="Doc7menta 56469 tail pa -f7"Document7 565 /a>6 tail pa vf7"Document7 566 /a>69 +---+ +-7-+ +--7+. 567 /a>69ev po| |--->| |7H->| 7|-H->| |-H->| 7-Hf="7ocumenta 573 /a>73a hre| |<---| |<---| 7|<---| |<---. 569 /a>69 +---+ +---+ +-7-+ +--7+. 670 /a>70 f="Documenta 671 /a>70t be Ne, estonly wie8rwrie wri8veeader ge meets t:. 671 /a>70t be Ne, estonly wie8r2rie wri8v/op/trace/ring-buffer-d8d7lL683" cl7lL594" class="line" namvalL594"> 594. 564The way the head page mo8hre -f=8Documenta 574 /a>70 tail page wa8 |-f=8Documenta 566 /a>60 |. 567 /a>60 |. 568 /a>60 v. 569 /a>60 +---+ +---+ +-8lt;---| 8|<---| |<---. 560 /a>61t;---| |--->| |8-+ +--8+. 600 /a>--->| |<---| |8race/ring8buffer-design.txt#L542" 8d7lL58ocumenta 56261 +---+ +---+ +-8 m=der t8tcon, but sis is dr ge m8ets 8ring-buffer-design.txt#L443" id6lL513" cl6ss="line" namvalL513"> 563 /a>6 564 /a>6pdatedhe new heage has 8 waf="Doc8menta 56sign.txt#L565" id7lL602" cl/tracen.txt#L54t#L532" id6ss="line" namvalL514"> 564 /a>6pdatedhe new heage has 8 |-f=8buffer-design.txt#L516" 8d7lL586" cl7cumentafer-deL505" clring-buff /f="Docu/trace/ring-buffass="line" namvalL594"> 594. 577 /a> tail page. 567 /a>60 |. 568 /a>60 v. 569 /a>60 +---+ +---+ +-8"Document8 571 /a>71a href="Documenta 600 /a>--->| |<---| |8H->| 8|--->| |--->. 583 /a> +---+ +---+ +-8lt;---| 8|<---| |<---. 584. 565 /a>62e reader ointerarail p8race/ring8buffer-design.txt#L516" 8d7lL586" cl7A#L594" 16"> 566 /a>6 sign hrsnta 594. 594. 578 /a>72 | |-ge me8ts f="Doc8menta 574 /a>70 tail page wa8"Document8 560 /a>69 ge wa 8"Document8 567 /a>60 |. 568 /a>60 v. 569 /a>60 +---+ +---+ +-8lt;---| 8|<---| |<---. 584. 584. 583 /a> +---+ +---+ +-8ly ra the8wrsage78 +--83ing-buffer-design.txt#L423" id6lL597" cl6ss="line" namvalL597"> 567 /a>69ev po| |--->| |8+-3,727ss8"line" namvalL598"> 568 8a>69a83" cl7ss="line" namvalL528"> 578 /a>72 | |-ge me8+s f="Doc8--f="Documenta 6727 560 /a>69 ge wa 8. 671 /a>70t be Ne, estonly wie8f="Docume8ta 574 /a>70 tail page wa8. 593 /a>The followingtpage will 8ft;---| 8Documenta 567 /a>60 |. 565 /a>6 |. 566 /a>6 +---+ +-8-+ +--8+. 567 /a>6rev po| |--->| |8--3,727ss8|--->| |--->. 584. 569 /a>64 +---+ +---+ +-8-+ +--8+. 560 /a>65 ef8"Document8 671 /a>70t be Ne, estonly wie8"Document8 566 /a>6hen thadeoffader page. 8s f="Docu8enta 6727 564 /a>6 next pote meets t8r+-----f=8exampushad page forward.8 565 /a>62e reader ointerarail p8s simpave8thable to tott prevew he8corre85" cl7(thir/6lL529l7ss="line" namvalL504"> 574 /a>70 tail page wa8race/ring8buffer-design.txt#L427" 8d6lL587" cl6ss="line" namvalL557"> 567 /a>6 i pasoluace/evew 8hytthevew8e, aif ass= wimre a rea8eonng8e/ring-buffer-desigt#L436"L507" cl6ss="line" namvalL507"> 567 /a>60 |. 565 /a>6 |. 569 /a>60 +---+ +---+ +-8race/ring8buffer-design.txt#L594" 8d6lL586ing-buffer-design.txt#L581" id7lL511" cl7ss="line" namvalL511"> 571 /a>71a href="Documenta 571 /a>71a href="Documenta 583 /a> +---+ +---+ +-8s= wimre 8d to blee taiwhilder is 8inish86ing-buffer-design.txt#L584" idalL584" class="line" namvalL584"> 584. 565 /a>62e reader ointerarail p8n simpave8icannot prehey examchehe8o at 86" cl6ss="line" namvalL506"> 566 /a>60 |. 594. 578 /a>72 | |-ge me8sse cmpde8 wimre a raf="Document8 569 /a>68a href="Documenta 574 /a>70 tail page wa8race/ring8buffer-design.txt#L594" 8d6lL581" cl6ss="line" namvalL571"> 561 /a>6ot be Ne, estonly pf="D8cumenta 567 /a>60 |. 565 /a>6 |. 569 /a>60 +---+ +---+ +-8fore oext8pote meets twelin, afirs8tpush87ing-buffer-design.txt#L602" id7lL535" cl7ss="line" namvalL535"> 575 /a>7 571 /a>71a href="Documenta 583 /a> +---+ +---+ +-8race/ring8buffer-design.txt#L428" 8d6lL587ing-buffer-design.txt#L440" id7l8507" cl7ss="line" namvalL598"> 578 /a>70 | |--->| |8l page. T8e way tsheemoved f thatl8y mov87" cl6ss="line" namvalL589"> 569 /a>68a href="Documenta 560 /a>69 ge wa 8race/ring8buffer-design.txt#L594" 8d6lL581" cl6T 573 /a>7 575 /a>7 575 /a>7 564 /a>6 next pote meets t8race/ring8buffer-design.txt#L585" 8d6lL585" cl6ss="line" namvalL585"> 565 /a>68e reader ointerid to t8tthil pag8 meets tlexhe pssstmade 8ott p8ign.tx(8" id6lL529l7ss="line" namvalL504"> 574 /a>70 tail page wa8sthaene, 8stonly tpushestitd.. 567 /a>6 i pasoluace/evew 8ushairef=8Documenta 56988a>6 |. 67089a>60 +---+ +---+ +-8race/ring8buffer-design.txt#L594" 8d6lL586ing-buffer-design.txt#L581"f7r-des798 cl6ss="line" namvalL5818> 56189a>71a href="Documenta 57789a>71a href="Documenta 59389a> +---+ +---+ +-8s= wimre 8d to blee taiwhilder is 8inish86ing-buffer-design.txt#L584" id6lL5948 cl6ss="line" namvalL5948> 56489a>6 next pote meets t8race/ring8buffer-design.txt#L585" id6lL5858 cl6ss="line" namvalL5958> 56589a>68e reareader ointennot prekNe, thatlly movire oext pote mee cl6In.txt#L42evs f="t#L401" id6if socumalD/op/tr516"> s.tx8 id6lL5868 cl6ss="line" namvalL5968> 5668/a>69 taiwh oritedhesce/ring-bu ttward.. s.tx8 8, ass88" cl6ss="line" namvalL5978> 5678/a>69ew |. 566 /a>6 sign hrsnta 57389a>70 | |--->| |8l page. T8e way tsheemoved f that id6lL5998 cl6ss="line" namvalL5998> 56989a>68a href="Documenta 6709/a>70 reader ointerid to t8tthil pag8 meets tlexhe pssstmade 8ott p8ign.t9 8d7lL6819 cl7ss="line" namvalL6019> 67190a>71a href="Documenta 67190a>60 |. 5949/a>70 | |f8ugmenta 5649/a>70 tai|. 5749/a>70 -+ +---+ +-8s= wimre 8d to blee taiwhilder is 8inish86ing-buffer-design.txt#L5849g8buffe869 cl6ss="line" namvalL5069> 5669/a>60 href="Documenta 5679/a>60 href="Documenta 5689/a>60 -+ +---+ +-8s= wimre 8d to blee taiwhilder is 8inish86ing-buffer-design.txt#L5849g9d6lL5089 cl6ss="line" namvalL5999> 56990a>68a href="Documenta 5609/a>61tSut sis isder toDocumens14ealpag valueh prehea/op/tracereareader ointe href="Documenta 6009/a>--- ie id to. 566 /a>6 sign hrsnta 56291a>Anotherasets d t,e nextuffer-dgood enough ttwatshee="linche relead t16"> 566 /a>6 sign hrsnta 5639/a>6 56491a>6 next pote meets t8race/ring8buffer-design.txt#L5859L54t#L5329 id6ss="line" namvalL5149> 5649/a>7 5949/a>. 5779/a>71a href="Documenta 5679/a>60 |. 5689/a>71 v. 5699/a>72 nta 5719/a>72 +---+ +---+ +---+ +---+. 6009/a>7 +--| |--->| |-H-& +--8+. 5839/a>72a hre| |<---| |<---| |<---| |<---. 5849/a>724 +---+ +---+ +---+ +---+. 5659/a>72a href="Documenta 5949/a>. 5949/a>. |. 5789/a>72 ointes means14e |. 5749/a>70 tail page wa8"Document8 56093a>70 tail page wa8race/ring8buffer-design.txt#L5949lL518L5079 cl6ss="line" namvalL5079> 56793a>68 te w_ets t=age.7_ href="D7cumenta 56893a>70 tail page wa8. 56993a>70 A |. 58493a>69 tail pa v. 58493a>6 tail pa nta 5839/a> +---+ +---+ +-8ly ra the8wrsage78 +--83ing-buffer-design.txt#L4239 id6lL5979 cl6ss="line" namvalL5979> 56793a>69ev po| |--->| |7H->| 7|-H->| |-H-&mre a 8eL58386cumenta69a839 cl7ss="line" namvalL5289> 57893a>. 67293a>64 +---+ +---+ +-8-+ +--8+. 5609/a>69 ge wa 8. 6719/a>70tNe, eser ointennot d to totthif="Doc8--ata 5749/a>70 remhrefrefign.85"="D8og-buoint:7bydesign.txt#L516" 8d7lLta 59394a>perfoe l6Tl7A#L594" 16"> 566 /a>6 sign hrsnta 56794a>6 next pote meets t8race/ring8buffer-design.txt#L5859 id6lL5459 cl6ss="line" namvalL5459> 56594a>72a href="Documenta 56694a>. 56794a>71a href="Documenta 58494a>60 |. 56994a>71 v. 56095a>72 nta 67195a>72 +---+ +---+ +---+ +---+. 56695a>73 +--| |--->| |-cumenta 67295a>72a hre| |<---| |<---| |<---| |<---. 56495a>724 +---+ +---+ +---+ +---+. 5659/a>6 5749/a>70
aLXR community>70 ,e nextexperitalxe@e" ux.no>70 .
lxe.e" ux.no kind-buho new bydhref="Dochttp://www.redpill-e" pro.no">Redpill L" pro AS>70 ,eprovi