167 points · by klaussilveira · 2y ago · 38 comments
Hi, it's my project. Feel free to ask me anything.
(I love the name but am always curious what people's inspirations are for naming their project. I love when a project name is unique, creative, descriptive, and playful, and Bytehound nails all four IMHO)
Also, thank you for doing this and sharing it!
Imagine a set of workers that ingest data in parallel, would that work?
Currently it's pretty simple and i am spawning a process within the worker so it reads some stuff such as memory usage, cpu usage etc... But I would like to improve it.
It could probably be done, but the analyzer would have to be mostly rewritten. (Which I currently have no plans to do.)
If it's a native program - possibly, depending on whether it's possible to LD_PRELOAD on Android, but you'd most likely have to connect to it through SSH and launch your program that way.
(Sorry, I have very little experience with Android so I can't really be of too much help here)
Although I could probably recommend you a hands-on project/exercise to do:
- Write a simple memory allocator in C/C++/Rust/Zig/any similar systems language using raw `mmap` and `munmap` syscalls (run "man 2 mmap" in your terminal for details). This is how fundamentally almost every program allocates memory on the lowest level (with some exceptions, but I'm not going to get into that).
- Allocate a bunch of memory with your allocator without actually reading/writing from than memory and check the program's RSS, then write to it and check the RSS again. Try allocating more memory than you have RAM and see if it works. Run the program under `perf` and check the page faults counter - see how the page fault number changes if you a) never write to the memory you allocated, b) only write to a single byte per page, c) write to every byte you allocated, d) write twice to every byte you allocated.
- Play around with the `madvise` syscall ("man 2 madvise"), in particular with `MADV_DONTNEED`.
- Try `mmap`ing on a file on your disk. `mmap` it with multiple processes at the same time.
Is it correct to say memory behaviour of a program entirely depends on what/how the program allocates and its memory access pattern? Is there any hello world memory allocator out there?
File system moves blocks to memory, and kernel access them as pages, and kernel also moves them back to disk(using file system) depending on memory pressure. Given this is ture, I am assuming, when studying memory behaviour, virtual memory setup is good enough to ignore file system level details initially - but at what point these details become important? For example, just as cache miss, I am assuming, it is also very expensive for file system(paired with underlying physical medium) to go out and gather non-contiguous blocks and put them together to respond to a file access request.
Frame-pointer-based, I imagine?
The main two tricks are: it preprocesses all of the DWARF info at startup for faster lookups, and it dynamically patches the return addresses of functions on the stack injecting an address to its own trampoline, which allows it to skip going through the whole stack trace every time it needs to dump a backtrace. For example, if you're running a function nested 100 stack frames deep and that function calls malloc 100 times then Bytehound will only go through ~300 stack frames in total (~100 times for the first call then only ~2 frames for each successive call, if my math is right), while other similar tools will go through 10000 stack frames (going through all ~100 frames to the very bottom for every call).
I had always assumed that if the time came to choose a permissive OSS license, I'd just go with Apache-2.0 for the more complete legal ground that it provides (especially wrt. patents). Didn't even occur to me that it would as much as make sense to offer MIT too (like, why not also BSD now that we're at it?)
Apache 2 has a patent grant so it's preferred by companies, but is not compatible with GPLv2, and MIT is compatible with GPLv2.
Source: https://prev.rust-lang.org/id-ID/faq.html#why-a-dual-mit-asl...
Apache 2 is compatible with GPL 3, which outside the kernel most of the world uses.
I'm... Not sure that is the case?
Some big projects still on (L)GPLv2, off the top of my head:
MySQL & MariaDB, QEMU, Busybox, Git, Wireshark, probably many many more.