Skip to contentSkip to conversation

xfs: dynamic speculative allocation beyond EOF V3

PATCH In review Dave Chinner 3 participants 9 messages Nov 29, 2010 – Dec 7, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover xfs: dynamic speculative allocation beyond EOF V3

This is the latest version of the dynamic speculative allocation beyond EOF patch set. The description of the patchset can be found here:

http://oss.sgi.com/archives/xfs/2010-10/msg00040.html

Version 3:

- allocsize mount option returned to fixed preallocation size only.
- reduces maximum dynamic prealloc size as the filesytem gets near full.
- split i_delayed_blks bug fixes into new patch (posted in 2.6.37-rc bug fix series)

Version 2:
- base speculative execution size on current inode size, not the number of previous speculative allocations.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw

PATCH 1/2 xfs: dynamic speculative EOF preallocation

From: Dave Chinner <[email protected]>

Currently the size of the speculative preallocation during delayed allocation is fixed by either the allocsize mount option of a default size. We are seeing a lot of cases where we need to recommend using the allocsize mount option to prevent fragmentation when buffered writes land in the same AG.

Rather than using a fixed preallocation size by default (up to 64k), make it dynamic by basing it on the current inode size. That way the EOF preallocation will increase as the file size increases. Hence for streaming writes we are much more likely to get large preallocations exactly when we need it to reduce fragementation.

For default settings, the size of the initial extents is determined by the number of parallel writers and the amount of memory in the machine. For 4GB RAM and 4 concurrent 32GB file writes:

EXT: FILE-OFFSET BLOCK-RANGE AG AG-OFFSET TOTAL

   0: [0..1048575]:         1048672..2097247      0 (1048672..2097247)      1048576
   1: [1048576..2097151]:   5242976..6291551      0 (5242976..6291551)      1048576
   2: [2097152..4194303]:   12583008..14680159    0 (12583008..14680159)    2097152
   3: [4194304..8388607]:   25165920..29360223    0 (25165920..29360223)    4194304
   4: [8388608..16777215]:  58720352..67108959    0 (58720352..67108959)    8388608
   5: [16777216..33554423]: 117440584..134217791  0 (117440584..134217791) 16777208
   6: [33554424..50331511]: 184549056..201326143  0 (184549056..201326143) 16777088
   7: [50331512..67108599]: 251657408..268434495  0 (251657408..268434495) 16777088

and for 16 concurrent 16GB file writes:

 EXT: FILE-OFFSET           BLOCK-RANGE          AG AG-OFFSET                 TOTAL
   0: [0..262143]:          2490472..2752615      0 (2490472..2752615)       262144
   1: [262144..524287]:     6291560..6553703      0 (6291560..6553703)       262144
   2: [524288..1048575]:    13631592..14155879    0 (13631592..14155879)     524288
   3: [1048576..2097151]:   30408808..31457383    0 (30408808..31457383)    1048576
   4: [2097152..4194303]:   52428904..54526055    0 (52428904..54526055)    2097152
   5: [4194304..8388607]:   104857704..109052007  0 (104857704..109052007)  4194304
   6: [8388608..16777215]:  209715304..218103911  0 (209715304..218103911)  8388608

7: [16777216..33554423]: 452984848..469762055 0 (452984848..469762055) 16777208

Because it is hard to take back specualtive preallocation, cases where there are large slow growing log files on a nearly full filesystem may cause premature ENOSPC. Hence as the filesystem nears full, the maximum dynamic prealloc size іs reduced according to this table (based on 4k block size):

freespace max prealloc size

Quoted 1 line

5% full extent (8GB)

4-5% 2GB (8GB >> 2)
3-4% 1GB (8GB >> 3)

  2-3%           512MB (8GB >> 4)
  1-2%           256MB (8GB >> 5)
  <1%            128MB (8GB >> 6)

This should reduce the amount of space held in speculative preallocation for such cases.

The allocsize mount option turns off the dynamic behaviour and fixes the prealloc size to whatever the mount option specifies. i.e. the behaviour is unchanged.

---
 fs/xfs/xfs_fsops.c |    1 +
 fs/xfs/xfs_iomap.c |   74 +++++++++++++++++++++++++++++++++++++++++++++-------
 fs/xfs/xfs_mount.c |   26 ++++++++++++-----
 fs/xfs/xfs_mount.h |   26 +++++++++++++++++-
 4 files changed, 107 insertions(+), 20 deletions(-)
fs/xfs/xfs_fsops.c +1 -0
index be34ff2..6d17206 100644
@@ -374,6 +374,7 @@ xfs_growfs_data_private(
 		mp->m_maxicount = icount << mp->m_sb.sb_inopblog;
 	} else
 		mp->m_maxicount = 0;
