From patchwork Fri Oct 21 17:22:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 9485947 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=-7.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.0 X-Spam-HP: BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_DNSWL_HI=-5,RP_MATCHES_RCVD=-0.1 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 6CF6217DE8 for ; Fri, 21 Oct 2016 12:22:16 -0500 (CDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933295AbcJURWR (ORCPT ); Fri, 21 Oct 2016 13:22:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39716 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932507AbcJURWP (ORCPT ); Fri, 21 Oct 2016 13:22:15 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7409543A47 for ; Fri, 21 Oct 2016 17:22:15 +0000 (UTC) Received: from bfoster.bfoster (dhcp-41-20.bos.redhat.com [10.18.41.20]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9LHMF66022355 for ; Fri, 21 Oct 2016 13:22:15 -0400 Received: by bfoster.bfoster (Postfix, from userid 1000) id B5BF51201A8; Fri, 21 Oct 2016 13:22:13 -0400 (EDT) From: Brian Foster To: linux-xfs@vger.kernel.org Subject: [PATCH 3/3] xfs: don't skip cow forks w/ delalloc blocks in cowblocks scan Date: Fri, 21 Oct 2016 13:22:13 -0400 Message-Id: <1477070533-59327-4-git-send-email-bfoster@redhat.com> In-Reply-To: <1477070533-59327-1-git-send-email-bfoster@redhat.com> References: <1477070533-59327-1-git-send-email-bfoster@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 21 Oct 2016 17:22:15 +0000 (UTC) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The cowblocks background scanner currently clears the cowblocks tag for inodes without any real allocations in the cow fork. This excludes inodes with only delalloc blocks in the cow fork. While we might never expect to clear delalloc blocks from the cow fork in the background scanner, it is not necessarily correct to clear the cowblocks tag from such inodes. For example, if the background scanner happens to process an inode between a buffered write and writeback, the scanner catches the inode in a state after delalloc blocks have been allocated to the cow fork but before the delalloc blocks have been converted to real blocks by writeback. The background scanner then incorrectly clears the cowblocks tag, even if part of the aforementioned delalloc reservation will not be remapped to the data fork (i.e., extra blocks due to the cowextsize hint). This means that any such additional blocks in the cow fork might never be reclaimed by the background scanner and could persist until the inode itself is reclaimed. To address this problem, only skip and clear inodes without any cow fork allocations whatsoever from the background scanner. While we generally do not want to cancel delalloc reservations from the background scanner, the pagecache dirty check following the cowblocks check should prevent that situation. If we do end up with delalloc cow fork blocks without a dirty address space mapping, this is probably an indication that something has gone wrong and the blocks should be reclaimed, as they may never be converted to a real allocation. XXX: There are probably multiple ways to deal with this. Another option could be to tweak the has_cow_blocks() helper to separately return whether a cow fork has delalloc blocks and skip over the inode without actually clearing the tag. Thoughts? Signed-off-by: Brian Foster --- fs/xfs/xfs_icache.c | 2 +- fs/xfs/xfs_reflink.c | 23 ++++------------------- fs/xfs/xfs_reflink.h | 2 +- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index f295049..1191064 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -1583,7 +1583,7 @@ xfs_inode_free_cowblocks( ASSERT(!eofb || (eofb && eofb->eof_scan_owner != 0)); - if (!xfs_reflink_has_real_cow_blocks(ip)) { + if (!xfs_reflink_has_cow_blocks(ip)) { trace_xfs_inode_free_cowblocks_invalid(ip); xfs_inode_clear_cowblocks_tag(ip); return 0; diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index a279b4e..6057c37 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1699,35 +1699,20 @@ xfs_reflink_unshare( } /* - * Does this inode have any real CoW reservations? + * Does this inode have any CoW reservations? */ bool -xfs_reflink_has_real_cow_blocks( +xfs_reflink_has_cow_blocks( struct xfs_inode *ip) { - struct xfs_bmbt_irec irec; struct xfs_ifork *ifp; - struct xfs_bmbt_rec_host *gotp; - xfs_extnum_t idx; if (!xfs_is_reflink_inode(ip)) return false; - /* Go find the old extent in the CoW fork. */ ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK); - gotp = xfs_iext_bno_to_ext(ifp, 0, &idx); - while (gotp) { - xfs_bmbt_get_all(gotp, &irec); - - if (!isnullstartblock(irec.br_startblock)) - return true; - - /* Roll on... */ - idx++; - if (idx >= ifp->if_bytes / sizeof(xfs_bmbt_rec_t)) - break; - gotp = xfs_iext_get_ext(ifp, idx); - } + if (ifp->if_bytes) + return true; return false; } diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index fad1160..cdd3b1a 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -50,6 +50,6 @@ extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip, extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t len); -extern bool xfs_reflink_has_real_cow_blocks(struct xfs_inode *ip); +extern bool xfs_reflink_has_cow_blocks(struct xfs_inode *ip); #endif /* __XFS_REFLINK_H */