From patchwork Tue Mar 17 15:04:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 6032331 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 9FE8F9F399 for ; Tue, 17 Mar 2015 15:04:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D80ED20426 for ; Tue, 17 Mar 2015 15:04:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 07899203F7 for ; Tue, 17 Mar 2015 15:04:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753791AbbCQPE1 (ORCPT ); Tue, 17 Mar 2015 11:04:27 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:3517 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753068AbbCQPE0 (ORCPT ); Tue, 17 Mar 2015 11:04:26 -0400 Received: from pps.filterd (m0044012 [127.0.0.1]) by mx0a-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id t2HEpLuU006383 for ; Tue, 17 Mar 2015 08:04:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : subject : date : message-id : mime-version : content-type; s=facebook; bh=IKNUwcG7puBLRS/4zXd2Jksfz7cX2GWE08eD+sidbYQ=; b=e4dItVhlj8lZFSZKokkd4sb804i5yzrTSz9caJ4qUuGilFWAgyym+qZZ8cig3wy1EU0w inZvX7y5qcgAHrU2bbw4IiDxL0uH0fMj0f7Sb5VbMSJteZwtEb0WCP/AXwJY8QVCLA9z gwOPW0ftodvy44ThmSIUQlzuL/FUaTCukdg= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 1t6m70gcv1-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT) for ; Tue, 17 Mar 2015 08:04:26 -0700 Received: from localhost (192.168.54.13) by mail.thefacebook.com (192.168.16.12) with Microsoft SMTP Server (TLS) id 14.3.195.1; Tue, 17 Mar 2015 08:04:25 -0700 From: Josef Bacik To: Subject: [PATCH] Btrfs: fix outstanding_extents accounting in DIO Date: Tue, 17 Mar 2015 11:04:23 -0400 Message-ID: <1426604663-7663-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [192.168.54.13] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.13.68, 1.0.33, 0.0.0000 definitions=2015-03-17_03:2015-03-17, 2015-03-17, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 kscore.is_bulkscore=1.08801856413265e-14 kscore.compositescore=0 circleOfTrustscore=0 compositescore=0.996183534634169 suspectscore=1 recipient_domain_to_sender_totalscore=0 phishscore=0 bulkscore=0 kscore.is_spamscore=0 rbsscore=0.996183534634169 recipient_to_sender_totalscore=0 recipient_domain_to_sender_domain_totalscore=0 spamscore=0 recipient_to_sender_domain_totalscore=0 urlsuspectscore=0.996183534634169 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1503170145 X-FB-Internal: deliver 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_SIGNED, 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 are keeping track of how many extents we need to reserve properly based on the amount we want to write, but we were still incrementing outstanding_extents if we wrote less than what we requested. We need to fix this logic to only do this if we request less than MAX_EXTENT_SIZE or if we write less than MAX_EXTENT_SIZE when we request an amount larger than MAX_EXTENT_SIZE. This fixes the problem Filipe reported with generic/300. Thanks, Reported-by: Filipe Manana Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 156d0f5..f6d2c56 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7387,7 +7387,24 @@ unlock: if (start + len > i_size_read(inode)) i_size_write(inode, start + len); - if (len < orig_len) { + /* + * direct_io can send down chunks > BTRFS_MAX_EXTENT_SIZE, so we + * don't want to jack up outstanding_extents if we're just + * allocating the largest extent we can for a range that we've + * already reserved the approriate number of outstanding_extents + * for. + * + * So if orig_len <= BTRFS_MAX_EXTENT_SIZE and our allocated len + * is less than orig_len then we know we're going to end up with + * more extents than we reserved. + * + * If orig_len > BTRFS_MAX_EXTENT_SIZE but we weren't able to + * allocate a BTRFS_MAX_EXTENT_SIZE extent then we know we have + * to add another outstanding extent. + */ + if (len < orig_len && + (orig_len <= BTRFS_MAX_EXTENT_SIZE || + len < BTRFS_MAX_EXTENT_SIZE)) { spin_lock(&BTRFS_I(inode)->lock); BTRFS_I(inode)->outstanding_extents++; spin_unlock(&BTRFS_I(inode)->lock);