From patchwork Thu Nov 17 20:11:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 9486443 X-Mozilla-Keys: nonjunk Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sandeen.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.0 X-Spam-HP: BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.001, RP_MATCHES_RCVD=-0.1,UNPARSEABLE_RELAY=0.001 X-Original-To: sandeen@sandeen.net Delivered-To: sandeen@sandeen.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by sandeen.net (Postfix) with ESMTP id 3D3E26F7BC6 for ; Thu, 17 Nov 2016 14:10:36 -0600 (CST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751688AbcKQULI (ORCPT ); Thu, 17 Nov 2016 15:11:08 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:41170 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751476AbcKQULI (ORCPT ); Thu, 17 Nov 2016 15:11:08 -0500 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id uAHKB4E4007571 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Nov 2016 20:11:05 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id uAHKB4XP022475 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Nov 2016 20:11:04 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id uAHKB4S4021860; Thu, 17 Nov 2016 20:11:04 GMT Received: from localhost (/10.145.178.207) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Nov 2016 12:11:03 -0800 Date: Thu, 17 Nov 2016 12:11:02 -0800 From: "Darrick J. Wong" To: Eryu Guan Cc: linux-xfs@vger.kernel.org Subject: Re: [BUG] dd doesn't return on ENOSPC and hang when fulfilling rmapbt XFS Message-ID: <20161117201102.GK16813@birch.djwong.org> References: <20161117163515.GB27776@eguan.usersys.redhat.com> <20161117173639.GJ16813@birch.djwong.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161117173639.GJ16813@birch.djwong.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org On Thu, Nov 17, 2016 at 09:36:39AM -0800, Darrick J. Wong wrote: > On Fri, Nov 18, 2016 at 12:35:15AM +0800, Eryu Guan wrote: > > Hi all, > > > > I hit a test hang in generic/224 when testing rmapbt enabled XFS on a > > host that has non-zero sunit/swidth reported from underlying device. And > > I simplified the reproducer to the following script, and the hang can be > > reproduced on any host now. > > > > ----- > > #!/bin/bash > > > > dev=/dev/sda5 > > mnt=/mnt/xfs > > > > mkfs -t xfs -m rmapbt=1 -d agcount=8,size=1g -f $dev > > Hm. I formatted with: > mkfs.xfs -m rmapbt=1 -d sunit=4096,swidth=40960 -f /dev/sdf > > (made up sunit numbers just to see how whacky it could get) > > and got a different hang instead. It looks like we are unable to > allocate any blocks to the bmbt and various things blow up from > there. Will go retry with tracepoints on to see if we're running > out of AG reservation or if we're really out of disk blocks or what. > > Crash message attached at the end. Hm. Looking at the indlen calculations, I see that we don't include the space that the rmapbt might need to store all the reverse mappings. I think this is a problem, since we decline delalloc reservations if (len + indlen) > fdblocks, but we potentially end up using more than indlen blocks to map len blocks into the file, so the allocator goes nuts. Eryu, does the following patch fix the problem you see? I ran your reproducer and mine and it fixed the problem in both cases. I didn't observe any issues running generic/224 either. --D --- From: Darrick J. Wong Subject: [PATCH] xfs: factor rmap btree size into the indlen calculations When we're estimating the amount of space it's going to take to satisfy a delalloc reservation, we need to include the space that we might need to grow the rmapbt. This helps us to avoid running out of space later when _iomap_write_allocate needs more space than we reserved. Eryu Guan observed this happening on generic/224 when sunit/swidth were set. Reported-by: Eryu Guan Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index b80a294..afedf96 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -49,6 +49,7 @@ #include "xfs_rmap.h" #include "xfs_ag_resv.h" #include "xfs_refcount.h" +#include "xfs_rmap_btree.h" kmem_zone_t *xfs_bmap_free_item_zone; @@ -190,8 +191,12 @@ xfs_bmap_worst_indlen( int maxrecs; /* maximum record count at this level */ xfs_mount_t *mp; /* mount structure */ xfs_filblks_t rval; /* return value */ + xfs_filblks_t orig_len; mp = ip->i_mount; + + /* Calculate the worst-case size of the bmbt. */ + orig_len = len; maxrecs = mp->m_bmap_dmxr[0]; for (level = 0, rval = 0; level < XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK); @@ -199,12 +204,20 @@ xfs_bmap_worst_indlen( len += maxrecs - 1; do_div(len, maxrecs); rval += len; - if (len == 1) - return rval + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - + if (len == 1) { + rval += XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - level - 1; + break; + } if (level == 0) maxrecs = mp->m_bmap_dmxr[1]; } + + /* Calculate the worst-case size of the rmapbt. */ + if (xfs_sb_version_hasrmapbt(&mp->m_sb)) + rval += 1 + xfs_rmapbt_calc_size(mp, orig_len) + + mp->m_rmap_maxlevels; + return rval; } -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in