Earlier quoted context omitted.
What we need is a page-based Vec that mmaps (anon) for the storage but leaves the unused portions zero-bytes and therefore not part of RSS until actually required. (And when clearing/shrinking sections, madvise DONTNEED the pages). That is, the vec could expand to areas much larger than the actual used size, but this would have no effect on process RSS until those pages get dirtied with actual data.
That can be not a great idea for subtle reasons even though it does seem like a better design at first. When you do the madvise, based on the contact of the API, the kernel has to do a TLB shoot down which is really expensive. And not just “expensive for my process” but expensive in terms of a significant slowdown for entire machine. Honestly you could probably DDOS a machine if you could reliably trigger that shootd…
Identifying Rust's collect: >() memory leak footgun
41–50 of 129 posts
Re: Identifying Rust's collect:<Vec<_>>() memory leak footgun
#42Earlier quoted context omitted.
That can be not a great idea for subtle reasons even though it does seem like a better design at first. When you do the madvise, based on the contact of the API, the kernel has to do a TLB shoot down which is really expensive. And not just “expensive for my process” but expensive in terms of a significant slowdown for entire machine. Honestly you could probably DDOS a machine if you could reliably trigger that shootd…
Yes, well, I think you're right it's a lot about the contract of the API and the expectation of the user. I'd certainly want intelligence (either by the user or by the framework) in how frequently you release pages back to the OS. But the DONTNEED is really not the core of the value. It's being able to create vectors that don't fragment as badly. And yes, you're right a decent allocator could help with this, and what…
I think fragmentation is an over focused on problem when in practice it’s rarely the problem. It’s also a problem that can be solved by an application reset and making sure to periodically reset your running application in a way that doesn’t result in severe disruption is a better practice that works around many more issues than just fragmentation.
Re: Identifying Rust's collect:<Vec<_>>() memory leak footgun
#43Re: Identifying Rust's collect:<Vec<_>>() memory leak footgun
#44I don't think it's a memory leak. It's re-using the same space of the underling array. It's allocated. Dropping the Vec will release the memory. In v1 you put in 128 containers is with each 1024 boxes. Then v2 is taking out the first box out of each container, tossing the container and putting the box at the space where the container was, packing them. The fact that capacity doubles when you remove the as u8 is... no…
Re: Identifying Rust's collect:<Vec<_>>() memory leak footgun
#45Earlier quoted context omitted.
>> Programmers’ expectations are not codified and do not need to be respected That's pretty negative attitude - my immediate gut response was "and neither do yours". But Rust isn't an ISO standard and is still in development. Even if we do think in those terms, people developing a standard have IMHO an obligation to the people who will be using the standard.
To be a bit pedantic, the people using the C++ standard are mostly compiler engineers.
Re: Identifying Rust's collect:<Vec<_>>() memory leak footgun
#46I don't think it's a memory leak. It's re-using the same space of the underling array. It's allocated. Dropping the Vec will release the memory. In v1 you put in 128 containers is with each 1024 boxes. Then v2 is taking out the first box out of each container, tossing the container and putting the box at the space where the container was, packing them. The fact that capacity doubles when you remove the as u8 is... no…
Re: Identifying Rust's collect:<Vec<_>>() memory leak footgun
#47I don't think it's a memory leak. It's re-using the same space of the underling array. It's allocated. Dropping the Vec will release the memory. In v1 you put in 128 containers is with each 1024 boxes. Then v2 is taking out the first box out of each container, tossing the container and putting the box at the space where the container was, packing them. The fact that capacity doubles when you remove the as u8 is... no…
But it's 200x.
Right?
Re: Identifying Rust's collect:<Vec<_>>() memory leak footgun
#48Earlier quoted context omitted.
That can be not a great idea for subtle reasons even though it does seem like a better design at first. When you do the madvise, based on the contact of the API, the kernel has to do a TLB shoot down which is really expensive. And not just “expensive for my process” but expensive in terms of a significant slowdown for entire machine. Honestly you could probably DDOS a machine if you could reliably trigger that shootd…
Is MADV_FREE on Linux any better in this regard? It's what the libc allocators tend to use, if I recall correctly.
Here’s a discussion [1] of a hypothetical lazy_munmap option that would initiate the unmap without an immediate shoot down (i.e. the CPUs would lazily evict from the TLB when they notice the request) but no such option exists. It’s also not immediately clear such a hypothetical API could exist on current CPU architectures or if it would require new HW support as I don’t have enough hands-on expertise at that level. Anyway, [1] is an interesting discussion of this idea and the note about huge pages making these even less valuable is interesting to keep in mind.
Re: Identifying Rust's collect:<Vec<_>>() memory leak footgun
#49Over allocating maps and arrays in standard libs is not really a memory "leak" . Other langs do it.
Re: Identifying Rust's collect:<Vec<_>>() memory leak footgun
#50> It’s also an illustration of how an optimization in one place can lead to bugs downstream by violating programmers’ expectations. This touched upon a pet peeve of mine for its resemblance with all the talk about undefined behaviour in C and C++. Programmers’ expectations are not codified and do not need to be respected: international standards do.
What if...stick with me...the standards sought to codify and respect programmers' expectations?
https://en.wikipedia.org/wiki/Principle_of_least_astonishmen...