Hacker News new | ask | show | jobs
by o11c 892 days ago
Worse, it breaks all pointers since you can't guarantee `mmap` can give you the same address.
3 comments

You absolutely can, with `MAP_FIXED`. But it's not trivial to do because you'd have to handle the case where the rtld and/or the kernel has already put something in memory where you want to put down your map. So it'd be tricky to implement, but definitely possible.
That can be fixed with a linker script, to reserve the range using ELF headers.

But then you're going to hit other problems. This isn't a new idea. Presumably one of the reasons you're restarting your server is to upgrade it ...

I think you could fixup the pointers if you tried. It's more or less the same problem as compacting GC.
Certainly there are solutions, but they aren't transparent, and at some point you have to ask "would serialization be easier?"
This is exactly what I thought: why not just save state to a file?
You can detect when it doesn't, though, I think. If memory serves you can request a specific memory address to mount it at and it'll do it if it's not already mapped. It should (in theory?) return an error in such a case, no?
I believe on conflict it will just fall back to placing it where it can by default. It will return the address it actually used, so you can catch the mismatch.