Commit 77c1a08fc9ece4cb130b9fd279738e799f0c2864

Authored by Dave Chinner
Committed by Ben Myers
1 parent 9a8d2fdbb4

xfs: struct xfs_buf_log_format isn't variable sized.

The struct xfs_buf_log_format wants to think the dirty bitmap is
variable sized.  In fact, it is variable size on disk simply due to
the way we map it from the in-memory structure, but we still just
use a fixed size memory allocation for the in-memory structure.

Hence it makes no sense to set the function up as a variable sized
structure when we already know it's maximum size, and we always
allocate it as such. Simplify the structure by making the dirty
bitmap a fixed sized array and just using the size of the structure
for the allocation size.

This will make it much simpler to allocate and manipulate an array
of format structures for discontiguous buffer support.

The previous struct xfs_buf_log_item size according to
/proc/slabinfo was 224 bytes. pahole doesn't give the same size
because of the variable size definition. With this modification,
pahole reports the same as /proc/slabinfo:

	/* size: 224, cachelines: 4, members: 6 */

Because the xfs_buf_log_item size is now determined by the maximum
supported block size we introduce a dependency on xfs_alloc_btree.h.
Avoid this dependency by moving the idefines for the maximum block
sizes supported to xfs_types.h with all the other max/min type
defines to avoid any new dependencies.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ben Myers <bpm@sgi.com>

Showing 5 changed files with 40 additions and 43 deletions Side-by-side Diff

fs/xfs/xfs_alloc_btree.h
... ... @@ -51,20 +51,6 @@
51 51 typedef __be32 xfs_alloc_ptr_t;
52 52  
53 53 /*
54   - * Minimum and maximum blocksize and sectorsize.
55   - * The blocksize upper limit is pretty much arbitrary.
56   - * The sectorsize upper limit is due to sizeof(sb_sectsize).
57   - */
58   -#define XFS_MIN_BLOCKSIZE_LOG 9 /* i.e. 512 bytes */
59   -#define XFS_MAX_BLOCKSIZE_LOG 16 /* i.e. 65536 bytes */
60   -#define XFS_MIN_BLOCKSIZE (1 << XFS_MIN_BLOCKSIZE_LOG)
61   -#define XFS_MAX_BLOCKSIZE (1 << XFS_MAX_BLOCKSIZE_LOG)
62   -#define XFS_MIN_SECTORSIZE_LOG 9 /* i.e. 512 bytes */
63   -#define XFS_MAX_SECTORSIZE_LOG 15 /* i.e. 32768 bytes */
64   -#define XFS_MIN_SECTORSIZE (1 << XFS_MIN_SECTORSIZE_LOG)
65   -#define XFS_MAX_SECTORSIZE (1 << XFS_MAX_SECTORSIZE_LOG)
66   -
67   -/*
68 54 * Block numbers in the AG:
69 55 * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
70 56 */
fs/xfs/xfs_buf_item.c
... ... @@ -240,15 +240,13 @@
240 240 (bip->bli_flags & XFS_BLI_STALE));
241 241  
242 242 /*
243   - * The size of the base structure is the size of the
244   - * declared structure plus the space for the extra words
245   - * of the bitmap. We subtract one from the map size, because
246   - * the first element of the bitmap is accounted for in the
247   - * size of the base structure.
  243 + * Base size is the actual size of the ondisk structure - it reflects
  244 + * the actual size of the dirty bitmap rather than the size of the in
  245 + * memory structure.
248 246 */
249   - base_size =
250   - (uint)(sizeof(xfs_buf_log_format_t) +
251   - ((bip->bli_format.blf_map_size - 1) * sizeof(uint)));
  247 + base_size = offsetof(struct xfs_buf_log_format, blf_data_map) +
  248 + (bip->bli_format.blf_map_size *
  249 + sizeof(bip->bli_format.blf_data_map[0]));
