Skip to content

Support physical memory hack ("magic ring buffer") #2

@Quuxplusone

Description

@Quuxplusone

Alex Rosenberg suggests that no "STL ring-buffer" will replace the most efficient real-world ring-buffer unless it supports the following performance hack:

Let's back our particular ring_view by a span of (virtual) memory exactly 2 pages[1] in length. But, in the page table, we map both of these virtual pages to the same 1 page of physical memory. This means that if you manage the head and tail pointers correctly, you can arrange it so that it is always true (in the virtual-memory space) that begin < end, which means that iterating over the ring-buffer from begin to end (or vice versa) never requires a % capacity operation.

Obviously this can't be the default behavior; but ring_view must be generic enough to support this particular idiom, or else nobody who uses this idiom will be able to switch to ring_view, which defeats the whole purpose.

How can we genericize out the % capacity part of this code so that you don't get it when it's not needed?

( [1] Well, I think 2N pages backed by N pages of physical memory would work for any N. But 2-by-1 is the easy-to-visualize case.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions