Skip to contentSkip to conversation

Use generic percpu counters in XFS

PATCH In review Dave Chinner 3 participants 10 messages Nov 29, 2010 – Nov 30, 2010

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

cover Use generic percpu counters in XFS

This series replaces the XFS per-cpu superblock counters with generic per-cpu counters. It adds a specialised operation to the generic counter implementation and then switches the XFS percpu superblock counters over to use the generic percpu counter implementation. The result is several hundred lines of complex code removed from XFS.

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

#1 lore raw

PATCH 1/3 lib: percpu counter add unless less than functionality

From: Dave Chinner <[email protected]>

To use the generic percpu counter infrastructure for counters that require conditional addition based on a threshold value we need special handling of the counter. Further, the caller needs to know the status of the conditional addition to determine what action to take depending on whether the addition occurred or not. Examples of this sort of usage are resource counters that cannot go below zero (e.g. filesystem free blocks).

To allow XFS to replace it's complex roll-your-own per-cpu superblock counters, a single generic conditional function is
required: percpu_counter_add_unless_lt(). This will add the amount to the counter unless the result would be less than the given threshold. A caller supplied threshold is required because XFS does not necessarily use the same threshold for every counter.

percpu_counter_add_unless_lt() attempts to minimise counter lock traversals by only taking the counter lock when the threshold is within the error range of the current counter value. Hence when the threshold is not within the counter error range, the counter will still have the same scalability characteristics as the normal percpu_counter_add() function.

Adding this functionality to the generic percpu counters allows us to remove the much more complex and less efficient XFS percpu counter code (~700 lines of code) and replace it with generic percpu counters.

---
 include/linux/percpu_counter.h |   20 ++++++++++
 lib/percpu_counter.c           |   78 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 0 deletions(-)
include/linux/percpu_counter.h +20 -0
index 46f6ba5..465b658f 100644
@@ -41,6 +41,8 @@ void percpu_counter_set(struct percpu_counter *fbc, s64 amount);
 void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch);
 s64 __percpu_counter_sum(struct percpu_counter *fbc);
 int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs);
+int percpu_counter_add_unless_lt(struct percpu_counter *fbc, s64 amount,
+							s64 threshold);
 
 static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount)
 {
@@ -153,6 +155,24 @@ static inline int percpu_counter_initialized(struct percpu_counter *fbc)
 	return 1;
 }
 
+static inline int percpu_counter_add_unless_lt(struct percpu_counter *fbc, s64 amount,
+							s64 threshold)
+{
+	s64 count;
+	int ret = ‐1;
+
+	preempt_disable();
+	count = fbc->count + amount;
+	if (count < threshold)
+		goto out;
+	fbc->count = count;
+	ret = count == threshold ? 0 : 1;
+out:
+	preempt_enable();
+	return ret;
+}
+
+
 #endif	/* CONFIG_SMP */
 
 static inline void percpu_counter_inc(struct percpu_counter *fbc)
lib/percpu_counter.c +78 -0

84 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
#2 lore raw

Re: [PATCH 1/3] lib: percpu counter add unless less than functionality

include/linux/percpu_counter.h void percpu_counter_set(struct percpu_counter *fbc, s64 amount); · line 45

Quoted 2 lines · Dave Chinner
include/linux/percpu_counter.h +2 -0
+int percpu_counter_add_unless_lt(struct percpu_counter *fbc, s64 amount,
+                                                       s64 threshold);

It might make sense to implement that as;

__percpu_counter_add_unless_lt(struct percpu_counter *fbc,

				 s64 amount,
				 s64 threshold,
				 s32 batch);

That way its consistent with the __percpu_counter_add() implementation where you can also specify the batch value.

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

#3 lore raw

Re: [PATCH 1/3] lib: percpu counter add unless less than functionality

Quoted 6 lines · Peter Zijlstra

include/linux/percpu_counter.h void percpu_counter_set(struct percpu_counter *fbc, s64 amount); · line 45

Quoted 2 lines · Dave Chinner
include/linux/percpu_counter.h +2 -0
+int percpu_counter_add_unless_lt(struct percpu_counter *fbc, s64 amount,
+                                                       s64 threshold);

It might make sense to implement that as;

Quoted 7 lines

__percpu_counter_add_unless_lt(struct percpu_counter *fbc,

				 s64 amount,
				 s64 threshold,
				 s32 batch);

