lkml.org 
[lkml]   [2008]   [Nov]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH V2 10/16] Squashfs: cache operations
Hi.

Couple comments below.

On Wed, Oct 29, 2008 at 01:49:56AM +0000, Phillip Lougher (phillip@lougher.demon.co.uk) wrote:
> +struct squashfs_cache_entry *squashfs_cache_get(struct super_block *sb,
> + struct squashfs_cache *cache, long long block, int length)
> +{
> + int i, n;
> + struct squashfs_cache_entry *entry;
> +
> + spin_lock(&cache->lock);
> +
> + while (1) {
> + for (i = 0; i < cache->entries; i++)
> + if (cache->entry[i].block == block)
> + break;
> +
> + if (i == cache->entries) {
> + /*
> + * Block not in cache, if all cache entries are locked
> + * go to sleep waiting for one to become available.
> + */
> + if (cache->unused == 0) {
> + cache->waiting++;
> + spin_unlock(&cache->lock);
> + wait_event(cache->wait_queue, cache->unused);
> + spin_lock(&cache->lock);
> + cache->waiting--;
> + continue;
> + }
> +
> + /*
> + * At least one unlocked cache entry. A simple
> + * round-robin strategy is used to choose the entry to
> + * be evicted from the cache.
> + */
> + i = cache->next_blk;
> + for (n = 0; n < cache->entries; n++) {
> + if (cache->entry[i].locked == 0)
> + break;
> + i = (i + 1) % cache->entries;
> + }
> +
> + cache->next_blk = (i + 1) % cache->entries;
> + entry = &cache->entry[i];

This is invoked for every read when cache is filled, if I understood
correctly, and having a modulo in this path is an additional overhead.
This may be hidden on behalf of compression overhead, but stil.

Also what happens when there are no unlocked entries? I.e. you will try
to work with existing one, while it is already locked and processed by
another thread?


--
Evgeniy Polyakov


\
 
 \ /
  Last update: 2008-11-03 15:13    [W:0.385 / U:0.012 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site