-
Notifications
You must be signed in to change notification settings - Fork 37
文件页缓存 #53
base: main
Are you sure you want to change the base?
文件页缓存 #53
Conversation
api/src/file/fs.rs
Outdated
| use axerrno::{LinuxError, LinuxResult}; | ||
| use axfs::fops::DirEntry; | ||
| use axio::PollState; | ||
| use axio::SeekFrom; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge it with axio::PollState
api/src/file/fs.rs
Outdated
| is_direct: bool, | ||
| cache: Weak<PageCache>, | ||
| ) -> Self { | ||
| debug!("Starry-api open file {}", path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this log
api/src/file/fs.rs
Outdated
| debug!("Starry-api open file {}", path); | ||
| let size = { | ||
| if is_direct { | ||
| let inner = inner.clone().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can you judge this inner is Some(..)?
api/src/file/fs.rs
Outdated
| } | ||
| } | ||
|
|
||
| pub fn get_cache(&self) -> Arc<PageCache> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename it as cache()
api/src/file/fs.rs
Outdated
| self.cache.upgrade().unwrap() | ||
| } | ||
|
|
||
| pub fn get_size(&self) -> usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename it as size()
api/src/imp/fs/fd_ops.rs
Outdated
| ) -> LinuxResult<isize> { | ||
| let path = path.get_as_str()?; | ||
| let opts = flags_to_options(flags, mode); | ||
| let opts: OpenOptions = flags_to_options(flags, mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this type comment.
api/src/imp/fs/stat.rs
Outdated
| Ok(file) => File::new( | ||
| Some(Arc::new(Mutex::new(file))), | ||
| path.into(), | ||
| false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why set is_direct as false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because stat_at_path(path) use path rather than fd, it may be called without open a file, so I don't use page cache here. Instead, sys_fstat(fd, statbuf) uses fd to query stat of an opened file, so I use page cache.
api/src/imp/mm/mmap.rs
Outdated
|
|
||
| let map_flags = MmapFlags::from_bits_truncate(flags); | ||
| if map_flags.contains(MmapFlags::PRIVATE | MmapFlags::SHARED) { | ||
| if !(map_flags.contains(MmapFlags::PRIVATE) ^ map_flags.contains(MmapFlags::SHARED)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When flags contained none of MAP_PRIVATE, MAP_SHARED, or MAP_SHARED_VALIDATE, it will cause EINVAL.
| } | ||
|
|
||
| let offset = offset as usize; | ||
| if offset % PAGE_SIZE_4K != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the offset is not align, it will not cause error.
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#define NORMAL_PAGE_SIZE 4096 // 4KB
int main()
{
// 输出当前 pid
printf("Current PID: %d\n", getpid());
// 申请 4KB 的普通页内存
void *normal_mem = mmap(NULL, NORMAL_PAGE_SIZE - 1024, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (normal_mem == MAP_FAILED)
{
perror("Normal page mmap failed");
}
else
{
printf("Normal memory allocated at %p\n", normal_mem);
}
return 0;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api/src/imp/mm/mmap.rs
Outdated
| false | ||
| let anonymous = map_flags.contains(MmapFlags::ANONYMOUS) || fd == -1; | ||
| let private = map_flags.contains(MmapFlags::PRIVATE); | ||
| let fd = { if anonymous { -1 } else { fd } }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why set fd repeatedly?

arceos 提交了相应的pr: oscomp/arceos#48