diff options
author | Anton Kling <anton@kling.gg> | 2024-02-07 11:36:21 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-02-07 22:25:47 +0100 |
commit | 35958c8c6b600482f68fef08ac26547b5655e987 (patch) | |
tree | a3329136adc1b92885c60462e7dd74c98eaa0953 /kernel/fs | |
parent | b7fa1457727338416499d1b0144f1042a6878a97 (diff) |
A lot of small changes
Diffstat (limited to 'kernel/fs')
-rw-r--r-- | kernel/fs/ext2.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/kernel/fs/ext2.c b/kernel/fs/ext2.c index cb4a0d4..60800a9 100644 --- a/kernel/fs/ext2.c +++ b/kernel/fs/ext2.c @@ -30,30 +30,39 @@ void get_inode_data_size(int inode_num, u64 *file_size) { } struct BLOCK_CACHE { + u32 usage; u32 block_num; u8 block[1024]; }; -#define NUM_BLOCK_CACHE 30 -struct BLOCK_CACHE cache[NUM_BLOCK_CACHE] = {0}; -u8 last_taken_cache = 0; +#define NUM_BLOCK_CACHE 3000 +struct BLOCK_CACHE *cache; + +u32 cold_cache_hits = 0; void cached_read_block(u32 block, void *address, size_t size, size_t offset) { int free_found = -1; for (int i = 0; i < NUM_BLOCK_CACHE; i++) { if (cache[i].block_num == block) { + cache[i].usage += 1; memcpy(address, cache[i].block + offset, size); return; } - if (0 == cache[i].block_num) + if (0 == cache[i].block_num) { free_found = i; + } } if (-1 == free_found) { - free_found = last_taken_cache; - last_taken_cache++; - if (last_taken_cache >= NUM_BLOCK_CACHE) - last_taken_cache = 0; + u32 min_usage_value = U32_MAX; + int min_index = 0; + for (int i = 0; i < NUM_BLOCK_CACHE; i++) { + if (cache[i].usage < min_usage_value) { + min_usage_value = cache[i].usage; + min_index = i; + } + } + free_found = min_index; } struct BLOCK_CACHE *c = &cache[free_found]; @@ -763,6 +772,7 @@ int ext2_create_file(const char *path, int mode) { vfs_inode_t *ext2_mount(void) { int fd = vfs_open("/dev/sda", O_RDWR, 0); + cache = kcalloc(3000, sizeof(struct BLOCK_CACHE)); // TODO: Can this be done better? Maybe create a seperate function in // the VFS? mount_fd = get_current_task()->file_descriptors[fd]; |