From patchwork Thu Aug 1 01:45:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: majianpeng X-Patchwork-Id: 2836699 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B24D69F4D4 for ; Thu, 1 Aug 2013 01:52:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 298CC20201 for ; Thu, 1 Aug 2013 01:52:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8FB4920200 for ; Thu, 1 Aug 2013 01:52:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751553Ab3HABwu (ORCPT ); Wed, 31 Jul 2013 21:52:50 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:48960 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751246Ab3HABwt (ORCPT ); Wed, 31 Jul 2013 21:52:49 -0400 Received: by mail-pd0-f172.google.com with SMTP id z11so680780pdj.3 for ; Wed, 31 Jul 2013 18:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:reply-to:subject:references:x-priority:x-guid :x-has-attach:x-mailer:mime-version:message-id:content-type :content-transfer-encoding; bh=WwrTvWHTsWTwzoReSmM0+sX4yPbw9fb1emFUrWvKpek=; b=IIh9AhFa12PVPfc6bo3ZRcH/gzra0CSUUbFvxlTw2SBEVXxBHWrAB3WbcNIy1Q5E2Y ZGrXVei0sQOCaMs32/D2zt1UotmPISUsi+JPe4Swrm7S3nS3I+Ek05FZITyb/plTb01N i27sxRhcBSZXBDLrCYk08VkSLE2xRDxnbGcpNun2WahlIbvb3cS750t0yuKBDPUxOmWC 6mBZ8oRjnRXhhsbTkz7VxRrBzYwklaYj+/U0BViXM2olOXqaMileAfzJZdynRTZzWhcM cHhWaa1o2nDxSH06ZXxyeCE4J9syhmhMHhX0fkw29Tl5DlYkvfEUzJDv4jYtoQADxzxJ fOGg== X-Received: by 10.66.139.193 with SMTP id ra1mr1170030pab.70.1375321968876; Wed, 31 Jul 2013 18:52:48 -0700 (PDT) Received: from majianpeng ([218.242.10.182]) by mx.google.com with ESMTPSA id x8sm612052pbb.39.2013.07.31.18.45.19 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 31 Jul 2013 18:52:47 -0700 (PDT) Date: Thu, 1 Aug 2013 09:45:16 +0800 From: majianpeng To: =?gb2312?B?WWFuLCBaaGVuZw==?= Cc: sage , ceph-devel Reply-To: majianpeng Subject: Re: Re: question about striped_read References: <201307250852310158703@gmail.com> <201307260848241340451@gmail.com> <201307260922285205344@gmail.com> <201307260938095935695@gmail.com> <201307261007003577701@gmail.com> <201307291100080913443@gmail.com> <201307301707312612641@gmail.com> <201307301941552785741@gmail.com> <201307310827296030660@gmail.com> <201307310844488455702@gmail.com> <201307310933358798964@gmail.com> <2013073113222469570311@gmail.com> <201307311532055128853@gmail.com>, X-Priority: 3 X-GUID: F067D42B-292B-42B8-9A5D-CD56A8745B85 X-Has-Attach: no X-Mailer: Foxmail 7.0.1.90[en] Mime-Version: 1.0 Message-ID: <201308010929458493571@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP >On Wed, Jul 31, 2013 at 3:32 PM, majianpeng wrote: >> >> [snip] >> Test case >> A: touch file >> dd if=file of=/dev/null bs=5M count=1 iflag=direct >> B: [data(2M)|hole(2m)][data(2M)] >> dd if=file of=/dev/null bs=8M count=1 iflag=direct >> C: [data(4M)[hole(4M)][hole(4M)][data(2M)] >> dd if=file of=/dev/null bs=16M count=1 iflag=direct >> D: touch file;truncate -s 5M file >> dd if=file of=/dev/null bs=8M count=1 iflag=direct >> >> Those cases can work. >> Now i make different processing for short-read between 'ret > 0' and "ret =0". >> For the short-read which ret > 0, it don't do read-page rather than zero the left area. >> This means reduce one meaningless read operation. >> > >This patch looks good. But I still hope not to duplicate code. > >how about change > "hit_stripe = this_len < left;" >to > "hit_stripe = this_len < left && (ret == this_len || pos + this_len < >inode->i_size);" > To make the code easy to understand, i don't apply your suggestion.But i add this check on the judgement of whether read more contents. The follow is the latest patch.Can you check? Thanks! Jianpeng Ma diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 2ddf061..3d8d14d 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -349,44 +349,38 @@ more: dout("striped_read %llu~%u (read %u) got %d%s%s\n", pos, left, read, ret, hit_stripe ? " HITSTRIPE" : "", was_short ? " SHORT" : ""); - if (ret > 0) { - int didpages = (page_align + ret) >> PAGE_CACHE_SHIFT; - - if (read < pos - off) { - dout(" zero gap %llu to %llu\n", off + read, pos); - ceph_zero_page_vector_range(page_align + read, - pos - off - read, pages); + if (ret >= 0) { + int didpages; + if (was_short && (pos + ret < inode->i_size)) { + u64 tmp = min(this_len - ret, + inode->i_size - pos - ret); + dout(" zero gap %llu to %llu\n", + pos + ret, pos + ret + tmp); + ceph_zero_page_vector_range(page_align + read + ret, + tmp, pages); + ret += tmp; } + + didpages = (page_align + ret) >> PAGE_CACHE_SHIFT; pos += ret; read = pos - off; left -= ret; page_pos += didpages; pages_left -= didpages; - /* hit stripe? */ - if (left && hit_stripe) + /* hit stripe and need continue*/ + if (left && hit_stripe && pos < inode->i_size) goto more; + } - if (was_short) { + if (ret >= 0) { + ret = read; /* did we bounce off eof? */ if (pos + left > inode->i_size) *checkeof = 1; - - /* zero trailing bytes (inside i_size) */ - if (left > 0 && pos < inode->i_size) { - if (pos + left > inode->i_size) - left = inode->i_size - pos; - - dout("zero tail %d\n", left); - ceph_zero_page_vector_range(page_align + read, left, - pages); - read += left; - } } - if (ret >= 0) - ret = read; dout("striped_read returns %d\n", ret); return ret; }