strat: use m_ for member variables

This commit is contained in:
Michael Scire
2021-10-10 00:14:06 -07:00
parent ce28591ab2
commit a595c232b9
425 changed files with 8531 additions and 8484 deletions

View File

@@ -23,14 +23,14 @@ namespace ams::fssystem::buffers {
class ThreadLocalStorageWrapper {
private:
os::TlsSlot tls_slot;
os::TlsSlot m_tls_slot;
public:
ThreadLocalStorageWrapper() { R_ABORT_UNLESS(os::AllocateTlsSlot(std::addressof(this->tls_slot), nullptr)); }
~ThreadLocalStorageWrapper() { os::FreeTlsSlot(this->tls_slot); }
ThreadLocalStorageWrapper() { R_ABORT_UNLESS(os::AllocateTlsSlot(std::addressof(m_tls_slot), nullptr)); }
~ThreadLocalStorageWrapper() { os::FreeTlsSlot(m_tls_slot); }
void SetValue(uintptr_t value) { os::SetTlsValue(this->tls_slot, value); }
uintptr_t GetValue() const { return os::GetTlsValue(this->tls_slot); }
os::TlsSlot GetTlsSlot() const { return this->tls_slot; }
void SetValue(uintptr_t value) { os::SetTlsValue(m_tls_slot, value); }
uintptr_t GetValue() const { return os::GetTlsValue(m_tls_slot); }
os::TlsSlot GetTlsSlot() const { return m_tls_slot; }
} g_buffer_manager_context_tls_slot;
}

View File

