Skip to contentSkip to conversation

tmpfs: Make tmpfs scalable with caches for free blocks

PATCH Superseded tim 2 participants 3 messages May 18, 2010 – May 26, 2010

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

tim

author
#0 lore raw

PATCH 2/2 tmpfs: Make tmpfs scalable with caches for free blocks

The current implementation of tmpfs is not scalable. The stat_lock is contended whenever we need to get a new page, leading to lots of lock contentions. This patch makes use of the qtoken library to maintain local caches of free pages to speed up getting and returning of pages without acquisition of stat_lock. It improved the performance of tmpfs by 270% for Aim7 fserver workload.

 include/linux/shmem_fs.h |    4 ++-
 mm/shmem.c               |   58 +++++++++++++++++++++++++--------------------
 2 files changed, 35 insertions(+), 27 deletions(-)
include/linux/shmem_fs.h +3 -1
index e164291..6ba014d 100644
@@ -3,10 +3,12 @@
 
 #include <linux/swap.h>
 #include <linux/mempolicy.h>
+#include <linux/qtoken.h>
 
 /* inode in-kernel data */
 
 #define SHMEM_NR_DIRECT 16
+#define SHMEM_FREE_BLK_CACHE_SZ 512
 
 struct shmem_inode_info {
 	spinlock_t		lock;
@@ -23,7 +25,7 @@ struct shmem_inode_info {
 
 struct shmem_sb_info {
 	unsigned long max_blocks;   /* How many blocks are allowed */
-	unsigned long free_blocks;  /* How many are left for allocation */
+	struct qtoken token_jar;    /* Token jar of free blocks */
 	unsigned long max_inodes;   /* How many inodes are allowed */
 	unsigned long free_inodes;  /* How many are left for allocation */
 	spinlock_t stat_lock;	    /* Serialize shmem_sb_info changes */
mm/shmem.c +32 -26

134 lines not on this page · raw message

maintainer
#1 lore raw
Quoted 11 lines · On Tue, 18 May 2010 16:34:32 -0700 tim <[email protected]> wrote:

The current implementation of tmpfs is not scalable. The stat_lock is contended whenever we need to get a new page, leading to lots of lock contentions. This patch makes use of the qtoken library to maintain local caches of free pages to speed up getting and returning of pages without acquisition of stat_lock. It improved the performance of tmpfs by 270% for Aim7 fserver workload.

...

mm/shmem.c static void shmem_free_blocks(struct inode *inode, long pages) · line 240

Quoted 7 lines
mm/shmem.c +3 -3
-		spin_lock(&sbinfo->stat_lock);
-		sbinfo->free_blocks += pages;
+		spin_lock(&inode->i_lock);
+		qtoken_return(&sbinfo->token_jar, pages);
 		inode->i_blocks -= pages*BLOCKS_PER_PAGE;
-		spin_unlock(&sbinfo->stat_lock);
+		spin_unlock(&inode->i_lock);

Well most of the calls into the qtoken layer occur under inode->i_lock. So did we really need that spinlock inside the qtoken library code?

It is a problem when library code such as qtoken performs its own internal locking. We have learned that such code is much more useful and flexible if it performs no locking at all, and requires that callers provide the locking (lib/rbtree.c, lib/radix-tree.c, lib/prio_heap.c, lib/flex_array.c, etcetera). Can we follow this approach with qtoken?

author
#2 lore raw
Quoted 12 lines · Andrew Morton

mm/shmem.c static void shmem_free_blocks(struct inode *inode, long pages) · line 240

Quoted 8 lines
mm/shmem.c +3 -3
-		spin_lock(&sbinfo->stat_lock);
-		sbinfo->free_blocks += pages;
+		spin_lock(&inode->i_lock);
+		qtoken_return(&sbinfo->token_jar, pages);
 		inode->i_blocks -= pages*BLOCKS_PER_PAGE;
-		spin_unlock(&sbinfo->stat_lock);
+		spin_unlock(&inode->i_lock);

Well most of the calls into the qtoken layer occur under inode->i_lock. So did we really need that spinlock inside the qtoken library code?

Quoted 7 lines

It is a problem when library code such as qtoken performs its own internal locking. We have learned that such code is much more useful and flexible if it performs no locking at all, and requires that callers provide the locking (lib/rbtree.c, lib/radix-tree.c, lib/prio_heap.c, lib/flex_array.c, etcetera). Can we follow this approach with qtoken?

Andrew,

The inode->i_lock only locks a single inode. The token jar is shared by all the inodes using the tmpfs so we do not want to use inode->i_lock to lock the entire token jar for performance reason. With the qtoken scheme, the spinlock inside the qtoken library is used only to protect the free tokens in the common pool of the token jar. Most of the time, this lock need not be taken as we can operate with the tokens in the per cpu cache of the token jar. We will only need to take the lock when we run out of tokens in cache. We put the intelligence in the library to manage the cache and decides when it is necessary to lock and access the free tokens in the common pool. It is better to leave the locking decision in the library code rather than exposing it to the user. Otherwise the user will need to check whether tokens should be taken from cache or the common pool and duplicate the code in qtoken library.

Regards,
Tim Chen