Length of memory mapping

21 views
Skip to first unread message

Vlad Khorsun

unread,
Feb 6, 2026, 7:51:27 AM (6 days ago) Feb 6
to firebir...@googlegroups.com
All,

Look at SharedMemoryBase::mapObject() - it maps memory range aligned by system allocation
page size. This is explicit requirement of both mmap() and MapViewOfFile(). But it also
aligns end of the mapped range - and this is a problem, as this point could be out of the
mapped file size. I see no such requirement in docs:

- mmap: https://man7.org/linux/man-pages/man2/mmap.2.html

in section ERRORS:

---
EINVAL We don't like addr, length, or offset (e.g., they are too
large, or not aligned on a page boundary).
---

it mention "length" but in EXAMPLES it uses aligned value for "offset" only
and "length" could be evaluated as part of file from offset to the end,
if not set.



- MapViewOfFile

https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffile

makes no special requirements for the "dwNumberOfBytesToMap" parameter and says:

---
If this parameter is 0 (zero), the mapping extends from the specified offset to the end of the file mapping.
---

So, the question is - do we really need to align end of mapping range by the system
page size ? Test on Windows shows it is not necessary (as expected).

Regards,
Vlad

Alex Peshkoff

unread,
Feb 6, 2026, 12:09:53 PM (6 days ago) Feb 6
to firebir...@googlegroups.com
On 2/6/26 15:51, Vlad Khorsun wrote:

>   So, the question is - do we really need to align end of mapping
> range by the system
> page size ? Test on Windows shows it is not necessary (as expected).
>

Vlad, looks like on linux it's also not a requirement. But I have not
understood - what problems do we solve with unaligned mapping length?


Vlad Khorsun

unread,
Feb 6, 2026, 12:57:07 PM (6 days ago) Feb 6
to firebir...@googlegroups.com
06.02.2026 19:09, Alex Peshkoff:
We could attempt to map area over the end of file. It is easy to do when currenlty mapped
size is not multiply of system allocation unit size (what getpagesize() returns) and almost
all mapped memory is already used.

Look at LockManager::create_process() that allocates memory for `struct prc` and then
creates new mapping for it.

Regards,
Vlad

Alex Peshkoff

unread,
Feb 7, 2026, 9:20:05 AM (5 days ago) Feb 7
to firebir...@googlegroups.com
If we always align length of shared file up to page boundary (in
remapFile and SharedMemoryBase's c-tor) we will also not have such
problems. On my mind this way appears to be much more straightforward
then use poorly documented details of system calls. Who knows how they
will behave in next version or on something like Mac?


Reply all
Reply to author
Forward
0 new messages