Skip to content

Commit d7fbd89

Browse files
Ajeet Yadavplougher
authored andcommitted
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>
1 parent 89cab5b commit d7fbd89

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎fs/squashfs/cache.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ struct squashfs_cache_entry *squashfs_cache_get(struct super_block *sb,
7070
spin_lock(&cache->lock);
7171

7272
while (1) {
73-
for (i = 0; i < cache->entries; i++)
74-
if (cache->entry[i].block == block)
73+
for (i = cache->curr_blk, n = 0; n < cache->entries; n++) {
74+
if (cache->entry[i].block == block) {
75+
cache->curr_blk = i;
7576
break;
77+
}
78+
i = (i + 1) % cache->entries;
79+
}
7680

77-
if (i == cache->entries) {
81+
if (n == cache->entries) {
7882
/*
7983
* Block not in cache, if all cache entries are used
8084
* go to sleep waiting for one to become available.
@@ -245,6 +249,7 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries,
245249
goto cleanup;
246250
}
247251

252+
cache->curr_blk = 0;
248253
cache->next_blk = 0;
249254
cache->unused = entries;
250255
cache->entries = entries;

‎fs/squashfs/squashfs_fs_sb.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
struct squashfs_cache {
2929
char *name;
3030
int entries;
31+
int curr_blk;
3132
int next_blk;
3233
int num_waiters;
3334
int unused;

0 commit comments

Comments
 (0)