summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-07-23 19:30:54 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-10-28 15:47:13 +0900
commitd0e647fee3b5ebe6e5c2905a4053a51283f27014 (patch)
treea29c5cc81ef7dca82b8aa8d9f7ec21112574ae4a /src/bin
parentacae35b4d1cb2a8aa602cc9c1e6de468997de059 (diff)
evas/cserve2: Repack File_Data shared array
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/evas/evas_cserve2.h6
-rw-r--r--src/bin/evas/evas_cserve2_cache.c65
-rw-r--r--src/bin/evas/evas_cserve2_index.c6
3 files changed, 60 insertions, 17 deletions
diff --git a/src/bin/evas/evas_cserve2.h b/src/bin/evas/evas_cserve2.h
index b6bdff3e63..361d08a768 100644
--- a/src/bin/evas/evas_cserve2.h
+++ b/src/bin/evas/evas_cserve2.h
@@ -322,7 +322,9 @@ void cserve2_shared_index_shutdown(void);
322 322
323typedef struct _Shared_Array Shared_Array; 323typedef struct _Shared_Array Shared_Array;
324typedef struct _Shared_Mempool Shared_Mempool; 324typedef struct _Shared_Mempool Shared_Mempool;
325typedef Eina_Bool (* Shared_Array_Repack_Skip_Cb) (Shared_Array *, const void *); 325typedef Eina_Bool (* Shared_Array_Repack_Skip_Cb) (Shared_Array *sa,
326 const void *elem,
327 void *user_data);
326 328
327// Shared arrays (arrays of fixed size object) 329// Shared arrays (arrays of fixed size object)
328Shared_Array *cserve2_shared_array_new(int tag, int elemsize, int initcount); 330Shared_Array *cserve2_shared_array_new(int tag, int elemsize, int initcount);
@@ -337,7 +339,7 @@ int cserve2_shared_array_item_new(Shared_Array *sa);
337void *cserve2_shared_array_item_data_get(Shared_Array *sa, int elemid); 339void *cserve2_shared_array_item_data_get(Shared_Array *sa, int elemid);
338Shared_Array *cserve2_shared_array_repack(Shared_Array *sa, 340Shared_Array *cserve2_shared_array_repack(Shared_Array *sa,
339 Shared_Array_Repack_Skip_Cb skip, 341 Shared_Array_Repack_Skip_Cb skip,
340 Eina_Compare_Cb cmp); 342 Eina_Compare_Cb cmp, void *user_data);
341int cserve2_shared_array_item_find(Shared_Array *sa, void *data, 343int cserve2_shared_array_item_find(Shared_Array *sa, void *data,
342 Eina_Compare_Cb cmp); 344 Eina_Compare_Cb cmp);
343void *cserve2_shared_array_item_data_find(Shared_Array *sa, void *data, 345void *cserve2_shared_array_item_data_find(Shared_Array *sa, void *data,
diff --git a/src/bin/evas/evas_cserve2_cache.c b/src/bin/evas/evas_cserve2_cache.c
index d3926e2a10..8624c08995 100644
--- a/src/bin/evas/evas_cserve2_cache.c
+++ b/src/bin/evas/evas_cserve2_cache.c
@@ -175,6 +175,8 @@ struct _File_Watch {
175}; 175};
176 176
177static unsigned int _entry_id = 0; 177static unsigned int _entry_id = 0;
178static unsigned int _freed_entry_count = 0;
179
178static Shared_Array *_file_data_array = NULL; 180static Shared_Array *_file_data_array = NULL;
179 181
180static Eina_Hash *file_ids = NULL; // maps path + key --> file_id 182static Eina_Hash *file_ids = NULL; // maps path + key --> file_id
@@ -242,7 +244,7 @@ _entry_load_reused(Entry *e)
242 244
243 245
244static int 246static int
245_shm_object_id_find_cb(const void *data1, const void *data2) 247_shm_object_id_cmp_cb(const void *data1, const void *data2)
246{ 248{
247 const Shm_Object *obj; 249 const Shm_Object *obj;
248 unsigned int key; 250 unsigned int key;
@@ -266,12 +268,14 @@ _file_data_find(unsigned int file_id)
266 File_Data *fd; 268 File_Data *fd;
267 269
268 fd = cserve2_shared_array_item_data_find(_file_data_array, &file_id, 270 fd = cserve2_shared_array_item_data_find(_file_data_array, &file_id,
269 _shm_object_id_find_cb); 271 _shm_object_id_cmp_cb);
270 if (fd && !fd->refcount) 272 if (fd && !fd->refcount)
271 { 273 {
272 ERR("Can not access object %u with refcount 0", file_id); 274 ERR("Can not access object %u with refcount 0", file_id);
273 return NULL; 275 return NULL;
274 } 276 }
277 else if (!fd)
278 ERR("Could not find file %u", file_id);
275 return fd; 279 return fd;
276} 280}
277 281
@@ -287,6 +291,45 @@ _file_entry_find(unsigned int entry_id)
287 return (File_Entry *) e; 291 return (File_Entry *) e;
288} 292}
289 293
294static Eina_Bool
295_repack_skip_cb(Shared_Array *sa EINA_UNUSED, const void *elem,
296 void *user_data EINA_UNUSED)
297{
298 const File_Data *fd = elem;
299 return (!fd->refcount);
300}
301
302static void
303_repack()
304{
305 Shared_Array *sa;
306 int count;
307
308 count = cserve2_shared_array_size_get(_file_data_array);
309 if (count <= 0) return;
310
311 // Repack when we have 10% fragmentation over the whole shm buffer
312 if (_freed_entry_count > 100 ||
313 ((_freed_entry_count * 100) / count >= 10))
314 {
315 DBG("Repacking file data array: %s",
316 cserve2_shared_array_name_get(_file_data_array));
317
318 sa = cserve2_shared_array_repack(_file_data_array,
319 _repack_skip_cb,
320 _shm_object_id_cmp_cb, NULL);
321 if (!sa)
322 {
323 ERR("Failed to repack array. Keeping previous references!");
324 return;
325 }
326
327 cserve2_shared_array_del(_file_data_array);
328 _freed_entry_count = 0;
329 _file_data_array = sa;
330 }
331}
332
290 333
291static Msg_Opened * 334static Msg_Opened *
292_image_opened_msg_create(File_Data *fd, int *size) 335_image_opened_msg_create(File_Data *fd, int *size)
@@ -845,8 +888,11 @@ _hash_file_entry_free(void *data)
845 888
846 fd = _file_data_find(ASENTRY(fentry)->id); 889 fd = _file_data_find(ASENTRY(fentry)->id);
847 _file_id_free(fd); 890 _file_id_free(fd);
848 _file_entry_free(fentry);
849 _file_data_free(fd); 891 _file_data_free(fd);
892 _file_entry_free(fentry);
893
894 _freed_entry_count++;
895 _repack();
850} 896}
851 897
852static void 898static void
@@ -1097,12 +1143,8 @@ _entry_reference_del(Entry *entry, Reference *ref)
1097 1143
1098 if (fd) 1144 if (fd)
1099 { 1145 {
1100 if (fd->invalid) 1146 // FIXME: Check difference with master (2 cases vs. only one)
1101 { 1147 if (fd->invalid || !fentry->images)
1102 _file_entry_free(fentry);
1103 _file_data_free(fd);
1104 }
1105 else if (!fentry->images)
1106 eina_hash_del_by_key(file_entries, &entry->id); 1148 eina_hash_del_by_key(file_entries, &entry->id);
1107 } 1149 }
1108 else 1150 else
@@ -1306,10 +1348,7 @@ _file_changed_cb(const char *path EINA_UNUSED, Eina_Bool deleted EINA_UNUSED, vo
1306 ASENTRY(fentry)->request = NULL; 1348 ASENTRY(fentry)->request = NULL;
1307 } 1349 }
1308 if (!fentry->images && !ASENTRY(fentry)->references) 1350 if (!fentry->images && !ASENTRY(fentry)->references)
1309 { 1351 _hash_file_entry_free(fentry);
1310 _file_entry_free(fentry);
1311 _file_data_free(fd);
1312 }
1313 } 1352 }
1314 1353
1315 eina_hash_del_by_key(file_watch, fw->path); 1354 eina_hash_del_by_key(file_watch, fw->path);
diff --git a/src/bin/evas/evas_cserve2_index.c b/src/bin/evas/evas_cserve2_index.c
index b79c2f8e73..fd95aa510d 100644
--- a/src/bin/evas/evas_cserve2_index.c
+++ b/src/bin/evas/evas_cserve2_index.c
@@ -406,7 +406,8 @@ cserve2_shared_array_foreach(Shared_Array *sa, Eina_Each_Cb cb, void *data)
406Shared_Array * 406Shared_Array *
407cserve2_shared_array_repack(Shared_Array *sa, 407cserve2_shared_array_repack(Shared_Array *sa,
408 Shared_Array_Repack_Skip_Cb skip, 408 Shared_Array_Repack_Skip_Cb skip,
409 Eina_Compare_Cb cmp) 409 Eina_Compare_Cb cmp,
410 void *user_data)
410{ 411{
411 Eina_List *l = NULL; 412 Eina_List *l = NULL;
412 Shared_Array *sa2; 413 Shared_Array *sa2;
@@ -422,7 +423,7 @@ cserve2_shared_array_repack(Shared_Array *sa,
422 for (k = 0; k < sa->header->emptyidx; k++) 423 for (k = 0; k < sa->header->emptyidx; k++)
423 { 424 {
424 const char *data = srcdata + k * elemsize; 425 const char *data = srcdata + k * elemsize;
425 if (skip(sa, data)) continue; 426 if (skip(sa, data, user_data)) continue;
426 l = eina_list_sorted_insert(l, cmp, data); 427 l = eina_list_sorted_insert(l, cmp, data);
427 newcount++; 428 newcount++;
428 } 429 }
@@ -443,6 +444,7 @@ cserve2_shared_array_repack(Shared_Array *sa,
443 const char *data = eina_list_data_get(l); 444 const char *data = eina_list_data_get(l);
444 l = eina_list_remove_list(l, l); 445 l = eina_list_remove_list(l, l);
445 memcpy(dstdata, data, elemsize); 446 memcpy(dstdata, data, elemsize);
447 dstdata += elemsize;
446 } 448 }
447 449
448 // Finalize & return 450 // Finalize & return