xfs
[Top] [All Lists]

[PATCH v2] xfs: use percpu_counter_read_positive for mp->m_icount

To: xfs@xxxxxxxxxxx
Subject: [PATCH v2] xfs: use percpu_counter_read_positive for mp->m_icount
From: xuw2015@xxxxxxxxx
Date: Fri, 17 Apr 2015 15:40:23 +0800
Cc: George Wang <xuw2015@xxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
From: George Wang <xuw2015@xxxxxxxxx>

Function percpu_counter_read just return the current counter, which can be
negative. This will cause the checking of "allocated inode
counts <= m_maxicount" false positive. Use percpu_counter_read_positive can
solve this problem, and be consistent with the purpose to introduce percpu
mechanism to xfs.

Signed-off-by: George Wang <xuw2015@xxxxxxxxx>
---
 fs/xfs/libxfs/xfs_ialloc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index 07349a1..1c9e755 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -376,7 +376,7 @@ xfs_ialloc_ag_alloc(
         */
        newlen = args.mp->m_ialloc_inos;
        if (args.mp->m_maxicount &&
-           percpu_counter_read(&args.mp->m_icount) + newlen >
+           percpu_counter_read_positive(&args.mp->m_icount) + newlen >
                                                        args.mp->m_maxicount)
                return -ENOSPC;
        args.minlen = args.maxlen = args.mp->m_ialloc_blks;
@@ -1339,10 +1339,13 @@ xfs_dialloc(
         * If we have already hit the ceiling of inode blocks then clear
         * okalloc so we scan all available agi structures for a free
         * inode.
+        *
+        * Read rough value of mp->m_icount by percpu_counter_read_positive,
+        * which will sacrifice the preciseness but improve the performance.
         */
        if (mp->m_maxicount &&
-           percpu_counter_read(&mp->m_icount) + mp->m_ialloc_inos >
-                                                       mp->m_maxicount) {
+           percpu_counter_read_positive(&mp->m_icount) + mp->m_ialloc_inos
+                                                       > mp->m_maxicount) {
                noroom = 1;
                okalloc = 0;
        }
-- 
1.9.3

<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH v2] xfs: use percpu_counter_read_positive for mp->m_icount, xuw2015 <=