Skip to contentSkip to conversation

xfs: enforce imax_pct when we have per-cpu SB accounting

PATCH In review Darrick J. Wong 2 participants 2 messages May 5, 2015 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: enforce imax_pct when we have per-cpu SB accounting

When per-CPU superblock counters are enabled (i.e. SMP=y), we don't update the in-core superblock's sb_icount value prior to checking if we're already at maximum inodes. Therefore, it's possible for a tight file creation loop (e.g. "for i in {0..100000}; do touch /mnt/$i; done") to allocate far more inodes than the administrator specified at mkfs time. Fix this by synchronizing the counters every time we think we need to allocate another chunk of inodes.

---
 fs/xfs/libxfs/xfs_ialloc.c |    4 ++++
 1 file changed, 4 insertions(+)
fs/xfs/libxfs/xfs_ialloc.c +4 -0
index 116ef1d..a8aaab6 100644
@@ -375,6 +375,8 @@ xfs_ialloc_ag_alloc(
 	 * at one time.
 	 */
 	newlen = args.mp->m_ialloc_inos;
+	if (args.mp->m_maxicount)
+		xfs_icsb_sync_counters(args.mp, 0);
 	if (args.mp->m_maxicount &&
 	    args.mp->m_sb.sb_icount + newlen > args.mp->m_maxicount)
 		return -ENOSPC;
@@ -1339,6 +1341,8 @@ xfs_dialloc(
 	 * okalloc so we scan all available agi structures for a free
 	 * inode.
 	 */
+	if (mp->m_maxicount)
+		xfs_icsb_sync_counters(mp, 0);
 	if (mp->m_maxicount &&
 	    mp->m_sb.sb_icount + mp->m_ialloc_inos > mp->m_maxicount) {
 		noroom = 1;

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

#1 lore raw
Quoted 27 lines · Darrick J. Wong

When per-CPU superblock counters are enabled (i.e. SMP=y), we don't update the in-core superblock's sb_icount value prior to checking if we're already at maximum inodes. Therefore, it's possible for a tight file creation loop (e.g. "for i in {0..100000}; do touch /mnt/$i; done") to allocate far more inodes than the administrator specified at mkfs time. Fix this by synchronizing the counters every time we think we need to allocate another chunk of inodes.

---
 fs/xfs/libxfs/xfs_ialloc.c |    4 ++++
 1 file changed, 4 insertions(+)
fs/xfs/libxfs/xfs_ialloc.c +2 -0
index 116ef1d..a8aaab6 100644
@@ -375,6 +375,8 @@ xfs_ialloc_ag_alloc(
 	 * at one time.
 	 */
 	newlen = args.mp->m_ialloc_inos;
+	if (args.mp->m_maxicount)
+		xfs_icsb_sync_counters(args.mp, 0);
 	if (args.mp->m_maxicount &&
 	    args.mp->m_sb.sb_icount + newlen > args.mp->m_maxicount)
 		return -ENOSPC;

fs/xfs/libxfs/xfs_ialloc.c xfs_dialloc( · line 1348

Quoted 8 lines
fs/xfs/libxfs/xfs_ialloc.c +2 -0
@@ -1339,6 +1341,8 @@ xfs_dialloc(
 	 * okalloc so we scan all available agi structures for a free
 	 * inode.
 	 */
+	if (mp->m_maxicount)
+		xfs_icsb_sync_counters(mp, 0);
 	if (mp->m_maxicount &&
 	    mp->m_sb.sb_icount + mp->m_ialloc_inos > mp->m_maxicount) {
 		noroom = 1;

As i mentioned on IRC, sb_icount is now using the generic percpu counter infrastrcture, so shouldn't have this problem - overshoot should be, at maximum, (Ncpus * 32).

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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