mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-15 00:06:47 +00:00
Fix RamFS readahead
This commit is contained in:
parent
c99069981e
commit
179705a3fc
@ -306,8 +306,12 @@ impl ReadaheadState {
|
|||||||
for async_idx in window.readahead_range() {
|
for async_idx in window.readahead_range() {
|
||||||
let mut async_page = Page::alloc()?;
|
let mut async_page = Page::alloc()?;
|
||||||
let pg_waiter = backend.read_page_async(async_idx, async_page.frame())?;
|
let pg_waiter = backend.read_page_async(async_idx, async_page.frame())?;
|
||||||
self.waiter.concat(pg_waiter);
|
if pg_waiter.nreqs() > 0 {
|
||||||
async_page.set_state(PageState::Uninit);
|
self.waiter.concat(pg_waiter);
|
||||||
|
} else {
|
||||||
|
// Some backends (e.g. RamFS) do not issue requests, but fill the page directly.
|
||||||
|
async_page.set_state(PageState::UpToDate);
|
||||||
|
}
|
||||||
pages.put(async_idx, async_page);
|
pages.put(async_idx, async_page);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -394,9 +398,7 @@ impl PageCacheManager {
|
|||||||
if let PageState::Uninit = page.state() {
|
if let PageState::Uninit = page.state() {
|
||||||
// Cond 2: We should wait for the previous readahead.
|
// Cond 2: We should wait for the previous readahead.
|
||||||
// If there is no previous readahead, an error must have occurred somewhere.
|
// If there is no previous readahead, an error must have occurred somewhere.
|
||||||
if ra_state.request_number() == 0 {
|
assert!(ra_state.request_number() != 0);
|
||||||
return_errno!(Errno::EINVAL)
|
|
||||||
}
|
|
||||||
ra_state.wait_for_prev_readahead(&mut pages)?;
|
ra_state.wait_for_prev_readahead(&mut pages)?;
|
||||||
pages.get(&idx).unwrap().frame().clone()
|
pages.get(&idx).unwrap().frame().clone()
|
||||||
} else {
|
} else {
|
||||||
|
39
test/apps/mmap/mmap_readahead.c
Normal file
39
test/apps/mmap/mmap_readahead.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "../network/test.h"
|
||||||
|
|
||||||
|
#define FILE_NAME "/tmp/mmap_readahead.txt"
|
||||||
|
|
||||||
|
#define PAGE_SIZE 4096
|
||||||
|
#define NR_PAGES 16
|
||||||
|
|
||||||
|
static char *addr;
|
||||||
|
|
||||||
|
FN_SETUP(mmap_readahead)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = CHECK(open(FILE_NAME, O_RDWR | O_CREAT));
|
||||||
|
CHECK(unlink(FILE_NAME));
|
||||||
|
|
||||||
|
CHECK(ftruncate(fd, PAGE_SIZE * NR_PAGES));
|
||||||
|
|
||||||
|
addr = mmap(NULL, PAGE_SIZE * NR_PAGES, PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED, fd, 0);
|
||||||
|
CHECK(addr == MAP_FAILED ? -1 : 0);
|
||||||
|
}
|
||||||
|
END_SETUP()
|
||||||
|
|
||||||
|
FN_TEST(mmap_readahead)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < NR_PAGES; ++i) {
|
||||||
|
TEST_RES(addr[i * PAGE_SIZE], _ret == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END_TEST()
|
@ -22,6 +22,7 @@ itimer/setitimer
|
|||||||
itimer/timer_create
|
itimer/timer_create
|
||||||
mmap/mmap_and_fork
|
mmap/mmap_and_fork
|
||||||
mmap/mmap_shared_filebacked
|
mmap/mmap_shared_filebacked
|
||||||
|
mmap/mmap_readahead
|
||||||
pthread/pthread_test
|
pthread/pthread_test
|
||||||
pty/open_pty
|
pty/open_pty
|
||||||
signal_c/parent_death_signal
|
signal_c/parent_death_signal
|
||||||
|
Loading…
x
Reference in New Issue
Block a user