summaryrefslogtreecommitdiffstats
path: root/fs/squashfs
diff options
context:
space:
mode:
authorAjeet Yadav <ajeet.yadav.77@gmail.com>2011-12-27 15:10:04 +0530
committerPhillip Lougher <phillip@squashfs.org.uk>2011-12-30 01:24:13 +0000
commitd7fbd893388d9e86d29b7cfbd5457bcf03496fbf (patch)
treeea94d043ee3e842f7273391b143a5949afb39975 /fs/squashfs
parent89cab5b5727d3139adc247e3a3d4ee5b10e3eda5 (diff)
downloadlinux-d7fbd893388d9e86d29b7cfbd5457bcf03496fbf.tar.bz2
Squashfs: optimise squashfs_cache_get entry search
squashfs_cache_get() iterates over all entries to search for block its looking for. Often get() / put() are called for same block. If we cache the current entry index, then we can optimise the subsequent *_get() calls. Signed-off-by: Ajeet Yadav <ajeet.yadav.77@gmail.com> Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Diffstat (limited to 'fs/squashfs')
-rw-r--r--fs/squashfs/cache.c11
-rw-r--r--fs/squashfs/squashfs_fs_sb.h1
2 files changed, 9 insertions, 3 deletions
diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c
index ea6e798e548b..af0b73802592 100644
--- a/fs/squashfs/cache.c
+++ b/fs/squashfs/cache.c
@@ -70,11 +70,15 @@ struct squashfs_cache_entry *squashfs_cache_get(struct super_block *sb,
spin_lock(&cache->lock);
while (1) {
- for (i = 0; i < cache->entries; i++)
- if (cache->entry[i].block == block)
+ for (i = cache->curr_blk, n = 0; n < cache->entries; n++) {
+ if (cache->entry[i].block == block) {
+ cache->curr_blk = i;
break;
+ }
+ i = (i + 1) % cache->entries;
+ }
- if (i == cache->entries) {
+ if (n == cache->entries) {
/*
* Block not in cache, if all cache entries are used
* go to sleep waiting for one to become available.
@@ -245,6 +249,7 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries,
goto cleanup;
}
+ cache->curr_blk = 0;
cache->next_blk = 0;
cache->unused = entries;
cache->entries = entries;
diff --git a/fs/squashfs/squashfs_fs_sb.h b/fs/squashfs/squashfs_fs_sb.h
index 651f0b31d296..52934a22f296 100644
--- a/fs/squashfs/squashfs_fs_sb.h
+++ b/fs/squashfs/squashfs_fs_sb.h
@@ -28,6 +28,7 @@
struct squashfs_cache {
char *name;
int entries;
+ int curr_blk;
int next_blk;
int num_waiters;
int unused;