Talloc sonsidered harmful to performance testing ...

Richard Sharpe realrichardsharpe at gmail.com
Sun Jun 7 13:46:24 MDT 2015

On Sun, Jun 7, 2015 at 12:28 PM, Matthieu Patou <mat at samba.org> wrote:
> On 06/07/2015 11:46 AM, Richard Sharpe wrote:
>> This seems to be because of the following code in smb2_pull_o16s16_blob:
>>          *blob = data_blob_talloc(mem_ctx, buf->hdr + ofs, size);
>>          NT_STATUS_HAVE_NO_MEMORY(blob->data);
>>          return NT_STATUS_OK;
>> Does anyone have any comments? If I get a chance I might modify that
>> code to use any passed in blob if it is big enough.
> Did you try to run perf on it ? if not can you run:
> perf -F 99 -g -a -- sleep 600
> perf script >smbtorture.perf.out
> Adapt 600 so that perf capture the time when you are running your
> smbtorture.
> Also have you tried to use a talloc_pool, with talloc pool you can allocate
> a big memory chunk and let talloc tap into it.
> It should be much faster.

The tallocs are being done in code I am calling. After this change:

--- a/source4/libcli/smb2/request.c
+++ b/source4/libcli/smb2/request.c
@@ -267,7 +267,10 @@ NTSTATUS smb2_pull_o16s16_blob(struct
smb2_request_buffer *buf, TALLOC_CTX *mem_
        if (smb2_oob(buf, buf->hdr + ofs, size)) {
                return NT_STATUS_INVALID_PARAMETER;
-       *blob = data_blob_talloc(mem_ctx, buf->hdr + ofs, size);
+       if (blob->length >= size) {
+               memcpy(blob->data, buf->hdr + ofs, size);
+       } else
+               *blob = data_blob_talloc(mem_ctx, buf->hdr + ofs, size);
        return NT_STATUS_OK;

I now see all of them taking around 3 minutes for 100,000 iterations
but top suggests that smbtorture is getting 88+% of the CPU and smbd
only around 10%, so there is still a lot of talloc being done in the
code I am calling.

That is a pity because smbtorture etc seems very useful for some types
of performance testing.

> Also you should check if you are not spending too much time feeing talloc
> stuff, even with a talloc pool it takes still a lot of time sometimes
> because you have a lot of objects and talloc has to go through all of them
> (I wish we had a way to say free the whole talloc pool at once, don't
> recurse).
> --
> Matthieu Patou
> Samba Team
> http://samba.org

Richard Sharpe

More information about the samba-technical mailing list