All of lore.kernel.org
 help / color / mirror / Atom feed
* memcpy() avoidance using decode(bufferlist)
@ 2016-04-22 13:53 David Disseldorp
  2016-04-22 18:05 ` Casey Bodley
  0 siblings, 1 reply; 3+ messages in thread
From: David Disseldorp @ 2016-04-22 13:53 UTC (permalink / raw)
  To: ceph-devel

Hi,

A question regarding bufferlist usage:

I'm working on the cmpext librados C API, and want to decode the OSD
response directly into a (char *buf/size_t len) buffer provided by the
caller.

I figured this would be straightforward via:
  bl.push_back(buffer::create_static(buf, len));
  ...
  ::decode_nohead(iter.get_remaining(), bl, iter);

However, the decoded data doesn't make it into buf, unless an extra copy
occurs via:
  bl.copy(0, bl.length(), buf);

Any suggestions on a clean way to avoid the extra copy here?

Cheers, David

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: memcpy() avoidance using decode(bufferlist)
  2016-04-22 13:53 memcpy() avoidance using decode(bufferlist) David Disseldorp
@ 2016-04-22 18:05 ` Casey Bodley
  2016-04-24 22:56   ` David Disseldorp
  0 siblings, 1 reply; 3+ messages in thread
From: Casey Bodley @ 2016-04-22 18:05 UTC (permalink / raw)
  To: David Disseldorp, ceph-devel



On 04/22/2016 09:53 AM, David Disseldorp wrote:
> Hi,
>
> A question regarding bufferlist usage:
>
> I'm working on the cmpext librados C API, and want to decode the OSD
> response directly into a (char *buf/size_t len) buffer provided by the
> caller.
>
> I figured this would be straightforward via:
>    bl.push_back(buffer::create_static(buf, len));
>    ...
>    ::decode_nohead(iter.get_remaining(), bl, iter);
>
> However, the decoded data doesn't make it into buf, unless an extra copy
> occurs via:
>    bl.copy(0, bl.length(), buf);
>
> Any suggestions on a clean way to avoid the extra copy here?
>
> Cheers, David
> --
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Hi David,

The decode logic is appending data to the end of the given bufferlist, 
which is why it's skipping over the buffer pointer that you provide. 
Internally, buffer::list is allocating its own 'buffer::ptr 
append_buffer' to batch these appends. This append_buffer is not 
currently exposed by the interface, but if there was a way to provide 
your own buffer::ptr from buffer::create_static(), you could 
hypothetically use that to avoid the copy.

Casey

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: memcpy() avoidance using decode(bufferlist)
  2016-04-22 18:05 ` Casey Bodley
@ 2016-04-24 22:56   ` David Disseldorp
  0 siblings, 0 replies; 3+ messages in thread
From: David Disseldorp @ 2016-04-24 22:56 UTC (permalink / raw)
  To: Casey Bodley; +Cc: ceph-devel

Thanks for the tips Casey!

On Fri, 22 Apr 2016 14:05:15 -0400, Casey Bodley wrote:

> This append_buffer is not 
> currently exposed by the interface, but if there was a way to provide 
> your own buffer::ptr from buffer::create_static(), you could 
> hypothetically use that to avoid the copy.

That's a pity. In that case, I guess I'll keep the extra memcpy until
there's an API to directly provide the bufferlist destination buffer
here.

Cheers, David

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-04-24 22:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-22 13:53 memcpy() avoidance using decode(bufferlist) David Disseldorp
2016-04-22 18:05 ` Casey Bodley
2016-04-24 22:56   ` David Disseldorp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.