FreeBSD/sys/fs/nfsserver/nfs_nfsdport.c
/*
 * Heuristic to detect sequential operation.
 */
Heuristic to detect sequential operation.
Heuristic to detect sequential operation .
static struct nfsheur *
nfsrv_sequential_heuristic(struct uio *uio, struct vnode *vp)
{
	struct nfsheur *nh;
	int hi, try;
	try = 32;
	hi = ((int)(vm_offset_t)vp / sizeof(struct vnode)) % NUM_HEURISTIC;
	nh = &nfsheur[hi];
	while (try--) {
		if (nfsheur[hi].nh_vp == vp) {
			nh = &nfsheur[hi];
			break;
		}
		if (nfsheur[hi].nh_use > 0)
			--nfsheur[hi].nh_use;
		hi = (hi + 1) % NUM_HEURISTIC;
		if (nfsheur[hi].nh_use < nh->nh_use)
			nh = &nfsheur[hi];
	}
	if (nh->nh_vp != vp) {
		nh->nh_vp = vp;
		nh->nh_nextoff = uio->uio_offset;
		nh->nh_use = NHUSE_INIT;
		if (uio->uio_offset == 0)
			nh->nh_seqcount = 4;
		else
			nh->nh_seqcount = 1;
	}
	if ((uio->uio_offset == 0 && nh->nh_seqcount > 0) ||
	    uio->uio_offset == nh->nh_nextoff) {
		nh->nh_seqcount += howmany(uio->uio_resid, 16384);
		if (nh->nh_seqcount > IO_SEQMAX)
			nh->nh_seqcount = IO_SEQMAX;
	} else if (qabs(uio->uio_offset - nh->nh_nextoff) <= MAX_REORDERED_RPC *
	    imax(vp->v_mount->mnt_stat.f_iosize, uio->uio_resid)) {
	} else if (nh->nh_seqcount > 1) {
		nh->nh_seqcount /= 2;
	} else {
		nh->nh_seqcount = 0;
	}
	nh->nh_use += NHUSE_INC;
	if (nh->nh_use > NHUSE_MAX)
		nh->nh_use = NHUSE_MAX;
	return (nh);
}
static struct nfsheur * nfsrv_sequential_heuristic ( struct uio * uio , struct vnode * vp ) { struct nfsheur * nh ; int hi , try ; try = 32 ; hi = ( ( int ) ( vm_offset_t ) vp / sizeof ( struct vnode ) ) % NUM_HEURISTIC ; nh = & nfsheur [ hi ] ; while ( try -- ) { if ( nfsheur [ hi ] . nh_vp == vp ) { nh = & nfsheur [ hi ] ; break ; } if ( nfsheur [ hi ] . nh_use > 0 ) -- nfsheur [ hi ] . nh_use ; hi = ( hi + 1 ) % NUM_HEURISTIC ; if ( nfsheur [ hi ] . nh_use < nh -> nh_use ) nh = & nfsheur [ hi ] ; } if ( nh -> nh_vp != vp ) { nh -> nh_vp = vp ; nh -> nh_nextoff = uio -> uio_offset ; nh -> nh_use = NHUSE_INIT ; if ( uio -> uio_offset == 0 ) nh -> nh_seqcount = 4 ; else nh -> nh_seqcount = 1 ; } if ( ( uio -> uio_offset == 0 && nh -> nh_seqcount > 0 ) || uio -> uio_offset == nh -> nh_nextoff ) { nh -> nh_seqcount += howmany ( uio -> uio_resid , 16384 ) ; if ( nh -> nh_seqcount > IO_SEQMAX ) nh -> nh_seqcount = IO_SEQMAX ; } else if ( qabs ( uio -> uio_offset - nh -> nh_nextoff ) <= MAX_REORDERED_RPC * imax ( vp -> v_mount -> mnt_stat . f_iosize , uio -> uio_resid ) ) { } else if ( nh -> nh_seqcount > 1 ) { nh -> nh_seqcount /= 2 ; } else { nh -> nh_seqcount = 0 ; } nh -> nh_use += NHUSE_INC ; if ( nh -> nh_use > NHUSE_MAX ) nh -> nh_use = NHUSE_MAX ; return ( nh ) ; }
Heuristic to detect sequential operation.
Heuristic to detect sequential operation .
/* Locate best candidate. */ /* Initialize hint if this is a new file. */ /* Calculate heuristic. */ /* See comments in vfs_vnops.c:sequential_heuristic(). */ /* Probably a reordered RPC, leave seqcount alone. */