Commit d7fbd893 authored by Ajeet Yadav's avatar Ajeet Yadav Committed by Phillip Lougher

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: default avatarAjeet Yadav <ajeet.yadav.77@gmail.com>
Signed-off-by: default avatarPhillip Lougher <phillip@squashfs.org.uk>
parent 89cab5b5
...@@ -70,11 +70,15 @@ struct squashfs_cache_entry *squashfs_cache_get(struct super_block *sb, ...@@ -70,11 +70,15 @@ struct squashfs_cache_entry *squashfs_cache_get(struct super_block *sb,
spin_lock(&cache->lock); spin_lock(&cache->lock);
while (1) { while (1) {
for (i = 0; i < cache->entries; i++) for (i = cache->curr_blk, n = 0; n < cache->entries; n++) {
if (cache->entry[i].block == block) if (cache->entry[i].block == block) {
cache->curr_blk = i;
break; break;
}
i = (i + 1) % cache->entries;
}
if (i == cache->entries) { if (n == cache->entries) {
/* /*
* Block not in cache, if all cache entries are used * Block not in cache, if all cache entries are used
* go to sleep waiting for one to become available. * go to sleep waiting for one to become available.
...@@ -245,6 +249,7 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries, ...@@ -245,6 +249,7 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries,
goto cleanup; goto cleanup;
} }
cache->curr_blk = 0;
cache->next_blk = 0; cache->next_blk = 0;
cache->unused = entries; cache->unused = entries;
cache->entries = entries; cache->entries = entries;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
struct squashfs_cache { struct squashfs_cache {
char *name; char *name;
int entries; int entries;
int curr_blk;
int next_blk; int next_blk;
int num_waiters; int num_waiters;
int unused; int unused;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment