4 ms·
Yes, and if I am writing an API service, for example, I don’t want to suddenly add latency because I hit pages that have been swapped out. I want guarantees abo
by adastra22 1y ago
Yes, and if I am writing an API service, for example, I don’t want to suddenly add latency because I hit pages that have been swapped out. I want guarantees about my API call latency variance, at least when the server isn’t overloaded.
I DON’T WANT THE KERNEL PRIORITIZING CACHE OVER NRU PAGES.
The easiest way to do this is to disable swap.
- eru 1y agoYou better not write your API in Python, or any language/library that uses amortised algorithms in the standard (like Rust and C++ do). And let's not mention garbage collection.
- pdimitar 1y agoHuh? Could you please clarify wrt to Rust and C++? Can't they use another allocator if needed? Or that's not the problem?
- sethherr 1y agoI’m asking because I genuinely don’t know - what are “pages” here?
- adastra22 1y agoThat’s a fair question. A page is the smallest allocatable unit of RAM, from the OS/kernel perspective. The size is set by the CPU, traditionally 4kB, but these days 8kB-4MB are also common. When you call malloc(), it requests a big chunk of memory from the OS, in units of pages. It then uses an allocator to divide it up into smaller, variable length chunks to form each malloc() request. You may have heard of “heap” memory vs “stack” memory. The stack of course is the execution/call stack, and heap is called that because the “heap allocator” is the algorithm originally used for keeping track of unused chunks of these pages. (This is beginner CS stuff so sorry if it came off as patronizing—I assume you’re either not a coder or self-taught, which is fine.)
- gnosek 1y agoOr you can set the vm.swappiness sysctl to 0.
- baq 1y agoIf you’re writing services in anything higher level than C you’re leaking something somewhere that you probably have no idea exists and the runtime won’t ever touch again.
- bayindirh 1y ago> I DON’T WANT THE KERNEL PRIORITIZING CACHE OVER NRU PAGES. Then tell the Kernel about it. Don't remove a feature which might benefit other things running on your system.
- dwattttt 1y agoIf you're getting this far into the details of your memory usage, shouldn't you use mlock to actually lock in the parts of memory you need to stay there? Then you get to have three tiers of priority: pages you never want swapped, cache, then pages that haven't been used recently.
- pdimitar 1y agoCan mlock be instructed to f.ex. "never swap pages from this pid"?
- bayindirh 1y agoThe application requests this itself from the Kernel. See https://man7.org/linux/man-pages/man2/mlock.2.html https://man7.org/linux/man-pages/man2/mlock.2.html
- dwattttt 1y agoFrom the link, mlockall with MCL_CURRENT | MCL_FUTURE > Lock all pages which are currently mapped into the address space of the process. > Lock all pages which will become mapped into the address space of the process in the future.