Skip to content

Add flags support to MmapAllocator #4845

@kubiak-jpl

Description

@kubiak-jpl
F´ Version 4.1.0
Affected Component Fw/TypesMmapAllocator

Feature Description

Add optional constructor arguments to Fw::MmapAllocator to set the allocation flags used when allocating memory with the created object

Something like

class MmapAllocator : public MemAllocator {
  public:
  MmapAllocator(int prot = PROT_READ | PROT_WRITE, int flags = MAP_SHARED | MAP_ANONYMOUS);

  private:
  int m_prot;
  int m_flags;
}

void* MmapAllocator::allocate(const FwEnumStoreType identifier,
                              FwSizeType& size,
                              bool& recoverable,
                              FwSizeType alignment) {
    void* addr = mmap(nullptr, size, m_prot, m_flags, -1, 0);
    return addr;
}

Fw::MmapAllocator my_alloc(PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_LOCKED);

Rationale

The MmapAllocator type is useful for allocating anonymous memory with the mmap system call. However I would like to allocate pages with the MAP_LOCKED flag set. Instead of creating a custom instance I think it would be more useful to amend the existing allocator for this strategy.

Open questions

  • Does the PROT field need to be exposed here? Any reason to allocate memory the allocator that isn't marked RW? Does adding the option just add noise?
  • Should custom fpp enums be used for the prot and flags arguments?
    • I think not. Just use the Posix defined flags. I don't believe this is intended to be an OS agnostic interface

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions