Skip to content

Conversation

Jomocool
Copy link
Collaborator

结构:

  • Page:物理页面信息(映射计数、共享页标志、vma集合)
  • PageManager:物理页面信息管理器,维护物理地址->对应Page的映射关系

机制:

  • 分配物理页时,生成相应Page并加入到PAGE_MANAGER中
  • 虚拟页面映射时,将vma加入Page的anon_vma中
  • 虚拟页面取消映射时,将vma从Page的anon_vma中移除
  • 释放物理页面时,将对应Page从PAGE_MANAGER中移除

@dragonosbot
Copy link
Contributor

r? @fslongjin

dragonosbot has assigned @fslongjin.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@dragonosbot dragonosbot added S-等待审查 Status: 等待assignee以及相关方的审查。 T-driver Relevant to the driver team, which will review and decide on the PR/issue. labels Mar 27, 2024
@fslongjin fslongjin added the A-mm Area: 内存管理子系统 label Mar 27, 2024
@fslongjin
Copy link
Member

#534

};

lazy_static! {
/// 全局物理页信息管理器
pub static ref PAGE_MANAGER: SpinLock<PageManager> = SpinLock::new(PageManager::new());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这玩意应当显式指定初始化的时机,而不是使用lazy_static

deallocate_page_frames(
PhysPageFrame::new(PhysAddr::new(paddr)),
page_count,
&mut PAGE_MANAGER.lock(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个PAGE_MANAGER.lock()最好封装成函数。

并且应当是lock_irqsave?因为hzp在写的那个pagefault处理,估计中断上下文内会使用到这个东西,因此得lock irqsave


// 如果物理页的anon_vma链表长度为0并且不是共享页,则释放物理页.
// 目前由于还没有实现共享页,所以直接释放物理页也没问题。
// 但是在实现共享页之后,就不能直接释放物理页了,需要在anon_vma链表长度为0的时候才能释放物理页
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

过时的注释得删掉

@fslongjin
Copy link
Member

@dragonosbot author

@dragonosbot dragonosbot added S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 and removed S-等待审查 Status: 等待assignee以及相关方的审查。 labels Mar 27, 2024
@Jomocool
Copy link
Collaborator Author

Jomocool commented Mar 31, 2024

@dragonosbot ready

@dragonosbot dragonosbot added S-等待审查 Status: 等待assignee以及相关方的审查。 and removed S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 labels Mar 31, 2024

/// 判断当前物理页是否能被回
pub fn can_deallocate(&self) -> bool {
self.map_count == 0 && !self.shared
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也许这个map_count为0就能释放?不然的话如果忘记清除shared,就永远无法释放

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我一开始也是这么想的,但是Linux的共享内存即使映射计数是0,在没有设置可被回收的情况下,是不会被释放的,进程依然能够连接到这块共享内存。或者看我们想怎么设计

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我一开始也是这么想的,但是Linux的共享内存即使映射计数是0,在没有设置可被回收的情况下,是不会被释放的,进程依然能够连接到这块共享内存。或者看我们想怎么设计

哦哦哦,确实有道理。

@fslongjin fslongjin merged commit 56cc4db into DragonOS-Community:master Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mm Area: 内存管理子系统 S-等待审查 Status: 等待assignee以及相关方的审查。 T-driver Relevant to the driver team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants