From: Dave Chinner <david@fromorbit.com>
To: Brian Foster <bfoster@redhat.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 12/18] xfs: helper to convert inobt record holemask to inode alloc. bitmap
Date: Fri, 25 Jul 2014 09:21:34 +1000 [thread overview]
Message-ID: <20140724232134.GU20518@dastard> (raw)
In-Reply-To: <1406211788-63206-13-git-send-email-bfoster@redhat.com>
On Thu, Jul 24, 2014 at 10:23:02AM -0400, Brian Foster wrote:
> The inobt record holemask field is a condensed data type designed to fit
> into the existing on-disk record and is zero based (allocated regions
> are set to 0, sparse regions are set to 1) to provide backwards
> compatibility. Thus the type is unnecessarily complex for use in higher
> level inode manipulations such as individual inode allocations, etc.
>
> Rather than foist the complexity of dealing with this field to every bit
> of logic that requires inode chunk allocation information, create the
> xfs_inobt_ialloc_bitmap() helper to convert the inobt record holemask to
> an inode allocation bitmap. The inode allocation bitmap is inode
> granularity similar to the inobt record free mask and indicates which
> inodes of the chunk are physically allocated on disk irrespective of
> whether the inode is considered allocated or free by the filesystem.
>
> Signed-off-by: Brian Foster <bfoster@redhat.com>
> ---
> fs/xfs/libxfs/xfs_format.h | 1 +
> fs/xfs/libxfs/xfs_ialloc.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 68 insertions(+)
>
> diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
> index 0baad50..cbc3296 100644
> --- a/fs/xfs/libxfs/xfs_format.h
> +++ b/fs/xfs/libxfs/xfs_format.h
> @@ -206,6 +206,7 @@ typedef __be32 xfs_alloc_ptr_t;
> #define XFS_FIBT_CRC_MAGIC 0x46494233 /* 'FIB3' */
>
> typedef __uint64_t xfs_inofree_t;
> +typedef __uint64_t xfs_inoalloc_t;
> #define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t))
> #define XFS_INODES_PER_CHUNK_LOG (XFS_NBBYLOG + 3)
> #define XFS_INOBT_ALL_FREE ((xfs_inofree_t)-1)
> diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
> index 4e98a21..166602e 100644
> --- a/fs/xfs/libxfs/xfs_ialloc.c
> +++ b/fs/xfs/libxfs/xfs_ialloc.c
> @@ -863,6 +863,73 @@ xfs_ialloc_get_rec(
> }
>
> /*
> + * Convert the inode record holemask to an inode allocation bitmap. The inode
> + * allocation bitmap is inode granularity and specifies whether an inode is
> + * physically allocated on disk (not whether the inode is considered allocated
> + * or free by the fs).
> + */
> +STATIC xfs_inoalloc_t
> +xfs_inobt_ialloc_bitmap(
> + struct xfs_inobt_rec_incore *rec)
> +{
> + xfs_inofree_t bitmap = 0;
> + xfs_inofree_t sparsebits;
> + int nextbit;
> + int shift;
> + __uint16_t allocmask;
> + uint allocbitmap;
allocbitmap should be a 64 bit value?
> +
> + /*
> + * Each holemask bit represents XFS_INODES_PER_SPCHUNK inodes. Determine
> + * the inode bits per holemask bit.
> + */
> + sparsebits = xfs_mask64lo(XFS_INODES_PER_SPCHUNK);
Can we just open code that?
sparsebits = (1ULL << XFS_INODES_PER_SPCHUNK) - 1;
> + /*
> + * The bit flip and type conversion are intentionally done separately
> + * here to zero-extend the bitmask.
> + */
> + allocmask = ~rec->ir_holemask;
> + allocbitmap = allocmask;
urk. That's a landmine.
> +
> + /*
> + * Each bit of allocbitmap represents an allocated region of the inode
> + * chunk. Thus, each bit represents XFS_INODES_PER_SPCHUNK physical
> + * inodes. Walk through allocbitmap and set the associated individual
> + * inode bits in the inode bitmap for each allocated chunk.
> + *
> + * For example, consider a 512b inode fs with a cluster size of 16k.
> + * Each holemask bit represents 4 inodes and each cluster contains 32
> + * inodes. Since sparse chunks are allocated at cluster granularity, a
> + * valid 16-bit holemask (and negated allocbitmap) with this geometry
> + * might look as follows:
> + *
> + * holemask ~ allocbitmap
> + * 0000 0000 1111 1111 => 1111 1111 0000 0000
> + *
> + * At 4 inodes per bit, this indicates that the first 32 inodes of the
> + * chunk are not physically allocated inodes. This is a hole from the
> + * perspective of the inode record. Converting the allocbitmap to a
> + * 64-bit inode allocation bitmap yields:
> + *
> + * 0xFFFFFFFF00000000
> + *
> + * ... where any of the 32 inodes defined by the higher order 32 bits of
> + * the map could be in use or free. Logically AND this bitmap with the
> + * record ir_free map to identify which of the physically allocated
> + * inodes are in use.
> + */
> + nextbit = xfs_next_bit(&allocbitmap, 1, 0);
> + while (nextbit != -1) {
> + shift = nextbit * XFS_INODES_PER_SPCHUNK;
> + bitmap |= (sparsebits << shift);
> + nextbit = xfs_next_bit(&allocbitmap, 1, nextbit + 1);
> + }
We need to get rid of xfs_next_bit() and friends, not add more
users. The generic bitmap functionality is better suited to this,
I think. A cleaned up version of something like this, perhaps:
DECLARE_BITMAP(allocmask, 16);
DECLARE_BITMAP(bitmap, 64);
bitmap_complement(&allocmask, &rec->ir_holemask, 16);
bitmap_full(&bitmap, 64);
for (i = 0; i < 16; i++) {
if (!test_bit(&allocmask, i)) {
bitmap_release_region(&bitmap, i * 4,
ilog2(XFS_INODES_PER_SPCHUNK));
}
}
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2014-07-24 23:21 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-24 14:22 [PATCH RFC 00/18] xfs: sparse inode chunks Brian Foster
2014-07-24 14:22 ` [PATCH 01/18] xfs: refactor xfs_inobt_insert() to eliminate loop and support variable count Brian Foster
2014-07-24 22:10 ` Dave Chinner
2014-07-28 16:03 ` Brian Foster
2014-07-28 23:32 ` Dave Chinner
2014-07-29 14:43 ` Brian Foster
2014-07-24 14:22 ` [PATCH 02/18] xfs: pass xfs_mount directly to xfs_ialloc_cluster_alignment() Brian Foster
2014-07-24 14:22 ` [PATCH 03/18] xfs: define sparse inode chunks v5 sb feature bit and helper function Brian Foster
2014-07-24 17:08 ` Mark Tinguely
2014-07-24 17:37 ` Brian Foster
2014-07-24 18:38 ` Mark Tinguely
2014-07-24 19:38 ` Brian Foster
2014-07-24 23:35 ` Dave Chinner
2014-07-24 14:22 ` [PATCH 04/18] xfs: introduce inode record hole mask for sparse inode chunks Brian Foster
2014-07-24 22:14 ` Dave Chinner
2014-07-28 16:16 ` Brian Foster
2014-08-07 15:18 ` Brian Foster
2014-07-24 14:22 ` [PATCH 05/18] xfs: create macros/helpers for dealing with " Brian Foster
2014-07-24 22:13 ` Dave Chinner
2014-07-24 14:22 ` [PATCH 06/18] xfs: pass inode count through ordered icreate log item Brian Foster
2014-07-24 14:22 ` [PATCH 07/18] xfs: handle sparse inode chunks in icreate log recovery Brian Foster
2014-07-24 14:22 ` [PATCH 08/18] xfs: create helper to manage record overlap for sparse inode chunks Brian Foster
2014-07-24 22:41 ` Dave Chinner
2014-07-28 16:19 ` Brian Foster
2014-07-29 0:07 ` Dave Chinner
2014-07-29 15:10 ` Brian Foster
2014-07-24 14:22 ` [PATCH 09/18] xfs: allocate sparse inode chunks on full chunk allocation failure Brian Foster
2014-07-24 14:23 ` [PATCH 10/18] xfs: set sparse inodes feature bit when a sparse chunk is allocated Brian Foster
2014-07-24 22:46 ` Dave Chinner
2014-07-28 16:23 ` Brian Foster
2014-07-24 14:23 ` [PATCH 11/18] xfs: reduce min. inode allocation space requirement for sparse inode chunks Brian Foster
2014-07-24 22:50 ` Dave Chinner
2014-07-24 14:23 ` [PATCH 12/18] xfs: helper to convert inobt record holemask to inode alloc. bitmap Brian Foster
2014-07-24 23:21 ` Dave Chinner [this message]
2014-07-24 14:23 ` [PATCH 13/18] xfs: filter out sparse regions from individual inode allocation Brian Foster
2014-07-24 14:23 ` [PATCH 14/18] xfs: update free inode record logic to support sparse inode records Brian Foster
2014-07-24 14:23 ` [PATCH 15/18] xfs: only free allocated regions of inode chunks Brian Foster
2014-07-24 23:24 ` Dave Chinner
2014-07-24 14:23 ` [PATCH 16/18] xfs: skip unallocated regions of inode chunks in xfs_ifree_cluster() Brian Foster
2014-07-24 14:23 ` [PATCH 17/18] xfs: use actual inode count for sparse records in bulkstat/inumbers Brian Foster
2014-07-24 23:29 ` Dave Chinner
2014-07-24 14:23 ` [PATCH 18/18] xfs: enable sparse inode chunks for v5 superblocks Brian Foster
2014-07-24 23:34 ` Dave Chinner
2014-07-24 16:28 ` [PATCH RFC 00/18] xfs: sparse inode chunks Brian Foster
2014-07-24 22:32 ` Dave Chinner
2014-07-25 16:30 ` Brian Foster
2014-07-26 0:03 ` Dave Chinner
2014-07-28 12:14 ` Brian Foster
2014-07-29 0:26 ` Dave Chinner
2014-07-29 15:25 ` Brian Foster
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=20140724232134.GU20518@dastard \
--to=david@fromorbit.com \
--cc=bfoster@redhat.com \
--cc=xfs@oss.sgi.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