Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pageserver: implement buffer bypass for aligned parts of the write #10101

Open
Tracked by #8130
yliang412 opened this issue Dec 11, 2024 · 0 comments
Open
Tracked by #8130

pageserver: implement buffer bypass for aligned parts of the write #10101

yliang412 opened this issue Dec 11, 2024 · 0 comments
Labels
c/storage/pageserver Component: storage: pageserver

Comments

@yliang412
Copy link
Contributor

yliang412 commented Dec 11, 2024

After implementing #9693, our buffered writer always copies writes into internal aligned buffer and write them out once a buffer is full due to O_DIRECT alignment requirement.

For larger writes (e.g. download_object, image layer values), it might make sense to implement buffer bypass for aligned parts of the write and avoid copying majority of the data into the internal buffer. Doing so allows us to save cpu cycles and potentially improve throughput.

Requirements

  • Create a wrapper type that wraps around bytes::Bytes. Make sure the view into the buffer is aligned at construction, impl aligned marker trait.

The actual workflow is something like

  • Memcpy unaligned head part of the buffer into the internal buffer and then flush.
    • We might need to pad zeros so that a single blob is contiguous on disk, and contiguous in vectored read. However this introduces internal fragmentation.
  • flush aligned part of the buffer.
  • Memcpy unaligned tail into the internal buffer.

For instance:

# `X` represents the bytes originally in the internal aligned buffer.
# `E` represents the bytes originally in the external maybe not-aligned buffer.

IoBufferMut                        Bytes
+-------+-------+-------+-------   ----+-------+----
XXXXXXXXXXXXXXXXXXXXXXXXXX         EEEEEEEEEEEEEEEEE
+-------+-------+-------+-------   ----+-------+----
A       A       A       A              A       A
       
                          ||
                          \/

IoBufferMut (flush)                    IoBufOwnedSlice<Bytes> (flush)
+-------+-------+-------+-------       +-------
XXXXXXXXXXXXXXXXXXXXXXXXXX00EEEE       EEEEEEEE
+-------+-------+-------+-------       +-------
A       A       A       A              A       

IoBufferMut                     
+-------+-------+-------+-------
EEEEE
+-------+-------+-------+-------
A       A       A       A     

Related

Using a mpsc channel to send request with oneshot channel callbacks to recycle the buffer might work better than current two mpsc channel based utils::sync::Duplex.

@yliang412 yliang412 added the c/storage/pageserver Component: storage: pageserver label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/storage/pageserver Component: storage: pageserver
Projects
None yet
Development

No branches or pull requests

1 participant