From 3cd5d7316484c92a2e7346369bc30e30fd96fc5e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 4 Sep 2009 15:11:08 -0700 Subject: [PATCH] uclient: use objectcacher->is_cached to make readahead smarter Only initiate readahead if we have less than 1/2 of what we want to readahead. Otherwise we still do small reads, just way ahead of the current read position. --- src/client/Client.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index dd16050d31783..7889f8fba4880 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -4112,13 +4112,19 @@ int Client::_read_async(Fh *f, __u64 off, __u64 len, bufferlist *bl) if (off+l > in->size) l = in->size - off; - dout(10) << "readahead " << f->nr_consec_read << " reads " + loff_t min = MIN((loff_t)len, l/2); + + dout(20) << "readahead " << f->nr_consec_read << " reads " << f->consec_read_bytes << " bytes ... readahead " << off << "~" << l + << " min " << min << " (caller wants " << off << "~" << len << ")" << dendl; if (l > (loff_t)len) { - objectcacher->file_read(in->ino, &in->layout, in->snapid, - off, l, NULL, 0, 0); - dout(10) << "readahead initiated" << dendl; + if (objectcacher->file_is_cached(in->ino, &in->layout, in->snapid, off, min)) + dout(20) << "readahead already have min" << dendl; + else { + objectcacher->file_read(in->ino, &in->layout, in->snapid, off, l, NULL, 0, 0); + dout(20) << "readahead initiated" << dendl; + } } } -- 2.39.5