class BufferChain

Defined at line 59 of file ../../zircon/kernel/object/include/object/buffer_chain.h

BufferChain is a list of buffers allocated from the PMM.

It's designed for use with channel messages. Pages backing a BufferChain are marked as

vm_page_state::IPC.

The BufferChain object itself lives *inside* its first buffer. Here's what it looks like:

+--------------------------------+ +--------------------------------+

| page | | page |

|+------------------------------+| |+------------------------------+|

|| Buffer |+---->|| Buffer ||

|| raw_data: +---------------+|| || raw_data: +--------------+||

|| | BufferChain ||| || | message data |||

|| reserved -> | ~~~~~~~~~~~~~ ||| || reserved = 0 | continued |||

|| | message data ||| || | |||

|| +---------------+|| || +--------------+||

|+------------------------------+| |+------------------------------+|

+--------------------------------+ +--------------------------------+

BufferChain does not dynamically allocate. An initial Alloc() call allocates a list of

pages that will be used to build the BufferChain. This allocation can exceed the size

actually used by the buffer chain and the excess buffers can be freed with a call to

FreeUnusedBuffers(). The motivation for sometimes allocating more than needed and later

freeing is that the number of needed buffers is sometimes initially unknown and it is

presumed to be more efficient to do a single allocation than multiple allocations.

BufferChain uses a private PageCache to improve performance under load by

avoiding contention on the PMM. The page cache is tunable by the kernel

command line parameter kernel.bufferchain.reserve-pages.

Public Members

static const size_t kSizeOfBuffer
static const size_t kSizeOfBufferFields
static const size_t kRawDataSize
static const size_t kSizeOfBufferChain
static const size_t kContig

Public Methods

zx_status_t AppendKernel (const char * src, size_t size)

Same as Append except |src| can be in kernel space.

If there is insufficient remaining space in the buffer chain, ZX_ERR_OUT_OF_RANGE will be

returned.

Defined at line 32 of file ../../zircon/kernel/object/buffer_chain.cc

void InitializePageCache (uint32_t level)

Defined at line 38 of file ../../zircon/kernel/object/buffer_chain.cc

zx_status_t CopyOut (user_out_ptr<char> dst, size_t src_offset, size_t size)

Copies |size| bytes from this chain starting at offset |src_offset| to |dst|.

|src_offset| must be in the range [0, kContig).

Defined at line 84 of file ../../zircon/kernel/object/include/object/buffer_chain.h

BufferChain * Alloc (size_t size)

Creates a BufferChain with enough buffers to store |size| bytes.

It is the caller's responsibility to free the chain with BufferChain::Free.

Returns nullptr on error.

Defined at line 108 of file ../../zircon/kernel/object/include/object/buffer_chain.h

void Free (BufferChain * chain)

Frees |chain| and its buffers.

Defined at line 135 of file ../../zircon/kernel/object/include/object/buffer_chain.h

void FreeUnusedBuffers ()

Free unused pages.

Defined at line 152 of file ../../zircon/kernel/object/include/object/buffer_chain.h

void Skip (size_t size)

Skips the specified number of bytes, so they won't be consumed by Append or AppendKernel.

Assumes that it is called only at the beginning of the buffer chain.

Defined at line 157 of file ../../zircon/kernel/object/include/object/buffer_chain.h

zx_status_t Append (user_in_ptr<const char> src, size_t size)

Appends |size| bytes from |src| to this chain|.

If there is insufficient remaining space in the buffer chain, ZX_ERR_OUT_OF_RANGE will be

returned.

Defined at line 167 of file ../../zircon/kernel/object/include/object/buffer_chain.h

BufferList * buffers ()

Defined at line 199 of file ../../zircon/kernel/object/include/object/buffer_chain.h

Records