Kernel: Implement copy-on-write memory for file backed mmaps
This commit is contained in:
@@ -12,6 +12,8 @@ namespace Kernel
|
||||
|
||||
void sync(size_t page_index);
|
||||
|
||||
Mutex mutex;
|
||||
|
||||
// FIXME: this should probably be ordered tree like map
|
||||
// for fast lookup and less memory usage
|
||||
BAN::Vector<paddr_t> pages;
|
||||
@@ -33,7 +35,7 @@ namespace Kernel
|
||||
virtual BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> clone(PageTable& new_page_table) override;
|
||||
|
||||
protected:
|
||||
virtual BAN::ErrorOr<bool> allocate_page_containing_impl(vaddr_t vaddr) override;
|
||||
virtual BAN::ErrorOr<bool> allocate_page_containing_impl(vaddr_t vaddr, bool wants_write) override;
|
||||
|
||||
private:
|
||||
FileBackedRegion(BAN::RefPtr<Inode>, PageTable&, off_t offset, ssize_t size, Type flags, PageTable::flags_t page_flags);
|
||||
@@ -42,7 +44,7 @@ namespace Kernel
|
||||
BAN::RefPtr<Inode> m_inode;
|
||||
const off_t m_offset;
|
||||
|
||||
// FIXME: is this even synchronized?
|
||||
BAN::Vector<paddr_t> m_dirty_pages;
|
||||
BAN::RefPtr<SharedFileData> m_shared_data;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Kernel
|
||||
BAN::ErrorOr<void> copy_data_to_region(size_t offset_into_region, const uint8_t* buffer, size_t buffer_size);
|
||||
|
||||
protected:
|
||||
virtual BAN::ErrorOr<bool> allocate_page_containing_impl(vaddr_t vaddr) override;
|
||||
virtual BAN::ErrorOr<bool> allocate_page_containing_impl(vaddr_t vaddr, bool wants_write) override;
|
||||
|
||||
private:
|
||||
MemoryBackedRegion(PageTable&, size_t size, Type, PageTable::flags_t);
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace Kernel
|
||||
bool contains_fully(vaddr_t address, size_t size) const;
|
||||
bool overlaps(vaddr_t address, size_t size) const;
|
||||
|
||||
bool writable() const { return m_flags & PageTable::Flags::ReadWrite; }
|
||||
|
||||
size_t size() const { return m_size; }
|
||||
vaddr_t vaddr() const { return m_vaddr; }
|
||||
|
||||
@@ -45,7 +47,7 @@ namespace Kernel
|
||||
// Returns error if no memory was available
|
||||
// Returns true if page was succesfully allocated
|
||||
// Returns false if page was already allocated
|
||||
BAN::ErrorOr<bool> allocate_page_containing(vaddr_t address);
|
||||
BAN::ErrorOr<bool> allocate_page_containing(vaddr_t address, bool wants_write);
|
||||
|
||||
virtual BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> clone(PageTable& new_page_table) = 0;
|
||||
|
||||
@@ -53,7 +55,7 @@ namespace Kernel
|
||||
MemoryRegion(PageTable&, size_t size, Type type, PageTable::flags_t flags);
|
||||
BAN::ErrorOr<void> initialize(AddressRange);
|
||||
|
||||
virtual BAN::ErrorOr<bool> allocate_page_containing_impl(vaddr_t address) = 0;
|
||||
virtual BAN::ErrorOr<bool> allocate_page_containing_impl(vaddr_t address, bool wants_write) = 0;
|
||||
|
||||
protected:
|
||||
PageTable& m_page_table;
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Kernel
|
||||
virtual BAN::ErrorOr<void> msync(vaddr_t, size_t, int) override { return {}; }
|
||||
|
||||
protected:
|
||||
virtual BAN::ErrorOr<bool> allocate_page_containing_impl(vaddr_t vaddr) override;
|
||||
virtual BAN::ErrorOr<bool> allocate_page_containing_impl(vaddr_t vaddr, bool wants_write) override;
|
||||
|
||||
private:
|
||||
SharedMemoryObject(BAN::RefPtr<SharedMemoryObjectManager::Object> object, PageTable& page_table)
|
||||
|
||||
Reference in New Issue
Block a user