Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp108018ybg; Mon, 8 Jun 2020 17:49:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeW9hNj7mbjrKuVwMAtVlvOcBSrFrn+dROuufAbP+FTXnEYrHVnpN6jZPcNj8CmIlLNKnb X-Received: by 2002:a50:fa8d:: with SMTP id w13mr24707824edr.324.1591663751678; Mon, 08 Jun 2020 17:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663751; cv=none; d=google.com; s=arc-20160816; b=lzFMRJZy8fDxhdJl+c4os9MqxKiTjWFcOdBLsUFbdyyNtdDuE9bQ8cCPGaIaz6bzSa ItlWBkZEAq+jRWig/E6EFm/TamaootDsgcx1Cabpf89ptI/Ji2amsKI3hQEVsFCrrpQo XiP70IqF39yEn5YydT3PDIYfsWJ+sVJVul/GzJbXY3R6FToVFt1a+edYfu729AsAXv2K 7NQdJC7KsoQczz2X5tQEMyUZob52Og7Ij/Qn7pDL2MIzDWrfSVGXoGI3Ajn245Sk1+uo nGElFPXTtBsDNA3VdIZjsBy8g5O5LJohB/xPHbel93nEhruGyrf3BYcU/pms3bkC5FgZ TEBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lsGqaSacmrhrapGLwQ4NglEEktPr3AQhVajXL4AvqP0=; b=oV96dYXHX7i2qlNhss+ILaGjGWZ8hFW+9bAauM1WCY96mM9IQikbpgT0uBj8i23grB 3oq5/fSTMmgf9rn4bIF/ocf1wXXjk+/X3erRTLcRihd/LNp06hMg9GUnBVdVBj9gBxhC LDHxBvlSGnNePZf2TXEio68nQWmBzMgZGM4tQnuItk9beDUH/3RsHYabdk+A4R9DRas3 C9WqvIlxCOr2LLW9OU3S7IxRmSh36p1b0pZE1WlHuCl7EPxULFHkP5BgYnV54wLD5TyE vznZXYnVM2L3Dt5lpskl9GVLDzLQ5d2+piPrpFvlO7IMqARZ260pbCu992jQka/ifXdu kmhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=szzMRUmN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s24si9707815edx.192.2020.06.08.17.48.48; Mon, 08 Jun 2020 17:49:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=szzMRUmN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733222AbgFIArD (ORCPT + 99 others); Mon, 8 Jun 2020 20:47:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:58342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728903AbgFHXL1 (ORCPT ); Mon, 8 Jun 2020 19:11:27 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ACE9E20C09; Mon, 8 Jun 2020 23:11:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657887; bh=c6jaHtTdzzzvmrih3uxZ8mvKcgiUbE+snM8tDjzWFGE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=szzMRUmN7qqizXeutbjU1wnnQKV3/zf8jtmoY18NQSQqvct5KajZDjqSME88lpzOe PJvuX82qrVbMInBiX1476umxe6Cp3w04Q40K9c8du4Fr7coSYaSJyQ1Wzfg/k8rhDh wJ+Fx56NACda9mGTYJ6BoDXdd0YOq6hH7noZ4nEU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Darrick J. Wong" , Christoph Hellwig , Brian Foster , Sasha Levin , linux-xfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 243/274] xfs: measure all contiguous previous extents for prealloc size Date: Mon, 8 Jun 2020 19:05:36 -0400 Message-Id: <20200608230607.3361041-243-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Darrick J. Wong" [ Upstream commit f0322c7cc05eb23ef034775f9b39254cbd4f3678 ] When we're estimating a new speculative preallocation length for an extending write, we should walk backwards through the extent list to determine the number of number of blocks that are physically and logically contiguous with the write offset, and use that as an input to the preallocation size computation. This way, preallocation length is truly measured by the effectiveness of the allocator in giving us contiguous allocations without being influenced by the state of a given extent. This fixes both the problem where ZERO_RANGE within an EOF can reduce preallocation, and prevents the unnecessary shrinkage of preallocation when delalloc extents are turned into unwritten extents. This was found as a regression in xfs/014 after changing delalloc writes to create unwritten extents during writeback. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Brian Foster Signed-off-by: Sasha Levin --- fs/xfs/xfs_iomap.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index bb590a267a7f..e3ca124a99e4 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -377,15 +377,17 @@ xfs_iomap_prealloc_size( loff_t count, struct xfs_iext_cursor *icur) { + struct xfs_iext_cursor ncur = *icur; + struct xfs_bmbt_irec prev, got; struct xfs_mount *mp = ip->i_mount; struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset); - struct xfs_bmbt_irec prev; - int shift = 0; int64_t freesp; xfs_fsblock_t qblocks; - int qshift = 0; xfs_fsblock_t alloc_blocks = 0; + xfs_extlen_t plen; + int shift = 0; + int qshift = 0; if (offset + count <= XFS_ISIZE(ip)) return 0; @@ -400,7 +402,7 @@ xfs_iomap_prealloc_size( */ if ((mp->m_flags & XFS_MOUNT_ALLOCSIZE) || XFS_ISIZE(ip) < XFS_FSB_TO_B(mp, mp->m_dalign) || - !xfs_iext_peek_prev_extent(ifp, icur, &prev) || + !xfs_iext_prev_extent(ifp, &ncur, &prev) || prev.br_startoff + prev.br_blockcount < offset_fsb) return mp->m_allocsize_blocks; @@ -413,16 +415,28 @@ xfs_iomap_prealloc_size( * preallocation size. * * If the extent is a hole, then preallocation is essentially disabled. - * Otherwise we take the size of the preceding data extent as the basis - * for the preallocation size. If the size of the extent is greater than - * half the maximum extent length, then use the current offset as the - * basis. This ensures that for large files the preallocation size - * always extends to MAXEXTLEN rather than falling short due to things - * like stripe unit/width alignment of real extents. + * Otherwise we take the size of the preceding data extents as the basis + * for the preallocation size. Note that we don't care if the previous + * extents are written or not. + * + * If the size of the extents is greater than half the maximum extent + * length, then use the current offset as the basis. This ensures that + * for large files the preallocation size always extends to MAXEXTLEN + * rather than falling short due to things like stripe unit/width + * alignment of real extents. */ - if (prev.br_blockcount <= (MAXEXTLEN >> 1)) - alloc_blocks = prev.br_blockcount << 1; - else + plen = prev.br_blockcount; + while (xfs_iext_prev_extent(ifp, &ncur, &got)) { + if (plen > MAXEXTLEN / 2 || + isnullstartblock(got.br_startblock) || + got.br_startoff + got.br_blockcount != prev.br_startoff || + got.br_startblock + got.br_blockcount != prev.br_startblock) + break; + plen += got.br_blockcount; + prev = got; + } + alloc_blocks = plen * 2; + if (alloc_blocks > MAXEXTLEN) alloc_blocks = XFS_B_TO_FSB(mp, offset); if (!alloc_blocks) goto check_writeio; -- 2.25.1