252 250 vecp->i_addr = &bip->bli_format;
253 251 vecp->i_len = base_size;
254 252 vecp->i_type = XLOG_REG_TYPE_BFORMAT;
fs/xfs/xfs_buf_item.h
... ... @@ -21,23 +21,6 @@
21 21 extern kmem_zone_t *xfs_buf_item_zone;
22 22  
23 23 /*
24   - * This is the structure used to lay out a buf log item in the
25   - * log. The data map describes which 128 byte chunks of the buffer
26   - * have been logged.
27   - * For 6.2 and beyond, this is XFS_LI_BUF. We use this to log everything.
28   - */
29   -typedef struct xfs_buf_log_format {
30   - unsigned short blf_type; /* buf log item type indicator */
31   - unsigned short blf_size; /* size of this item */
32   - ushort blf_flags; /* misc state */
33   - ushort blf_len; /* number of blocks in this buf */
34   - __int64_t blf_blkno; /* starting blkno of this buf */
35   - unsigned int blf_map_size; /* size of data bitmap in words */
36   - unsigned int blf_data_map[1];/* variable size bitmap of */
37   - /* regions of buffer in this item */
38   -} xfs_buf_log_format_t;
39   -
40   -/*
41 24 * This flag indicates that the buffer contains on disk inodes
42 25 * and requires special recovery handling.
43 26 */
... ... @@ -61,6 +44,23 @@
61 44 #define NBWORD (NBBY * sizeof(unsigned int))
62 45  
63 46 /*
  47 + * This is the structure used to lay out a buf log item in the
  48 + * log. The data map describes which 128 byte chunks of the buffer
  49 + * have been logged.
  50 + */
  51 +#define XFS_BLF_DATAMAP_SIZE ((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) / NBWORD)
  52 +
  53 +typedef struct xfs_buf_log_format {
  54 + unsigned short blf_type; /* buf log item type indicator */
  55 + unsigned short blf_size; /* size of this item */
  56 + ushort blf_flags; /* misc state */
  57 + ushort blf_len; /* number of blocks in this buf */
  58 + __int64_t blf_blkno; /* starting blkno of this buf */
  59 + unsigned int blf_map_size; /* used size of data bitmap in words */
  60 + unsigned int blf_data_map[XFS_BLF_DATAMAP_SIZE]; /* dirty bitmap */
  61 +} xfs_buf_log_format_t;
  62 +
  63 +/*
64 64 * buf log item flags
65 65 */
66 66 #define XFS_BLI_HOLD 0x01
... ... @@ -102,7 +102,7 @@
102 102 char *bli_orig; /* original buffer copy */
103 103 char *bli_logged; /* bytes logged (bitmap) */
104 104 #endif
105   - xfs_buf_log_format_t bli_format; /* in-log header */
  105 + struct xfs_buf_log_format bli_format; /* embedded in-log header */
106 106 } xfs_buf_log_item_t;
107 107  
108 108 void xfs_buf_item_init(struct xfs_buf *, struct xfs_mount *);
... ... @@ -1514,9 +1514,8 @@
1514 1514 * size possible under XFS. This wastes a little bit of memory,
1515 1515 * but it is much faster.
1516 1516 */
1517   - xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
1518   - (((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) /
1519   - NBWORD) * sizeof(int))), "xfs_buf_item");
  1517 + xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
  1518 + "xfs_buf_item");
1520 1519 if (!xfs_buf_item_zone)
1521 1520 goto out_destroy_log_item_desc_zone;
1522 1521  
... ... @@ -133,6 +133,20 @@
133 133 #define MAXAEXTNUM ((xfs_aextnum_t)0x7fff) /* signed short */
134 134  
135 135 /*
  136 + * Minimum and maximum blocksize and sectorsize.
  137 + * The blocksize upper limit is pretty much arbitrary.
  138 + * The sectorsize upper limit is due to sizeof(sb_sectsize).
  139 + */
  140 +#define XFS_MIN_BLOCKSIZE_LOG 9 /* i.e. 512 bytes */
  141 +#define XFS_MAX_BLOCKSIZE_LOG 16 /* i.e. 65536 bytes */
  142 +#define XFS_MIN_BLOCKSIZE (1 << XFS_MIN_BLOCKSIZE_LOG)
  143 +#define XFS_MAX_BLOCKSIZE (1 << XFS_MAX_BLOCKSIZE_LOG)
  144 +#define XFS_MIN_SECTORSIZE_LOG 9 /* i.e. 512 bytes */
  145 +#define XFS_MAX_SECTORSIZE_LOG 15 /* i.e. 32768 bytes */
  146 +#define XFS_MIN_SECTORSIZE (1 << XFS_MIN_SECTORSIZE_LOG)
  147 +#define XFS_MAX_SECTORSIZE (1 << XFS_MAX_SECTORSIZE_LOG)
  148 +
  149 +/*
136 150 * Min numbers of data/attr fork btree root pointers.
137 151 */
138 152 #define MINDBTPTRS 3