Commit 43518812 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: remove support for inlining data/extents into the inode fork

Supporting a small bit of data inside the inode fork blows up the fork size
a lot, removing the 32 bytes of inline data halves the effective size of
the inode fork (and it still has a lot of unused padding left), and the
performance of a single kmalloc doesn't show up compared to the size to read
an inode or create one.

It also simplifies the fork management code a lot.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent b121459c
...@@ -269,19 +269,14 @@ xfs_init_local_fork( ...@@ -269,19 +269,14 @@ xfs_init_local_fork(
if (zero_terminate) if (zero_terminate)
mem_size++; mem_size++;
if (size == 0) if (size) {
ifp->if_u1.if_data = NULL;
else if (mem_size <= sizeof(ifp->if_u2.if_inline_data))
ifp->if_u1.if_data = ifp->if_u2.if_inline_data;
else {
real_size = roundup(mem_size, 4); real_size = roundup(mem_size, 4);
ifp->if_u1.if_data = kmem_alloc(real_size, KM_SLEEP | KM_NOFS); ifp->if_u1.if_data = kmem_alloc(real_size, KM_SLEEP | KM_NOFS);
}
if (size) {
memcpy(ifp->if_u1.if_data, data, size); memcpy(ifp->if_u1.if_data, data, size);
if (zero_terminate) if (zero_terminate)
ifp->if_u1.if_data[size] = '\0'; ifp->if_u1.if_data[size] = '\0';
} else {
ifp->if_u1.if_data = NULL;
} }
ifp->if_bytes = size; ifp->if_bytes = size;
...@@ -292,13 +287,6 @@ xfs_init_local_fork( ...@@ -292,13 +287,6 @@ xfs_init_local_fork(
/* /*
* The file is in-lined in the on-disk inode. * The file is in-lined in the on-disk inode.
* If it fits into if_inline_data, then copy
* it there, otherwise allocate a buffer for it
* and copy the data there. Either way, set
* if_data to point at the data.
* If we allocate a buffer for the data, make
* sure that its size is a multiple of 4 and
* record the real size in i_real_bytes.
*/ */
STATIC int STATIC int
xfs_iformat_local( xfs_iformat_local(
...@@ -328,9 +316,7 @@ xfs_iformat_local( ...@@ -328,9 +316,7 @@ xfs_iformat_local(
/* /*
* The file consists of a set of extents all of which fit into the on-disk * The file consists of a set of extents all of which fit into the on-disk
* inode. If there are few enough extents to fit into the if_inline_ext, then * inode.
* copy them there. Otherwise allocate a buffer for them and copy them into it.
* Either way, set if_extents to point at the extents.
*/ */
STATIC int STATIC int
xfs_iformat_extents( xfs_iformat_extents(
...@@ -362,8 +348,6 @@ xfs_iformat_extents( ...@@ -362,8 +348,6 @@ xfs_iformat_extents(
ifp->if_real_bytes = 0; ifp->if_real_bytes = 0;
if (nex == 0) if (nex == 0)
ifp->if_u1.if_extents = NULL; ifp->if_u1.if_extents = NULL;
else if (nex <= XFS_INLINE_EXTS)
ifp->if_u1.if_extents = ifp->if_u2.if_inline_ext;
else else
xfs_iext_add(ifp, 0, nex); xfs_iext_add(ifp, 0, nex);
...@@ -618,26 +602,9 @@ xfs_idata_realloc( ...@@ -618,26 +602,9 @@ xfs_idata_realloc(
ASSERT(new_size >= 0); ASSERT(new_size >= 0);
if (new_size == 0) { if (new_size == 0) {
if (ifp->if_u1.if_data != ifp->if_u2.if_inline_data) { kmem_free(ifp->if_u1.if_data);
kmem_free(ifp->if_u1.if_data);
}
ifp->if_u1.if_data = NULL; ifp->if_u1.if_data = NULL;
real_size = 0; real_size = 0;
} else if (new_size <= sizeof(ifp->if_u2.if_inline_data)) {
/*
* If the valid extents/data can fit in if_inline_ext/data,
* copy them from the malloc'd vector and free it.
*/
if (ifp->if_u1.if_data == NULL) {
ifp->if_u1.if_data = ifp->if_u2.if_inline_data;
} else if (ifp->if_u1.if_data != ifp->if_u2.if_inline_data) {
ASSERT(ifp->if_real_bytes != 0);
memcpy(ifp->if_u2.if_inline_data, ifp->if_u1.if_data,
new_size);
kmem_free(ifp->if_u1.if_data);
ifp->if_u1.if_data = ifp->if_u2.if_inline_data;
}
real_size = 0;
} else { } else {
/* /*
* Stuck with malloc/realloc. * Stuck with malloc/realloc.
...@@ -651,7 +618,7 @@ xfs_idata_realloc( ...@@ -651,7 +618,7 @@ xfs_idata_realloc(
ASSERT(ifp->if_real_bytes == 0); ASSERT(ifp->if_real_bytes == 0);
ifp->if_u1.if_data = kmem_alloc(real_size, ifp->if_u1.if_data = kmem_alloc(real_size,
KM_SLEEP | KM_NOFS); KM_SLEEP | KM_NOFS);
} else if (ifp->if_u1.if_data != ifp->if_u2.if_inline_data) { } else {
/* /*
* Only do the realloc if the underlying size * Only do the realloc if the underlying size
* is really changing. * is really changing.
...@@ -662,12 +629,6 @@ xfs_idata_realloc( ...@@ -662,12 +629,6 @@ xfs_idata_realloc(
real_size, real_size,
KM_SLEEP | KM_NOFS); KM_SLEEP | KM_NOFS);
} }
} else {
ASSERT(ifp->if_real_bytes == 0);
ifp->if_u1.if_data = kmem_alloc(real_size,
KM_SLEEP | KM_NOFS);
memcpy(ifp->if_u1.if_data, ifp->if_u2.if_inline_data,
ifp->if_bytes);
} }
} }
ifp->if_real_bytes = real_size; ifp->if_real_bytes = real_size;
...@@ -695,8 +656,7 @@ xfs_idestroy_fork( ...@@ -695,8 +656,7 @@ xfs_idestroy_fork(
* so check and free it up if we do. * so check and free it up if we do.
*/ */
if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL) { if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL) {
if ((ifp->if_u1.if_data != ifp->if_u2.if_inline_data) && if (ifp->if_u1.if_data != NULL) {
(ifp->if_u1.if_data != NULL)) {
ASSERT(ifp->if_real_bytes != 0); ASSERT(ifp->if_real_bytes != 0);
kmem_free(ifp->if_u1.if_data); kmem_free(ifp->if_u1.if_data);
ifp->if_u1.if_data = NULL; ifp->if_u1.if_data = NULL;
...@@ -704,13 +664,11 @@ xfs_idestroy_fork( ...@@ -704,13 +664,11 @@ xfs_idestroy_fork(
} }
} else if ((ifp->if_flags & XFS_IFEXTENTS) && } else if ((ifp->if_flags & XFS_IFEXTENTS) &&
((ifp->if_flags & XFS_IFEXTIREC) || ((ifp->if_flags & XFS_IFEXTIREC) ||
((ifp->if_u1.if_extents != NULL) && (ifp->if_u1.if_extents != NULL))) {
(ifp->if_u1.if_extents != ifp->if_u2.if_inline_ext)))) {
ASSERT(ifp->if_real_bytes != 0); ASSERT(ifp->if_real_bytes != 0);
xfs_iext_destroy(ifp); xfs_iext_destroy(ifp);
} }
ASSERT(ifp->if_u1.if_extents == NULL || ASSERT(ifp->if_u1.if_extents == NULL);
ifp->if_u1.if_extents == ifp->if_u2.if_inline_ext);
ASSERT(ifp->if_real_bytes == 0); ASSERT(ifp->if_real_bytes == 0);
if (whichfork == XFS_ATTR_FORK) { if (whichfork == XFS_ATTR_FORK) {
kmem_zone_free(xfs_ifork_zone, ip->i_afp); kmem_zone_free(xfs_ifork_zone, ip->i_afp);
...@@ -943,28 +901,14 @@ xfs_iext_add( ...@@ -943,28 +901,14 @@ xfs_iext_add(
ASSERT((idx >= 0) && (idx <= nextents)); ASSERT((idx >= 0) && (idx <= nextents));
byte_diff = ext_diff * sizeof(xfs_bmbt_rec_t); byte_diff = ext_diff * sizeof(xfs_bmbt_rec_t);
new_size = ifp->if_bytes + byte_diff; new_size = ifp->if_bytes + byte_diff;
/* /*
* If the new number of extents (nextents + ext_diff) * Use a linear (direct) extent list.
* fits inside the inode, then continue to use the inline
* extent buffer.
*/
if (nextents + ext_diff <= XFS_INLINE_EXTS) {
if (idx < nextents) {
memmove(&ifp->if_u2.if_inline_ext[idx + ext_diff],
&ifp->if_u2.if_inline_ext[idx],
(nextents - idx) * sizeof(xfs_bmbt_rec_t));
memset(&ifp->if_u2.if_inline_ext[idx], 0, byte_diff);
}
ifp->if_u1.if_extents = ifp->if_u2.if_inline_ext;
ifp->if_real_bytes = 0;
}
/*
* Otherwise use a linear (direct) extent list.
* If the extents are currently inside the inode, * If the extents are currently inside the inode,
* xfs_iext_realloc_direct will switch us from * xfs_iext_realloc_direct will switch us from
* inline to direct extent allocation mode. * inline to direct extent allocation mode.
*/ */
else if (nextents + ext_diff <= XFS_LINEAR_EXTS) { if (nextents + ext_diff <= XFS_LINEAR_EXTS) {
xfs_iext_realloc_direct(ifp, new_size); xfs_iext_realloc_direct(ifp, new_size);
if (idx < nextents) { if (idx < nextents) {
memmove(&ifp->if_u1.if_extents[idx + ext_diff], memmove(&ifp->if_u1.if_extents[idx + ext_diff],
...@@ -1172,43 +1116,10 @@ xfs_iext_remove( ...@@ -1172,43 +1116,10 @@ xfs_iext_remove(
xfs_iext_remove_indirect(ifp, cur->idx, ext_diff); xfs_iext_remove_indirect(ifp, cur->idx, ext_diff);
} else if (ifp->if_real_bytes) { } else if (ifp->if_real_bytes) {
xfs_iext_remove_direct(ifp, cur->idx, ext_diff); xfs_iext_remove_direct(ifp, cur->idx, ext_diff);
} else {
xfs_iext_remove_inline(ifp, cur->idx, ext_diff);
} }
ifp->if_bytes = new_size; ifp->if_bytes = new_size;
} }
/*
* This removes ext_diff extents from the inline buffer, beginning
* at extent index idx.
*/
void
xfs_iext_remove_inline(
xfs_ifork_t *ifp, /* inode fork pointer */
xfs_extnum_t idx, /* index to begin removing exts */
int ext_diff) /* number of extents to remove */
{
int nextents; /* number of extents in file */
ASSERT(!(ifp->if_flags & XFS_IFEXTIREC));
ASSERT(idx < XFS_INLINE_EXTS);
nextents = xfs_iext_count(ifp);
ASSERT(((nextents - ext_diff) > 0) &&
(nextents - ext_diff) < XFS_INLINE_EXTS);
if (idx + ext_diff < nextents) {
memmove(&ifp->if_u2.if_inline_ext[idx],
&ifp->if_u2.if_inline_ext[idx + ext_diff],
(nextents - (idx + ext_diff)) *
sizeof(xfs_bmbt_rec_t));
memset(&ifp->if_u2.if_inline_ext[nextents - ext_diff],
0, ext_diff * sizeof(xfs_bmbt_rec_t));
} else {
memset(&ifp->if_u2.if_inline_ext[idx], 0,
ext_diff * sizeof(xfs_bmbt_rec_t));
}
}
/* /*
* This removes ext_diff extents from a linear (direct) extent list, * This removes ext_diff extents from a linear (direct) extent list,
* beginning at extent index idx. If the extents are being removed * beginning at extent index idx. If the extents are being removed
...@@ -1351,16 +1262,7 @@ xfs_iext_realloc_direct( ...@@ -1351,16 +1262,7 @@ xfs_iext_realloc_direct(
/* Free extent records */ /* Free extent records */
if (new_size == 0) { if (new_size == 0) {
xfs_iext_destroy(ifp); xfs_iext_destroy(ifp);
} } else {
/* Resize direct extent list and zero any new bytes */
else if (ifp->if_real_bytes) {
/* Check if extents will fit inside the inode */
if (new_size <= XFS_INLINE_EXTS * sizeof(xfs_bmbt_rec_t)) {
xfs_iext_direct_to_inline(ifp, new_size /
(uint)sizeof(xfs_bmbt_rec_t));
ifp->if_bytes = new_size;
return;
}
if (!is_power_of_2(new_size)){ if (!is_power_of_2(new_size)){
rnew_size = roundup_pow_of_two(new_size); rnew_size = roundup_pow_of_two(new_size);
} }
...@@ -1375,63 +1277,10 @@ xfs_iext_realloc_direct( ...@@ -1375,63 +1277,10 @@ xfs_iext_realloc_direct(
rnew_size - ifp->if_real_bytes); rnew_size - ifp->if_real_bytes);
} }
} }
/* Switch from the inline extent buffer to a direct extent list */
else {
if (!is_power_of_2(new_size)) {
rnew_size = roundup_pow_of_two(new_size);
}
xfs_iext_inline_to_direct(ifp, rnew_size);
}
ifp->if_real_bytes = rnew_size; ifp->if_real_bytes = rnew_size;
ifp->if_bytes = new_size; ifp->if_bytes = new_size;
} }
/*
* Switch from linear (direct) extent records to inline buffer.
*/
void
xfs_iext_direct_to_inline(
xfs_ifork_t *ifp, /* inode fork pointer */
xfs_extnum_t nextents) /* number of extents in file */
{
ASSERT(ifp->if_flags & XFS_IFEXTENTS);
ASSERT(nextents <= XFS_INLINE_EXTS);
/*
* The inline buffer was zeroed when we switched
* from inline to direct extent allocation mode,
* so we don't need to clear it here.
*/
memcpy(ifp->if_u2.if_inline_ext, ifp->if_u1.if_extents,
nextents * sizeof(xfs_bmbt_rec_t));
kmem_free(ifp->if_u1.if_extents);
ifp->if_u1.if_extents = ifp->if_u2.if_inline_ext;
ifp->if_real_bytes = 0;
}
/*
* Switch from inline buffer to linear (direct) extent records.
* new_size should already be rounded up to the next power of 2
* by the caller (when appropriate), so use new_size as it is.
* However, since new_size may be rounded up, we can't update
* if_bytes here. It is the caller's responsibility to update
* if_bytes upon return.
*/
void
xfs_iext_inline_to_direct(
xfs_ifork_t *ifp, /* inode fork pointer */
int new_size) /* number of extents in file */
{
ifp->if_u1.if_extents = kmem_alloc(new_size, KM_NOFS);
memset(ifp->if_u1.if_extents, 0, new_size);
if (ifp->if_bytes) {
memcpy(ifp->if_u1.if_extents, ifp->if_u2.if_inline_ext,
ifp->if_bytes);
memset(ifp->if_u2.if_inline_ext, 0, XFS_INLINE_EXTS *
sizeof(xfs_bmbt_rec_t));
}
ifp->if_real_bytes = new_size;
}
/* /*
* Resize an extent indirection array to new_size bytes. * Resize an extent indirection array to new_size bytes.
*/ */
...@@ -1511,9 +1360,6 @@ xfs_iext_destroy( ...@@ -1511,9 +1360,6 @@ xfs_iext_destroy(
xfs_iext_irec_remove_all(ifp); xfs_iext_irec_remove_all(ifp);
} else if (ifp->if_real_bytes) { } else if (ifp->if_real_bytes) {
kmem_free(ifp->if_u1.if_extents); kmem_free(ifp->if_u1.if_extents);
} else if (ifp->if_bytes) {
memset(ifp->if_u2.if_inline_ext, 0, XFS_INLINE_EXTS *
sizeof(xfs_bmbt_rec_t));
} }
ifp->if_u1.if_extents = NULL; ifp->if_u1.if_extents = NULL;
ifp->if_real_bytes = 0; ifp->if_real_bytes = 0;
...@@ -1708,8 +1554,6 @@ xfs_iext_irec_init( ...@@ -1708,8 +1554,6 @@ xfs_iext_irec_init(
if (nextents == 0) { if (nextents == 0) {
ifp->if_u1.if_extents = kmem_alloc(XFS_IEXT_BUFSZ, KM_NOFS); ifp->if_u1.if_extents = kmem_alloc(XFS_IEXT_BUFSZ, KM_NOFS);
} else if (!ifp->if_real_bytes) {
xfs_iext_inline_to_direct(ifp, XFS_IEXT_BUFSZ);
} else if (ifp->if_real_bytes < XFS_IEXT_BUFSZ) { } else if (ifp->if_real_bytes < XFS_IEXT_BUFSZ) {
xfs_iext_realloc_direct(ifp, XFS_IEXT_BUFSZ); xfs_iext_realloc_direct(ifp, XFS_IEXT_BUFSZ);
} }
...@@ -1829,9 +1673,6 @@ xfs_iext_irec_compact( ...@@ -1829,9 +1673,6 @@ xfs_iext_irec_compact(
if (nextents == 0) { if (nextents == 0) {
xfs_iext_destroy(ifp); xfs_iext_destroy(ifp);
} else if (nextents <= XFS_INLINE_EXTS) {
xfs_iext_indirect_to_direct(ifp);
xfs_iext_direct_to_inline(ifp, nextents);
} else if (nextents <= XFS_LINEAR_EXTS) { } else if (nextents <= XFS_LINEAR_EXTS) {
xfs_iext_indirect_to_direct(ifp); xfs_iext_indirect_to_direct(ifp);
} else if (nextents < (nlists * XFS_LINEAR_EXTS) >> 1) { } else if (nextents < (nlists * XFS_LINEAR_EXTS) >> 1) {
......
...@@ -51,8 +51,6 @@ typedef struct xfs_ext_irec { ...@@ -51,8 +51,6 @@ typedef struct xfs_ext_irec {
*/ */
#define XFS_IEXT_BUFSZ 4096 #define XFS_IEXT_BUFSZ 4096
#define XFS_LINEAR_EXTS (XFS_IEXT_BUFSZ / (uint)sizeof(xfs_bmbt_rec_t)) #define XFS_LINEAR_EXTS (XFS_IEXT_BUFSZ / (uint)sizeof(xfs_bmbt_rec_t))
#define XFS_INLINE_EXTS 2
#define XFS_INLINE_DATA 32
typedef struct xfs_ifork { typedef struct xfs_ifork {
int if_bytes; /* bytes in if_u1 */ int if_bytes; /* bytes in if_u1 */
int if_real_bytes; /* bytes allocated in if_u1 */ int if_real_bytes; /* bytes allocated in if_u1 */
...@@ -64,12 +62,6 @@ typedef struct xfs_ifork { ...@@ -64,12 +62,6 @@ typedef struct xfs_ifork {
xfs_ext_irec_t *if_ext_irec; /* irec map file exts */ xfs_ext_irec_t *if_ext_irec; /* irec map file exts */
char *if_data; /* inline file data */ char *if_data; /* inline file data */
} if_u1; } if_u1;
union {
xfs_bmbt_rec_host_t if_inline_ext[XFS_INLINE_EXTS];
/* very small file extents */
char if_inline_data[XFS_INLINE_DATA];
/* very small file data */
} if_u2;
} xfs_ifork_t; } xfs_ifork_t;
/* /*
...@@ -158,12 +150,9 @@ void xfs_iext_add_indirect_multi(struct xfs_ifork *, int, ...@@ -158,12 +150,9 @@ void xfs_iext_add_indirect_multi(struct xfs_ifork *, int,
xfs_extnum_t, int); xfs_extnum_t, int);
void xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *, void xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *,
int, int); int, int);
void xfs_iext_remove_inline(struct xfs_ifork *, xfs_extnum_t, int);
void xfs_iext_remove_direct(struct xfs_ifork *, xfs_extnum_t, int); void xfs_iext_remove_direct(struct xfs_ifork *, xfs_extnum_t, int);
void xfs_iext_remove_indirect(struct xfs_ifork *, xfs_extnum_t, int); void xfs_iext_remove_indirect(struct xfs_ifork *, xfs_extnum_t, int);
void xfs_iext_realloc_direct(struct xfs_ifork *, int); void xfs_iext_realloc_direct(struct xfs_ifork *, int);
void xfs_iext_direct_to_inline(struct xfs_ifork *, xfs_extnum_t);
void xfs_iext_inline_to_direct(struct xfs_ifork *, int);
void xfs_iext_destroy(struct xfs_ifork *); void xfs_iext_destroy(struct xfs_ifork *);
struct xfs_bmbt_rec_host * struct xfs_bmbt_rec_host *
xfs_iext_bno_to_ext(struct xfs_ifork *, xfs_fileoff_t, int *); xfs_iext_bno_to_ext(struct xfs_ifork *, xfs_fileoff_t, int *);
......
...@@ -1709,7 +1709,6 @@ xfs_swap_extent_forks( ...@@ -1709,7 +1709,6 @@ xfs_swap_extent_forks(
xfs_filblks_t aforkblks = 0; xfs_filblks_t aforkblks = 0;
xfs_filblks_t taforkblks = 0; xfs_filblks_t taforkblks = 0;
xfs_extnum_t junk; xfs_extnum_t junk;
xfs_extnum_t nextents;
uint64_t tmp; uint64_t tmp;
int error; int error;
...@@ -1784,13 +1783,6 @@ xfs_swap_extent_forks( ...@@ -1784,13 +1783,6 @@ xfs_swap_extent_forks(
switch (ip->i_d.di_format) { switch (ip->i_d.di_format) {
case XFS_DINODE_FMT_EXTENTS: case XFS_DINODE_FMT_EXTENTS:
/*
* If the extents fit in the inode, fix the pointer. Otherwise
* it's already NULL or pointing to the extent.
*/
nextents = xfs_iext_count(&ip->i_df);
if (nextents <= XFS_INLINE_EXTS)
ifp->if_u1.if_extents = ifp->if_u2.if_inline_ext;
(*src_log_flags) |= XFS_ILOG_DEXT; (*src_log_flags) |= XFS_ILOG_DEXT;
break; break;
case XFS_DINODE_FMT_BTREE: case XFS_DINODE_FMT_BTREE:
...@@ -1802,13 +1794,6 @@ xfs_swap_extent_forks( ...@@ -1802,13 +1794,6 @@ xfs_swap_extent_forks(
switch (tip->i_d.di_format) { switch (tip->i_d.di_format) {
case XFS_DINODE_FMT_EXTENTS: case XFS_DINODE_FMT_EXTENTS:
/*
* If the extents fit in the inode, fix the pointer. Otherwise
* it's already NULL or pointing to the extent.
*/
nextents = xfs_iext_count(&tip->i_df);
if (nextents <= XFS_INLINE_EXTS)
tifp->if_u1.if_extents = tifp->if_u2.if_inline_ext;
(*target_log_flags) |= XFS_ILOG_DEXT; (*target_log_flags) |= XFS_ILOG_DEXT;
break; break;
case XFS_DINODE_FMT_BTREE: case XFS_DINODE_FMT_BTREE:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment