mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:47:34 +00:00
Kernel: Cache blocks_per_page in StorageDevice class
Instead of calculating blocks_per_page in every IO, cache it to save CPU cycles as that value will not change after initialization.
This commit is contained in:
parent
cf44d71edf
commit
3b27e28e67
2 changed files with 7 additions and 9 deletions
|
@ -18,6 +18,7 @@ StorageDevice::StorageDevice(MajorNumber major, MinorNumber minor, size_t sector
|
||||||
: BlockDevice(major, minor, sector_size)
|
: BlockDevice(major, minor, sector_size)
|
||||||
, m_early_storage_device_name(move(device_name))
|
, m_early_storage_device_name(move(device_name))
|
||||||
, m_max_addressable_block(max_addressable_block)
|
, m_max_addressable_block(max_addressable_block)
|
||||||
|
, m_blocks_per_page(PAGE_SIZE / block_size())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,12 +33,10 @@ ErrorOr<size_t> StorageDevice::read(OpenFileDescription&, u64 offset, UserOrKern
|
||||||
size_t whole_blocks = len / block_size();
|
size_t whole_blocks = len / block_size();
|
||||||
size_t remaining = len % block_size();
|
size_t remaining = len % block_size();
|
||||||
|
|
||||||
size_t blocks_per_page = PAGE_SIZE / block_size();
|
|
||||||
|
|
||||||
// PATAChannel will chuck a wobbly if we try to read more than PAGE_SIZE
|
// PATAChannel will chuck a wobbly if we try to read more than PAGE_SIZE
|
||||||
// at a time, because it uses a single page for its DMA buffer.
|
// at a time, because it uses a single page for its DMA buffer.
|
||||||
if (whole_blocks >= blocks_per_page) {
|
if (whole_blocks >= m_blocks_per_page) {
|
||||||
whole_blocks = blocks_per_page;
|
whole_blocks = m_blocks_per_page;
|
||||||
remaining = 0;
|
remaining = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,12 +95,10 @@ ErrorOr<size_t> StorageDevice::write(OpenFileDescription&, u64 offset, const Use
|
||||||
size_t whole_blocks = len / block_size();
|
size_t whole_blocks = len / block_size();
|
||||||
size_t remaining = len % block_size();
|
size_t remaining = len % block_size();
|
||||||
|
|
||||||
size_t blocks_per_page = PAGE_SIZE / block_size();
|
|
||||||
|
|
||||||
// PATAChannel will chuck a wobbly if we try to write more than PAGE_SIZE
|
// PATAChannel will chuck a wobbly if we try to write more than PAGE_SIZE
|
||||||
// at a time, because it uses a single page for its DMA buffer.
|
// at a time, because it uses a single page for its DMA buffer.
|
||||||
if (whole_blocks >= blocks_per_page) {
|
if (whole_blocks >= m_blocks_per_page) {
|
||||||
whole_blocks = blocks_per_page;
|
whole_blocks = m_blocks_per_page;
|
||||||
remaining = 0;
|
remaining = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,8 @@ private:
|
||||||
|
|
||||||
// FIXME: Remove this method after figuring out another scheme for naming.
|
// FIXME: Remove this method after figuring out another scheme for naming.
|
||||||
NonnullOwnPtr<KString> m_early_storage_device_name;
|
NonnullOwnPtr<KString> m_early_storage_device_name;
|
||||||
u64 m_max_addressable_block;
|
u64 m_max_addressable_block { 0 };
|
||||||
|
size_t m_blocks_per_page { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue