Contur 2
Educational OS kernel simulator
Loading...
Searching...
No Matches
contur::Mmu Class Referencefinal

Concrete Memory Management Unit implementation. More...

#include <mmu.h>

Inheritance diagram for contur::Mmu:

Public Member Functions

 Mmu (IMemory &memory, std::unique_ptr< IPageReplacementPolicy > replacementPolicy, ITracer &tracer)
 Constructs an MMU backed by the given physical memory.
 ~Mmu () override
 Destroys MMU and associated paging state.
 Mmu (const Mmu &)=delete
Mmuoperator= (const Mmu &)=delete
 Mmu (Mmu &&) noexcept
 Move-constructs MMU state.
Mmuoperator= (Mmu &&) noexcept
 Move-assigns MMU state.
Result< Blockread (ProcessId processId, MemoryAddress virtualAddress) const override
 Reads a Block from a virtual address in a given process's address space.
Result< void > write (ProcessId processId, MemoryAddress virtualAddress, const Block &block) override
 Writes a Block to a virtual address in a given process's address space.
Result< MemoryAddressallocate (ProcessId processId, std::size_t pageCount) override
 Allocates a range of frames for a process.
Result< void > deallocate (ProcessId processId) override
 Deallocates all frames owned by a process.
Result< void > swapIn (ProcessId processId, MemoryAddress virtualAddress) override
 Swaps a page into physical memory.
Result< void > swapOut (ProcessId processId, MemoryAddress virtualAddress) override
 Swaps a page out of physical memory (to simulated disk).
std::size_t totalFrames () const noexcept override
 Returns the total number of physical frames managed.
std::size_t freeFrames () const noexcept override
 Returns the number of free (unallocated) physical frames.
Public Member Functions inherited from contur::IMMU
virtual ~IMMU ()=default

Private Attributes

std::unique_ptr< Impl > impl_

Detailed Description

Concrete Memory Management Unit implementation.

Manages per-process page tables, translates virtual addresses to physical frame addresses, handles frame allocation/deallocation, and delegates page replacement decisions to an IPageReplacementPolicy.

The MMU operates on top of an IMemory instance (physical memory) and maintains a simulated swap space for pages evicted from RAM.

Definition at line 25 of file mmu.h.

Constructor & Destructor Documentation

◆ Mmu() [1/3]

contur::Mmu::Mmu ( IMemory & memory,
std::unique_ptr< IPageReplacementPolicy > replacementPolicy,
ITracer & tracer )
explicit

Constructs an MMU backed by the given physical memory.

Parameters
memoryThe physical memory to manage (non-owning reference).
replacementPolicyThe page replacement policy to use.

Referenced by Mmu(), Mmu(), operator=(), and operator=().

◆ ~Mmu()

contur::Mmu::~Mmu ( )
override

Destroys MMU and associated paging state.

◆ Mmu() [2/3]

contur::Mmu::Mmu ( const Mmu & )
delete

References Mmu().

◆ Mmu() [3/3]

contur::Mmu::Mmu ( Mmu && )
noexcept

Move-constructs MMU state.

References Mmu().

Member Function Documentation

◆ allocate()

Result< MemoryAddress > contur::Mmu::allocate ( ProcessId processId,
std::size_t pageCount )
nodiscardoverridevirtual

Allocates a range of frames for a process.

Parameters
processIdThe owning process.
pageCountNumber of pages (frames) to allocate.
Returns
The starting virtual address, or an error if out of memory.

Implements contur::IMMU.

References allocate().

Referenced by allocate().

◆ deallocate()

Result< void > contur::Mmu::deallocate ( ProcessId processId)
nodiscardoverridevirtual

Deallocates all frames owned by a process.

Parameters
processIdThe process whose frames should be freed.
Returns
Success, or an error if the process has no allocations.

Implements contur::IMMU.

References deallocate().

Referenced by deallocate().

◆ freeFrames()

std::size_t contur::Mmu::freeFrames ( ) const
nodiscardoverridevirtualnoexcept

Returns the number of free (unallocated) physical frames.

Implements contur::IMMU.

References freeFrames().

Referenced by freeFrames().

◆ operator=() [1/2]

Mmu & contur::Mmu::operator= ( const Mmu & )
delete

References Mmu().

◆ operator=() [2/2]

Mmu & contur::Mmu::operator= ( Mmu && )
noexcept

Move-assigns MMU state.

References Mmu().

◆ read()

Result< Block > contur::Mmu::read ( ProcessId processId,
MemoryAddress virtualAddress ) const
nodiscardoverridevirtual

Reads a Block from a virtual address in a given process's address space.

Parameters
processIdThe owning process.
virtualAddressThe virtual address to read from.
Returns
The Block at the translated physical address, or an error.

Implements contur::IMMU.

References read().

Referenced by read().

◆ swapIn()

Result< void > contur::Mmu::swapIn ( ProcessId processId,
MemoryAddress virtualAddress )
nodiscardoverridevirtual

Swaps a page into physical memory.

Parameters
processIdThe owning process.
virtualAddressA virtual address within the target page.
Returns
Success, or an error if swap fails.

Implements contur::IMMU.

References swapIn().

Referenced by swapIn().

◆ swapOut()

Result< void > contur::Mmu::swapOut ( ProcessId processId,
MemoryAddress virtualAddress )
nodiscardoverridevirtual

Swaps a page out of physical memory (to simulated disk).

Parameters
processIdThe owning process.
virtualAddressA virtual address within the target page.
Returns
Success, or an error if swap fails.

Implements contur::IMMU.

References swapOut().

Referenced by swapOut().

◆ totalFrames()

std::size_t contur::Mmu::totalFrames ( ) const
nodiscardoverridevirtualnoexcept

Returns the total number of physical frames managed.

Implements contur::IMMU.

References totalFrames().

Referenced by totalFrames().

◆ write()

Result< void > contur::Mmu::write ( ProcessId processId,
MemoryAddress virtualAddress,
const Block & block )
nodiscardoverridevirtual

Writes a Block to a virtual address in a given process's address space.

Parameters
processIdThe owning process.
virtualAddressThe virtual address to write to.
blockThe Block to store.
Returns
Success, or an error if translation fails.

Implements contur::IMMU.

References write().

Referenced by write().

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> contur::Mmu::impl_
private

Definition at line 73 of file mmu.h.


The documentation for this class was generated from the following file:
  • include/contur/memory/mmu.h