@@ -18,22 +18,22 @@
namespace ams::fssystem {
FileSystemBuddyHeap::PageEntry *FileSystemBuddyHeap::PageList::PopFront() {
AMS_ASSERT(this->entry_count > 0);
AMS_ASSERT(m_entry_count > 0);
/* Get the first entry. */
auto page_entry = this->first_page_entry;
auto page_entry = m_first_page_entry;
/* Advance our list. */
this->first_page_entry = page_entry->next;
m_first_page_entry = page_entry->next;
page_entry->next = nullptr;
/* Decrement our count. */
--this->entry_count;
AMS_ASSERT(this->entry_count >= 0);
--m_entry_count;
AMS_ASSERT(m_entry_count >= 0);
/* If this was our last page, clear our last entry. */
if (this->entry_count == 0) {
this->last_page_entry = nullptr;
if (m_entry_count == 0) {
m_last_page_entry = nullptr;
}
return page_entry;
@@ -44,20 +44,20 @@ namespace ams::fssystem {
/* If we're empty, we want to set the first page entry. */
if (this->IsEmpty()) {
this->first_page_entry = page_entry;
m_first_page_entry = page_entry;
} else {
/* We're not empty, so push the page to the back. */
AMS_ASSERT(this->last_page_entry != page_entry);
this->last_page_entry->next = page_entry;
AMS_ASSERT(m_last_page_entry != page_entry);
m_last_page_entry->next = page_entry;
}
/* Set our last page entry to be this one, and link it to the list. */
this->last_page_entry = page_entry;
this->last_page_entry->next = nullptr;
m_last_page_entry = page_entry;
m_last_page_entry->next = nullptr;
/* Increment our entry count. */
++this->entry_count;
AMS_ASSERT(this->entry_count > 0);
++m_entry_count;
AMS_ASSERT(m_entry_count > 0);
}
bool FileSystemBuddyHeap::PageList::Remove(PageEntry *page_entry) {
@@ -70,18 +70,18 @@ namespace ams::fssystem {
/* We're going to loop over all pages to find this one, then unlink it. */
PageEntry *prev_entry = nullptr;
PageEntry *cur_entry = this->first_page_entry;
PageEntry *cur_entry = m_first_page_entry;
while (true) {
/* Check if we found the page. */
if (cur_entry == page_entry) {
if (cur_entry == this->first_page_entry) {
if (cur_entry == m_first_page_entry) {
/* If it's the first page, we just set our first. */
this->first_page_entry = cur_entry->next;
} else if (cur_entry == this->last_page_entry) {
m_first_page_entry = cur_entry->next;
} else if (cur_entry == m_last_page_entry) {
/* If it's the last page, we set our last. */
this->last_page_entry = prev_entry;
this->last_page_entry->next = nullptr;
m_last_page_entry = prev_entry;
m_last_page_entry->next = nullptr;
} else {
/* If it's in the middle, we just unlink. */
prev_entry->next = cur_entry->next;
@@ -91,8 +91,8 @@ namespace ams::fssystem {
cur_entry->next = nullptr;
/* Update our entry count. */
--this->entry_count;
AMS_ASSERT(this->entry_count >= 0);
--m_entry_count;
AMS_ASSERT(m_entry_count >= 0);
return true;
}
@@ -110,7 +110,7 @@ namespace ams::fssystem {
Result FileSystemBuddyHeap::Initialize(uintptr_t address, size_t size, size_t block_size, s32 order_max) {
/* Ensure our preconditions. */
AMS_ASSERT(this->free_lists == nullptr);
AMS_ASSERT(m_free_lists == nullptr);
AMS_ASSERT(address != 0);
AMS_ASSERT(util::IsAligned(address, BufferAlignment));
AMS_ASSERT(block_size >= BlockSizeMin);
@@ -120,74 +120,74 @@ namespace ams::fssystem {
AMS_ASSERT(order_max < OrderUpperLimit);
/* Set up our basic member variables */
this->block_size = block_size;
this->order_max = order_max;
this->heap_start = address;
this->heap_size = (size / this->block_size) * this->block_size;
m_block_size = block_size;
m_order_max = order_max;
m_heap_start = address;
m_heap_size = (size / m_block_size) * m_block_size;
this->total_free_size = 0;
m_total_free_size = 0;
/* Determine page sizes. */
const auto max_page_size = this->block_size << this->order_max;
const auto max_page_count = util::AlignUp(this->heap_size, max_page_size) / max_page_size;
const auto max_page_size = m_block_size << m_order_max;
const auto max_page_count = util::AlignUp(m_heap_size, max_page_size) / max_page_size;
AMS_ASSERT(max_page_count > 0);
/* Setup the free lists. */
if (this->external_free_lists != nullptr) {
AMS_ASSERT(this->internal_free_lists == nullptr);
this->free_lists = this->external_free_lists;
if (m_external_free_lists != nullptr) {
AMS_ASSERT(m_internal_free_lists == nullptr);
m_free_lists = m_external_free_lists;
} else {
this->internal_free_lists.reset(new PageList[this->order_max + 1]);
this->free_lists = this->internal_free_lists.get();
R_UNLESS(this->free_lists != nullptr, fs::ResultAllocationFailureInFileSystemBuddyHeapA());
m_internal_free_lists.reset(new PageList[m_order_max + 1]);
m_free_lists = m_internal_free_lists.get();
R_UNLESS(m_free_lists != nullptr, fs::ResultAllocationFailureInFileSystemBuddyHeapA());
}
/* All but the last page region should go to the max order. */
for (size_t i = 0; i < max_page_count - 1; i++) {
auto page_entry = this->GetPageEntryFromAddress(this->heap_start + i * max_page_size);
this->free_lists[this->order_max].PushBack(page_entry);
auto page_entry = this->GetPageEntryFromAddress(m_heap_start + i * max_page_size);
m_free_lists[m_order_max].PushBack(page_entry);
}
this->total_free_size += this->free_lists[this->order_max].GetSize() * this->GetBytesFromOrder(this->order_max);
m_total_free_size += m_free_lists[m_order_max].GetSize() * this->GetBytesFromOrder(m_order_max);
/* Allocate remaining space to smaller orders as possible. */
{
auto remaining = this->heap_size - (max_page_count - 1) * max_page_size;
auto cur_address = this->heap_start + (max_page_count - 1) * max_page_size;
AMS_ASSERT(util::IsAligned(remaining, this->block_size));
auto remaining = m_heap_size - (max_page_count - 1) * max_page_size;
auto cur_address = m_heap_start + (max_page_count - 1) * max_page_size;
AMS_ASSERT(util::IsAligned(remaining, m_block_size));
do {
/* Determine what order we can use. */
auto order = GetOrderFromBytes(remaining + 1);
if (order < 0) {
AMS_ASSERT(GetOrderFromBytes(remaining) == this->order_max);
order = this->order_max + 1;
AMS_ASSERT(GetOrderFromBytes(remaining) == m_order_max);
order = m_order_max + 1;
}
AMS_ASSERT(0 < order);
AMS_ASSERT(order <= this->order_max + 1);
AMS_ASSERT(order <= m_order_max + 1);
/* Add to the correct free list. */
this->free_lists[order - 1].PushBack(GetPageEntryFromAddress(cur_address));
this->total_free_size += GetBytesFromOrder(order - 1);
m_free_lists[order - 1].PushBack(GetPageEntryFromAddress(cur_address));
m_total_free_size += GetBytesFromOrder(order - 1);
/* Move on to the next order. */
const auto page_size = GetBytesFromOrder(order - 1);
cur_address += page_size;
remaining -= page_size;
} while (this->block_size <= remaining);
} while (m_block_size <= remaining);
}
return ResultSuccess();
}
void FileSystemBuddyHeap::Finalize() {
AMS_ASSERT(this->free_lists != nullptr);
this->free_lists = nullptr;
this->external_free_lists = nullptr;
this->internal_free_lists.reset();
AMS_ASSERT(m_free_lists != nullptr);
m_free_lists = nullptr;
m_external_free_lists = nullptr;
m_internal_free_lists.reset();
}
void *FileSystemBuddyHeap::AllocateByOrder(s32 order) {
AMS_ASSERT(this->free_lists != nullptr);
AMS_ASSERT(m_free_lists != nullptr);
AMS_ASSERT(order >= 0);
AMS_ASSERT(order <= this->GetOrderMax());
@@ -204,7 +204,7 @@ namespace ams::fssystem {
}
void FileSystemBuddyHeap::Free(void *ptr, s32 order) {
AMS_ASSERT(this->free_lists != nullptr);
AMS_ASSERT(m_free_lists != nullptr);
AMS_ASSERT(order >= 0);
AMS_ASSERT(order <= this->GetOrderMax());
@@ -214,7 +214,7 @@ namespace ams::fssystem {
}
/* Ensure the pointer is block aligned. */
AMS_ASSERT(util::IsAligned(reinterpret_cast<uintptr_t>(ptr) - this->heap_start, this->GetBlockSize()));
AMS_ASSERT(util::IsAligned(reinterpret_cast<uintptr_t>(ptr) - m_heap_start, this->GetBlockSize()));
/* Get the page entry. */
auto page_entry = this->GetPageEntryFromAddress(reinterpret_cast<uintptr_t>(ptr));
@@ -225,16 +225,16 @@ namespace ams::fssystem {
}
size_t FileSystemBuddyHeap::GetTotalFreeSize() const {
AMS_ASSERT(this->free_lists != nullptr);
return this->total_free_size;
AMS_ASSERT(m_free_lists != nullptr);
return m_total_free_size;
}
size_t FileSystemBuddyHeap::GetAllocatableSizeMax() const {
AMS_ASSERT(this->free_lists != nullptr);
AMS_ASSERT(m_free_lists != nullptr);
/* The maximum allocatable size is a chunk from the biggest non-empty order. */
for (s32 order = this->GetOrderMax(); order >= 0; --order) {
if (!this->free_lists[order].IsEmpty()) {
if (!m_free_lists[order].IsEmpty()) {
return this->GetBytesFromOrder(order);
}
}
@@ -244,7 +244,7 @@ namespace ams::fssystem {
}
void FileSystemBuddyHeap::Dump() const {
AMS_ASSERT(this->free_lists != nullptr);
AMS_ASSERT(m_free_lists != nullptr);
/* TODO: Support logging metrics. */
}
@@ -263,8 +263,8 @@ namespace ams::fssystem {
auto divided_entry = this->GetPageEntryFromAddress(address);
/* Push back to the list. */
this->free_lists[order - 1].PushBack(divided_entry);
this->total_free_size += this->GetBytesFromOrder(order - 1);
m_free_lists[order - 1].PushBack(divided_entry);
m_total_free_size += this->GetBytesFromOrder(order - 1);
}
}
@@ -281,8 +281,8 @@ namespace ams::fssystem {
const auto buddy_entry = this->GetBuddy(cur_entry, cur_order);
/* Check whether the buddy is in the relevant free list. */
if (buddy_entry != nullptr && this->free_lists[cur_order].Remove(buddy_entry)) {
this->total_free_size -= GetBytesFromOrder(cur_order);
if (buddy_entry != nullptr && m_free_lists[cur_order].Remove(buddy_entry)) {
m_total_free_size -= GetBytesFromOrder(cur_order);
/* Ensure we coalesce with the correct buddy when page is aligned */
if (!this->IsAlignedToOrder(cur_entry, cur_order + 1)) {
@@ -297,8 +297,8 @@ namespace ams::fssystem {
}
/* Insert the coalesced entry into the free list. */
this->free_lists[cur_order].PushBack(cur_entry);
this->total_free_size += this->GetBytesFromOrder(cur_order);
m_free_lists[cur_order].PushBack(cur_entry);
m_total_free_size += this->GetBytesFromOrder(cur_order);
}
FileSystemBuddyHeap::PageEntry *FileSystemBuddyHeap::GetBuddy(PageEntry *page_entry, s32 order) {
@@ -311,10 +311,10 @@ namespace ams::fssystem {
if (this->IsAlignedToOrder(page_entry, order + 1)) {
/* If the page entry is aligned to the next order, return the buddy block to the right of the current entry. */
return (address + offset < this->heap_start + this->heap_size) ? GetPageEntryFromAddress(address + offset) : nullptr;
return (address + offset < m_heap_start + m_heap_size) ? GetPageEntryFromAddress(address + offset) : nullptr;
} else {
/* If the page entry isn't aligned, return the buddy block to the left of the current entry. */
return (this->heap_start <= address - offset) ? GetPageEntryFromAddress(address - offset) : nullptr;
return (m_heap_start <= address - offset) ? GetPageEntryFromAddress(address - offset) : nullptr;
}
}
@@ -324,13 +324,13 @@ namespace ams::fssystem {
/* Try orders from low to high until we find a free page entry. */
for (auto cur_order = order; cur_order <= this->GetOrderMax(); cur_order++) {
if (auto &free_list = this->free_lists[cur_order]; !free_list.IsEmpty()) {
if (auto &free_list = m_free_lists[cur_order]; !free_list.IsEmpty()) {
/* The current list isn't empty, so grab an entry from it. */
PageEntry *page_entry = free_list.PopFront();
AMS_ASSERT(page_entry != nullptr);
/* Update size bookkeeping. */
this->total_free_size -= GetBytesFromOrder(cur_order);
m_total_free_size -= GetBytesFromOrder(cur_order);
/* If we allocated more memory than needed, free the unneeded portion. */
this->DivideBuddies(page_entry, order, cur_order);

View File

@@ -19,54 +19,54 @@ namespace ams::fssystem {
Result FileSystemBufferManager::CacheHandleTable::Initialize(s32 max_cache_count) {
/* Validate pre-conditions. */
AMS_ASSERT(this->entries == nullptr);
AMS_ASSERT(this->internal_entry_buffer == nullptr);
AMS_ASSERT(m_entries == nullptr);
AMS_ASSERT(m_internal_entry_buffer == nullptr);
/* If we don't have an external buffer, try to allocate an internal one. */
if (this->external_entry_buffer == nullptr) {
this->entry_buffer_size = sizeof(Entry) * max_cache_count;
this->internal_entry_buffer = fs::impl::MakeUnique<char[]>(this->entry_buffer_size);
if (m_external_entry_buffer == nullptr) {
m_entry_buffer_size = sizeof(Entry) * max_cache_count;
m_internal_entry_buffer = fs::impl::MakeUnique<char[]>(m_entry_buffer_size);
}
/* We need to have at least one entry buffer. */
R_UNLESS(this->internal_entry_buffer != nullptr || this->external_entry_buffer != nullptr, fs::ResultAllocationFailureInFileSystemBufferManagerA());
R_UNLESS(m_internal_entry_buffer != nullptr || m_external_entry_buffer != nullptr, fs::ResultAllocationFailureInFileSystemBufferManagerA());
/* Set entries. */
this->entries = reinterpret_cast<Entry *>(this->external_entry_buffer != nullptr ? this->external_entry_buffer : this->internal_entry_buffer.get());
this->entry_count = 0;
this->entry_count_max = max_cache_count;
AMS_ASSERT(this->entries != nullptr);
m_entries = reinterpret_cast<Entry *>(m_external_entry_buffer != nullptr ? m_external_entry_buffer : m_internal_entry_buffer.get());
m_entry_count = 0;
m_entry_count_max = max_cache_count;
AMS_ASSERT(m_entries != nullptr);
this->cache_count_min = max_cache_count / 16;
this->cache_size_min = this->cache_count_min * 0x100;
m_cache_count_min = max_cache_count / 16;
m_cache_size_min = m_cache_count_min * 0x100;
return ResultSuccess();
}
void FileSystemBufferManager::CacheHandleTable::Finalize() {
if (this->entries != nullptr) {
AMS_ASSERT(this->entry_count == 0);
if (m_entries != nullptr) {
AMS_ASSERT(m_entry_count == 0);
if (this->external_attr_info_buffer == nullptr) {
auto it = this->attr_list.begin();
while (it != this->attr_list.end()) {
if (m_external_attr_info_buffer == nullptr) {
auto it = m_attr_list.begin();
while (it != m_attr_list.end()) {
const auto attr_info = std::addressof(*it);
it = this->attr_list.erase(it);
it = m_attr_list.erase(it);
delete attr_info;
}
}
this->internal_entry_buffer.reset();
this->external_entry_buffer = nullptr;
this->entry_buffer_size = 0;
this->entries = nullptr;
this->total_cache_size = 0;
m_internal_entry_buffer.reset();
m_external_entry_buffer = nullptr;
m_entry_buffer_size = 0;
m_entries = nullptr;
m_total_cache_size = 0;
}
}
bool FileSystemBufferManager::CacheHandleTable::Register(CacheHandle *out, uintptr_t address, size_t size, const BufferAttribute &attr) {
/* Validate pre-conditions. */
AMS_ASSERT(this->entries != nullptr);
AMS_ASSERT(m_entries != nullptr);
AMS_ASSERT(out != nullptr);
/* Get the entry. */
@@ -85,10 +85,10 @@ namespace ams::fssystem {
/* Make a new attr info and add it to the list. */
AttrInfo *new_info = nullptr;
if (this->external_attr_info_buffer == nullptr) {
if (m_external_attr_info_buffer == nullptr) {
new_info = new AttrInfo(attr.GetLevel(), 1, size);
} else if (0 <= attr.GetLevel() && attr.GetLevel() < this->external_attr_info_count) {
void *buffer = this->external_attr_info_buffer + attr.GetLevel() * sizeof(AttrInfo);
} else if (0 <= attr.GetLevel() && attr.GetLevel() < m_external_attr_info_count) {
void *buffer = m_external_attr_info_buffer + attr.GetLevel() * sizeof(AttrInfo);
new_info = std::construct_at(reinterpret_cast<AttrInfo *>(buffer), attr.GetLevel(), 1, size);
}
@@ -98,27 +98,27 @@ namespace ams::fssystem {
return false;
}
this->attr_list.push_back(*new_info);
m_attr_list.push_back(*new_info);
}
this->total_cache_size += size;
m_total_cache_size += size;
*out = entry->GetHandle();
return true;
}
bool FileSystemBufferManager::CacheHandleTable::Unregister(uintptr_t *out_address, size_t *out_size, CacheHandle handle) {
/* Validate pre-conditions. */
AMS_ASSERT(this->entries != nullptr);
AMS_ASSERT(m_entries != nullptr);
AMS_ASSERT(out_address != nullptr);
AMS_ASSERT(out_size != nullptr);
/* Find the lower bound for the entry. */
const auto entry = std::lower_bound(this->entries, this->entries + this->entry_count, handle, [](const Entry &entry, CacheHandle handle) {
const auto entry = std::lower_bound(m_entries, m_entries + m_entry_count, handle, [](const Entry &entry, CacheHandle handle) {
return entry.GetHandle() < handle;
});
/* If the entry is a match, unregister it. */
if (entry != this->entries + this->entry_count && entry->GetHandle() == handle) {
if (entry != m_entries + m_entry_count && entry->GetHandle() == handle) {
this->UnregisterCore(out_address, out_size, entry);
return true;
} else {
@@ -130,12 +130,12 @@ namespace ams::fssystem {
AMS_UNUSED(attr, required_size);
/* Validate pre-conditions. */
AMS_ASSERT(this->entries != nullptr);
AMS_ASSERT(m_entries != nullptr);
AMS_ASSERT(out_address != nullptr);
AMS_ASSERT(out_size != nullptr);
/* If we have no entries, we can't unregister any. */
if (this->entry_count == 0) {
if (m_entry_count == 0) {
return false;
}
@@ -150,19 +150,19 @@ namespace ams::fssystem {
};
/* Find an entry, falling back to the first entry. */
auto entry = std::find_if(this->entries, this->entries + this->entry_count, CanUnregister);
if (entry == this->entries + this->entry_count) {
entry = this->entries;
auto entry = std::find_if(m_entries, m_entries + m_entry_count, CanUnregister);
if (entry == m_entries + m_entry_count) {
entry = m_entries;
}
AMS_ASSERT(entry != this->entries + this->entry_count);
AMS_ASSERT(entry != m_entries + m_entry_count);
this->UnregisterCore(out_address, out_size, entry);
return true;
}
void FileSystemBufferManager::CacheHandleTable::UnregisterCore(uintptr_t *out_address, size_t *out_size, Entry *entry) {
/* Validate pre-conditions. */
AMS_ASSERT(this->entries != nullptr);
AMS_ASSERT(m_entries != nullptr);
AMS_ASSERT(out_address != nullptr);
AMS_ASSERT(out_size != nullptr);
AMS_ASSERT(entry != nullptr);
@@ -178,8 +178,8 @@ namespace ams::fssystem {
attr_info->SubtractCacheSize(entry->GetSize());
/* Release from cached size. */
AMS_ASSERT(this->total_cache_size >= entry->GetSize());
this->total_cache_size -= entry->GetSize();
AMS_ASSERT(m_total_cache_size >= entry->GetSize());
m_total_cache_size -= entry->GetSize();
/* Release the entry. */
*out_address = entry->GetAddress();
@@ -188,24 +188,24 @@ namespace ams::fssystem {
}
FileSystemBufferManager::CacheHandle FileSystemBufferManager::CacheHandleTable::PublishCacheHandle() {
AMS_ASSERT(this->entries != nullptr);
return (++this->current_handle);
AMS_ASSERT(m_entries != nullptr);
return (++m_current_handle);
}
size_t FileSystemBufferManager::CacheHandleTable::GetTotalCacheSize() const {
return this->total_cache_size;
return m_total_cache_size;
}
FileSystemBufferManager::CacheHandleTable::Entry *FileSystemBufferManager::CacheHandleTable::AcquireEntry(uintptr_t address, size_t size, const BufferAttribute &attr) {
/* Validate pre-conditions. */
AMS_ASSERT(this->entries != nullptr);
AMS_ASSERT(m_entries != nullptr);
Entry *entry = nullptr;
if (this->entry_count < this->entry_count_max) {
entry = this->entries + this->entry_count;
if (m_entry_count < m_entry_count_max) {
entry = m_entries + m_entry_count;
entry->Initialize(this->PublishCacheHandle(), address, size, attr);
++this->entry_count;
AMS_ASSERT(this->entry_count == 1 || (entry-1)->GetHandle() < entry->GetHandle());
++m_entry_count;
AMS_ASSERT(m_entry_count == 1 || (entry-1)->GetHandle() < entry->GetHandle());
}
return entry;
@@ -213,52 +213,52 @@ namespace ams::fssystem {
void FileSystemBufferManager::CacheHandleTable::ReleaseEntry(Entry *entry) {
/* Validate pre-conditions. */
AMS_ASSERT(this->entries != nullptr);
AMS_ASSERT(m_entries != nullptr);
AMS_ASSERT(entry != nullptr);
/* Ensure the entry is valid. */
{
const auto entry_buffer = this->external_entry_buffer != nullptr ? this->external_entry_buffer : this->internal_entry_buffer.get();
const auto entry_buffer = m_external_entry_buffer != nullptr ? m_external_entry_buffer : m_internal_entry_buffer.get();
AMS_ASSERT(static_cast<void *>(entry_buffer) <= static_cast<void *>(entry));
AMS_ASSERT(static_cast<void *>(entry) < static_cast<void *>(entry_buffer + this->entry_buffer_size));
AMS_ASSERT(static_cast<void *>(entry) < static_cast<void *>(entry_buffer + m_entry_buffer_size));
AMS_UNUSED(entry_buffer);
}
/* Copy the entries back by one. */
std::memmove(entry, entry + 1, sizeof(Entry) * (this->entry_count - ((entry + 1) - this->entries)));
std::memmove(entry, entry + 1, sizeof(Entry) * (m_entry_count - ((entry + 1) - m_entries)));
/* Decrement our entry count. */
--this->entry_count;
--m_entry_count;
}
FileSystemBufferManager::CacheHandleTable::AttrInfo *FileSystemBufferManager::CacheHandleTable::FindAttrInfo(const BufferAttribute &attr) {
const auto it = std::find_if(this->attr_list.begin(), this->attr_list.end(), [&attr](const AttrInfo &info) {
const auto it = std::find_if(m_attr_list.begin(), m_attr_list.end(), [&attr](const AttrInfo &info) {
return attr.GetLevel() == info.GetLevel();
});
return it != this->attr_list.end() ? std::addressof(*it) : nullptr;
return it != m_attr_list.end() ? std::addressof(*it) : nullptr;
}
const std::pair<uintptr_t, size_t> FileSystemBufferManager::AllocateBufferImpl(size_t size, const BufferAttribute &attr) {
std::scoped_lock lk(this->mutex);
std::scoped_lock lk(m_mutex);
std::pair<uintptr_t, size_t> range = {};
const auto order = this->buddy_heap.GetOrderFromBytes(size);
const auto order = m_buddy_heap.GetOrderFromBytes(size);
AMS_ASSERT(order >= 0);
while (true) {
if (auto address = this->buddy_heap.AllocateByOrder(order); address != 0) {
const auto allocated_size = this->buddy_heap.GetBytesFromOrder(order);
if (auto address = m_buddy_heap.AllocateByOrder(order); address != 0) {
const auto allocated_size = m_buddy_heap.GetBytesFromOrder(order);
AMS_ASSERT(size <= allocated_size);
range.first = reinterpret_cast<uintptr_t>(address);
range.second = allocated_size;
const size_t free_size = this->buddy_heap.GetTotalFreeSize();
this->peak_free_size = std::min(this->peak_free_size, free_size);
const size_t free_size = m_buddy_heap.GetTotalFreeSize();
m_peak_free_size = std::min(m_peak_free_size, free_size);
const size_t total_allocatable_size = free_size + this->cache_handle_table.GetTotalCacheSize();
this->peak_total_allocatable_size = std::min(this->peak_total_allocatable_size, total_allocatable_size);
const size_t total_allocatable_size = free_size + m_cache_handle_table.GetTotalCacheSize();
m_peak_total_allocatable_size = std::min(m_peak_total_allocatable_size, total_allocatable_size);
break;
}
@@ -266,8 +266,8 @@ namespace ams::fssystem {
uintptr_t deallocate_address = 0;
size_t deallocate_size = 0;
++this->retried_count;
if (this->cache_handle_table.UnregisterOldest(std::addressof(deallocate_address), std::addressof(deallocate_size), attr, size)) {
++m_retried_count;
if (m_cache_handle_table.UnregisterOldest(std::addressof(deallocate_address), std::addressof(deallocate_size), attr, size)) {
this->DeallocateBuffer(deallocate_address, deallocate_size);
} else {
break;
@@ -280,18 +280,18 @@ namespace ams::fssystem {
void FileSystemBufferManager::DeallocateBufferImpl(uintptr_t address, size_t size) {
AMS_ASSERT(util::IsPowerOfTwo(size));
std::scoped_lock lk(this->mutex);
std::scoped_lock lk(m_mutex);
this->buddy_heap.Free(reinterpret_cast<void *>(address), this->buddy_heap.GetOrderFromBytes(size));
m_buddy_heap.Free(reinterpret_cast<void *>(address), m_buddy_heap.GetOrderFromBytes(size));
}
FileSystemBufferManager::CacheHandle FileSystemBufferManager::RegisterCacheImpl(uintptr_t address, size_t size, const BufferAttribute &attr) {
std::scoped_lock lk(this->mutex);
std::scoped_lock lk(m_mutex);
CacheHandle handle = 0;
while (true) {
/* Try to register the handle. */
if (this->cache_handle_table.Register(std::addressof(handle), address, size, attr)) {
if (m_cache_handle_table.Register(std::addressof(handle), address, size, attr)) {
break;
}
@@ -299,12 +299,12 @@ namespace ams::fssystem {
uintptr_t deallocate_address = 0;
size_t deallocate_size = 0;
++this->retried_count;
if (this->cache_handle_table.UnregisterOldest(std::addressof(deallocate_address), std::addressof(deallocate_size), attr)) {
++m_retried_count;
if (m_cache_handle_table.UnregisterOldest(std::addressof(deallocate_address), std::addressof(deallocate_size), attr)) {
this->DeallocateBuffer(deallocate_address, deallocate_size);
} else {
this->DeallocateBuffer(address, size);
handle = this->cache_handle_table.PublishCacheHandle();
handle = m_cache_handle_table.PublishCacheHandle();
break;
}
}
@@ -313,12 +313,12 @@ namespace ams::fssystem {
}
const std::pair<uintptr_t, size_t> FileSystemBufferManager::AcquireCacheImpl(CacheHandle handle) {
std::scoped_lock lk(this->mutex);
std::scoped_lock lk(m_mutex);
std::pair<uintptr_t, size_t> range = {};
if (this->cache_handle_table.Unregister(std::addressof(range.first), std::addressof(range.second), handle)) {
const size_t total_allocatable_size = this->buddy_heap.GetTotalFreeSize() + this->cache_handle_table.GetTotalCacheSize();
this->peak_total_allocatable_size = std::min(this->peak_total_allocatable_size, total_allocatable_size);
if (m_cache_handle_table.Unregister(std::addressof(range.first), std::addressof(range.second), handle)) {
const size_t total_allocatable_size = m_buddy_heap.GetTotalFreeSize() + m_cache_handle_table.GetTotalCacheSize();
m_peak_total_allocatable_size = std::min(m_peak_total_allocatable_size, total_allocatable_size);
} else {
range.first = 0;
range.second = 0;
@@ -328,34 +328,34 @@ namespace ams::fssystem {
}
size_t FileSystemBufferManager::GetTotalSizeImpl() const {
return this->total_size;
return m_total_size;
}
size_t FileSystemBufferManager::GetFreeSizeImpl() const {
std::scoped_lock lk(this->mutex);
std::scoped_lock lk(m_mutex);
return this->buddy_heap.GetTotalFreeSize();
return m_buddy_heap.GetTotalFreeSize();
}
size_t FileSystemBufferManager::GetTotalAllocatableSizeImpl() const {
return this->GetFreeSize() + this->cache_handle_table.GetTotalCacheSize();
return this->GetFreeSize() + m_cache_handle_table.GetTotalCacheSize();
}
size_t FileSystemBufferManager::GetPeakFreeSizeImpl() const {
return this->peak_free_size;
return m_peak_free_size;
}
size_t FileSystemBufferManager::GetPeakTotalAllocatableSizeImpl() const {
return this->peak_total_allocatable_size;
return m_peak_total_allocatable_size;
}
size_t FileSystemBufferManager::GetRetriedCountImpl() const {
return this->retried_count;
return m_retried_count;
}
void FileSystemBufferManager::ClearPeakImpl() {
this->peak_free_size = this->GetFreeSize();
this->retried_count = 0;
m_peak_free_size = this->GetFreeSize();
m_retried_count = 0;
}
}