This is an archive of the discontinued LLVM Phabricator instance.

lldb: do more than 1 kilobyte at a time to vastly increase binary sync speed
ClosedPublic

Authored by russelltg on Jun 15 2023, 11:39 AM.

Details

Summary

https://github.com/llvm/llvm-project/issues/62750

I setup a simple test with a large .so (~100MiB) that was only present on the target machine
but not present on the local machine, and ran a lldb server on the target and connectd to it.

LLDB properly downloads the file from the remote, but it does so at a very slow speed, even over a hardwired 1Gbps connection!

Increasing the buffer size for downloading these helps quite a bit.

Test setup:

$ cat gen.py
print('const char* hugeglobal = ')

for _ in range(1000*500):
    print('  "' + '1234'*50 + '"')

print(';')
print('const char* mystring() { return hugeglobal; }')
$ gen.py > huge.c
$ mkdir libdir
$ gcc -fPIC huge.c -Wl,-soname,libhuge.so -o libdir/libhuge.so -shared
$ cat test.c
#include <string.h>
#include <stdio.h>
extern const char* mystring();
int main() {
        printf("%d\n", strlen(mystring()));
}
$ gcc test.c -L libdir -l huge -Wl,-rpath='$ORIGIN' -o test
$ rsync -a libdir remote:~/
$ ssh remote bash -c "cd ~/libdir && /llvm/buildr/bin/lldb-server platform --server --listen '*:1234'"

in another terminal

$ rm -rf ~/.lldb # clear cache
$ cat connect.lldb
platform select remote-linux
platform connect connect://10.0.0.14:1234
file test
b main
r
image list
c
q
$ time /llvm/buildr/bin/lldb --source connect.lldb

Times with various buffer sizes:

1kiB (current): ~22s
8kiB: ~8s
16kiB: ~4s
32kiB: ~3.5s
64kiB: ~2.8s
128kiB: ~2.6s
256kiB: ~2.1s
512kiB: ~2.1s
1MiB: ~2.1s
2MiB: ~2.1s

I choose 512kiB from this list as it seems to be the place where the returns start diminishing and still isn't that much memory

My understanding of how this makes such a difference is ReadFile issues a request for each call, and larger buffer means less round trip times. The "ideal" situation is ReadFile() being async and being able to issue multiple of these, but that is much more work for probably little gains.

NOTE: this is my first contribution, so wasn't sure who to choose as a reviewer. Greg Clayton seems to be the most appropriate of those in CODE_OWNERS.txt

Diff Detail

Event Timeline

russelltg created this revision.Jun 15 2023, 11:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2023, 11:39 AM
russelltg requested review of this revision.Jun 15 2023, 11:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2023, 11:39 AM
russelltg edited the summary of this revision. (Show Details)Jun 15 2023, 11:43 AM
russelltg added a reviewer: clayborg.
russelltg edited the summary of this revision. (Show Details)
russelltg edited the summary of this revision. (Show Details)
russelltg edited the summary of this revision. (Show Details)Jun 15 2023, 11:46 AM
russelltg edited the summary of this revision. (Show Details)Jun 15 2023, 11:59 AM
russelltg edited the summary of this revision. (Show Details)Jun 15 2023, 12:15 PM
russelltg edited the summary of this revision. (Show Details)
jasonmolenda accepted this revision.Jun 15 2023, 1:05 PM
jasonmolenda added a subscriber: jasonmolenda.

Yeah that's an unintended bottleneck. If you're debugging to debugserver on a darwin system, it will tell lldb it uses a 128k max packet size, so larger read requests are still being broken up in to 128k chunks. The 128k size was set when we found little perf benefit from larger packet sizes. But using a 1k local buffer in this method to transfer binaries is unnecessary.

This revision is now accepted and ready to land.Jun 15 2023, 1:05 PM
clayborg accepted this revision.Jun 15 2023, 4:22 PM

Thanks for the reviews and approval. I don't have git access so if someone could push this that'd be fantastic.

Sure, what name and email address should go on the commit?

Name: Russell Greene
Email: russellgreene8@gmail.com

Thank you :)

Done, thanks for the contribution!