That way its consistent with the __percpu_counter_add() implementation where you can also specify the batch value.

Good point. I'll fix that up.

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/3 xfs: use generic per-cpu counter infrastructure

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

XFS has a per-cpu counter implementation for in-core superblock counters that pre-dated the generic implementation. It is complex and baroque as it is tailored directly to the needs of ENOSPC detection.

Now that the generic percpu counter infrastructure has the percpu_counter_add_unless_lt() function that implements the necessary threshold checks for us, switch the XFS per-cpu superblock counters to use the generic percpu counter infrastructure.

---
 fs/xfs/linux-2.6/xfs_linux.h |    9 -
 fs/xfs/linux-2.6/xfs_super.c |    4 +-
 fs/xfs/xfs_fsops.c           |    4 +-
 fs/xfs/xfs_mount.c           |  842 ++++++++++--------------------------------
 fs/xfs/xfs_mount.h           |   71 +---
 5 files changed, 211 insertions(+), 719 deletions(-)
fs/xfs/linux-2.6/xfs_linux.h +0 -9
index 214ddd7..9fa4f2a 100644
@@ -88,15 +88,6 @@
 #include <xfs_super.h>
 #include <xfs_buf.h>
 
-/*
- * Feature macros (disable/enable)
- */
-#ifdef CONFIG_SMP
-#define HAVE_PERCPU_SB	/* per cpu superblock counters are a 2.6 feature */
-#else
-#undef  HAVE_PERCPU_SB	/* per cpu superblock counters are a 2.6 feature */
-#endif
-
 #define irix_sgid_inherit	xfs_params.sgid_inherit.val
 #define irix_symlink_mode	xfs_params.symlink_mode.val
 #define xfs_panic_mask		xfs_params.panic_mask.val
