public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: use percpu_counter_compare instead of naive comparing
@ 2015-04-17  2:22 xuw2015
  2015-04-17  4:06 ` Dave Chinner
  0 siblings, 1 reply; 4+ messages in thread
From: xuw2015 @ 2015-04-17  2:22 UTC (permalink / raw)
  To: xfs; +Cc: George Wang

From: George Wang <xuw2015@gmail.com>

Function percpu_counter_read just return the current counter, regardless of
every cpu's count. This counter can be negative value, which will cause the
checking of "allocated inode counts <= m_maxicount" false positive.
Commit 501ab3238753 "xfs: use generic percpu counters for inode counter
" introduced this problem.
Use the percpu_counter_compare, which will first do stuff in current cpu for
performance; if can not get the result, it will get the exactly counter
based on the count of every cpu.

Signed-off-by: George Wang <xuw2015@gmail.com>
---
 fs/xfs/libxfs/xfs_ialloc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index 07349a1..af9e7d2 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -376,8 +376,8 @@ xfs_ialloc_ag_alloc(
 	 */
 	newlen = args.mp->m_ialloc_inos;
 	if (args.mp->m_maxicount &&
-	    percpu_counter_read(&args.mp->m_icount) + newlen >
-							args.mp->m_maxicount)
+	    percpu_counter_compare(&args.mp->m_icount,
+					args.mp->m_maxicount - newlen) > 0)
 		return -ENOSPC;
 	args.minlen = args.maxlen = args.mp->m_ialloc_blks;
 	/*
@@ -1341,8 +1341,8 @@ xfs_dialloc(
 	 * inode.
 	 */
 	if (mp->m_maxicount &&
-	    percpu_counter_read(&mp->m_icount) + mp->m_ialloc_inos >
-							mp->m_maxicount) {
+	    percpu_counter_compare(&mp->m_icount,
+				mp->m_maxicount - mp->m_ialloc_inos) > 0) {
 		noroom = 1;
 		okalloc = 0;
 	}
-- 
1.9.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-17  8:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-17  2:22 [PATCH] xfs: use percpu_counter_compare instead of naive comparing xuw2015
2015-04-17  4:06 ` Dave Chinner
2015-04-17  7:15   ` 王旭
2015-04-17  8:15     ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox