sunshowers edited PR #9681.
sunshowers edited PR #9681:
This is part of the work to centralize memory management into the
mmap
module. This commit introduces a few structures which aid in that process, and
starts converting one of the functions (MemoryImageSource::map_at
) into this
module.The structures introduced are:
MemoryBase
:RuntimeLinearMemory::base_ptr
is now
RuntimeLinearMemory::base
, which returns aMemoryBase
. This is either a
raw pointer or an mmap + an offset into it.
MmapOffset
: A combination of a reference to an mmap and an offset into it.
Logically represents a pointer into a mapped section of memory.
MmapOffsetRaw
: Some components likeMemoryImageSlot
logically work on
borrowed memory, but adding lifetime parameters to them would introduce
self-reference issues. Instead, store a raw form of theMmapOffset
such
that it can be reconstructed at runtime. This should work for most future
work here, but not all of it -- I've written out some comments along with
ideas.On Zulip there was a suggestion to use
Arc<Mmap>
rather than a lifetime
parameter. To be honest it's quite appealing! One of the challenges though
is thatMmap
has several&mut
methods. The methods fall into two categories:
- Methods like
make_accessible
, which can be changed to be&self
since the OS performs synchronization of mapped memory.- Methods like
slice_mut
, which are quite difficult to turn into&self
methods. It would be too easy to callself.slice_mut(0..host_page_size()); self.slice_mut(0..host_page_size());
and cause an insta-UB. I spent some time looking at how to do this but found it too difficult :(
sunshowers commented on PR #9681:
Methods like slice_mut, which are quite difficult to turn into &self methods. It would be too easy to call self.slice_mut(0..host_page_size()); self.slice_mut(0..host_page_size()); and cause an insta-UB. I spent some time looking at how to do this but found it too difficult :(
Ah interesting, it looks like the only seriously affected use is in some tests.
sunshowers edited a comment on PR #9681:
Methods like slice_mut, which are quite difficult to turn into &self methods. It would be too easy to call self.slice_mut(0..host_page_size()); self.slice_mut(0..host_page_size()); and cause an insta-UB. I spent some time looking at how to do this but found it too difficult :(
Ah interesting, it looks like the only seriously affected use is in some tests. Maybe this is more feasible than I think.
sunshowers commented on PR #9681:
Moving to draft for now -- I think
Arc
is possible to make work.
sunshowers closed without merge PR #9681.
sunshowers commented on PR #9681:
Yeah
Arc
is definitely possible -- going to re-do this after moving over toArc
.
Last updated: Dec 23 2024 at 12:05 UTC