Skip to content
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

fix(mm): 修复fat文件系统的PageCache同步问题 #1005

Merged
merged 44 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
add9d4b
实现read系统调用读取pagecache
MemoryShore Oct 19, 2024
d2ad608
完善read逻辑
MemoryShore Oct 20, 2024
60e36ca
完善create_pages
MemoryShore Oct 21, 2024
773e36d
添加read_direct
MemoryShore Oct 21, 2024
f99aec5
解决create_pages时的死锁问题
MemoryShore Oct 21, 2024
032db07
修复元数据未更新的问题
MemoryShore Oct 21, 2024
19ea62b
Merge branch 'master' into patch-fix-pagecache
MemoryShore Oct 21, 2024
8365ca3
重构read逻辑
MemoryShore Oct 26, 2024
acc821a
重写write逻辑
MemoryShore Oct 26, 2024
7d13a5b
修正页面回写逻辑
MemoryShore Oct 26, 2024
f97b0b7
Merge branch 'master' into patch-fix-pagecache
MemoryShore Oct 26, 2024
0553021
优化代码
MemoryShore Oct 27, 2024
63bd233
优化代码
MemoryShore Nov 10, 2024
fd59c5b
Merge branch 'master' into patch-fix-pagecache
MemoryShore Nov 10, 2024
1a7e9cc
修复lru链表缩减逻辑
MemoryShore Nov 10, 2024
668a279
修正page_writeback逻辑
MemoryShore Nov 11, 2024
ec98b84
添加write_direct
MemoryShore Nov 11, 2024
74c7059
Merge branch 'master' into patch-fix-pagecache
MemoryShore Nov 12, 2024
7a3608b
完善页面释放逻辑
MemoryShore Nov 12, 2024
0ba9483
完善Page结构体和页面创建流程
MemoryShore Nov 16, 2024
8c8051d
优化PageCache的drop逻辑
MemoryShore Nov 16, 2024
839bef9
PageCache改为HashMap存储页面
MemoryShore Nov 18, 2024
da46956
修正PageCache读写逻辑
MemoryShore Nov 18, 2024
67039ad
完善fat元数据的更新逻辑
MemoryShore Nov 18, 2024
49ab468
允许execve加载文件时缓存到PageCache
MemoryShore Nov 18, 2024
bac195a
优化代码
MemoryShore Nov 20, 2024
2e3f29f
修复内存泄露
MemoryShore Nov 25, 2024
0b281af
Page添加truncate方法
MemoryShore Nov 25, 2024
b9938e1
修复重复释放内存
MemoryShore Nov 25, 2024
9336e3a
PageCache加锁
MemoryShore Nov 26, 2024
f2d383f
PageCache创建单独模块
MemoryShore Nov 26, 2024
df1e8e3
Page外部添加PhysAddr
MemoryShore Nov 26, 2024
7951698
完善Page结构
MemoryShore Nov 27, 2024
f71462b
修复PageFlags初始化错误
MemoryShore Nov 27, 2024
62c2948
修正ShmId释放逻辑
MemoryShore Dec 1, 2024
1fd0146
完善shm_id释放逻辑
MemoryShore Dec 6, 2024
57b9eb3
Merge branch 'master' into patch-fix-pagecache
MemoryShore Dec 6, 2024
14bf62b
修正进程退出时未分离共享内存的问题
MemoryShore Dec 7, 2024
b863ac3
修复脏页未自动回写的问题
MemoryShore Dec 11, 2024
2d3912b
优化代码
MemoryShore Dec 12, 2024
b4b6ca8
解决死锁
MemoryShore Dec 12, 2024
ce41895
把回写间隔改为0.5s
fslongjin Dec 15, 2024
50bf8c3
更新novashell版本到feaebefaef
fslongjin Dec 15, 2024
7716697
Merge remote-tracking branch 'origin/master' into huzhaopeng-patch-fi…
fslongjin Dec 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kernel/src/filesystem/fat/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl FATInode {

/// 更新访问时间
pub fn update_time(&mut self) {
log::warn!("update_time has not yet been implemented");
// log::warn!("update_time has not yet been implemented");
}

fn find(&mut self, name: &str) -> Result<Arc<LockedFATInode>, SystemError> {
Expand Down
12 changes: 7 additions & 5 deletions kernel/src/filesystem/page_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,22 @@ impl InnerPageCache {
MMArch::PAGE_SIZE
};

let exist = self.get_page(page_index).is_some();
let mut page = self.get_page(page_index);

if !exist {
if page.is_none() {
let page_buf = vec![0u8; MMArch::PAGE_SIZE];
self.create_pages(page_index, &page_buf)?;
page = self.get_page(page_index);
}

if let Some(page) = self.get_page(page_index) {
if let Some(page) = page {
let sub_buf = &buf[buf_offset..(buf_offset + sub_len)];

let mut page_guard = page.write_irqsave();
unsafe {
page.write_irqsave().as_slice_mut()[page_offset..page_offset + sub_len]
page_guard.as_slice_mut()[page_offset..page_offset + sub_len]
.copy_from_slice(sub_buf);
}
page_guard.add_flags(PageFlags::PG_DIRTY);

ret += sub_len;

Expand Down
24 changes: 16 additions & 8 deletions kernel/src/mm/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl PageReclaimer {
for _ in 0..count.data() {
let (_, page) = self.lru.pop_lru().expect("pagecache is empty");
if page.read_irqsave().flags.contains(PageFlags::PG_DIRTY) {
Self::page_writeback(&page, true);
self.page_writeback(&page, true);
}
}
}
Expand All @@ -322,8 +322,8 @@ impl PageReclaimer {
///
/// ## 返回值
/// - VmFaultReason: 页面错误处理信息标志
pub fn page_writeback(page: &Arc<Page>, unmap: bool) {
// log::debug!("page writeback: {page:?}");
pub fn page_writeback(&mut self, page: &Arc<Page>, unmap: bool) {
log::debug!("page writeback: {page:?}");

let guard = page.read_irqsave();
let (page_cache, page_index) = match guard.page_type() {
Expand Down Expand Up @@ -372,7 +372,7 @@ impl PageReclaimer {
};

inode
.write_at(
.write_direct(
page_index * MMArch::PAGE_SIZE,
len,
unsafe {
Expand All @@ -389,19 +389,27 @@ impl PageReclaimer {
// 删除页面
page_cache.lock_irqsave().remove_page(page_index);
page_manager_lock_irqsave().remove_page(&paddr);
MemoryShore marked this conversation as resolved.
Show resolved Hide resolved
self.remove_page(&paddr);
} else {
// 清除标记
page.write_irqsave().remove_flags(PageFlags::PG_DIRTY);
}
}
MemoryShore marked this conversation as resolved.
Show resolved Hide resolved

/// lru脏页刷新
pub fn flush_dirty_pages(&self) {
pub fn flush_dirty_pages(&mut self) {
// log::info!("flush_dirty_pages");
let iter = self.lru.iter();
for (_, page) in iter {
let iter = self.lru.iter().filter_map(|(_, page)| {
if page.read_irqsave().flags().contains(PageFlags::PG_DIRTY) {
Self::page_writeback(page, false);
Some(page.clone())
} else {
None
}
});
let collection: Vec<Arc<Page>> = iter.collect();
for page in collection {
if page.read_irqsave().flags().contains(PageFlags::PG_DIRTY) {
self.page_writeback(&page, false);
}
fslongjin marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
Loading