From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 41EB38017D for ; Tue, 10 Nov 2026 21:26:32 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AALPD5O018786; Wed, 11 Nov 2026 00:25:14 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AALPD5O018786 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1794345918; bh=l1QOT02eJVSzjShU79LZRyIUm9j2yCamkW8olaYZ0sg=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=aFnbhCi4kDVDiZ9pOU6AXfXJI7Y7nQqtXCLUw5e2IFEFsqa/Yw9/6RdFS4jWLrEIi vcZwuy0xwCXivnYuUttJnschHW1zsEoHUKO+7B2TgpL1aq1WSIgazXwsWBPsiv8RLi 7oaBYvKnw2rglUzrhDWVOEwHeNube7oCWszuwe1AirgR/ErsZUaJDYikJxEkivZs0W kAK1CsTXsLenaUlCYbpxCfhXAbuxp37SdQoaKPzyPEewU7u7Le4KhAzNXiKxf8Bw3s +wUDExpj2c3+H/lL/kLlLEB7t/SrvBoejAEHJP9e3Gd1I/4+hTtcpklPRkC/zj5yf+ OAJ0RzmHb0ToA== Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AALP63m018773 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 11 Nov 2026 00:25:06 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AALP63m018773 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="rqC7L6ht" Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-49205554e17so1648359f8f.1 for ; Tue, 10 Nov 2026 13:25:06 -0800 (PST) X-Gm-Message-State: APuU4Z8mKD65ouDIXQM5D+26ElSj+bx7UffC7rwl6rYzciiUiwNeKfY2 icoyQS7+AOx59Jomepw9lNq/UfTnPwd7rui7+zfBwhYiatok6IjLY3KACMLvRTVOrT9ltKhgb3f 9BW51ND8UgQLyTz2gy++5MZGNcJdx25csUIlii2Lzwp4N7Mf7NlX4fQ== X-Gm-Gg: AYBFou1DSG98tIq8uR/jezVEZrTI15ZAYHfJtTE+dP3XxiUMhfkUb68HKNN+LHWlZ6N uRgVNfkX3aVw8lw5JrTxE1QNqftG2JxGMvDgYgVdv5arjaK6fFs4ZT3c+VTyzLhzZ/6zqVHEjVL PpkTCZbIXPQqb9KS4eHNj03+BOVElBJF4JeHYD28bJ1UmiMp+DIkE83RqRv/8Qxg3vhDLbjWZri bH0oycc+JtphBi2upV7kkIrP6MgFO3KrH4NARuzqOSuvRJyy6YHRBqNg9kTJRk27JGYlx9OQVrp Le0tVjsftQ== X-Received: by 2002:a05:6000:4b1c:b0:48e:3fc:e393 with SMTP id ffacd0b85a97d-499c3ba0605mr367284f8f.6.1794345905969; Tue, 10 Nov 2026 13:25:05 -0800 (PST) X-Received: by 2002:a05:6000:4b1c:b0:48e:3fc:e393 with SMTP id ffacd0b85a97d-499c3ba0605mr367265f8f.6.1794345905585; Tue, 10 Nov 2026 13:25:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794345905; cv=none; d=google.com; s=arc-20260327; b=k+mhYV6i4aPRhNHyB3nPSLJ6k4mG1nqCW3ySfLXMA6T2BCuUnzSDD1Mb4CRI5UamUY vvhSaXcXZiaygKEaItUhhEoVIcOYKVJQjFM58Zs4xVZ/89w+//ng/mTHwSKmwIa63jMT O+rss4plACoM4bq1Jc+gcW4Q1OylqecucqR6A1lqhLTWOEmIrT+FZ/a107WYokdKO8cQ 6eXKyTkahMJTReOHImtTSRIM55pfFk4EUPJRR5rYmga1PCYu5JX7ntkVK/MsdaHt3xh3 +13JflinOk5zCLjE3+o9VMNAnHhfxy0TQhUekeDX+tVLE/45OLJsNzxtRoXEagqUMxDe lPWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=J0ew8Q8hfLijrOjhZa8urejrpc0LTTBPyY+Ww1/QF0s=; fh=ozrYJQ1t3QIP6s65KBq5xgJxiFM2qf+5wwn3ABTusyU=; b=UVTNyLj/zkHmb2II5Q1EUJI15nmD/mmZl1v4VZV4yuyMpJapCUB9q0C31aVOX6F2FC 6cFQUHt4144LSocV1A9zwnk2dAYGYv4dj0HAEQY0UsrLrO1Ozr75RQtAbV6Q7zaZPGnY UdXGn+XdrU6K/wknrO8t+h8tRfNohW9zLm5MDu2L5YbdfKTpr3OCVnRG/62OcX1Z4i3S 0SewnEVDodIr4QwnRfCQ45I4I3ZCjcL4D9E2FT9bMpGtWewmdVWteDfN0wLGG3kLxwTl IoGbDAUcjM1ucQ8aearfwnebD5f4ZNUX1p0mB8jhAobyrSUvCsvh388LBoG7YVnRwZzf hfJQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=rqC7L6ht; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:4f78:6441:d0f1:22af as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-49834609492sor643169f8f.8.2026.11.10.13.25.05 for (Google Transport Security); Tue, 10 Nov 2026 13:25:05 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:4f78:6441:d0f1:22af as permitted sender) client-ip=2a06:5b06:b600:300:4f78:6441:d0f1:22af; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=rqC7L6ht; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:4f78:6441:d0f1:22af as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1794345905; x=1794950705; darn=openvz.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=J0ew8Q8hfLijrOjhZa8urejrpc0LTTBPyY+Ww1/QF0s=; b=rqC7L6ht7eWd5uYDmccW6yLEy6U3yBmPkqwOrZ0Y+VFvIbyX5K1MQ7XgVDs/sveYMw bdmMdDUvUJwmTr1DZgTzLINsUyzA4qUyL4kq2lFxKPRN8sCcy05+6RG+0Ic7gjQjZQ4f /7PBDwCIxm56XNw0SSRAMvMa9asIiwLzFxs+AItopfw29Qr0d097XaTRWgqRmVNQinWw CGt2JjxVS60wq5hIxDhg6zto8hZ6vEOcpuXNWObjqEG9ZRK+/J2XowacnN4PpxSSaiSD +wA60PwmUY14z+0mAr/haH+LaSmP1qQtsSu3JYZLWmL+4ISG0rGyfkybnya4w19Kl5Cg 5fJA== X-Received: by 2002:a05:6000:4717:b0:48e:66d0:664c with SMTP id ffacd0b85a97d-499c5f30f9amr317016f8f.15.1794345905160; Tue, 10 Nov 2026 13:25:05 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:4f78:6441:d0f1:22af]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-49835d2c05dsm7051999f8f.25.2026.11.10.13.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 13:25:04 -0800 (PST) From: "Denis V. Lunev" To: khorenko@virtuozzo.com Date: Tue, 10 Nov 2026 22:24:59 +0100 Message-ID: <20261110212459.3158424-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261110212459.3158424-1-den@openvz.org> References: <20261110212459.3158424-1-den@openvz.org> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 2/2] xfs: discard the balloon on FITRIM X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Denis V. Lunev The balloon holds file system space that never carries data, but its blocks are allocated, so the free space walk of xfs_ioc_trim() never discards them, and inflating the balloon is a plain fallocate() that does not discard either. Once the balloon is inflated over blocks that held data, e.g. on an online shrink after files were removed, the device below keeps them allocated: a ploop or qcow2 image keeps host disk space the container can never use, and compaction, which is FITRIM, does not give it back. Walk the balloon after the free space of the data device and discard its unwritten extents that fall into the requested range, merging physically adjacent ones into one discard. The shared IOLOCK keeps fallocate and truncate away from the balloon meanwhile, so none of its blocks can be freed and reused under the discard. An unwritten extent reads as zeroes whatever the device returns, so the discard changes nothing visible, and repeating it is harmless. A balloon inflated before this change is released by the next FITRIM. https://virtuozzo.atlassian.net/browse/VSTOR-153590 Feature: fs/xfs: fast online shrink support Signed-off-by: Denis V. Lunev --- fs/xfs/xfs_discard.c | 106 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c index 93943e698eea..a7f1491dc35a 100644 --- a/fs/xfs/xfs_discard.c +++ b/fs/xfs/xfs_discard.c @@ -22,6 +22,10 @@ #include "xfs_health.h" #include "xfs_rtbitmap.h" #include "xfs_rtgroup.h" +#include "xfs_bit.h" +#include "xfs_inode.h" +#include "xfs_bmap.h" +#include "xfs_super.h" /* * Notes on an efficient, low latency fstrim algorithm @@ -833,6 +837,102 @@ xfs_trim_rtdev_extents( # define xfs_trim_rtdev_extents(...) (-EOPNOTSUPP) #endif /* CONFIG_XFS_RT */ +static int +xfs_trim_balloon_run( + struct xfs_mount *mp, + xfs_daddr_t daddr, + xfs_daddr_t len, + xfs_daddr_t start, + xfs_daddr_t end, + xfs_extlen_t minlen) +{ + xfs_daddr_t last = daddr + len - 1; + + if (!len) + return 0; + if (daddr < start) + daddr = start; + if (last > end) + last = end; + if (last < daddr || last - daddr + 1 < XFS_FSB_TO_BB(mp, minlen)) + return 0; + + return blkdev_issue_discard(mp->m_ddev_targp->bt_bdev, daddr, + last - daddr + 1, GFP_NOFS); +} + +/* + * Blocks of the balloon never hold data, but they are allocated, so the + * free space btree walk never discards them. Discard its unwritten + * extents, merging physically adjacent ones, so that the device below + * can release the space as it does for free blocks. + */ +static int +xfs_trim_balloon( + struct xfs_mount *mp, + xfs_daddr_t start, + xfs_daddr_t end, + xfs_extlen_t minlen) +{ + u64 balloon_ino = READ_ONCE(mp->m_balloon_ino); + xfs_daddr_t run_daddr = 0, run_len = 0; + struct xfs_bmbt_irec map; + struct xfs_inode *ip; + xfs_fileoff_t off = 0, end_fsb; + unsigned int lock_mode; + bool unwritten; + int nmaps, error = 0; + + if (!balloon_ino || xfs_is_readonly(mp)) + return 0; + ip = xfs_balloon_get(mp, balloon_ino, 0); + if (IS_ERR(ip)) + return 0; + if (XFS_IS_REALTIME_INODE(ip)) + goto out_rele; + + xfs_ilock(ip, XFS_IOLOCK_SHARED); + end_fsb = XFS_B_TO_FSB(mp, i_size_read(VFS_I(ip))); + while (off < end_fsb) { + if (xfs_trim_should_stop()) + break; + cond_resched(); + + nmaps = 1; + lock_mode = xfs_ilock_data_map_shared(ip); + error = xfs_bmapi_read(ip, off, end_fsb - off, &map, &nmaps, 0); + xfs_iunlock(ip, lock_mode); + if (error || !nmaps || !map.br_blockcount) + break; + off = map.br_startoff + map.br_blockcount; + + unwritten = xfs_bmap_is_real_extent(&map) && + map.br_state == XFS_EXT_UNWRITTEN; + if (unwritten && run_len && run_daddr + run_len == + XFS_FSB_TO_DADDR(mp, map.br_startblock)) { + run_len += XFS_FSB_TO_BB(mp, map.br_blockcount); + continue; + } + + error = xfs_trim_balloon_run(mp, run_daddr, run_len, start, + end, minlen); + if (error) + break; + run_len = 0; + if (unwritten) { + run_daddr = XFS_FSB_TO_DADDR(mp, map.br_startblock); + run_len = XFS_FSB_TO_BB(mp, map.br_blockcount); + } + } + if (!error && !xfs_trim_should_stop()) + error = xfs_trim_balloon_run(mp, run_daddr, run_len, start, + end, minlen); + xfs_iunlock(ip, XFS_IOLOCK_SHARED); +out_rele: + xfs_irele(ip); + return error; +} + /* * trim a range of the filesystem. * @@ -905,6 +1005,12 @@ xfs_ioc_trim( error = xfs_trim_datadev_extents(mp, start, end, minlen); if (error) last_error = error; + + if (!xfs_trim_should_stop()) { + error = xfs_trim_balloon(mp, start, end, minlen); + if (error) + last_error = error; + } } if (rt_bdev && !xfs_trim_should_stop()) { -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel