Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/vfs_cluster.c
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
#if defined(CLUSTERDEBUG) | #if defined(CLUSTERDEBUG) | ||||
static int rcluster= 0; | static int rcluster= 0; | ||||
SYSCTL_INT(_debug, OID_AUTO, rcluster, CTLFLAG_RW, &rcluster, 0, | SYSCTL_INT(_debug, OID_AUTO, rcluster, CTLFLAG_RW, &rcluster, 0, | ||||
"Debug VFS clustering code"); | "Debug VFS clustering code"); | ||||
#endif | #endif | ||||
static MALLOC_DEFINE(M_SEGMENT, "cl_savebuf", "cluster_save buffer"); | static MALLOC_DEFINE(M_SEGMENT, "cl_savebuf", "cluster_save buffer"); | ||||
static uma_zone_t cluster_pbuf_zone; | |||||
static void cluster_init(void *); | |||||
static struct cluster_save *cluster_collectbufs(struct vnode *vp, | static struct cluster_save *cluster_collectbufs(struct vnode *vp, | ||||
struct buf *last_bp, int gbflags); | struct buf *last_bp, int gbflags); | ||||
static struct buf *cluster_rbuild(struct vnode *vp, u_quad_t filesize, | static struct buf *cluster_rbuild(struct vnode *vp, u_quad_t filesize, | ||||
daddr_t lbn, daddr_t blkno, long size, int run, int gbflags, | daddr_t lbn, daddr_t blkno, long size, int run, int gbflags, | ||||
struct buf *fbp); | struct buf *fbp); | ||||
static void cluster_callback(struct buf *); | static void cluster_callback(struct buf *); | ||||
static int write_behind = 1; | static int write_behind = 1; | ||||
SYSCTL_INT(_vfs, OID_AUTO, write_behind, CTLFLAG_RW, &write_behind, 0, | SYSCTL_INT(_vfs, OID_AUTO, write_behind, CTLFLAG_RW, &write_behind, 0, | ||||
"Cluster write-behind; 0: disable, 1: enable, 2: backed off"); | "Cluster write-behind; 0: disable, 1: enable, 2: backed off"); | ||||
static int read_max = 64; | static int read_max = 64; | ||||
SYSCTL_INT(_vfs, OID_AUTO, read_max, CTLFLAG_RW, &read_max, 0, | SYSCTL_INT(_vfs, OID_AUTO, read_max, CTLFLAG_RW, &read_max, 0, | ||||
"Cluster read-ahead max block count"); | "Cluster read-ahead max block count"); | ||||
static int read_min = 1; | static int read_min = 1; | ||||
SYSCTL_INT(_vfs, OID_AUTO, read_min, CTLFLAG_RW, &read_min, 0, | SYSCTL_INT(_vfs, OID_AUTO, read_min, CTLFLAG_RW, &read_min, 0, | ||||
"Cluster read min block count"); | "Cluster read min block count"); | ||||
SYSINIT(cluster, SI_SUB_CPU, SI_ORDER_ANY, cluster_init, NULL); | |||||
static void | |||||
cluster_init(void *dummy) | |||||
{ | |||||
cluster_pbuf_zone = uma_zsecond_create("clpbuf", pbuf_ctor, pbuf_dtor, | |||||
pbuf_init, NULL, pbuf_zone); | |||||
uma_zone_set_max(cluster_pbuf_zone, nswbuf / 2); | |||||
} | |||||
/* | /* | ||||
* Read data to a buf, including read-ahead if we find this to be beneficial. | * Read data to a buf, including read-ahead if we find this to be beneficial. | ||||
* cluster_read replaces bread. | * cluster_read replaces bread. | ||||
*/ | */ | ||||
int | int | ||||
cluster_read(struct vnode *vp, u_quad_t filesize, daddr_t lblkno, long size, | cluster_read(struct vnode *vp, u_quad_t filesize, daddr_t lblkno, long size, | ||||
struct ucred *cred, long totread, int seqcount, int gbflags, | struct ucred *cred, long totread, int seqcount, int gbflags, | ||||
struct buf **bpp) | struct buf **bpp) | ||||
▲ Show 20 Lines • Show All 273 Lines • ▼ Show 20 Lines | if (fbp) { | ||||
tbp->b_flags |= B_ASYNC | B_RAM; | tbp->b_flags |= B_ASYNC | B_RAM; | ||||
tbp->b_iocmd = BIO_READ; | tbp->b_iocmd = BIO_READ; | ||||
} | } | ||||
tbp->b_blkno = blkno; | tbp->b_blkno = blkno; | ||||
if( (tbp->b_flags & B_MALLOC) || | if( (tbp->b_flags & B_MALLOC) || | ||||
((tbp->b_flags & B_VMIO) == 0) || (run <= 1) ) | ((tbp->b_flags & B_VMIO) == 0) || (run <= 1) ) | ||||
return tbp; | return tbp; | ||||
bp = trypbuf(&cluster_pbuf_freecnt); | bp = uma_zalloc(cluster_pbuf_zone, M_NOWAIT); | ||||
if (bp == NULL) | if (bp == NULL) | ||||
return tbp; | return tbp; | ||||
/* | /* | ||||
* We are synthesizing a buffer out of vm_page_t's, but | * We are synthesizing a buffer out of vm_page_t's, but | ||||
* if the block size is not page aligned then the starting | * if the block size is not page aligned then the starting | ||||
* address may not be either. Inherit the b_data offset | * address may not be either. Inherit the b_data offset | ||||
* from the original buffer. | * from the original buffer. | ||||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | if (error) { | ||||
* to be freed. | * to be freed. | ||||
*/ | */ | ||||
if (tbp->b_flags & B_DIRECT) | if (tbp->b_flags & B_DIRECT) | ||||
tbp->b_flags |= B_RELBUF; | tbp->b_flags |= B_RELBUF; | ||||
} | } | ||||
bufdone(tbp); | bufdone(tbp); | ||||
} | } | ||||
pbrelvp(bp); | pbrelvp(bp); | ||||
relpbuf(bp, &cluster_pbuf_freecnt); | uma_zfree(cluster_pbuf_zone, bp); | ||||
} | } | ||||
/* | /* | ||||
* cluster_wbuild_wb: | * cluster_wbuild_wb: | ||||
* | * | ||||
* Implement modified write build for cluster. | * Implement modified write build for cluster. | ||||
* | * | ||||
* write_behind = 0 write behind disabled | * write_behind = 0 write behind disabled | ||||
▲ Show 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | while (len > 0) { | ||||
* up if the cluster was terminated prematurely--too much | * up if the cluster was terminated prematurely--too much | ||||
* hassle. | * hassle. | ||||
*/ | */ | ||||
if (((tbp->b_flags & (B_CLUSTEROK | B_MALLOC | B_VMIO)) != | if (((tbp->b_flags & (B_CLUSTEROK | B_MALLOC | B_VMIO)) != | ||||
(B_CLUSTEROK | B_VMIO)) || | (B_CLUSTEROK | B_VMIO)) || | ||||
(tbp->b_bcount != tbp->b_bufsize) || | (tbp->b_bcount != tbp->b_bufsize) || | ||||
(tbp->b_bcount != size) || | (tbp->b_bcount != size) || | ||||
(len == 1) || | (len == 1) || | ||||
((bp = (vp->v_vflag & VV_MD) != 0 ? | ((bp = uma_zalloc(cluster_pbuf_zone, | ||||
trypbuf(&cluster_pbuf_freecnt) : | (vp->v_vflag & VV_MD) != 0 ? M_NOWAIT : M_WAITOK)) == NULL)) { | ||||
getpbuf(&cluster_pbuf_freecnt)) == NULL)) { | |||||
totalwritten += tbp->b_bufsize; | totalwritten += tbp->b_bufsize; | ||||
bawrite(tbp); | bawrite(tbp); | ||||
++start_lbn; | ++start_lbn; | ||||
--len; | --len; | ||||
continue; | continue; | ||||
} | } | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 199 Lines • Show Last 20 Lines |