From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Brian Foster <bfoster@redhat.com>
Cc: linux-xfs@vger.kernel.org, Patrick Dung <mpatdung@gmail.com>
Subject: Re: [PATCH 2/2] xfs: split indlen reservations fairly when under reserved
Date: Mon, 6 Feb 2017 17:21:59 -0800 [thread overview]
Message-ID: <20170207012159.GC12378@birch.djwong.org> (raw)
In-Reply-To: <1486146865-47286-3-git-send-email-bfoster@redhat.com>
On Fri, Feb 03, 2017 at 01:34:25PM -0500, Brian Foster wrote:
> Certain workoads that punch holes into speculative preallocation can
> cause delalloc indirect reservation splits when the delalloc extent is
> split in two. If further splits occur, an already short-handed extent
> can be split into two in a manner that leaves zero indirect blocks for
> one of the two new extents. This occurs because the shortage is large
> enough that the xfs_bmap_split_indlen() algorithm completely drains the
> requested indlen of one of the extents before it honors the existing
> reservation.
>
> This ultimately results in a warning from xfs_bmap_del_extent(). This
> has been observed during file copies of large, sparse files using 'cp
> --sparse=always.'
>
> To avoid this problem, update xfs_bmap_split_indlen() to explicitly
> apply the reservation shortage fairly between both extents. This smooths
> out the overall indlen shortage and defers the situation where we end up
> with a delalloc extent with zero indlen reservation to extreme
> circumstances.
>
> Reported-by: Patrick Dung <mpatdung@gmail.com>
> Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
> ---
> fs/xfs/libxfs/xfs_bmap.c | 58 +++++++++++++++++++++++++++++++++---------------
> 1 file changed, 40 insertions(+), 18 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index d2e48ed..4ca4606 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -4790,34 +4790,56 @@ xfs_bmap_split_indlen(
> xfs_filblks_t len2 = *indlen2;
> xfs_filblks_t nres = len1 + len2; /* new total res. */
> xfs_filblks_t stolen = 0;
> + xfs_filblks_t resfactor;
>
> /*
> * Steal as many blocks as we can to try and satisfy the worst case
> * indlen for both new extents.
> */
> - while (nres > ores && avail) {
> - nres--;
> - avail--;
> - stolen++;
> - }
> + if (ores < nres && avail)
> + stolen = XFS_FILBLKS_MIN(nres - ores, avail);
> + ores += stolen;
> +
> + /* nothing else to do if we've satisfied the new reservation */
> + if (ores >= nres)
> + return stolen;
> +
> + /*
> + * We can't meet the total required reservation for the two extents.
> + * Calculate the percent of the overall shortage between both extents
> + * and apply this percentage to each of the requested indlen values.
> + * This distributes the shortage fairly and reduces the chances that one
> + * of the two extents is left with nothing when extents are repeatedly
> + * split.
> + */
> + resfactor = (ores * 100) / nres;
> + len1 = resfactor * len1 / 100;
> + len2 = resfactor * len2 / 100;
> + ASSERT(len1 + len2 <= ores);
> + ASSERT(len1 < *indlen1 && len2 < *indlen2);
>
> /*
> - * The only blocks available are those reserved for the original
> - * extent and what we can steal from the extent being removed.
> - * If this still isn't enough to satisfy the combined
> - * requirements for the two new extents, skim blocks off of each
> - * of the new reservations until they match what is available.
> + * Hand out the remainder to each extent. If one of the two reservations
> + * is zero, we want to make sure that one gets a block first. The loop
> + * below starts with len1, so hand len2 a block right off the bat if it
> + * is zero.
> */
> - while (nres > ores) {
> - if (len1) {
> - len1--;
> - nres--;
> + ores -= (len1 + len2);
> + ASSERT((*indlen1 - len1) + (*indlen2 - len2) >= ores);
> + if (ores && !len2 && *indlen2) {
> + len2++;
> + ores--;
> + }
> + while (ores) {
> + if (len1 < *indlen1) {
> + len1++;
> + ores--;
> }
> - if (nres == ores)
> + if (!ores)
> break;
> - if (len2) {
> - len2--;
> - nres--;
> + if (len2 < *indlen2) {
> + len2++;
> + ores--;
> }
> }
>
> --
> 2.7.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2017-02-07 1:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-03 18:34 [PATCH 0/2] divide indirect blocks fairly on delalloc extent split Brian Foster
2017-02-03 18:34 ` [PATCH 1/2] xfs: handle indlen shortage on delalloc extent merge Brian Foster
2017-02-07 1:14 ` Darrick J. Wong
2017-02-03 18:34 ` [PATCH 2/2] xfs: split indlen reservations fairly when under reserved Brian Foster
2017-02-03 22:02 ` Darrick J. Wong
2017-02-06 15:34 ` Brian Foster
2017-02-07 1:41 ` Darrick J. Wong
2017-02-07 13:37 ` Brian Foster
2017-02-07 1:21 ` Darrick J. Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170207012159.GC12378@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=bfoster@redhat.com \
--cc=linux-xfs@vger.kernel.org \
--cc=mpatdung@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).