fs/xfs/linux-2.6/xfs_super.c +2 -2
index 6f02771..6cbebb2 100644
@@ -1227,9 +1227,9 @@ xfs_fs_statfs(
 	statp->f_fsid.val[0] = (u32)id;
 	statp->f_fsid.val[1] = (u32)(id >> 32);
 
-	xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
-
 	spin_lock(&mp->m_sb_lock);
+	xfs_icsb_sync_counters(mp);
+
 	statp->f_bsize = sbp->sb_blocksize;
 	lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
 	statp->f_blocks = sbp->sb_dblocks - lsize;
fs/xfs/xfs_fsops.c +2 -2
index a7c116e..fb9a9c8 100644
@@ -478,8 +478,8 @@ xfs_fs_counts(
 	xfs_mount_t		*mp,
 	xfs_fsop_counts_t	*cnt)
 {
-	xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
 	spin_lock(&mp->m_sb_lock);
+	xfs_icsb_sync_counters(mp);
 	cnt->freedata = mp->m_sb.sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
 	cnt->freertx = mp->m_sb.sb_frextents;
 	cnt->freeino = mp->m_sb.sb_ifree;
@@ -540,7 +540,7 @@ xfs_reserve_blocks(
 	 */
 retry:
 	spin_lock(&mp->m_sb_lock);
-	xfs_icsb_sync_counters_locked(mp, 0);
+	xfs_icsb_sync_counters(mp);
 
 	/*
 	 * If our previous reservation was larger than the current value,
fs/xfs/xfs_mount.c +194 -648

888 lines not on this page · raw message

fs/xfs/xfs_mount.h +13 -58

107 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/3] xfs: use generic per-cpu counter infrastructure

Quoted 7 lines · Dave Chinner

From: Dave Chinner <[email protected]>

XFS has a per-cpu counter implementation for in-core superblock counters that pre-dated the generic implementation. It is complex and baroque as it is tailored directly to the needs of ENOSPC detection.

Quoted 5 lines

Now that the generic percpu counter infrastructure has the percpu_counter_add_unless_lt() function that implements the necessary threshold checks for us, switch the XFS per-cpu superblock counters to use the generic percpu counter infrastructure.

Looks good, but a few comments below:

Quoted 6 lines

+/*
+ * Per-cpu incore superblock counters
+ *
+ * Simple concept, difficult implementation, now somewhat simplified by generic
+ * per-cpu counter support. This provides distributed per cpu counters for
+ * contended fields (e.g. free block count).

The kind of historic comments like now simplified by .. don't make any sense after only a short while. I'd just remove the first senstence above, as the details of the problems are explained much better later.

Quoted 22 lines
(quoted diff) +22 -0
+static inline int
+xfs_icsb_add(
+	struct xfs_mount	*mp,
+	int			counter,
+	int64_t			delta,
+	int64_t			threshold)
+{
+	int			ret;
+
+	ret = percpu_counter_add_unless_lt(&mp->m_icsb[counter], delta,
+								threshold);
+	if (ret < 0)
+		return -ENOSPC;
+	return 0;
+}
+
+static inline void
+xfs_icsb_set(
+	struct xfs_mount	*mp,
+	int			counter,
+	int64_t			value)
+{

Review

Quoted 10 lines
(quoted diff) +10 -0
+	percpu_counter_set(&mp->m_icsb[counter], value);
+}
+
+static inline int64_t
+xfs_icsb_sum(
+	struct xfs_mount	*mp,
+	int			counter)
+{
+	return percpu_counter_sum_positive(&mp->m_icsb[counter]);
+}

I still don't like these wrappers. They are all local to xfs_mount.c, and only have a single function calling them. See the RFC patch below which removes them, and imho makes the code more readable. Especially in xfs _add case where we can get rid of one level of error remapping, and go directly from the weird percpu return values to the positive xfs errors instead of doing a detour via the negative linux errors.

Review

Quoted 7 lines
(quoted diff) +7 -0
+static inline int64_t
+xfs_icsb_read(
+	struct xfs_mount	*mp,
+	int			counter)
+{
+	return percpu_counter_read_positive(&mp->m_icsb[counter]);
+}

this one is entirely unused.

fs/xfs/xfs_mount.c +14 -52
Index: xfs/fs/xfs/xfs_mount.c
===================================================================
@@ -282,54 +282,14 @@ xfs_free_perag(
  * so we only need to modify the fast path to handle per-cpu counter error
  * cases.
  */
-static inline int
-xfs_icsb_add(
-	struct xfs_mount	*mp,
-	int			counter,
-	int64_t			delta,
-	int64_t			threshold)
-{
-	int			ret;
-
-	ret = percpu_counter_add_unless_lt(&mp->m_icsb[counter], delta,
-								threshold);
-	if (ret < 0)
-		return -ENOSPC;
-	return 0;
-}
-
-static inline void
-xfs_icsb_set(
-	struct xfs_mount	*mp,
-	int			counter,
-	int64_t			value)
-{
-	percpu_counter_set(&mp->m_icsb[counter], value);
-}
-
-static inline int64_t
-xfs_icsb_sum(
-	struct xfs_mount	*mp,
-	int			counter)
-{
-	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)
 {
-	xfs_icsb_set(mp, XFS_ICSB_FDBLOCKS, mp->m_sb.sb_fdblocks);
-	xfs_icsb_set(mp, XFS_ICSB_IFREE, mp->m_sb.sb_ifree);
-	xfs_icsb_set(mp, XFS_ICSB_ICOUNT, mp->m_sb.sb_icount);
+	percpu_counter_set(&mp->m_icsb[XFS_ICSB_FDBLOCKS],
+			   mp->m_sb.sb_fdblocks);
+	percpu_counter_set(&mp->m_icsb[XFS_ICSB_IFREE], mp->m_sb.sb_ifree);
+	percpu_counter_set(&mp->m_icsb[XFS_ICSB_ICOUNT], mp->m_sb.sb_icount);
 }
 
 int
@@ -368,9 +328,12 @@ xfs_icsb_sync_counters(
 	xfs_mount_t	*mp)
 {
 	assert_spin_locked(&mp->m_sb_lock);
-	mp->m_sb.sb_icount = xfs_icsb_sum(mp, XFS_ICSB_ICOUNT);
-	mp->m_sb.sb_ifree = xfs_icsb_sum(mp, XFS_ICSB_IFREE);
-	mp->m_sb.sb_fdblocks = xfs_icsb_sum(mp, XFS_ICSB_FDBLOCKS);
+	mp->m_sb.sb_icount =
+		percpu_counter_sum_positive(&mp->m_icsb[XFS_ICSB_ICOUNT]);
+	mp->m_sb.sb_ifree =
+		percpu_counter_sum_positive(&mp->m_icsb[XFS_ICSB_IFREE]);
+	mp->m_sb.sb_fdblocks =
+		percpu_counter_sum_positive(&mp->m_icsb[XFS_ICSB_FDBLOCKS]);
 }
 
 /*
@@ -1953,7 +1916,7 @@ xfs_icsb_modify_counters(
 
 	switch (field) {
 	case XFS_SBS_ICOUNT:
-		ret = xfs_icsb_add(mp, cntr, delta, 0);
+		ret = percpu_counter_add_unless_lt(&mp->m_icsb[XFS_SBS_ICOUNT], delta, 0);
 		if (ret < 0) {
 			ASSERT(0);
 			return XFS_ERROR(EINVAL);
@@ -1961,7 +1924,7 @@ xfs_icsb_modify_counters(
 		return 0;
 
 	case XFS_SBS_IFREE:
-		ret = xfs_icsb_add(mp, XFS_ICSB_IFREE, delta, 0);
+		ret = percpu_counter_add_unless_lt(&mp->m_icsb[XFS_SBS_IFREE], delta, 0);
 		if (ret < 0) {
 			ASSERT(0);
 			return XFS_ERROR(EINVAL);
@@ -1990,13 +1953,12 @@ xfs_icsb_modify_counters(
 		}
 
 		/* try the change */
-		ret = xfs_icsb_add(mp, XFS_ICSB_FDBLOCKS, delta,
-						XFS_ALLOC_SET_ASIDE(mp));
+		ret = percpu_counter_add_unless_lt(&mp->m_icsb[XFS_ICSB_FDBLOCKS],
+						   delta, XFS_ALLOC_SET_ASIDE(mp));
 		if (likely(ret >= 0))
 			return 0;
 
 		/* ENOSPC */
-		ASSERT(ret == -ENOSPC);
 		ASSERT(delta < 0);
 
 		if (!rsvd)

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

#6 lore raw

Re: [PATCH 2/3] xfs: use generic per-cpu counter infrastructure

Quoted 23 lines · Christoph Hellwig
Quoted 7 lines · Dave Chinner

From: Dave Chinner <[email protected]>

XFS has a per-cpu counter implementation for in-core superblock counters that pre-dated the generic implementation. It is complex and baroque as it is tailored directly to the needs of ENOSPC detection.

Quoted 5 lines

Now that the generic percpu counter infrastructure has the percpu_counter_add_unless_lt() function that implements the necessary threshold checks for us, switch the XFS per-cpu superblock counters to use the generic percpu counter infrastructure.

Looks good, but a few comments below:

Quoted 6 lines

+/*
+ * Per-cpu incore superblock counters
+ *
+ * Simple concept, difficult implementation, now somewhat simplified by generic
+ * per-cpu counter support. This provides distributed per cpu counters for
+ * contended fields (e.g. free block count).

Quoted 3 lines

The kind of historic comments like now simplified by .. don't make any sense after only a short while. I'd just remove the first senstence above, as the details of the problems are explained much better later.

Ok, will do.

Quoted 32 lines
Quoted 32 lines
(quoted diff) +31 -0
+static inline int
+xfs_icsb_add(
+	struct xfs_mount	*mp,
+	int			counter,
+	int64_t			delta,
+	int64_t			threshold)
+{
+	int			ret;
+
+	ret = percpu_counter_add_unless_lt(&mp->m_icsb[counter], delta,
+								threshold);
+	if (ret < 0)
+		return -ENOSPC;
+	return 0;
+}
+
+static inline void
+xfs_icsb_set(
+	struct xfs_mount	*mp,
+	int			counter,
+	int64_t			value)
+{
+	percpu_counter_set(&mp->m_icsb[counter], value);
+}
+
+static inline int64_t
+xfs_icsb_sum(
+	struct xfs_mount	*mp,
+	int			counter)
+{
+	return percpu_counter_sum_positive(&mp->m_icsb[counter]);
Quoted 8 lines
Quoted 1 line

+}

I still don't like these wrappers. They are all local to xfs_mount.c, and only have a single function calling them. See the RFC patch below which removes them, and imho makes the code more readable. Especially in xfs _add case where we can get rid of one level of error remapping, and go directly from the weird percpu return values to the positive xfs errors instead of doing a detour via the negative linux errors.

Ok, if we need to tweak the batch size in future, then we can deal with it then. I'll clean it up as you suggest...

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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

PATCH 3/3 xfs: demultiplex xfs_icsb_modify_counters()

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

With the conversion to percpu counters, xfs_icsb_modify_counters() really does not need to exist. Convert the inode counter modifications to use a common helper function for the one place that calls them, and add another function for the free block modification and convert all the callers to use that.

---
 fs/xfs/xfs_bmap.c  |   34 +++++-------
 fs/xfs/xfs_fsops.c |    3 +-
 fs/xfs/xfs_mount.c |  160 +++++++++++++++++++++++++---------------------------
 fs/xfs/xfs_mount.h |    4 +-
 fs/xfs/xfs_trans.c |   19 +++---
 5 files changed, 103 insertions(+), 117 deletions(-)
fs/xfs/xfs_bmap.c +14 -20
index 4111cd3..6a47556 100644
@@ -614,8 +614,8 @@ xfs_bmap_add_extent(
 			nblks += cur->bc_private.b.allocated;
 		ASSERT(nblks <= da_old);
 		if (nblks < da_old)
-			xfs_icsb_modify_counters(ip->i_mount, XFS_SBS_FDBLOCKS,
-				(int64_t)(da_old - nblks), rsvd);
+			xfs_icsb_modify_free_blocks(ip->i_mount,
+					(int64_t)(da_old - nblks), rsvd);
 	}
 	/*
 	 * Clear out the allocated field, done with it now in any case.
@@ -1079,7 +1079,7 @@ xfs_bmap_add_extent_delay_real(
 		diff = (int)(temp + temp2 - startblockval(PREV.br_startblock) -
 			(cur ? cur->bc_private.b.allocated : 0));
 		if (diff > 0 &&
-		    xfs_icsb_modify_counters(ip->i_mount, XFS_SBS_FDBLOCKS,
+		    xfs_icsb_modify_free_blocks(ip->i_mount,
 					     -((int64_t)diff), rsvd)) {
 			/*
 			 * Ick gross gag me with a spoon.
@@ -1090,8 +1090,7 @@ xfs_bmap_add_extent_delay_real(
 					temp--;
 					diff--;
 					if (!diff ||
-					    !xfs_icsb_modify_counters(ip->i_mount,
-						    XFS_SBS_FDBLOCKS,
+					    !xfs_icsb_modify_free_blocks(ip->i_mount,
 						    -((int64_t)diff), rsvd))
 						break;
 				}
@@ -1099,8 +1098,7 @@ xfs_bmap_add_extent_delay_real(
 					temp2--;
 					diff--;
 					if (!diff ||
-					    !xfs_icsb_modify_counters(ip->i_mount,
-						    XFS_SBS_FDBLOCKS,
+					    !xfs_icsb_modify_free_blocks(ip->i_mount,
 						    -((int64_t)diff), rsvd))
 						break;
 				}
@@ -1769,8 +1767,8 @@ xfs_bmap_add_extent_hole_delay(
 	}
 	if (oldlen != newlen) {
 		ASSERT(oldlen > newlen);
-		xfs_icsb_modify_counters(ip->i_mount, XFS_SBS_FDBLOCKS,
-			(int64_t)(oldlen - newlen), rsvd);
+		xfs_icsb_modify_free_blocks(ip->i_mount,
+					(int64_t)(oldlen - newlen), rsvd);
 		/*
 		 * Nothing to do for disk quota accounting here.
 		 */
@@ -3114,10 +3112,9 @@ xfs_bmap_del_extent(
 	 * Nothing to do for disk quota accounting here.
 	 */
 	ASSERT(da_old >= da_new);
-	if (da_old > da_new) {
-		xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS,
-			(int64_t)(da_old - da_new), rsvd);
-	}
+	if (da_old > da_new)
+		xfs_icsb_modify_free_blocks(ip->i_mount,
+					(int64_t)(da_old - da_new), rsvd);
 done:
 	*logflagsp = flags;
 	return error;
@@ -4530,14 +4527,12 @@ xfs_bmapi(
 							-((int64_t)extsz), (flags &
 							XFS_BMAPI_RSVBLOCKS));
 				} else {
-					error = xfs_icsb_modify_counters(mp,
-							XFS_SBS_FDBLOCKS,
+					error = xfs_icsb_modify_free_blocks(mp,
 							-((int64_t)alen), (flags &
 							XFS_BMAPI_RSVBLOCKS));
 				}
 				if (!error) {
-					error = xfs_icsb_modify_counters(mp,
-							XFS_SBS_FDBLOCKS,
+					error = xfs_icsb_modify_free_blocks(mp,
 							-((int64_t)indlen), (flags &
 							XFS_BMAPI_RSVBLOCKS));
 					if (error && rt)
@@ -4546,8 +4541,7 @@ xfs_bmapi(
 							(int64_t)extsz, (flags &
 							XFS_BMAPI_RSVBLOCKS));
 					else if (error)
-						xfs_icsb_modify_counters(mp,
-							XFS_SBS_FDBLOCKS,
+						xfs_icsb_modify_free_blocks(mp,
 							(int64_t)alen, (flags &
 							XFS_BMAPI_RSVBLOCKS));
 				}
@@ -5210,7 +5204,7 @@ xfs_bunmapi(
 					ip, -((long)del.br_blockcount), 0,
 					XFS_QMOPT_RES_RTBLKS);
 			} else {
-				xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS,
+				xfs_icsb_modify_free_blocks(mp,
 						(int64_t)del.br_blockcount, rsvd);
 				(void)xfs_trans_reserve_quota_nblks(NULL,
 					ip, -((long)del.br_blockcount), 0,
fs/xfs/xfs_fsops.c +1 -2
index fb9a9c8..be34ff2 100644
@@ -596,8 +596,7 @@ out:
 		 * the extra reserve blocks from the reserve.....
 		 */
 		int error;
-		error = xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS,
-						 fdblks_delta, 0);
+		error = xfs_icsb_modify_free_blocks(mp, fdblks_delta, 0);
 		if (error == ENOSPC)
 			goto retry;
 	}
fs/xfs/xfs_mount.c +77 -83

172 lines not on this page · raw message

fs/xfs/xfs_mount.h +2 -2
index 42d31df..c8ff435 100644
@@ -75,8 +75,8 @@ enum {
 	XFS_ICSB_MAX,
 };
 
-extern int	xfs_icsb_modify_counters(struct xfs_mount *, xfs_sb_field_t,
-						int64_t, int);
+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);
 
 typedef struct xfs_mount {
 	struct super_block	*m_super;
fs/xfs/xfs_trans.c +9 -10
index f6d956b..cf2214d 100644
@@ -696,7 +696,7 @@ xfs_trans_reserve(
 	 * fail if the count would go below zero.
 	 */
 	if (blocks > 0) {
-		error = xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS,
+		error = xfs_icsb_modify_free_blocks(tp->t_mountp,
 					  -((int64_t)blocks), rsvd);
 		if (error != 0) {
 			current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
@@ -767,8 +767,8 @@ undo_log:
 
 undo_blocks:
 	if (blocks > 0) {
-		xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS,
-					 (int64_t)blocks, rsvd);
+		xfs_icsb_modify_free_blocks(tp->t_mountp,
+						(int64_t)blocks, rsvd);
 		tp->t_blk_res = 0;
 	}
 
@@ -1045,21 +1045,20 @@ xfs_trans_unreserve_and_mod_sb(
 
 	/* apply the per-cpu counters */
 	if (blkdelta) {
-		error = xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS,
-						 blkdelta, rsvd);
+		error = xfs_icsb_modify_free_blocks(mp, blkdelta, rsvd);
 		if (error)
 			goto out;
 	}
 
 	if (idelta) {
-		error = xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT,
+		error = xfs_icsb_modify_inodes(mp, XFS_ICSB_ICOUNT,
 						 idelta, rsvd);
 		if (error)
 			goto out_undo_fdblocks;
 	}
 
 	if (ifreedelta) {
-		error = xfs_icsb_modify_counters(mp, XFS_SBS_IFREE,
+		error = xfs_icsb_modify_inodes(mp, XFS_ICSB_IFREE,
 						 ifreedelta, rsvd);
 		if (error)
 			goto out_undo_icount;
@@ -1129,13 +1128,13 @@ xfs_trans_unreserve_and_mod_sb(
 
 out_undo_ifreecount:
 	if (ifreedelta)
-		xfs_icsb_modify_counters(mp, XFS_SBS_IFREE, -ifreedelta, rsvd);
+		xfs_icsb_modify_inodes(mp, XFS_ICSB_IFREE, -ifreedelta, rsvd);
 out_undo_icount:
 	if (idelta)
-		xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT, -idelta, rsvd);
+		xfs_icsb_modify_inodes(mp, XFS_ICSB_ICOUNT, -idelta, rsvd);
 out_undo_fdblocks:
 	if (blkdelta)
-		xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, -blkdelta, rsvd);
+		xfs_icsb_modify_free_blocks(mp, -blkdelta, rsvd);
 out:
 	ASSERT(error = 0);
 	return;
Signature · 6 lines
1.7.2.3

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

Re: [PATCH 3/3] xfs: demultiplex xfs_icsb_modify_counters()

Review

Quoted 9 lines · Dave Chinner

From: Dave Chinner <[email protected]>

With the conversion to percpu counters, xfs_icsb_modify_counters() really does not need to exist. Convert the inode counter modifications to use a common helper function for the one place that calls them, and add another function for the free block modification and convert all the callers to use that.

(quoted diff) +2 -0
+xfs_icsb_modify_inodes(
+	xfs_mount_t	*mp,

struct xfs_mount, please.

fs/xfs/xfs_mount.c xfs_icsb_sync_counters( · line 381

Quoted 3 lines
fs/xfs/xfs_mount.c +3 -0
+	int		cntr,
+	int64_t		delta,
+	int		rsvd)

the rsvd argument isn't used at all.

fs/xfs/xfs_mount.c xfs_icsb_sync_counters( · line 392

Quoted 11 lines
fs/xfs/xfs_mount.c +11 -0
+{
+	int		ret = 0;
+
+	ASSERT(cntr == XFS_ICSB_ICOUNT || cntr == XFS_ICSB_IFREE);
+
+	ret = xfs_icsb_add(mp, cntr, delta, 0);
+	if (ret < 0) {
+		ASSERT(0);
+		return XFS_ERROR(EINVAL);
+	}
+	return 0;

You could get rdif of the ret argument as we don't care about the value. I also don't think we need the assert here - the caller already does one for us.

fs/xfs/xfs_mount.c xfs_icsb_sync_counters( · line 397

Quoted 2 lines
fs/xfs/xfs_mount.c +2 -0
+xfs_icsb_modify_free_blocks(
+	xfs_mount_t	*mp,

same here.

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

#9 lore raw

Re: [PATCH 3/3] xfs: demultiplex xfs_icsb_modify_counters()

Quoted 35 lines · Christoph Hellwig

Review

Quoted 9 lines · Dave Chinner

From: Dave Chinner <[email protected]>

With the conversion to percpu counters, xfs_icsb_modify_counters() really does not need to exist. Convert the inode counter modifications to use a common helper function for the one place that calls them, and add another function for the free block modification and convert all the callers to use that.

(quoted diff) +2 -0
+xfs_icsb_modify_inodes(
+	xfs_mount_t	*mp,

struct xfs_mount, please.

fs/xfs/xfs_mount.c xfs_icsb_sync_counters( · line 381

Quoted 3 lines
fs/xfs/xfs_mount.c +3 -0
+	int		cntr,
+	int64_t		delta,
+	int		rsvd)

the rsvd argument isn't used at all.

fs/xfs/xfs_mount.c xfs_icsb_sync_counters( · line 392

Quoted 11 lines
fs/xfs/xfs_mount.c +11 -0
+{
+	int		ret = 0;
+
+	ASSERT(cntr == XFS_ICSB_ICOUNT || cntr == XFS_ICSB_IFREE);
+
+	ret = xfs_icsb_add(mp, cntr, delta, 0);
+	if (ret < 0) {
+		ASSERT(0);
+		return XFS_ERROR(EINVAL);
+	}
+	return 0;

You could get rdif of the ret argument as we don't care about the value. I also don't think we need the assert here - the caller already does one for us.

Quoted 4 lines

fs/xfs/xfs_mount.c xfs_icsb_sync_counters( · line 397

Quoted 2 lines
fs/xfs/xfs_mount.c +2 -0
+xfs_icsb_modify_free_blocks(
+	xfs_mount_t	*mp,

same here.

Ok, makes sense. I'll clean it up.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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