From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 2/6] xfs: simplify xfs_idata_realloc
Date: Wed, 11 Jul 2018 09:23:11 -0700 [thread overview]
Message-ID: <20180711162311.GB32415@magnolia> (raw)
In-Reply-To: <20180710060528.4071-3-hch@lst.de>
On Tue, Jul 10, 2018 at 08:05:24AM +0200, Christoph Hellwig wrote:
> Streamline the code and take advantage of the fact that kmem_realloc
> through krealloc will be have like a normal allocation if passing in a
> NULL old pointer.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Looks good to me,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
> ---
> fs/xfs/libxfs/xfs_inode_fork.c | 55 ++++++++++++----------------------
> 1 file changed, 19 insertions(+), 36 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c
> index dee85b0f8846..a0e3fb804605 100644
> --- a/fs/xfs/libxfs/xfs_inode_fork.c
> +++ b/fs/xfs/libxfs/xfs_inode_fork.c
> @@ -468,51 +468,34 @@ xfs_iroot_realloc(
> */
> void
> xfs_idata_realloc(
> - xfs_inode_t *ip,
> - int byte_diff,
> - int whichfork)
> + struct xfs_inode *ip,
> + int byte_diff,
> + int whichfork)
> {
> - xfs_ifork_t *ifp;
> - int new_size;
> - int real_size;
> -
> - if (byte_diff == 0) {
> - return;
> - }
> + struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
> + int new_size = (int)ifp->if_bytes + byte_diff;
>
> - ifp = XFS_IFORK_PTR(ip, whichfork);
> - new_size = (int)ifp->if_bytes + byte_diff;
> ASSERT(new_size >= 0);
> + ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));
> +
> + if (byte_diff == 0)
> + return;
>
> if (new_size == 0) {
> kmem_free(ifp->if_u1.if_data);
> ifp->if_u1.if_data = NULL;
> - real_size = 0;
> - } else {
> - /*
> - * Stuck with malloc/realloc.
> - * For inline data, the underlying buffer must be
> - * a multiple of 4 bytes in size so that it can be
> - * logged and stay on word boundaries. We enforce
> - * that here.
> - */
> - real_size = roundup(new_size, 4);
> - if (ifp->if_u1.if_data == NULL) {
> - ifp->if_u1.if_data = kmem_alloc(real_size,
> - KM_SLEEP | KM_NOFS);
> - } else {
> - /*
> - * Only do the realloc if the underlying size
> - * is really changing.
> - */
> - ifp->if_u1.if_data =
> - kmem_realloc(ifp->if_u1.if_data,
> - real_size,
> - KM_SLEEP | KM_NOFS);
> - }
> + ifp->if_bytes = 0;
> + return;
> }
> +
> + /*
> + * For inline data, the underlying buffer must be a multiple of 4 bytes
> + * in size so that it can be logged and stay on word boundaries.
> + * We enforce that here.
> + */
> + ifp->if_u1.if_data = kmem_realloc(ifp->if_u1.if_data,
> + roundup(new_size, 4), KM_SLEEP | KM_NOFS);
> ifp->if_bytes = new_size;
> - ASSERT(ifp->if_bytes <= XFS_IFORK_SIZE(ip, whichfork));
> }
>
> void
> --
> 2.18.0
>
> --
> 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
next prev parent reply other threads:[~2018-07-11 16:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-10 6:05 reduce lookups in the COW extent tree Christoph Hellwig
2018-07-10 6:05 ` [PATCH 1/6] xfs: remove if_real_bytes Christoph Hellwig
2018-07-11 16:22 ` Darrick J. Wong
2018-07-10 6:05 ` [PATCH 2/6] xfs: simplify xfs_idata_realloc Christoph Hellwig
2018-07-11 16:23 ` Darrick J. Wong [this message]
2018-07-10 6:05 ` [PATCH 3/6] xfs: remove the xfs_ifork_t typedef Christoph Hellwig
2018-07-11 16:23 ` Darrick J. Wong
2018-07-10 6:05 ` [PATCH 4/6] xfs: introduce a new xfs_inode_has_cow_data helper Christoph Hellwig
2018-07-11 16:24 ` Darrick J. Wong
2018-07-10 6:05 ` [PATCH 5/6] xfs: maintain a sequence count for inode fork manipulations Christoph Hellwig
2018-07-10 6:05 ` [PATCH 6/6] xfs: avoid COW fork extent lookups in writeback if the fork didn't change Christoph Hellwig
2018-07-11 17:15 ` Darrick J. Wong
2018-07-11 17:20 ` Christoph Hellwig
2018-07-11 17:31 ` Darrick J. Wong
2018-07-11 17:35 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2018-07-12 13:49 reduce lookups in the COW extent tree V2 Christoph Hellwig
2018-07-12 13:49 ` [PATCH 2/6] xfs: simplify xfs_idata_realloc Christoph Hellwig
2018-07-17 23:23 reduce lookups in the COW extent tree V3 Christoph Hellwig
2018-07-17 23:24 ` [PATCH 2/6] xfs: simplify xfs_idata_realloc Christoph Hellwig
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=20180711162311.GB32415@magnolia \
--to=darrick.wong@oracle.com \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/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).