From patchwork Tue Apr 7 05:09:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davide Italiano X-Patchwork-Id: 6167371 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E2B9E9F2EC for ; Tue, 7 Apr 2015 05:09:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 15C15202C8 for ; Tue, 7 Apr 2015 05:09:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 363F2202B4 for ; Tue, 7 Apr 2015 05:09:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752792AbbDGFJa (ORCPT ); Tue, 7 Apr 2015 01:09:30 -0400 Received: from mail-pd0-f181.google.com ([209.85.192.181]:34784 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750862AbbDGFJa (ORCPT ); Tue, 7 Apr 2015 01:09:30 -0400 Received: by pdbqa5 with SMTP id qa5so9789335pdb.1 for ; Mon, 06 Apr 2015 22:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WJYzSjBgAQa6vPXdp6etsfiOqKv+fugJ6saCFd+Egi0=; b=m40n0KbV2PSvuDxgQ7P13cjukek2PjXl0R3IVpB2y/+NOeNDpVVXj0iwA1T7KYneFM 1dnAkenwwVrAJfKbMp+62sOy9MpVwC1o7feiYK0zoLchBwrRgmFKfIeEYFF6GtxdtNgX ItyFrAJE2VuFmobKEjyKZNrJaRIo9093iMEHqNwpIVH5X2rkhgqW/tku1W1B3L5C8OD8 QBvw2KwV/H2s7kISdHf2JaQQr02EMG/EKQNW51syx3ibJOqeuR9wiZSfHKffNOMaV+l4 KOJiIX7IaQJC1pb6FlGrNDVBBC9zH4ol9P2FLoUMGV1Gien/kJdUzCS5xU/dnJAMY68m SlXA== X-Received: by 10.70.41.202 with SMTP id h10mr33632491pdl.84.1428383369582; Mon, 06 Apr 2015 22:09:29 -0700 (PDT) Received: from linux-5sub.site.site (c-24-7-63-120.hsd1.ca.comcast.net. [24.7.63.120]) by mx.google.com with ESMTPSA id qv9sm6576444pab.27.2015.04.06.22.09.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Apr 2015 22:09:28 -0700 (PDT) From: Davide Italiano To: linux-btrfs@vger.kernel.org Cc: Davide Italiano Subject: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate. Date: Mon, 6 Apr 2015 22:09:15 -0700 Message-Id: <1428383355-1686-2-git-send-email-dccitaliano@gmail.com> X-Mailer: git-send-email 2.3.4 In-Reply-To: <1428383355-1686-1-git-send-email-dccitaliano@gmail.com> References: <1428383355-1686-1-git-send-email-dccitaliano@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 - We call inode_size_ok() only if FL_KEEP_SIZE isn't specified. - As an optimisation we can skip the call if (off + len) isn't greater than the current size of the file. This operation is called under the lock so the less work we do, the better. - If we call inode_size_ok() pass to it the correct value rather than a more conservative estimation. Signed-off-by: Davide Italiano Reviewed-by: Liu Bo Reviewed-by: David Sterba --- fs/btrfs/file.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 30982bb..f649bfc 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2586,9 +2586,13 @@ static long btrfs_fallocate(struct file *file, int mode, } mutex_lock(&inode->i_mutex); - ret = inode_newsize_ok(inode, alloc_end); - if (ret) - goto out; + + if (!(mode & FALLOC_FL_KEEP_SIZE) && + offset + len > inode->i_size) { + ret = inode_newsize_ok(inode, offset + len); + if (ret) + goto out; + } if (alloc_start > inode->i_size) { ret = btrfs_cont_expand(inode, i_size_read(inode),