From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E81D5313550 for ; Thu, 28 Aug 2025 16:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756398166; cv=none; b=p4OBc17ecf7uvFFa85dKZhTflirA3I7oWkZC4pRMM7DDgWYx4fd906dJJNMjVMHRm10R//3bdfRdrAh/8MHJRbPgaScn0I60YN/sMuXmtBd4Bsuj3vaR5yjXQA/9jKFa4j+m8pB24VMcX5r1fKA5dr6v64pompl4SU3x9o8TQQo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756398166; c=relaxed/simple; bh=NkEbx+fLW5nIY2A+6gQI4PGcEcP2owtibmroC2I+qR8=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=rWQMw/Iai0QVtMwVf6AOpUcl9svHQ1Uf+RqoLP+WQP5ytt7RCGRgQTJ6N6EHtzmwNn+u9NE4cLTn+k665JAO4oLaUrcUmSMZ5cLO5jsPZx720Y4oXXe6kHylH7E2d62cyRcZU/r+AYRmJ4Uni7bu8LolKh2s1stlkWFQ31Vts1M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nw32Y9nB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nw32Y9nB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08552C4CEEB; Thu, 28 Aug 2025 16:22:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756398165; bh=NkEbx+fLW5nIY2A+6gQI4PGcEcP2owtibmroC2I+qR8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=nw32Y9nBviRJTjzxAWnTadmmF7p56lavwW0h4Iu9fpFxmCbwzlSxX5uPKpaZtaJ29 tzVOKRgp/HRJDUHsxN1FUqjR9tW7PAzBDz3ModLujuCSnBQpgJzW3O1Ktx90lZo29I lfaxj47foOYqs1ZMHsyDhRjxqIDeu5qVyZoSAFda/j8orA2rklSclTh+sXH2LTEJqa h6okiyl6M+4iXkUivf3QU2kR0T4r12zDq7xmYb0sCEm/sn262G5LfXfXCFoUlH6Ozl xWCMbhtv0LIV5DWg9G6VMYXKvLV/Jn1Kc0hJ44GTbbQdwY4r5Kr6t470/HDRweS0+q uFURrUvLBlVLQ== Message-ID: <45ccb9b479b2c5af09755c95f3dbd5b29db4370a.camel@kernel.org> Subject: Re: [PATCH v8 5/7] NFSD: issue READs using O_DIRECT even if IO is misaligned From: Jeff Layton To: Mike Snitzer , Chuck Lever Cc: linux-nfs@vger.kernel.org Date: Thu, 28 Aug 2025 12:22:43 -0400 In-Reply-To: References: <20250826185718.5593-1-snitzer@kernel.org> <20250826185718.5593-6-snitzer@kernel.org> Autocrypt: addr=jlayton@kernel.org; prefer-encrypt=mutual; keydata=mQINBE6V0TwBEADXhJg7s8wFDwBMEvn0qyhAnzFLTOCHooMZyx7XO7dAiIhDSi7G1NPxw n8jdFUQMCR/GlpozMFlSFiZXiObE7sef9rTtM68ukUyZM4pJ9l0KjQNgDJ6Fr342Htkjxu/kFV1Wv egyjnSsFt7EGoDjdKqr1TS9syJYFjagYtvWk/UfHlW09X+jOh4vYtfX7iYSx/NfqV3W1D7EDi0PqV T2h6v8i8YqsATFPwO4nuiTmL6I40ZofxVd+9wdRI4Db8yUNA4ZSP2nqLcLtFjClYRBoJvRWvsv4lm 0OX6MYPtv76hka8lW4mnRmZqqx3Ut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sph3EaiZfdXKhiQqSGdK4La3OTJOJYZphPdGgnkvDV9Pl1QZ0ijXQrVIy3zd6VCNaKYq7B AKidn5g/2Q8oio9Tf4XfdZ9dtwcB+bwDJFgvvDYaZ5bI3ln4V3EyW5i2NfXazz/GA/I/ZtbsigCFc 8ftCBKZWZmIExheXRvbiA8amxheXRvbkBrZXJuZWwub3JnPokCOAQTAQIAIgUCWe8u6AIbAwYLCQg HAwIGFQgCCQoLBBYCAwECHgECF4AACgkQAA5oQRlWghUuCg/+Lb/xGxZD2Q1oJVAE37uW308UpVSD 2tAMJUvFTdDbfe3zKlPDTuVsyNsALBGclPLagJ5ZTP+Vp2irAN9uwBuacBOTtmOdz4ZN2tdvNgozz uxp4CHBDVzAslUi2idy+xpsp47DWPxYFIRP3M8QG/aNW052LaPc0cedYxp8+9eiVUNpxF4SiU4i9J DfX/sn9XcfoVZIxMpCRE750zvJvcCUz9HojsrMQ1NFc7MFT1z3MOW2/RlzPcog7xvR5ENPH19ojRD CHqumUHRry+RF0lH00clzX/W8OrQJZtoBPXv9ahka/Vp7kEulcBJr1cH5Wz/WprhsIM7U9pse1f1g Yy9YbXtWctUz8uvDR7shsQxAhX3qO7DilMtuGo1v97I/Kx4gXQ52syh/w6EBny71CZrOgD6kJwPVV AaM1LRC28muq91WCFhs/nzHozpbzcheyGtMUI2Ao4K6mnY+3zIuXPygZMFr9KXE6fF7HzKxKuZMJO aEZCiDOq0anx6FmOzs5E6Jqdpo/mtI8beK+BE7Va6ni7YrQlnT0i3vaTVMTiCThbqsB20VrbMjlhp f8lfK1XVNbRq/R7GZ9zHESlsa35ha60yd/j3pu5hT2xyy8krV8vGhHvnJ1XRMJBAB/UYb6FyC7S+m QZIQXVeAA+smfTT0tDrisj1U5x6ZB9b3nBg65kc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-1.fc42) Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Wed, 2025-08-27 at 15:41 -0400, Mike Snitzer wrote: > On Wed, Aug 27, 2025 at 11:34:03AM -0400, Chuck Lever wrote: > > On 8/26/25 2:57 PM, Mike Snitzer wrote: > > > If NFSD_IO_DIRECT is used, expand any misaligned READ to the next > > > DIO-aligned block (on either end of the READ). The expanded READ is > > > verified to have proper offset/len (logical_block_size) and > > > dma_alignment checking. > > >=20 > > > Must allocate and use a bounce-buffer page (called 'start_extra_page'= ) > > > if/when expanding the misaligned READ requires reading extra partial > > > page at the start of the READ so that its DIO-aligned. Otherwise that > > > extra page at the start will make its way back to the NFS client and > > > corruption will occur. As found, and then this fix of using an extra > > > page verified, using the 'dt' utility: > > > dt of=3D/mnt/share1/dt_a.test passes=3D1 bs=3D47008 count=3D2 \ > > > iotype=3Dsequential pattern=3Diot onerr=3Dabort oncerr=3Dabort > > > see: https://github.com/RobinTMiller/dt.git > > >=20 > > > Any misaligned READ that is less than 32K won't be expanded to be > > > DIO-aligned (this heuristic just avoids excess work, like allocating > > > start_extra_page, for smaller IO that can generally already perform > > > well using buffered IO). > > >=20 > > > Suggested-by: Jeff Layton > > > Suggested-by: Chuck Lever > > > Signed-off-by: Mike Snitzer > > > Reviewed-by: Jeff Layton > > > --- > > > fs/nfsd/vfs.c | 200 +++++++++++++++++++++++++++++++++++= -- > > > include/linux/sunrpc/svc.h | 5 +- > > > 2 files changed, 194 insertions(+), 11 deletions(-) > > >=20 > > > diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c > > > index c340708fbab4d..64732dc8985d6 100644 > > > --- a/fs/nfsd/vfs.c > > > +++ b/fs/nfsd/vfs.c > > > @@ -19,6 +19,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > #include > > > #include > > > #include > > > @@ -1073,6 +1074,153 @@ __be32 nfsd_splice_read(struct svc_rqst *rqst= p, struct svc_fh *fhp, > > > return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_= err); > > > } > > > =20 > > > +struct nfsd_read_dio { > > > + loff_t start; > > > + loff_t end; > > > + unsigned long start_extra; > > > + unsigned long end_extra; > > > + struct page *start_extra_page; > > > +}; > > > + > > > +static void init_nfsd_read_dio(struct nfsd_read_dio *read_dio) > > > +{ > > > + memset(read_dio, 0, sizeof(*read_dio)); > > > + read_dio->start_extra_page =3D NULL; > > > +} > > > + > > > +#define NFSD_READ_DIO_MIN_KB (32 << 10) > > > + > > > +static bool nfsd_analyze_read_dio(struct svc_rqst *rqstp, struct svc= _fh *fhp, > > > + struct nfsd_file *nf, loff_t offset, > > > + unsigned long len, unsigned int base, > > > + struct nfsd_read_dio *read_dio) > > > +{ > > > + const u32 dio_blocksize =3D nf->nf_dio_read_offset_align; > > > + loff_t middle_end, orig_end =3D offset + len; > > > + > > > + if (WARN_ONCE(!nf->nf_dio_mem_align || !nf->nf_dio_read_offset_alig= n, > > > + "%s: underlying filesystem has not provided DIO alignment in= fo\n", > > > + __func__)) > > > + return false; > > > + if (WARN_ONCE(dio_blocksize > PAGE_SIZE, > > > + "%s: underlying storage's dio_blocksize=3D%u > PAGE_SIZE=3D%= lu\n", > > > + __func__, dio_blocksize, PAGE_SIZE)) > > > + return false; > >=20 > > IMHO these checks do not warrant a WARN. Perhaps a trace event, instead= ? >=20 > I won't die on this hill, I just don't see the risk of these given > they are highly unlikely ("famous last words"). >=20 > But if they trigger we should surely be made aware immediately. Not > only if someone happens to have a trace event enabled (which would > only happen with further support and engineering involvement to chase > "why isn't O_DIRECT being used like NFSD was optionally configured > to!?"). >=20 A kernel log message in this case makes sense to me, since it is a (minor) administrative issue. WARN_ONCE() is going to throw a big, scary stack trace, however that won't be terribly useful. We'll get hit with bug reports from it for years. Maybe pr_notice_once() for this? Or, maybe a pr_notice_once, but do it on a per-export basis? > > > + /* Return early if IO is irreparably misaligned (len < PAGE_SIZE, > > > + * or base not aligned). > > > + * Ondisk alignment is implied by the following code that expands > > > + * misaligned IO to have a DIO-aligned offset and len. > > > + */ > > > + if (unlikely(len < dio_blocksize) || ((base & (nf->nf_dio_mem_align= -1)) !=3D 0)) > > > + return false; > > > + > > > + init_nfsd_read_dio(read_dio); > > > + > > > + read_dio->start =3D round_down(offset, dio_blocksize); > > > + read_dio->end =3D round_up(orig_end, dio_blocksize); > > > + read_dio->start_extra =3D offset - read_dio->start; > > > + read_dio->end_extra =3D read_dio->end - orig_end; > > > + > > > + /* > > > + * Any misaligned READ less than NFSD_READ_DIO_MIN_KB won't be expa= nded > > > + * to be DIO-aligned (this heuristic avoids excess work, like alloc= ating > > > + * start_extra_page, for smaller IO that can generally already perf= orm > > > + * well using buffered IO). > > > + */ > > > + if ((read_dio->start_extra || read_dio->end_extra) && > > > + (len < NFSD_READ_DIO_MIN_KB)) { > > > + init_nfsd_read_dio(read_dio); > > > + return false; > > > + } > > > + > > > + if (read_dio->start_extra) { > > > + read_dio->start_extra_page =3D alloc_page(GFP_KERNEL); > >=20 > > This introduces a page allocation where there weren't any before. For > > NFSD, I/O pages come from rqstp->rq_pages[] so that memory allocation > > like this is not needed on an I/O path. >=20 > NFSD never supported DIO before. Yes, with this patch there is > a single page allocation in the misaligned DIO READ path (if it > requires reading extra before the client requested data starts). >=20 > I tried to succinctly explain the need for the extra page allocation > for misaligned DIO READ in this patch's header (in 2nd paragraph > of the above header). >=20 > I cannot see how to read extra, not requested by the client, into the > head of rq_pages without causing serious problems. So that cannot be > what you're saying needed. >=20 > > So I think the answer to this is that I want you to implement reading > > an entire aligned range from the file and then forming the NFS READ > > response with only the range of bytes that the client requested, as we > > discussed before. >=20 > That is what I'm doing. But you're taking issue with my implementation > that uses a single extra page. >=20 > > The use of xdr_buf and bvec should make that quite > > straightforward. >=20 > Is your suggestion to, rather than allocate a disjoint single page, > borrow the extra page from the end of rq_pages? Just map it into the > bvec instead of my extra page? >=20 > > This should make the aligned and unaligned cases nearly identical and > > much less fraught. >=20 > Regardless of which memory used to read the extra data, I don't see > how the care I've taken to read extra but hide that fact from the > client can be avoided. So the pre/post misaligned DIO READ code won't > change a whole lot. But once I understand your suggestion better > (after a clarifying response to this message) hopefully I'll see what > you're saying. >=20 > All said, this patchset is very important to me, I don't want it to > miss v6.18 -- I'm still "in it to win it" but it feels like I do need > your or others' help to pull this off. >=20 > And/or is it possible to accept this initial implementation with > mutual understanding that we must revisit your concern about my > allocating an extra page for the misaligned DIO READ path? >=20 > > > + if (WARN_ONCE(read_dio->start_extra_page =3D=3D NULL, > > > + "%s: Unable to allocate start_extra_page\n", __func__)) { > > > + init_nfsd_read_dio(read_dio); > > > + return false; > > > + } > > > + } > > > + > > > + return true; > > > +} > > > + > > > +static ssize_t nfsd_complete_misaligned_read_dio(struct svc_rqst *rq= stp, > > > + struct nfsd_read_dio *read_dio, > > > + ssize_t bytes_read, > > > + unsigned long bytes_expected, > > > + loff_t *offset, > > > + unsigned long *rq_bvec_numpages) > > > +{ > > > + ssize_t host_err =3D bytes_read; > > > + loff_t v; > > > + > > > + if (!read_dio->start_extra && !read_dio->end_extra) > > > + return host_err; > > > + > > > + /* If nfsd_analyze_read_dio() allocated a start_extra_page it must > > > + * be removed from rqstp->rq_bvec[] to avoid returning unwanted dat= a. > > > + */ > > > + if (read_dio->start_extra_page) { > > > + __free_page(read_dio->start_extra_page); > > > + *rq_bvec_numpages -=3D 1; > > > + v =3D *rq_bvec_numpages; > > > + memmove(rqstp->rq_bvec, rqstp->rq_bvec + 1, > > > + v * sizeof(struct bio_vec)); > > > + } > > > + /* Eliminate any end_extra bytes from the last page */ > > > + v =3D *rq_bvec_numpages; > > > + rqstp->rq_bvec[v].bv_len -=3D read_dio->end_extra; > > > + > > > + if (host_err < 0) { > > > + /* Underlying FS will return -EINVAL if misaligned > > > + * DIO is attempted because it shouldn't be. > > > + */ > > > + WARN_ON_ONCE(host_err =3D=3D -EINVAL); > > > + return host_err; > > > + } > > > + > > > + /* nfsd_analyze_read_dio() may have expanded the start and end, > > > + * if so adjust returned read size to reflect original extent. > > > + */ > > > + *offset +=3D read_dio->start_extra; > > > + if (likely(host_err >=3D read_dio->start_extra)) { > > > + host_err -=3D read_dio->start_extra; > > > + if (host_err > bytes_expected) > > > + host_err =3D bytes_expected; > > > + } else { > > > + /* Short read that didn't read any of requested data */ > > > + host_err =3D 0; > > > + } > > > + > > > + return host_err; > > > +} > > > + > > > +static bool nfsd_iov_iter_aligned_bvec(const struct iov_iter *i, > > > + unsigned addr_mask, unsigned len_mask) > > > +{ > > > + const struct bio_vec *bvec =3D i->bvec; > > > + unsigned skip =3D i->iov_offset; > > > + size_t size =3D i->count; > >=20 > > checkpatch.pl is complaining about the use of "unsigned" rather than > > "unsigned int". >=20 > OK. >=20 > > > + > > > + if (size & len_mask) > > > + return false; > > > + do { > > > + size_t len =3D bvec->bv_len; > > > + > > > + if (len > size) > > > + len =3D size; > > > + if ((unsigned long)(bvec->bv_offset + skip) & addr_mask) > > > + return false; > > > + bvec++; > > > + size -=3D len; > > > + skip =3D 0; > > > + } while (size); > > > + > > > + return true; > > > +} > > > + > > > /** > > > * nfsd_iter_read - Perform a VFS read using an iterator > > > * @rqstp: RPC transaction context > > > @@ -1094,7 +1242,8 @@ __be32 nfsd_iter_read(struct svc_rqst *rqstp, s= truct svc_fh *fhp, > > > unsigned int base, u32 *eof) > > > { > > > struct file *file =3D nf->nf_file; > > > - unsigned long v, total; > > > + unsigned long v, total, in_count =3D *count; > > > + struct nfsd_read_dio read_dio; > > > struct iov_iter iter; > > > struct kiocb kiocb; > > > ssize_t host_err; > > > @@ -1102,13 +1251,34 @@ __be32 nfsd_iter_read(struct svc_rqst *rqstp,= struct svc_fh *fhp, > > > =20 > > > init_sync_kiocb(&kiocb, file); > > > =20 > > > + v =3D 0; > > > + total =3D in_count; > > > + > > > switch (nfsd_io_cache_read) { > > > case NFSD_IO_DIRECT: > > > - /* Verify ondisk and memory DIO alignment */ > > > - if (nf->nf_dio_mem_align && nf->nf_dio_read_offset_align && > > > - (((offset | *count) & (nf->nf_dio_read_offset_align - 1)) =3D= =3D 0) && > > > - (base & (nf->nf_dio_mem_align - 1)) =3D=3D 0) > > > - kiocb.ki_flags =3D IOCB_DIRECT; > > > + /* > > > + * If NFSD_IO_DIRECT enabled, expand any misaligned READ to > > > + * the next DIO-aligned block (on either end of the READ). > > > + */ > > > + if (nfsd_analyze_read_dio(rqstp, fhp, nf, offset, > > > + in_count, base, &read_dio)) { > > > + /* trace_nfsd_read_vector() will reflect larger > > > + * DIO-aligned READ. > > > + */ > > > + offset =3D read_dio.start; > > > + in_count =3D read_dio.end - offset; > > > + total =3D in_count; > > > + > > > + kiocb.ki_flags |=3D IOCB_DIRECT; > > > + if (read_dio.start_extra) { > > > + len =3D read_dio.start_extra; > > > + bvec_set_page(&rqstp->rq_bvec[v], > > > + read_dio.start_extra_page, > > > + len, PAGE_SIZE - len); > > > + total -=3D len; > > > + ++v; > > > + } > > > + } > > > break; > > > case NFSD_IO_DONTCACHE: > > > kiocb.ki_flags =3D IOCB_DONTCACHE; > > > @@ -1120,8 +1290,6 @@ __be32 nfsd_iter_read(struct svc_rqst *rqstp, s= truct svc_fh *fhp, > > > =20 > > > kiocb.ki_pos =3D offset; > > > =20 > > > - v =3D 0; > > > - total =3D *count; > > > while (total) { > > > len =3D min_t(size_t, total, PAGE_SIZE - base); > > > bvec_set_page(&rqstp->rq_bvec[v], *(rqstp->rq_next_page++), > > > @@ -1132,9 +1300,21 @@ __be32 nfsd_iter_read(struct svc_rqst *rqstp, = struct svc_fh *fhp, > > > } > > > WARN_ON_ONCE(v > rqstp->rq_maxpages); > > > =20 > > > - trace_nfsd_read_vector(rqstp, fhp, offset, *count); > > > - iov_iter_bvec(&iter, ITER_DEST, rqstp->rq_bvec, v, *count); > > > + trace_nfsd_read_vector(rqstp, fhp, offset, in_count); > > > + iov_iter_bvec(&iter, ITER_DEST, rqstp->rq_bvec, v, in_count); > > > + > > > + if ((kiocb.ki_flags & IOCB_DIRECT) && > > > + !nfsd_iov_iter_aligned_bvec(&iter, nf->nf_dio_mem_align-1, > > > + nf->nf_dio_read_offset_align-1)) > > > + kiocb.ki_flags &=3D ~IOCB_DIRECT; > > > + > > > host_err =3D vfs_iocb_iter_read(file, &kiocb, &iter); > > > + > > > + if (in_count !=3D *count) { > > > + /* misaligned DIO expanded read to be DIO-aligned */ > > > + host_err =3D nfsd_complete_misaligned_read_dio(rqstp, &read_dio, > > > + host_err, *count, &offset, &v); > > > + } > > > return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_= err); > > > } > > > =20 > > > diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h > > > index e64ab444e0a7f..190c2667500e2 100644 > > > --- a/include/linux/sunrpc/svc.h > > > +++ b/include/linux/sunrpc/svc.h > > > @@ -163,10 +163,13 @@ extern u32 svc_max_payload(const struct svc_rqs= t *rqstp); > > > * pages, one for the request, and one for the reply. > > > * nfsd_splice_actor() might need an extra page when a READ payload > > > * is not page-aligned. > > > + * nfsd_iter_read() might need two extra pages when a READ payload > > > + * is not DIO-aligned -- but nfsd_iter_read() and nfsd_splice_actor(= ) > > > + * are mutually exclusive (so reuse page reserved for nfsd_splice_ac= tor). > > > */ > > > static inline unsigned long svc_serv_maxpages(const struct svc_serv = *serv) > > > { > > > - return DIV_ROUND_UP(serv->sv_max_mesg, PAGE_SIZE) + 2 + 1; > > > + return DIV_ROUND_UP(serv->sv_max_mesg, PAGE_SIZE) + 2 + 1 + 1; > > > } > > > =20 > > > /* > >=20 > > To properly evaluate the impact of using direct I/O for reads with real > > world user workloads, we will want to identify (or construct) some > > metrics (and this is future work, but near-term future). > >=20 > > Seems like allocating memory becomes difficult only when too many pages > > are dirty. I am skeptical that the issue is due to read caching, since > > clean pages in the page cache are pretty easy to evict quickly, AIUI. I= f > > that's incorrect, I'd like to understand why. >=20 > The much more problematic case is heavy WRITE workload with a working > set that far exceeds system memory. >=20 > But I agree it doesn't make a whole lot of sense that clean pages in > the page cache would be getting in the way. All I can tell you is > that in my experience MM seems to _not_ evict them quickly (but more > focused read-only testing is warranted to further understand the > dynamics and heuristics in MM and beyond -- especially if/when > READ-only then a pivot to a mix of heavy READ and WRITE or > WRITE-only). >=20 > NFSD using DIO is optional. I thought the point was to get it as an > available option so that _others_ could experiment and help categorize > the benefits/pitfalls further? >=20 > I cannot be a one man show on all this. I welcome more help from > anyone interested. --=20 Jeff Layton