+	xfs_set_low_space_thresholds(mp);
 
 	/* update secondary superblocks. */
 	for (agno = 1; agno < nagcount; agno++) {
fs/xfs/xfs_iomap.c +64 -10

124 lines not on this page · raw message

fs/xfs/xfs_mount.c +18 -8
index 3905fc3..98cb266 100644
@@ -315,14 +315,6 @@ xfs_icsb_sum(
 	return percpu_counter_sum_positive(&mp->m_icsb[counter]);
 }
 
-static inline int64_t
-xfs_icsb_read(
-	struct xfs_mount	*mp,
-	int			counter)
-{
-	return percpu_counter_read_positive(&mp->m_icsb[counter]);
-}
-
 void
 xfs_icsb_reinit_counters(
 	struct xfs_mount	*mp)
@@ -1145,6 +1137,21 @@ xfs_set_rw_sizes(xfs_mount_t *mp)
 }
 
 /*
+ * precalculate the low space thresholds for dynamic speculative preallocation.
+ */
+void
+xfs_set_low_space_thresholds(
+	struct xfs_mount	*mp)
+{
+	int i;
+
+	for (i = 0; i < XFS_LOWSP_MAX; i++) {
+		mp->m_low_space[i] = mp->m_sb.sb_dblocks / 100 * (i + 1);
+	}
+}
+
+
+/*
  * Set whether we're using inode alignment.
  */
 STATIC void
