mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
1682f0b760
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/NonnullRefPtrVector.h>
|
|
#include <Kernel/Process.h>
|
|
#include <Kernel/VM/AnonymousVMObject.h>
|
|
#include <Kernel/VM/InodeVMObject.h>
|
|
#include <Kernel/VM/MemoryManager.h>
|
|
|
|
namespace Kernel {
|
|
|
|
KResultOr<int> Process::sys$purge(int mode)
|
|
{
|
|
REQUIRE_NO_PROMISES;
|
|
if (!is_superuser())
|
|
return EPERM;
|
|
int purged_page_count = 0;
|
|
if (mode & PURGE_ALL_VOLATILE) {
|
|
NonnullRefPtrVector<AnonymousVMObject> vmobjects;
|
|
{
|
|
InterruptDisabler disabler;
|
|
MM.for_each_vmobject([&](auto& vmobject) {
|
|
if (vmobject.is_anonymous())
|
|
vmobjects.append(vmobject);
|
|
return IterationDecision::Continue;
|
|
});
|
|
}
|
|
for (auto& vmobject : vmobjects) {
|
|
purged_page_count += vmobject.purge();
|
|
}
|
|
}
|
|
if (mode & PURGE_ALL_CLEAN_INODE) {
|
|
NonnullRefPtrVector<InodeVMObject> vmobjects;
|
|
{
|
|
InterruptDisabler disabler;
|
|
MM.for_each_vmobject([&](auto& vmobject) {
|
|
if (vmobject.is_inode())
|
|
vmobjects.append(static_cast<InodeVMObject&>(vmobject));
|
|
return IterationDecision::Continue;
|
|
});
|
|
}
|
|
for (auto& vmobject : vmobjects) {
|
|
purged_page_count += vmobject.release_all_clean_pages();
|
|
}
|
|
}
|
|
return purged_page_count;
|
|
}
|
|
|
|
}
|