How do i madvise the mapped_region for managed_shared_memory?

Open
#268 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
28/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp

Research direction

Start by reading managed_shared_memory and managed_open_or_create_impl, focusing on how get_mapped_region reaches mapped_region and how advice_types are handled. Determine the API and platform support needed for MADV_POPULATE_WRITE; done means managed shared memory can expose the mapped region and apply this advice through the public interface.

Written by the indexing model from the issue text.

Description

For performance reasons we want to preallocate memory in the shared memory by calling madvise(MADV_POPULATE_WRITE). This generally has significant benefit in performance during the bootstrap phase as compared to allocate memory when the memory is accessed. However there are 2 reasons why we cannot do this today:

  1. First the managed_shared_memory does not expose the public apis of managed_open_or_create_impl so we are unable to access to api get_mapped_region
  2. Even we would have access to the mapped_region, the advise api supports only selected options (enum advice_types) and MADV_POPULATE_WRITE is not part of it.

Do you plan to support this?

I guess the only viable alternative is I separately create the shared_memory and madvise it before initializing using boost's shared_memory something like this:

fd= shm_open("BoostShmem", O_CREATE)
ptr = mmap64(
NULL, fileSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
madvise(ptr, fileSize, MADV_POPULATE_WRITE);
boost::interprocess::managed_shared_memory shared_memory(boost::interprocess::create_only,
"BoostShmem", fileSize);

Dominant language
C++
Stars
185
Forks
131
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/interprocess

All issues in boostorg/interprocess

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.