@@ -1366,6 +1373,9 @@ xfs_mountfs(
 	 */
 	xfs_set_rw_sizes(mp);
 
+	/* set the low space thresholds for dynamic preallocation */
+	xfs_set_low_space_thresholds(mp);
+
 	/*
 	 * Set the inode cluster size.
 	 * This may still be overridden by the file system
fs/xfs/xfs_mount.h +24 -2
index c8ff435..9f99a62 100644
@@ -75,8 +75,15 @@ enum {
 	XFS_ICSB_MAX,
 };
 
-extern int	xfs_icsb_modify_inodes(struct xfs_mount *, int, int64_t, int);
-extern int	xfs_icsb_modify_free_blocks(struct xfs_mount *, int64_t, int);
+/* dynamic preallocation free space thresholds, 5% down to 1% */
+enum {
+	XFS_LOWSP_1_PCNT = 0,
+	XFS_LOWSP_2_PCNT,
+	XFS_LOWSP_3_PCNT,
+	XFS_LOWSP_4_PCNT,
+	XFS_LOWSP_5_PCNT,
+	XFS_LOWSP_MAX,
+};
 
 typedef struct xfs_mount {
 	struct super_block	*m_super;
@@ -172,6 +179,8 @@ typedef struct xfs_mount {
 						   on the next remount,rw */
 	struct shrinker		m_inode_shrink;	/* inode reclaim shrinker */
 	struct percpu_counter	m_icsb[XFS_ICSB_MAX];
+	int64_t			m_low_space[XFS_LOWSP_MAX];
+						/* low free space thresholds */
 } xfs_mount_t;
 
 /*
@@ -333,6 +342,19 @@ extern int	xfs_icsb_init_counters(struct xfs_mount *);
 extern void	xfs_icsb_reinit_counters(struct xfs_mount *);
 extern void	xfs_icsb_destroy_counters(struct xfs_mount *);
 extern void	xfs_icsb_sync_counters(struct xfs_mount *);
+extern int	xfs_icsb_modify_inodes(struct xfs_mount *, int, int64_t, int);
+extern int	xfs_icsb_modify_free_blocks(struct xfs_mount *, int64_t, int);
+
+static inline int64_t
+xfs_icsb_read(
+	struct xfs_mount	*mp,
+	int			counter)
+{
+	return percpu_counter_read_positive(&mp->m_icsb[counter]);
+}
+
+extern void	xfs_set_low_space_thresholds(struct xfs_mount *);
+
 
 #endif	/* __KERNEL__ */
 
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw

Re: [PATCH 1/2] xfs: dynamic speculative EOF preallocation

I need the patch below to make the new code link on 32-bit systems:

fs/xfs/xfs_mount.c +4 -1
Index: xfs/fs/xfs/xfs_mount.c
===================================================================
@@ -1111,7 +1111,10 @@ xfs_set_low_space_thresholds(
 	int i;
 
 	for (i = 0; i < XFS_LOWSP_MAX; i++) {
-		mp->m_low_space[i] = mp->m_sb.sb_dblocks / 100 * (i + 1);
+		__uint64_t space = mp->m_sb.sb_dblocks;
+		do_div(space, 100);
+
+		mp->m_low_space[i] = space * (i + 1);
 	}
 }
 

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw

Re: [PATCH 1/2] xfs: dynamic speculative EOF preallocation

Quoted 7 lines · Christoph Hellwig

I need the patch below to make the new code link on 32-bit systems:

Index: xfs/fs/xfs/xfs_mount.c
===================================================================

fs/xfs/xfs_mount.c xfs_set_low_space_thresholds( · line 1119

Quoted 10 lines
fs/xfs/xfs_mount.c +4 -1
@@ -1111,7 +1111,10 @@ xfs_set_low_space_thresholds(
 	int i;
 
 	for (i = 0; i < XFS_LOWSP_MAX; i++) {
-		mp->m_low_space[i] = mp->m_sb.sb_dblocks / 100 * (i + 1);
+		__uint64_t space = mp->m_sb.sb_dblocks;
+		do_div(space, 100);
+
+		mp->m_low_space[i] = space * (i + 1);
 	}
 }

Yes, makes sense. I'll fold that into the latest version of the patch. Thanks.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#4 lore raw

PATCH 2/2 xfs: don't truncate prealloc from frequently accessed inodes

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

A long standing problem for streaming writeѕ through the NFS server has been that the NFS server opens and closes file descriptors on an inode for every write. The result of this behaviour is that the ->release() function is called on every close and that results in XFS truncating speculative preallocation beyond the EOF. This has an adverse effect on file layout when multiple files are being written at the same time - they interleave their extents and can result in severe fragmentation.

To avoid this problem, keep a count of the number of ->release calls made on an inode. For most cases, an inode is only going to be opened once for writing and then closed again during it's lifetime in cache. Hence if there are multiple ->release calls, there is a good chance that the inode is being accessed by the NFS server. Hence count up every time ->release is called while there are delalloc blocks still outstanding on the inode.

If this count is non-zero when ->release is next called, then do no truncate away the speculative preallocation - leave it there so that subsequent writes do not need to reallocate the delalloc space. This will prevent interleaving of extents of different inodes written concurrently to the same AG.

If we get this wrong, it is not a big deal as we truncate speculative allocation beyond EOF anyway in xfs_inactive() when the inode is thrown out of the cache.

The new counter in the struct xfs_inode fits into a hole in the structure on 64 bit machines, so does not grow the size of the inode at all.

---
 fs/xfs/xfs_iget.c     |    1 +
 fs/xfs/xfs_inode.h    |    1 +
 fs/xfs/xfs_vnodeops.c |   61 ++++++++++++++++++++++++++++++++-----------------
 3 files changed, 42 insertions(+), 21 deletions(-)
fs/xfs/xfs_iget.c +1 -0
index 0cdd269..18991a9 100644
@@ -84,6 +84,7 @@ xfs_inode_alloc(
 	memset(&ip->i_d, 0, sizeof(xfs_icdinode_t));
 	ip->i_size = 0;
 	ip->i_new_size = 0;
+	ip->i_dirty_releases = 0;
 
 	/* prevent anyone from using this yet */
 	VFS_I(ip)->i_state = I_NEW;
fs/xfs/xfs_inode.h +1 -0
index fb2ca2e..ea2f34e 100644
@@ -260,6 +260,7 @@ typedef struct xfs_inode {
 	xfs_fsize_t		i_size;		/* in-memory size */
 	xfs_fsize_t		i_new_size;	/* size when write completes */
 	atomic_t		i_iocount;	/* outstanding I/O count */
+	int			i_dirty_releases; /* dirty ->release calls */
 
 	/* VFS inode */
 	struct inode		i_vnode;	/* embedded VFS inode */
fs/xfs/xfs_vnodeops.c +40 -21

69 lines not on this page · raw message

Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#5 lore raw

Re: [PATCH 2/2] xfs: don't truncate prealloc from frequently accessed inodes

Quoted 8 lines · Dave Chinner

To avoid this problem, keep a count of the number of ->release calls made on an inode. For most cases, an inode is only going to be opened once for writing and then closed again during it's lifetime in cache. Hence if there are multiple ->release calls, there is a good chance that the inode is being accessed by the NFS server. Hence count up every time ->release is called while there are delalloc blocks still outstanding on the inode.

Seems like a hack. It would be cleaner and less fragile to add a explicit VFS hint that is passed down from the nfs server, similar to the existing open intents.

-Andi

Signature · 6 lines
[email protected] -- Speaking for myself only.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#6 lore raw

Re: [PATCH 2/2] xfs: don't truncate prealloc from frequently accessed inodes

Quoted 10 lines · Andi Kleen
Quoted 8 lines · Dave Chinner

To avoid this problem, keep a count of the number of ->release calls made on an inode. For most cases, an inode is only going to be opened once for writing and then closed again during it's lifetime in cache. Hence if there are multiple ->release calls, there is a good chance that the inode is being accessed by the NFS server. Hence count up every time ->release is called while there are delalloc blocks still outstanding on the inode.

Quoted 3 lines

Seems like a hack. It would be cleaner and less fragile to add a explicit VFS hint that is passed down from the nfs server, similar to the existing open intents.

Agreed.

However, we've been asking for the nfsd to change it's behaviour for various operations for quite some time (i.e. years) to help filesystems behave better, but and we're no closer to having it fixed now than we were 3 or 4 years ago. What the nfsd really needs is an an open file cache so that IO looks like normal file IO rather than every write being an "open-write-close" operation....

While we wait for nfsd to be fixed, we've still got people reporting excessive fragmentation during concurrent sequential writes to nfs servers running XFS, so we really need some kind of fix for the problem...

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#8 lore raw

Re: [PATCH 2/2] xfs: don't truncate prealloc from frequently accessed inodes

Quoted 2 lines · Christoph Hellwig

Did any problems show up with just trying to use an inode flag instead of the counter? I'd really hate to bloat the inode without reason.

None that I've noticed in local testing, but I haven't been focussing on this aspect so I hadn't changed it. I'll change it to a flag, and we can go back to a counter if necessary.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs