From 877532e0009b864a95da045b9d123d27d70e3b9b Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Tue, 27 Aug 2013 11:14:21 +0900 Subject: [PATCH] evas/cserve2: Repack strings index when too fragmented --- src/bin/evas/evas_cserve2.h | 1 + src/bin/evas/evas_cserve2_cache.c | 7 +++++-- src/bin/evas/evas_cserve2_index.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/bin/evas/evas_cserve2.h b/src/bin/evas/evas_cserve2.h index c0a703a..fda088f 100644 --- a/src/bin/evas/evas_cserve2.h +++ b/src/bin/evas/evas_cserve2.h @@ -388,5 +388,6 @@ int cserve2_shared_string_add(const char *str); int cserve2_shared_string_ref(int id); void cserve2_shared_string_del(int id); const char *cserve2_shared_string_get(int id); +int cserve2_shared_strings_repack(Shared_Array_Repack_Skip_Cb skip, Eina_Compare_Cb cmp); #endif /* _EVAS_CSERVE2_H */ diff --git a/src/bin/evas/evas_cserve2_cache.c b/src/bin/evas/evas_cserve2_cache.c index f351dd7..b71ce01 100644 --- a/src/bin/evas/evas_cserve2_cache.c +++ b/src/bin/evas/evas_cserve2_cache.c @@ -318,8 +318,8 @@ static Eina_Bool _repack_skip_cb(Shared_Array *sa EINA_UNUSED, const void *elem, void *user_data EINA_UNUSED) { - const File_Data *fd = elem; - return (!fd->refcount); + const Shm_Object *obj = elem; + return (!obj->refcount); } static void @@ -411,6 +411,9 @@ skip_images: } skip_fonts: + if (cserve2_shared_strings_repack(_repack_skip_cb, _shm_object_id_cmp_cb) == 1) + updated = EINA_TRUE; + if (updated) { // TODO: Update strings table generation_id? diff --git a/src/bin/evas/evas_cserve2_index.c b/src/bin/evas/evas_cserve2_index.c index fdff6b5..2c4d9dc 100644 --- a/src/bin/evas/evas_cserve2_index.c +++ b/src/bin/evas/evas_cserve2_index.c @@ -896,6 +896,8 @@ cserve2_shared_mempool_generation_id_set(Shared_Mempool *sm, int generation_id) // Shared strings +static int _shared_strings_unref_items = 0; + const char * cserve2_shared_strings_table_name_get() { @@ -957,7 +959,12 @@ new_entry: int cserve2_shared_string_ref(int id) { + Index_Entry *ie; if (id <= 0) return 0; + ie = _shared_index_entry_get_by_id(_string_mempool->index, id); + if (!ie) return 0; + if (!ie->refcount) + _string_mempool--; return cserve2_shared_mempool_buffer_ref(_string_mempool, id); } @@ -975,6 +982,7 @@ cserve2_shared_string_del(int id) CRIT("Invalid free"); } } + _shared_strings_unref_items++; } const char * @@ -984,6 +992,35 @@ cserve2_shared_string_get(int id) return cserve2_shared_mempool_buffer_get(_string_mempool, id); } +int +cserve2_shared_strings_repack(Shared_Array_Repack_Skip_Cb skip, + Eina_Compare_Cb cmp) +{ + int count; + + if (!_string_mempool->index) return -1; + count = _string_mempool->index->lastid; + if (!count) return -1; + if (_shared_strings_unref_items * 100 / count >= 25 + && _shared_strings_unref_items > 100) + { + Shared_Array *sa; + int genid; + + genid = _string_mempool->index->sa->header->generation_id + 1; + sa = cserve2_shared_array_repack(_string_mempool->index->sa, genid, + skip, cmp, NULL); + if (!sa) return -1; + + cserve2_shared_array_del(_string_mempool->index->sa); + _string_mempool->index->sa = sa; + _shared_strings_unref_items = 0; + return 1; + } + + return 0; +} + // Init/destroy @@ -1002,6 +1039,7 @@ cserve2_shared_index_init(void) memcpy(faketag, &ifaketag, sizeof(int)); cserve2_shared_string_add(faketag); + _shared_strings_unref_items = 0; } _instances++; } -- 2.7.4