Commit d7fbd893388d9e86d29b7cfbd5457bcf03496fbf
Committed by
Phillip Lougher
1 parent
89cab5b572
Exists in
master
and in
6 other branches
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>
Showing 2 changed files with 9 additions and 3 deletions Side-by-side Diff
fs/squashfs/cache.c
... | ... | @@ -70,11 +70,15 @@ |
70 | 70 | spin_lock(&cache->lock); |
71 | 71 | |
72 | 72 | 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; | |
75 | 76 | break; |
77 | + } | |
78 | + i = (i + 1) % cache->entries; | |
79 | + } | |
76 | 80 | |
77 | - if (i == cache->entries) { | |
81 | + if (n == cache->entries) { | |
78 | 82 | /* |
79 | 83 | * Block not in cache, if all cache entries are used |
80 | 84 | * go to sleep waiting for one to become available. |
... | ... | @@ -245,6 +249,7 @@ |
245 | 249 | goto cleanup; |
246 | 250 | } |
247 | 251 | |
252 | + cache->curr_blk = 0; | |
248 | 253 | cache->next_blk = 0; |
249 | 254 | cache->unused = entries; |
250 | 255 | cache->entries = entries; |