-
-
Notifications
You must be signed in to change notification settings - Fork 158
BlockCache支持 #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
BlockCache支持 #521
Changes from 11 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
cc6e6c0
save
ZZJJWarth a533535
save
ZZJJWarth a65400a
save
ZZJJWarth dfa85f4
strange error
ZZJJWarth 18d419e
一个优化的尝试
ZZJJWarth 5eed550
dev stable 0.1.0
ZZJJWarth 9cfd87d
save
ZZJJWarth 6287525
完成了简单的blockcache支持,完成了代码注释
ZZJJWarth 053edc3
complete merge
ZZJJWarth 95361e5
save
ZZJJWarth 6e6a6d7
save
ZZJJWarth b2a733c
save
ZZJJWarth c1eb2c7
1
fslongjin 0934fb9
进行了修改
ZZJJWarth 03d9c43
Merge github.com:ZZJJWarth/DragonOS into stable_0.1.1
ZZJJWarth af6a333
修改后的blockcache
ZZJJWarth 7c80caf
Merge branch 'DragonOS-Community:master' into master
ZZJJWarth 7a4a81c
Merge branch 'DragonOS-Community:master' into stable_0.1.1
ZZJJWarth 8335673
Merge branch 'stable_0.1.1' of github.com:ZZJJWarth/DragonOS into sta…
ZZJJWarth 022e65c
第二次修改
ZZJJWarth d173c95
Merge github.com:DragonOS-Community/DragonOS into stable_0.1.1
ZZJJWarth b26b85f
Merge branch 'DragonOS-Community:master' into master
ZZJJWarth 4f909a8
Merge branch 'master' of github.com:ZZJJWarth/DragonOS into stable_0.1.1
ZZJJWarth 5df3212
fmt code
ZZJJWarth 9d64e0c
Merge branch 'DragonOS-Community:master' into master
ZZJJWarth 5041858
Merge branch 'master' of github.com:ZZJJWarth/DragonOS into stable_0.1.1
ZZJJWarth 5eadc37
merge
ZZJJWarth 2fc092b
进行了必要的修改
ZZJJWarth f61989b
Merge branch 'DragonOS-Community:master' into stable_0.1.1
ZZJJWarth 80f32c2
注释修改
ZZJJWarth 49857d0
Merge branch 'stable_0.1.1' of github.com:ZZJJWarth/DragonOS into sta…
ZZJJWarth 3fc6e16
删除无用注释
ZZJJWarth fff4031
Merge branch 'master' of https://github.com/DragonOS-Community/Dragon…
ZZJJWarth 3c67798
fmt
ZZJJWarth d53e8dd
Merge branch 'master' of https://github.com/DragonOS-Community/Dragon…
ZZJJWarth 628b6ec
修复了clippy error
ZZJJWarth 342c56b
save
ZZJJWarth a908a07
save
ZZJJWarth 4e1661d
Merge branch 'DragonOS-Community:master' into stable_0.1.1
ZZJJWarth 127cee5
Merge branch 'stable_0.1.1' of github.com:ZZJJWarth/DragonOS into dev…
ZZJJWarth 09a203c
完成了block_cache的上锁操作
ZZJJWarth 8b1a8bc
Merge branch 'DragonOS-Community:master' into stable_0.1.1
ZZJJWarth dc4af16
Merge branch 'DragonOS-Community:master' into stable_0.1.1
ZZJJWarth f4b8f63
Merge branch 'stable_0.1.1' of github.com:ZZJJWarth/DragonOS into dev…
ZZJJWarth 8df080b
Merge branch 'master' of https://github.com/DragonOS-Community/Dragon…
ZZJJWarth 1a0c493
将部分usize修改为BlockId
ZZJJWarth f9cefd6
Merge branch 'master' of https://github.com/DragonOS-Community/Dragon…
ZZJJWarth 16c6a5e
初步修改
ZZJJWarth 7dd2ebc
完成了blockcache代码文件位置的迁移
ZZJJWarth f84a7bd
Merge branch 'DragonOS-Community:master' into stable_0.1.1
ZZJJWarth 772f5ea
Merge branch 'master' of https://github.com/DragonOS-Community/Dragon…
ZZJJWarth 375fc6a
Merge branch 'stable_0.1.1' of github.com:ZZJJWarth/DragonOS into dev…
ZZJJWarth 739347c
删除了无关注释,规范了注释格式
ZZJJWarth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ cppcheck.xml | |
Cargo.lock | ||
.cache | ||
compile_commands.json | ||
/logs/ | ||
/logs/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use core::cmp::Ordering; | ||
|
||
use alloc::{boxed::Box, vec::Vec}; | ||
|
||
use super::cache_config::BLOCK_SIZE; | ||
/// @brief 该枚举设计来是用于实现回写法的,但是目前并未使用 | ||
#[allow(dead_code)] | ||
pub enum CacheBlockFlag { | ||
Unused, | ||
Unwrited, | ||
Writed, | ||
} | ||
#[derive(Copy, Clone)] | ||
pub struct CacheBlockAddr(usize); | ||
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
impl CacheBlockAddr { | ||
pub fn new(num: usize) -> Self { | ||
Self(num) | ||
} | ||
|
||
pub fn data(&self) -> usize { | ||
self.0 | ||
} | ||
} | ||
impl PartialEq<usize> for CacheBlockAddr { | ||
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fn eq(&self, other: &usize) -> bool { | ||
self.0 == *other | ||
} | ||
} | ||
|
||
impl PartialOrd<usize> for CacheBlockAddr { | ||
fn partial_cmp(&self, other: &usize) -> Option<Ordering> { | ||
Some(self.0.cmp(other)) | ||
} | ||
} | ||
|
||
/// @brief存储数据的最小单位 | ||
pub struct CacheBlock { | ||
data: Box<[u8]>, | ||
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_flag: CacheBlockFlag, | ||
lba_id: usize, | ||
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
impl CacheBlock { | ||
pub fn new(data: Box<[u8]>, flag: CacheBlockFlag, lba_id: usize) -> Self { | ||
CacheBlock { | ||
data, | ||
_flag: flag, | ||
lba_id, | ||
} | ||
} | ||
|
||
pub fn from_data(lba_id: usize, data: Vec<u8>) -> Self { | ||
let space_box = data.into_boxed_slice(); | ||
CacheBlock::new(space_box, CacheBlockFlag::Unwrited, lba_id) | ||
} | ||
|
||
pub fn _set_flag(&mut self, _flag: CacheBlockFlag) -> Option<()> { | ||
todo!() | ||
} | ||
#[inline] | ||
pub fn get_data(&self, buf: &mut [u8]) -> usize { | ||
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
buf.copy_from_slice(&self.data); | ||
return BLOCK_SIZE; | ||
} | ||
|
||
pub fn get_lba_id(&self) -> usize { | ||
self.lba_id | ||
} | ||
} |
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub const BLOCK_SIZE_LOG:usize=9; | ||
///块大小这里固定为512 | ||
pub const BLOCK_SIZE: usize = 1<<BLOCK_SIZE_LOG; | ||
///这里规定Cache的threshold大小,单位为:MB | ||
pub const CACHE_THRESHOLD:usize=64; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/// @brief 一个简单的结构体,是BlockIter的输出 | ||
/// | ||
/// #数据成员: | ||
/// - 'iba_id' :表示单个块对应的iba_id | ||
/// - '_data_start_addr' :表示该块在buf中的起始地址,目前并没有作用(例如:若该块是第2个块,那么该数据成员值为2*BLOCK_SIZE) | ||
fslongjin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// - '_block_size' :表示该块的大小 | ||
#[derive(Debug)] | ||
pub struct BlockData { | ||
iba_id: usize, | ||
_data_start_addr: usize, | ||
_block_size: usize, | ||
} | ||
|
||
impl BlockData { | ||
pub fn new(iba_id: usize, data_start_addr: usize, block_size: usize) -> Self { | ||
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Self { | ||
iba_id, | ||
_data_start_addr: data_start_addr, | ||
_block_size: block_size, | ||
} | ||
} | ||
#[inline] | ||
pub fn iba_id(&self) -> usize { | ||
self.iba_id | ||
} | ||
#[inline] | ||
pub fn _data_start_addr(&self) -> usize { | ||
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self._data_start_addr | ||
} | ||
#[inline] | ||
pub fn _block_size(&self) -> usize { | ||
self._block_size | ||
} | ||
} | ||
|
||
/// @brief块迭代器,它获取需求(起始块,连续块的个数),并将连续的块输出为单一的块(如你需要读取lba_id为10~20的连续块,它就可以输出10,11...,20的BlockData) | ||
fslongjin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// #数据成员: | ||
/// - 'iba_id_start' :表示起始块的iba_id | ||
/// - 'count' :表示从起始块开始你需要读多少个块 | ||
/// - 'current' :表示当前遍历到第几个块了 | ||
/// - 'block_size' :规定块的大小 | ||
|
||
#[derive(Copy, Clone)] | ||
pub struct BlockIter { | ||
iba_id_start: usize, | ||
fslongjin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
count: usize, | ||
current: usize, | ||
block_size: usize, | ||
} | ||
|
||
impl BlockIter { | ||
pub fn new(lba_id_start: usize, count: usize, block_size: usize) -> Self { | ||
Self { | ||
iba_id_start: lba_id_start, | ||
count, | ||
block_size, | ||
current: 0, | ||
} | ||
} | ||
} | ||
|
||
impl Iterator for BlockIter { | ||
type Item = BlockData; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
if self.current < self.count { | ||
let ans = BlockData::new( | ||
self.iba_id_start + self.current, | ||
self.current * self.block_size, | ||
self.block_size, | ||
); | ||
self.current += 1; | ||
Some(ans) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
/// @brief 表示缺块信息的数据结构,往往在读取的时候发现缺块并产生FailData,在插入的时候使用FailData | ||
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// #数据成员: | ||
/// - 'lba_id' :表示缺块的lba_id | ||
/// - 'index' :表示缺块在buf中的位置,用于在insert的时候定位缺块数据的位置 | ||
pub struct FailData { | ||
ZZJJWarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
lba_id: usize, | ||
index: usize, | ||
} | ||
|
||
impl FailData { | ||
pub fn new(lba_id: usize, index: usize) -> Self { | ||
FailData { lba_id, index } | ||
} | ||
#[inline] | ||
pub fn lba_id(&self) -> usize { | ||
self.lba_id | ||
} | ||
///@brief 该函数返回的是缺块在buf中的位置,比如:index=1,那么我们就应该取buf\[512..1024\] | ||
pub fn index(&self) -> usize { | ||
self.index | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.