Kernel: Reduce ByteBuffer thrashing in inode block list generation

Instead of creating and destroying a new ByteBuffer for every block we
process during block list generation, just use stack memory instead.
This commit is contained in:
Andreas Kling 2020-11-24 18:38:41 +01:00
parent 68abd1cb29
commit 76308c2e1f
Notes: sideshowbarker 2024-07-19 01:16:58 +09:00

View file

@ -484,13 +484,10 @@ Vector<Ext2FS::BlockIndex> Ext2FS::block_list_for_inode_impl(const ext2_inode& e
auto process_block_array = [&](unsigned array_block_index, auto&& callback) {
if (include_block_list_blocks)
add_block(array_block_index);
unsigned count = min(blocks_remaining, entries_per_block);
size_t read_size = count * sizeof(__u32);
auto array_block = ByteBuffer::create_uninitialized(read_size);
auto buffer = UserOrKernelBuffer::for_kernel_buffer(array_block.data());
read_block(array_block_index, &buffer, read_size, 0);
ASSERT(array_block);
auto* array = reinterpret_cast<const __u32*>(array_block.data());
auto count = min(blocks_remaining, entries_per_block);
u32 array[count];
auto buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)array);
read_block(array_block_index, &buffer, sizeof(array), 0);
for (BlockIndex i = 0; i < count; ++i)
callback(array[i]);
};