summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPankaj Raghav <pankydev8@gmail.com>2022-01-29 11:51:21 +0530
committerIdan Horowitz <idan.horowitz@gmail.com>2022-01-29 17:41:06 +0200
commit3b27e28e6745428e832bd0ef5094765f7ea328b1 (patch)
treeb61c26eda8dd489e6145b50038476970f53a2909
parentcf44d71edfec9a8533c2e224d6ec56fbeb48cc7d (diff)
downloadserenity-3b27e28e6745428e832bd0ef5094765f7ea328b1.zip
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.
-rw-r--r--Kernel/Storage/StorageDevice.cpp13
-rw-r--r--Kernel/Storage/StorageDevice.h3
2 files changed, 7 insertions, 9 deletions
diff --git a/Kernel/Storage/StorageDevice.cpp b/Kernel/Storage/StorageDevice.cpp
index 67cc38bcd9..7f9b41ff18 100644
--- a/Kernel/Storage/StorageDevice.cpp
+++ b/Kernel/Storage/StorageDevice.cpp
@@ -18,6 +18,7 @@ StorageDevice::StorageDevice(MajorNumber major, MinorNumber minor, size_t sector
: BlockDevice(major, minor, sector_size)
, m_early_storage_device_name(move(device_name))
, 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 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
// at a time, because it uses a single page for its DMA buffer.
- if (whole_blocks >= blocks_per_page) {
- whole_blocks = blocks_per_page;
+ if (whole_blocks >= m_blocks_per_page) {
+ whole_blocks = m_blocks_per_page;
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 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
// at a time, because it uses a single page for its DMA buffer.
- if (whole_blocks >= blocks_per_page) {
- whole_blocks = blocks_per_page;
+ if (whole_blocks >= m_blocks_per_page) {
+ whole_blocks = m_blocks_per_page;
remaining = 0;
}
diff --git a/Kernel/Storage/StorageDevice.h b/Kernel/Storage/StorageDevice.h
index 404551b69c..b852653a67 100644
--- a/Kernel/Storage/StorageDevice.h
+++ b/Kernel/Storage/StorageDevice.h
@@ -66,7 +66,8 @@ private:
// FIXME: Remove this method after figuring out another scheme for naming.
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 };
};
}