Bug 37456 - canvas cache on server is inefficient (contains two entries only!)
Summary: canvas cache on server is inefficient (contains two entries only!)
Status: RESOLVED MOVED
Alias: None
Product: Spice
Classification: Unclassified
Component: server (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Spice Bug List
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-22 02:26 UTC by Yaniv Kaul
Modified: 2018-06-03 10:15 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Yaniv Kaul 2011-05-22 02:26:21 UTC
It appears there is some nice caching infrastructure for canvas in the server (regretfully called image_put and image_get (server/red_worker.c), but it contains only up to 2(!) entries (IMAGE_CACHE_MAX_ITEMS is defined as 2), making it completely useless.
I changed it to contain more, and saw no issues with it. 
I did see XP guests use more entries when it was enabled.
Linux (F15) guests did not use it anyway.


All that I've done to gather the above is sprinkle some red_printf()'s after reading the code: 

[ykaul@ykaul spice]$ git diff server/red_worker.c
diff --git a/server/red_worker.c b/server/red_worker.c
index bee86b9..16bf4b6 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -3494,7 +3494,7 @@ static int image_cache_hit(ImageCache *cache, uint64_t id)
 static void image_cache_remove(ImageCache *cache, ImageCacheItem *item)
 {
     ImageCacheItem **now;
-
+    red_printf("id %lu, hash location: %lu", item->id, item->id % IMAGE_CACHE_HASH_SIZE);
     now = &cache->hash_table[item->id % IMAGE_CACHE_HASH_SIZE];
     for (;;) {
         ASSERT(*now);
@@ -3518,9 +3518,10 @@ static void image_cache_put(SpiceImageCache *spice_cache, uint64_t id, pixman_im
 {
     ImageCache *cache = (ImageCache *)spice_cache;
     ImageCacheItem *item;
-
 #ifndef IMAGE_CACHE_AGE
+    red_printf("cache->num_items: %u", cache->num_items);
     if (cache->num_items == IMAGE_CACHE_MAX_ITEMS) {
+    red_printf("cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!");
         ImageCacheItem *tail = (ImageCacheItem *)ring_get_tail(&cache->lru);
         ASSERT(tail);
         image_cache_remove(cache, tail);
@@ -3536,7 +3537,7 @@ static void image_cache_put(SpiceImageCache *spice_cache, uint64_t id, pixman_im
 #endif
     item->image = pixman_image_ref(image);
     ring_item_init(&item->lru_link);
-
+    red_printf("id %lu, hash location: %lu", item->id, item->id % IMAGE_CACHE_HASH_SIZE);
     item->next = cache->hash_table[item->id % IMAGE_CACHE_HASH_SIZE];
     cache->hash_table[item->id % IMAGE_CACHE_HASH_SIZE] = item;




here's a run example:
do_spice_init: ykaul: starting 0.6.3
spice_server_add_interface: SPICE_INTERFACE_KEYBOARD
spice_server_add_interface: SPICE_INTERFACE_MOUSE
spice_server_add_interface: SPICE_INTERFACE_QXL
red_worker_main: begin
spice_server_add_interface: SPICE_INTERFACE_PLAYBACK
handle_dev_destroy_surfaces:
handle_dev_destroy_surfaces:
handle_dev_input: start
QEMU 0.14.50 monitor - type 'help' for more information
(qemu) handle_dev_destroy_surfaces:
handle_dev_destroy_surfaces:
reds_handle_read_link_done: Peer doesn't support AUTH selection
reds_handle_main_link:
reds_show_new_channel: channel 1:0, connected successfully, over Non Secure link
main_channel_link:
reds_handle_read_link_done: Peer doesn't support AUTH selection
reds_show_new_channel: channel 4:0, connected successfully, over Non Secure link
red_dispatcher_set_cursor_peer:
main_channel_handle_parsed: net test: latency 0.260000 ms, bitrate 141221900 bps (134.679699 Mbps)
handle_dev_input: cursor connect
reds_handle_read_link_done: Peer doesn't support AUTH selection
reds_show_new_channel: channel 5:0, connected successfully, over Non Secure link
reds_handle_read_link_done: Peer doesn't support AUTH selection
reds_show_new_channel: channel 2:0, connected successfully, over Non Secure link
red_dispatcher_set_peer:
handle_dev_input: connect
handle_new_display_channel: jpeg disabled
handle_new_display_channel: zlib-over-glz disabled
image_cache_put: cache->num_items: 0
image_cache_put: id 16692984622346338345, hash location: 41
image_cache_put: cache->num_items: 1
image_cache_put: id 3280720828400402688, hash location: 256
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 16692984622346338345, hash location: 41
image_cache_put: id 9713389464692457571, hash location: 99
reds_handle_read_link_done: Peer doesn't support AUTH selection
reds_show_new_channel: channel 3:0, connected successfully, over Non Secure link
inputs_link:
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 9713389464692457571, hash location: 99
image_cache_put: id 16692984622346338345, hash location: 41
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 16692984622346338345, hash location: 41
image_cache_put: id 9323874577061568761, hash location: 249
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 3280720828400402688, hash location: 256
image_cache_put: id 9713389464692457571, hash location: 99
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 9323874577061568761, hash location: 249
image_cache_put: id 10655197967897838368, hash location: 800
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 9713389464692457571, hash location: 99
image_cache_put: id 6355812529235034368, hash location: 256
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 10655197967897838368, hash location: 800
image_cache_put: id 17566795881926623488, hash location: 256
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 6355812529235034368, hash location: 256
image_cache_put: id 13707069709730971904, hash location: 256
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 17566795881926623488, hash location: 256
image_cache_put: id 1412022055884816640, hash location: 256
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 13707069709730971904, hash location: 256
image_cache_put: id 6355812529235034368, hash location: 256
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 1412022055884816640, hash location: 256
image_cache_put: id 7051416241264910410, hash location: 74
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 6355812529235034368, hash location: 256
image_cache_put: id 12743327117782106113, hash location: 1
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 7051416241264910410, hash location: 74
image_cache_put: id 3738288703970295809, hash location: 1
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 12743327117782106113, hash location: 1
image_cache_put: id 16714730741845475333, hash location: 5
image_cache_put: cache->num_items: 2
image_cache_put: cache->num_items == IMAGE_CACHE_MAX_ITEMS !!!
image_cache_remove: id 3738288703970295809, hash location: 1
image_cache_put: id 12743327117782106113, hash location: 1
Comment 1 Victor Toso 2016-05-04 10:18:49 UTC
I guess this still relevant today?

$ grep -rniI "IMAGE_CACHE_MAX_ITEMS" *
server/image-cache.c:73:#define IMAGE_CACHE_MAX_ITEMS 2
server/image-cache.c:81:    if (cache->num_items == IMAGE_CACHE_MAX_ITEMS) {
Comment 2 Yaniv Kaul 2016-05-04 14:08:59 UTC
Perhaps - I have not touched Spice for years and do not know if current code still uses this cache. If it does, it is still relevant.
Note - I don't know the implications either.
Comment 3 GitLab Migration User 2018-06-03 10:15:57 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/spice/spice-server/issues/26.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.