mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:37:34 +00:00
Kernel: Handle string format errors in SlabAllocator stats :^)
Switch to KString::formatted and fix API so we can propagate errors.
This commit is contained in:
parent
a0e59099fc
commit
74ee491b84
3 changed files with 25 additions and 17 deletions
|
@ -412,11 +412,14 @@ private:
|
||||||
json.add("super_physical_available", system_memory.super_physical_pages - system_memory.super_physical_pages_used);
|
json.add("super_physical_available", system_memory.super_physical_pages - system_memory.super_physical_pages_used);
|
||||||
json.add("kmalloc_call_count", stats.kmalloc_call_count);
|
json.add("kmalloc_call_count", stats.kmalloc_call_count);
|
||||||
json.add("kfree_call_count", stats.kfree_call_count);
|
json.add("kfree_call_count", stats.kfree_call_count);
|
||||||
slab_alloc_stats([&json](size_t slab_size, size_t num_allocated, size_t num_free) {
|
TRY(slab_alloc_stats([&json](size_t slab_size, size_t num_allocated, size_t num_free) -> ErrorOr<void> {
|
||||||
auto prefix = String::formatted("slab_{}", slab_size);
|
auto prefix = TRY(KString::formatted("slab_{}", slab_size));
|
||||||
json.add(String::formatted("{}_num_allocated", prefix), num_allocated);
|
auto formatted_num_allocated = TRY(KString::formatted("{}_num_allocated", prefix));
|
||||||
json.add(String::formatted("{}_num_free", prefix), num_free);
|
auto formatted_num_free = TRY(KString::formatted("{}_num_free", prefix));
|
||||||
});
|
json.add(formatted_num_allocated->view(), num_allocated);
|
||||||
|
json.add(formatted_num_free->view(), num_free);
|
||||||
|
return {};
|
||||||
|
}));
|
||||||
json.finish();
|
json.finish();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -952,7 +955,8 @@ ErrorOr<void> ProcFSRootDirectory::traverse_as_directory(FileSystemID fsid, Func
|
||||||
VERIFY(!(process.pid() < 0));
|
VERIFY(!(process.pid() < 0));
|
||||||
u64 process_id = (u64)process.pid().value();
|
u64 process_id = (u64)process.pid().value();
|
||||||
InodeIdentifier identifier = { fsid, static_cast<InodeIndex>(process_id << 36) };
|
InodeIdentifier identifier = { fsid, static_cast<InodeIndex>(process_id << 36) };
|
||||||
TRY(callback({ String::formatted("{:d}", process.pid().value()), identifier, 0 }));
|
auto process_id_string = TRY(KString::formatted("{:d}", process_id));
|
||||||
|
TRY(callback({ process_id_string->view(), identifier, 0 }));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
|
@ -116,13 +116,14 @@ static_assert(sizeof(Memory::Region) <= s_slab_allocator_128.slab_size());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void for_each_allocator(Callback callback)
|
ErrorOr<void> for_each_allocator(Callback callback)
|
||||||
{
|
{
|
||||||
callback(s_slab_allocator_16);
|
TRY(callback(s_slab_allocator_16));
|
||||||
callback(s_slab_allocator_32);
|
TRY(callback(s_slab_allocator_32));
|
||||||
callback(s_slab_allocator_64);
|
TRY(callback(s_slab_allocator_64));
|
||||||
callback(s_slab_allocator_128);
|
TRY(callback(s_slab_allocator_128));
|
||||||
callback(s_slab_allocator_256);
|
TRY(callback(s_slab_allocator_256));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT void slab_alloc_init()
|
UNMAP_AFTER_INIT void slab_alloc_init()
|
||||||
|
@ -164,13 +165,16 @@ void slab_dealloc(void* ptr, size_t slab_size)
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void slab_alloc_stats(Function<void(size_t slab_size, size_t allocated, size_t free)> callback)
|
ErrorOr<void> slab_alloc_stats(Function<ErrorOr<void>(size_t slab_size, size_t allocated, size_t free)> callback)
|
||||||
{
|
{
|
||||||
for_each_allocator([&](auto& allocator) {
|
TRY(for_each_allocator([&](auto& allocator) -> ErrorOr<void> {
|
||||||
auto num_allocated = allocator.num_allocated();
|
auto num_allocated = allocator.num_allocated();
|
||||||
auto num_free = allocator.slab_count() - num_allocated;
|
auto num_free = allocator.slab_count() - num_allocated;
|
||||||
callback(allocator.slab_size(), num_allocated, num_free);
|
TRY(callback(allocator.slab_size(), num_allocated, num_free));
|
||||||
});
|
return {};
|
||||||
|
}));
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Kernel {
|
||||||
void* slab_alloc(size_t slab_size);
|
void* slab_alloc(size_t slab_size);
|
||||||
void slab_dealloc(void*, size_t slab_size);
|
void slab_dealloc(void*, size_t slab_size);
|
||||||
void slab_alloc_init();
|
void slab_alloc_init();
|
||||||
void slab_alloc_stats(Function<void(size_t slab_size, size_t allocated, size_t free)>);
|
ErrorOr<void> slab_alloc_stats(Function<ErrorOr<void>(size_t slab_size, size_t allocated, size_t free)>);
|
||||||
|
|
||||||
#define MAKE_SLAB_ALLOCATED(type) \
|
#define MAKE_SLAB_ALLOCATED(type) \
|
||||||
public: \
|
public: \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue