- add a function to perform explicit read-ahead.

- ra_startio: tweak locking a bit.
This commit is contained in:
yamt 2009-06-10 01:54:08 +00:00
parent 9f591f8731
commit c87ccfd341
2 changed files with 27 additions and 7 deletions

View File

@ -1,7 +1,7 @@
/* $NetBSD: uvm_readahead.c,v 1.5 2008/01/02 11:49:20 ad Exp $ */
/* $NetBSD: uvm_readahead.c,v 1.6 2009/06/10 01:54:08 yamt Exp $ */
/*-
* Copyright (c)2003, 2005 YAMAMOTO Takashi,
* Copyright (c)2003, 2005, 2009 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uvm_readahead.c,v 1.5 2008/01/02 11:49:20 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: uvm_readahead.c,v 1.6 2009/06/10 01:54:08 yamt Exp $");
#include <sys/param.h>
#include <sys/pool.h>
@ -145,11 +145,11 @@ ra_startio(struct uvm_object *uobj, off_t off, size_t sz)
* use UVM_ADV_RANDOM to avoid recursion.
*/
mutex_enter(&uobj->vmobjlock);
error = (*uobj->pgops->pgo_get)(uobj, off, NULL,
&npages, 0, VM_PROT_READ, UVM_ADV_RANDOM, 0);
DPRINTF(("%s: off=%" PRIu64 ", bytelen=%zu -> %d\n",
__func__, off, bytelen, error));
mutex_enter(&uobj->vmobjlock);
if (error != 0 && error != EBUSY) {
if (error != EINVAL) { /* maybe past EOF */
DPRINTF(("%s: error=%d\n", __func__, error));
@ -313,7 +313,12 @@ do_readahead:
*/
if (rasize >= RA_MINSIZE) {
ra->ra_next = ra_startio(uobj, raoff, rasize);
off_t next;
mutex_exit(&uobj->vmobjlock);
next = ra_startio(uobj, raoff, rasize);
mutex_enter(&uobj->vmobjlock);
ra->ra_next = next;
}
}
@ -329,3 +334,17 @@ do_readahead:
done:;
}
int
uvm_readahead(struct uvm_object *uobj, off_t off, off_t size)
{
/*
* don't allow too much read-ahead.
*/
if (size > RA_WINSIZE_MAX) {
size = RA_WINSIZE_MAX;
}
ra_startio(uobj, off, size);
return 0;
}

View File

@ -1,7 +1,7 @@
/* $NetBSD: uvm_readahead.h,v 1.3 2008/01/02 11:49:21 ad Exp $ */
/* $NetBSD: uvm_readahead.h,v 1.4 2009/06/10 01:54:08 yamt Exp $ */
/*-
* Copyright (c)2003, 2005 YAMAMOTO Takashi,
* Copyright (c)2003, 2005, 2009 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -37,5 +37,6 @@ struct uvm_ractx *uvm_ra_allocctx(void);
void uvm_ra_freectx(struct uvm_ractx *);
void uvm_ra_request(struct uvm_ractx *, int, struct uvm_object *, off_t,
size_t);
int uvm_readahead(struct uvm_object *, off_t, off_t);
#endif /* defined(_UVM_UVM_READAHEAD_H_) */