mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
Kernel: Add for_each_vmobject_of_type<T>
This makes iterating over a specific type of VMObjects a bit nicer.
This commit is contained in:
parent
239fd33405
commit
55f61c0004
8 changed files with 57 additions and 16 deletions
|
@ -671,9 +671,8 @@ int Process::sys$purge(int mode)
|
||||||
NonnullRefPtrVector<PurgeableVMObject> vmobjects;
|
NonnullRefPtrVector<PurgeableVMObject> vmobjects;
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
MM.for_each_vmobject([&](auto& vmobject) {
|
MM.for_each_vmobject_of_type<PurgeableVMObject>([&](auto& vmobject) {
|
||||||
if (vmobject.is_purgeable())
|
vmobjects.append(vmobject);
|
||||||
vmobjects.append(static_cast<PurgeableVMObject&>(vmobject));
|
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -685,9 +684,8 @@ int Process::sys$purge(int mode)
|
||||||
NonnullRefPtrVector<InodeVMObject> vmobjects;
|
NonnullRefPtrVector<InodeVMObject> vmobjects;
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
MM.for_each_vmobject([&](auto& vmobject) {
|
MM.for_each_vmobject_of_type<InodeVMObject>([&](auto& vmobject) {
|
||||||
if (vmobject.is_inode())
|
vmobjects.append(vmobject);
|
||||||
vmobjects.append(static_cast<InodeVMObject&>(vmobject));
|
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,4 +56,10 @@ private:
|
||||||
virtual bool is_anonymous() const override { return true; }
|
virtual bool is_anonymous() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool is<AnonymousVMObject>(const VMObject& vmobject)
|
||||||
|
{
|
||||||
|
return vmobject.is_anonymous();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,4 +50,11 @@ private:
|
||||||
|
|
||||||
virtual bool is_contiguous() const override { return true; }
|
virtual bool is_contiguous() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool is<ContiguousVMObject>(const VMObject& vmobject)
|
||||||
|
{
|
||||||
|
return vmobject.is_contiguous();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,4 +66,10 @@ protected:
|
||||||
Bitmap m_dirty_pages;
|
Bitmap m_dirty_pages;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool is<InodeVMObject>(const VMObject& vmobject)
|
||||||
|
{
|
||||||
|
return vmobject.is_inode();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,16 +441,13 @@ RefPtr<PhysicalPage> MemoryManager::allocate_user_physical_page(ShouldZeroFill s
|
||||||
klog() << "MM: no user physical regions available (?)";
|
klog() << "MM: no user physical regions available (?)";
|
||||||
}
|
}
|
||||||
|
|
||||||
for_each_vmobject([&](auto& vmobject) {
|
for_each_vmobject_of_type<PurgeableVMObject>([&](auto& vmobject) {
|
||||||
if (vmobject.is_purgeable()) {
|
int purged_page_count = vmobject.purge_with_interrupts_disabled({});
|
||||||
auto& purgeable_vmobject = static_cast<PurgeableVMObject&>(vmobject);
|
if (purged_page_count) {
|
||||||
int purged_page_count = purgeable_vmobject.purge_with_interrupts_disabled({});
|
klog() << "MM: Purge saved the day! Purged " << purged_page_count << " pages from PurgeableVMObject{" << &vmobject << "}";
|
||||||
if (purged_page_count) {
|
page = find_free_user_physical_page();
|
||||||
klog() << "MM: Purge saved the day! Purged " << purged_page_count << " pages from PurgeableVMObject{" << &purgeable_vmobject << "}";
|
ASSERT(page);
|
||||||
page = find_free_user_physical_page();
|
return IterationDecision::Break;
|
||||||
ASSERT(page);
|
|
||||||
return IterationDecision::Break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|
|
@ -125,6 +125,17 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename Callback>
|
||||||
|
static void for_each_vmobject_of_type(Callback callback)
|
||||||
|
{
|
||||||
|
for (auto& vmobject : MM.m_vmobjects) {
|
||||||
|
if (!is<T>(vmobject))
|
||||||
|
continue;
|
||||||
|
if (callback(static_cast<T&>(vmobject)) == IterationDecision::Break)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Region* region_from_vaddr(Process&, VirtualAddress);
|
static Region* region_from_vaddr(Process&, VirtualAddress);
|
||||||
static const Region* region_from_vaddr(const Process&, VirtualAddress);
|
static const Region* region_from_vaddr(const Process&, VirtualAddress);
|
||||||
|
|
||||||
|
|
|
@ -64,4 +64,10 @@ private:
|
||||||
bool m_volatile { false };
|
bool m_volatile { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool is<PurgeableVMObject>(const VMObject& vmobject)
|
||||||
|
{
|
||||||
|
return vmobject.is_purgeable();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,4 +84,14 @@ private:
|
||||||
VMObject(VMObject&&) = delete;
|
VMObject(VMObject&&) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool is(const VMObject&) { return false; }
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline T& to(VMObject& object)
|
||||||
|
{
|
||||||
|
ASSERT(is<typename RemoveConst<T>::Type>(object));
|
||||||
|
return static_cast<T&>(object);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue