Skip to content

Commit

Permalink
Squashfs: optimise squashfs_cache_get entry search
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Phillip Lougher <[email protected]>
  • Loading branch information
Ajeet Yadav authored and plougher committed Dec 30, 2011
1 parent 89cab5b commit d7fbd89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions fs/squashfs/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions fs/squashfs/squashfs_fs_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
struct squashfs_cache {
char *name;
int entries;
int curr_blk;
int next_blk;
int num_waiters;
int unused;
Expand Down

0 comments on commit d7fbd89

Please sign in to comment.