<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div><br></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div><br></div><style>body { line-height: 1.5; }blockquote { margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em; }body { font-size: 10.5pt; font-family: 微软雅黑; color: rgb(0, 0, 0); line-height: 1.5; }</style><div><span><div style="MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt"><div style="font-family: 'Microsoft YaHei UI', Tahoma; font-size: 14px; line-height: normal;"><div style="font-family: Verdana;">OK, I have modified it.</div></div></div></span></div><blockquote style="margin-Top: 0px; margin-Bottom: 0px; margin-Left: 0.5em"><div><span style="background-color: transparent;">From 87be8732bf36038c9ba9faabb1aae58f7b830d05 Mon Sep 17 00:00:00 2001</span></div><div>From: =?UTF-8?q?=E4=B9=90=E4=B9=89=E5=8D=8E?= <yueyihua@os-easy.com></div><div>Date: Thu, 12 Jul 2018 13:16:53 +0800</div><div>Subject: [PATCH] Fix image cache memory usage</div><div><br></div><div>When image flag is SPICE_IMAGE_FLAGS_CACHE_REPLACE_ME, and if found it</div><div>in hash table, we will do refcount increase, but this image will only</div><div>destroy once, so the cache will usage more and more memory. In this</div><div>circumstance, we should not increase refconut.</div></blockquote></blockquote><div><br></div><div>Was the removal of refcount copy on purpose or a mistake?<br></div><div><br></div><div>typo: refconut -> refcount<br></div><div><br></div><div>Frediano<br></div><div><br></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><blockquote style="margin-Top: 0px; margin-Bottom: 0px; margin-Left: 0.5em"><div>---</div><div> src/channel-display.c     | 5 ++++-</div><div> src/spice-channel-cache.h | 8 ++++++++</div><div> 2 files changed, 12 insertions(+), 1 deletion(-)</div><div><br></div><div>diff --git a/src/channel-display.c b/src/channel-display.c</div><div>index 7c14c76..ebb8695 100755</div><div>--- a/src/channel-display.c</div><div>+++ b/src/channel-display.c</div><div>@@ -659,7 +659,10 @@ static void image_put_lossy(SpiceImageCache *cache, uint64_t id,</div><div> static void image_replace_lossy(SpiceImageCache *cache, uint64_t id,</div><div>                                 pixman_image_t *surface)</div><div> {</div><div>-    image_put(cache, id, surface);</div><div>+    SpiceDisplayChannelPrivate *c =</div><div>+        SPICE_CONTAINEROF(cache, SpiceDisplayChannelPrivate, image_cache);</div><div>+</div><div>+    cache_replace_lossy(c->images, id, pixman_image_ref(surface), FALSE);</div><div> }</div><div> static pixman_image_t* image_get_lossless(SpiceImageCache *cache, uint64_t id)</div><div>diff --git a/src/spice-channel-cache.h b/src/spice-channel-cache.h</div><div>index ca1fd5d..da88a39 100755</div><div>--- a/src/spice-channel-cache.h</div><div>+++ b/src/spice-channel-cache.h</div><div>@@ -101,6 +101,14 @@ static inline void cache_add_lossy(display_cache *cache, uint64_t id,</div><div>     g_hash_table_replace(cache->table, item, value);</div><div> }</div><div>+static inline void cache_replace_lossy(display_cache *cache, uint64_t id,</div><div>+                                   gpointer value, gboolean lossy)</div><div>+{</div><div>+    display_cache_item *item = cache_item_new(id, lossy);</div><div>+</div><div>+    g_hash_table_replace(cache->table, item, value);</div><div>+}</div><div>+</div><div> static inline void cache_add(display_cache *cache, uint64_t id, gpointer value)</div><div> {</div><div>     cache_add_lossy(cache, id, value, FALSE);</div><div>-- </div><div>2.5.5</div><div><br></div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-SIZE: 12px;FONT-FAMILY:tahoma;COLOR:#000000; BACKGROUND: #efefef; PADDING-BOTTOM: 8px; PADDING-TOP: 8px"><div><b>From:</b><a href="mailto:cfergeau@redhat.com" target="_blank">Christophe Fergeau</a><br data-mce-bogus="1"></div><div><b>Date:</b> 2018-07-17 18:07</div><div><b>To:</b><a href="mailto:fziglio@redhat.com" target="_blank">Frediano Ziglio</a><br data-mce-bogus="1"></div><div><b>CC:</b><a href="mailto:spice-devel@lists.freedesktop.org" target="_blank">spice-devel</a>; <a href="mailto:yueyihua@os-easy.com" target="_blank">乐义华</a><br data-mce-bogus="1"></div><div><b>Subject:</b> Re: [Spice-devel] [PATCH spice-gtk] If replace me, should not do refcount plus one</div></div></div><div><div>On Tue, Jul 17, 2018 at 08:17:53AM +0100, Frediano Ziglio wrote:</div><div>> From: 乐义华 <yueyihua@os-easy.com></div><div>> </div><div>> When an image with SPICE_IMAGE_FLAGS_CACHE_REPLACE_ME is received the</div><div>> reference counter should stay the same to avoid the cache to grow</div><div>> continously.</div><div>> </div><div>> This fixes https://gitlab.freedesktop.org/spice/spice-gtk/issues/72</div><div>Can you reword the shortlog a bit?</div><div>Christophe</div><div>> </div><div>> Signed-off-by: 乐义华 <yueyihua@os-easy.com></div><div>> Signed-off-by: Frediano Ziglio <fziglio@redhat.com></div><div>> ---</div><div>>  src/channel-display.c     |  5 ++++-</div><div>>  src/spice-channel-cache.h | 17 +++++++++++++++++</div><div>>  2 files changed, 21 insertions(+), 1 deletion(-)</div><div>> </div><div>> diff --git a/src/channel-display.c b/src/channel-display.c</div><div>> index 44ba0439..138cd8ce 100644</div><div>> --- a/src/channel-display.c</div><div>> +++ b/src/channel-display.c</div><div>> @@ -788,7 +788,10 @@ static void image_put_lossy(SpiceImageCache *cache, uint64_t id,</div><div>>  static void image_replace_lossy(SpiceImageCache *cache, uint64_t id,</div><div>>                                  pixman_image_t *surface)</div><div>>  {</div><div>> -    image_put(cache, id, surface);</div><div>> +    SpiceDisplayChannelPrivate *c =</div><div>> +        SPICE_CONTAINEROF(cache, SpiceDisplayChannelPrivate, image_cache);</div><div>> +</div><div>> +    cache_replace_lossy(c->images, id, pixman_image_ref(surface), FALSE);</div><div>>  }</div><div>>  </div><div>>  static pixman_image_t* image_get_lossless(SpiceImageCache *cache, uint64_t id)</div><div>> diff --git a/src/spice-channel-cache.h b/src/spice-channel-cache.h</div><div>> index 75cc2cd8..fc25c354 100644</div><div>> --- a/src/spice-channel-cache.h</div><div>> +++ b/src/spice-channel-cache.h</div><div>> @@ -101,6 +101,23 @@ static inline void cache_add_lossy(display_cache *cache, uint64_t id,</div><div>>      g_hash_table_replace(cache->table, item, value);</div><div>>  }</div><div>>  </div><div>> +static inline void cache_replace_lossy(display_cache *cache, uint64_t id,</div><div>> +                                       gpointer value, gboolean lossy)</div><div>> +{</div><div>> +    display_cache_item *item = cache_item_new(id, lossy);</div><div>> +</div><div>> +    // If image is currently in the table consider its reference count before replacing it</div><div>> +    if (cache->ref_counted) {</div><div>> +        display_cache_item *current_item;</div><div>> +        gpointer current_image;</div><div>> +        if (g_hash_table_lookup_extended(cache->table, &id, (gpointer*) &current_item,</div><div>> +                                         &current_image)) {</div><div>> +            item->ref_count = current_item->ref_count;</div><div>> +        }</div><div>> +    }</div><div>> +    g_hash_table_replace(cache->table, item, value);</div><div>> +}</div><div>> +</div><div>>  static inline void cache_add(display_cache *cache, uint64_t id, gpointer value)</div><div>>  {</div><div>>      cache_add_lossy(cache, id, value, FALSE);</div><div>> -- </div><div>> 2.17.1</div><div>> </div><div>> _______________________________________________</div><div>> Spice-devel mailing list</div><div>> Spice-devel@lists.freedesktop.org</div><div>> https://lists.freedesktop.org/mailman/listinfo/spice-devel</div></div></blockquote></blockquote><div><br></div></div></body></html>