abd_get_from_buf_struct: wrap existing buf with ABD stored on stack
This allows a simple "wrapping" ABD for an existing linear buffer to be allocated on the stack, avoiding an allocation. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
This commit is contained in:
parent
9e15877dfb
commit
ba2209ec9e
|
@ -93,6 +93,7 @@ abd_t *abd_get_offset_size(abd_t *, size_t, size_t);
|
|||
abd_t *abd_get_offset_struct(abd_t *, abd_t *, size_t, size_t);
|
||||
abd_t *abd_get_zeros(size_t);
|
||||
abd_t *abd_get_from_buf(void *, size_t);
|
||||
abd_t *abd_get_from_buf_struct(abd_t *, void *, size_t);
|
||||
void abd_cache_reap_now(void);
|
||||
|
||||
/*
|
||||
|
|
|
@ -603,13 +603,11 @@ abd_get_zeros(size_t size)
|
|||
}
|
||||
|
||||
/*
|
||||
* Allocate a linear ABD structure for buf.
|
||||
* Create a linear ABD for an existing buf.
|
||||
*/
|
||||
abd_t *
|
||||
abd_get_from_buf(void *buf, size_t size)
|
||||
static abd_t *
|
||||
abd_get_from_buf_impl(abd_t *abd, void *buf, size_t size)
|
||||
{
|
||||
abd_t *abd = abd_alloc_struct(0);
|
||||
|
||||
VERIFY3U(size, <=, SPA_MAXBLOCKSIZE);
|
||||
|
||||
/*
|
||||
|
@ -625,6 +623,20 @@ abd_get_from_buf(void *buf, size_t size)
|
|||
return (abd);
|
||||
}
|
||||
|
||||
abd_t *
|
||||
abd_get_from_buf(void *buf, size_t size)
|
||||
{
|
||||
abd_t *abd = abd_alloc_struct(0);
|
||||
return (abd_get_from_buf_impl(abd, buf, size));
|
||||
}
|
||||
|
||||
abd_t *
|
||||
abd_get_from_buf_struct(abd_t *abd, void *buf, size_t size)
|
||||
{
|
||||
abd_init_struct(abd);
|
||||
return (abd_get_from_buf_impl(abd, buf, size));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the raw buffer associated with a linear ABD.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue