1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

mmap all the font files!

Font now uses the same in-memory format as the font files we have on disk.
This allows us to simply mmap() the font files and not use any additional
memory for them. Very cool! :^)

Hacking on this exposed a bug in file-backed VMObjects where the first client
to instantiate a VMObject for a specific inode also got to decide its size.
Since file-backed VMObjects always have the same size as the underlying file,
this made no sense, so I removed the ability to even set a size in that case.
This commit is contained in:
Andreas Kling 2019-02-05 06:43:33 +01:00
parent 612c02307e
commit a258d6507a
11 changed files with 134 additions and 110 deletions

View file

@ -304,15 +304,12 @@ bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_re
auto& vmo_page = vmo.physical_pages()[region.first_page_index() + page_index_in_region];
bool interrupts_were_enabled = are_interrupts_enabled();
if (!interrupts_were_enabled)
sti();
// FIXME: Maybe this should have a separate class like InterruptFlagSaver?
InterruptDisabler disabler;
disabler.temporarily_sti();
LOCKER(vmo.m_paging_lock);
if (!interrupts_were_enabled)
cli();
disabler.temporarily_cli();
if (!vmo_page.is_null()) {
kprintf("MM: page_in_from_inode() but page already present. Fine with me!\n");
@ -321,9 +318,9 @@ bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_re
}
#ifdef MM_DEBUG
dbgprintf("MM: page_in_from_inode ready to read from inode, will write to L%x!\n", dest_ptr);
dbgprintf("MM: page_in_from_inode ready to read from inode\n");
#endif
sti(); // Oh god here we go...
disabler.temporarily_sti();
byte page_buffer[PAGE_SIZE];
auto& inode = *vmo.inode();
auto nread = inode.read_bytes(vmo.inode_offset() + ((region.first_page_index() + page_index_in_region) * PAGE_SIZE), PAGE_SIZE, page_buffer, nullptr);
@ -335,7 +332,7 @@ bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_re
// If we read less than a page, zero out the rest to avoid leaking uninitialized data.
memset(page_buffer + nread, 0, PAGE_SIZE - nread);
}
cli();
disabler.temporarily_cli();
vmo_page = allocate_physical_page(ShouldZeroFill::No);
if (vmo_page.is_null()) {
kprintf("MM: page_in_from_inode was unable to allocate a physical page\n");
@ -610,7 +607,7 @@ Region::Region(LinearAddress a, size_t s, String&& n, bool r, bool w, bool cow)
Region::Region(LinearAddress a, size_t s, RetainPtr<Inode>&& inode, String&& n, bool r, bool w)
: m_laddr(a)
, m_size(s)
, m_vmo(VMObject::create_file_backed(move(inode), s))
, m_vmo(VMObject::create_file_backed(move(inode)))
, m_name(move(n))
, m_readable(r)
, m_writable(w)
@ -661,13 +658,12 @@ void PhysicalPage::return_to_freelist()
#endif
}
RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode, size_t size)
RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode)
{
InterruptDisabler disabler;
if (inode->vmo())
return static_cast<VMObject*>(inode->vmo());
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
auto vmo = adopt(*new VMObject(move(inode), size));
auto vmo = adopt(*new VMObject(move(inode)));
vmo->inode()->set_vmo(vmo.ptr());
return vmo;
}
@ -720,10 +716,11 @@ VMObject::VMObject(PhysicalAddress paddr, size_t size)
}
VMObject::VMObject(RetainPtr<Inode>&& inode, size_t size)
: m_size(size)
, m_inode(move(inode))
VMObject::VMObject(RetainPtr<Inode>&& inode)
: m_inode(move(inode))
{
ASSERT(m_inode);
m_size = ceil_div(m_inode->size(), PAGE_SIZE) * PAGE_SIZE;
m_physical_pages.resize(page_count());
MM.register_vmo(*this);
}

View file

@ -79,7 +79,7 @@ private:
class VMObject : public Retainable<VMObject> {
friend class MemoryManager;
public:
static RetainPtr<VMObject> create_file_backed(RetainPtr<Inode>&&, size_t);
static RetainPtr<VMObject> create_file_backed(RetainPtr<Inode>&&);
static RetainPtr<VMObject> create_anonymous(size_t);
static RetainPtr<VMObject> create_framebuffer_wrapper(PhysicalAddress, size_t);
RetainPtr<VMObject> clone();
@ -99,7 +99,7 @@ public:
Vector<RetainPtr<PhysicalPage>>& physical_pages() { return m_physical_pages; }
private:
VMObject(RetainPtr<Inode>&&, size_t);
VMObject(RetainPtr<Inode>&&);
explicit VMObject(VMObject&);
explicit VMObject(size_t);
VMObject(PhysicalAddress, size_t);

View file

@ -325,7 +325,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
#endif
ProcessPagingScope paging_scope(*this);
auto vmo = VMObject::create_file_backed(descriptor->inode(), descriptor->metadata().size);
auto vmo = VMObject::create_file_backed(descriptor->inode());
vmo->set_name(descriptor->absolute_path());
RetainPtr<Region> region = allocate_region_with_vmo(LinearAddress(), descriptor->metadata().size, vmo.copy_ref(), 0, "helper", true, false);

View file

@ -52,6 +52,7 @@ class Process : public InlineLinkedListNode<Process>, public Weakable<Process> {
friend class InlineLinkedListNode<Process>;
friend class WSWindowManager; // FIXME: Make a better API for allocate_region().
friend class GraphicsBitmap; // FIXME: Make a better API for allocate_region().
friend class Font; //FIXME: This is beyond gross.
public:
static Process* create_kernel_process(String&& name, void (*entry)());
static Process* create_user_process(const String& path, uid_t, gid_t, pid_t ppid, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);

View file

@ -120,6 +120,16 @@ public:
sti();
}
void temporarily_cli()
{
cli();
}
void temporarily_sti()
{
sti();
}
private:
dword m_flags;
};