On Wed, 21 Jul 2021 10:13:01 +0800 contact me <www@xxxxxxxxxxxxxx> wrote: > I'll have a try and tell you the result. But I've seen the code written on Thanks. > > https://github.com/torvalds/linux/blob/2734d6c1b1a089fb593ef6a23d4b70903526fe0c/kernel/trace/ring_buffer.c#L4513 > cpu_buffer->reader_page->read = 0; Yeah, that clears the "read" for the reader page after it gets swapped out of the writers buffer, and before the reader gets to it. > > I though the algorithm is to reset the reader_page->read when it swaps with the > head page. And following the original algorithm the read field of a buffer page > should be either 0 or its original value when the content to read exhaust. So I > added an extra conditional to ensure that. Actually, we could just change it to ignore read as well, and that could be the fix. Basically, the bug is that we use that "read" field that's in the writer's buffer (the main ring buffer outside the reader page), and it has stale data. So we either need to clear the "read" before placing it back into the writer's buffer (which my patch does). Or we can simply ignore it, which would change your patch to: return reader->read == rb_page_commit(reader) && (commit == reader || (commit == head && - head->read == rb_page_commit(commit))); + (rb_page_commit(commit) == 0))); } In which case, you can send me that patch with the cleanup that Linus suggested, and my commenting. -- Steve