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() {
|
||||
let mut async_page = Page::alloc()?;
|
||||
let pg_waiter = backend.read_page_async(async_idx, async_page.frame())?;
|
||||
self.waiter.concat(pg_waiter);
|
||||
async_page.set_state(PageState::Uninit);
|
||||
if pg_waiter.nreqs() > 0 {
|
||||
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);
|
||||
}
|
||||
Ok(())
|
||||
|
@ -394,9 +398,7 @@ impl PageCacheManager {
|
|||
if let PageState::Uninit = page.state() {
|
||||
// Cond 2: We should wait for the previous readahead.
|
||||
// If there is no previous readahead, an error must have occurred somewhere.
|
||||
if ra_state.request_number() == 0 {
|
||||
return_errno!(Errno::EINVAL)
|
||||
}
|
||||
assert!(ra_state.request_number() != 0);
|
||||
ra_state.wait_for_prev_readahead(&mut pages)?;
|
||||
pages.get(&idx).unwrap().frame().clone()
|
||||
} else {
|
||||
|
|
|
@ -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
|
||||
mmap/mmap_and_fork
|
||||
mmap/mmap_shared_filebacked
|
||||
mmap/mmap_readahead
|
||||
pthread/pthread_test
|
||||
pty/open_pty
|
||||
signal_c/parent_death_signal
|
||||
|
|
Loading…
Reference in New Issue