All of lore.kernel.org
 help / color / mirror / Atom feed
From: Orit Wasserman <owasserm@redhat.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: blauwirbel@gmail.com, qemu-devel@nongnu.org, quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH v5 1/9] Add cache handling functions
Date: Wed, 04 Jan 2012 15:27:53 +0200	[thread overview]
Message-ID: <4F0453D9.1070200@redhat.com> (raw)
In-Reply-To: <CAJSP0QV+j1-Kj274P+XDd7CKRnYJQc-vdgxKNBozNnqFmppT1Q@mail.gmail.com>

On 01/04/2012 01:46 PM, Stefan Hajnoczi wrote:
> On Tue, Jan 3, 2012 at 3:34 PM, Orit Wasserman <owasserm@redhat.com> wrote:
>> +static unsigned long cache_get_cache_pos(ram_addr_t address)
>> +{
>> +    unsigned long pos;
>> +
>> +    assert(cache_num_buckets);
>> +    pos = (address/TARGET_PAGE_SIZE) & (cache_num_buckets - 1);
> 
> Where do we guarantee that cache_num_buckets is a power of 2?

We should do it  to when setting cache size , I will add the check.
> 
>> +static void cache_insert(unsigned long addr, uint8_t *pdata)
>> +{
>> +    unsigned long pos;
>> +    int slot = -1;
>> +    CacheBucket *bucket;
>> +
>> +    pos = cache_get_cache_pos(addr);
>> +    assert(page_cache);
>> +    bucket = &page_cache[pos];
>> +    slot = cache_get_oldest(bucket); /* evict LRU */
>> +
>> +    /* actual update of entry */
>> +    CacheItem *it = cache_item_get(pos, slot);
>> +    if (!it->it_data) {
>> +        cache_num_items++;
>> +    }
>> +    g_free(it->it_data);
>> +
>> +    it->it_data = g_malloc0(TARGET_PAGE_SIZE);
>> +    memcpy(it->it_data, pdata, TARGET_PAGE_SIZE);
> 
> If we're evicting an entry:
> 1. Free existing data.
> 2. Allocate new data.
> 3. Zero new data.
> 4. Memcpy pdata into new data.
> 
> That does a bunch of extra work.  How about:
> 1. Memcpy pdata over old data.

I noticed it too , i will fix it in next version.
> 
> So:
> if (!it->it_data) {
>     cache_num_items++;
>     it->it_data = g_malloc(TARGET_PAGE_SIZE);
> }
> memcpy(it->it_data, pdata, TARGET_PAGE_SIZE);

  reply	other threads:[~2012-01-04 13:28 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-03 15:34 [Qemu-devel] [PATCH v5 0/9] XBZRLE delta for live migration of large memory apps Orit Wasserman
2012-01-03 15:34 ` [Qemu-devel] [PATCH v5 1/9] Add cache handling functions Orit Wasserman
2012-01-03 19:54   ` Anthony Liguori
2012-01-04  9:29     ` Orit Wasserman
2012-01-04 22:20       ` Michael Roth
2012-01-04 11:46   ` Stefan Hajnoczi
2012-01-04 13:27     ` Orit Wasserman [this message]
2012-01-03 15:34 ` [Qemu-devel] [PATCH v5 2/9] Add rle_encode and rle_decode functions Implement Run Length Encoding compression Orit Wasserman
2012-01-03 19:57   ` Anthony Liguori
2012-01-04  9:31     ` Orit Wasserman
2012-01-04 16:52       ` Paolo Bonzini
2012-01-04 12:59   ` Avi Kivity
2012-01-04 13:35     ` Stefan Hajnoczi
2012-01-04 13:45       ` Avi Kivity
2012-01-03 15:34 ` [Qemu-devel] [PATCH v5 3/9] Add save_block_hdr function Orit Wasserman
2012-01-03 15:34 ` [Qemu-devel] [PATCH v5 4/9] Add host_from_stream_offset_versioned function Orit Wasserman
2012-01-04 12:00   ` Stefan Hajnoczi
2012-01-04 20:59     ` Michael Roth
2012-01-03 15:34 ` [Qemu-devel] [PATCH v5 5/9] Add XBRLE to ram_save_block and ram_save_live Orit Wasserman
2012-01-04 12:14   ` Stefan Hajnoczi
2012-01-04 13:29     ` Orit Wasserman
2012-01-03 15:34 ` [Qemu-devel] [PATCH v5 6/9] Add xbrle parameters to MigrationState Orit Wasserman
2012-01-04 21:17   ` Michael Roth
2012-01-03 15:34 ` [Qemu-devel] [PATCH v5 7/9] Add set_cachesize to change XBRLE cache size Orit Wasserman
2012-01-03 15:34 ` [Qemu-devel] [PATCH v5 8/9] QMP commands changes Orit Wasserman
2012-01-03 15:47   ` Stefan Hajnoczi
2012-01-03 15:57     ` Orit Wasserman
2012-01-03 16:20       ` Stefan Hajnoczi
2012-01-03 15:34 ` [Qemu-devel] [PATCH v5 9/9] Add XBRLE statistics information Orit Wasserman
2012-01-04 22:45   ` Michael Roth
2012-01-07 16:31   ` Blue Swirl
2012-01-03 16:32 ` [Qemu-devel] [PATCH v5 0/9] XBZRLE delta for live migration of large memory apps Anthony Liguori
2012-01-03 17:02   ` Orit Wasserman
2012-01-04 13:02 ` Avi Kivity
2012-01-04 16:03   ` Orit Wasserman
  -- strict thread matches above, loose matches on Subject: below --
2012-01-03 13:35 Orit Wasserman
2012-01-03 13:35 ` [Qemu-devel] [PATCH v5 1/9] Add cache handling functions Orit Wasserman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F0453D9.1070200@redhat.com \
    --to=owasserm@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.