From 6b2676d33f2e6c25dc98eda57325e7185a6ff763 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 28 Nov 2014 19:17:42 +0000 Subject: Improve llcache writeout stratagy --- content/fs_backing_store.c | 2 ++ content/llcache.c | 63 ++++++++++++++++++++++++++++++---------------- content/llcache.h | 21 +++++++++++----- desktop/netsurf.c | 24 ++++++++++++------ 4 files changed, 75 insertions(+), 35 deletions(-) diff --git a/content/fs_backing_store.c b/content/fs_backing_store.c index 34bb149ec..27cd95213 100644 --- a/content/fs_backing_store.c +++ b/content/fs_backing_store.c @@ -412,6 +412,8 @@ invalidate_entry(struct store_state *state, struct store_entry *bse) return NSERROR_OK; } + LOG(("Removing entry for %p", bse)); + /* remove the entry from the index */ ret = remove_store_entry(state, &bse); if (ret != NSERROR_OK) { diff --git a/content/llcache.c b/content/llcache.c index 5defb1121..e862f901c 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -66,9 +66,6 @@ #define LLCACHE_LOG(x) #endif -#define LLCACHE_MIN_DISC_LIFETIME 3600 -#define LLCACHE_MAX_DISC_BANDWIDTH (512*1024) - /** * State of a low-level cache object fetch. */ @@ -236,8 +233,20 @@ struct llcache_s { */ int minimum_lifetime; - /** The maximum bandwidth to allow the backing store to use. */ - size_t bandwidth; + /** The time over which to apply the bandwidth calculations in ms */ + unsigned long time_quantum; + + /** The minimum bandwidth to allow the backing store to use in + * bytes/second. Below this the backing store will be + * disabled. + */ + size_t minimum_bandwidth; + + /** The maximum bandwidth to allow the backing store to + * use in bytes/second + */ + size_t maximum_bandwidth; + /** Whether or not our users are caught up */ bool all_caught_up; @@ -2256,8 +2265,9 @@ build_candidate_list(struct llcache_object ***lst_out, int *lst_len_out) #define MAX_PERSIST_PER_RUN 512 lst = calloc(MAX_PERSIST_PER_RUN, sizeof(struct llcache_object *)); - if (lst == NULL) + if (lst == NULL) { return NSERROR_NOMEM; + } for (object = llcache->cached_objects; object != NULL; object = next) { next = object->next; @@ -2374,7 +2384,8 @@ static void llcache_persist(void *p) struct llcache_object **lst; int lst_count; int idx; - unsigned long total_elapsed = 0; + unsigned long write_limit; /* max number of bytes to write */ + unsigned long total_elapsed = 1; unsigned long elapsed; ret = build_candidate_list(&lst, &lst_count); @@ -2383,25 +2394,33 @@ static void llcache_persist(void *p) return; } + write_limit = (llcache->maximum_bandwidth * llcache->time_quantum) / 1000; + /* obtained a candidate list, make each object persistant in turn */ for (idx = 0; idx < lst_count; idx++) { ret = write_backing_store(lst[idx], &size_written, &elapsed); - if (ret != NSERROR_OK) { - break; - } - total_written += size_written; - total_elapsed += elapsed; - LOG(("Wrote %d bytes in %dms %s", size_written, total_elapsed, nsurl_access(lst[idx]->url) )); - - if (total_written > llcache->bandwidth) { - /* The bandwidth limit has been reached. - * Writeout scheduled for the remaining objects - */ - guit->browser->schedule(1000, llcache_persist, NULL); - break; + if (ret == NSERROR_OK) { + /* sucessfully wrote object to backing store */ + total_written += size_written; + total_elapsed += elapsed; + LOG(("Wrote %d bytes in %dms %s", + size_written, + elapsed, + nsurl_access(lst[idx]->url) )); + + if (total_written > write_limit) { + /* The bandwidth limit has been reached. + * Writeout scheduled for the remaining objects + */ + guit->browser->schedule(llcache->time_quantum, llcache_persist, NULL); + break; + } } } + LOG(("writeout size:%d time:%d bandwidth:%dbytes/s", + total_written, total_elapsed, (total_written * 1000) / total_elapsed)); + free(lst); } @@ -3129,7 +3148,9 @@ llcache_initialise(const struct llcache_parameters *prm) llcache->query_cb_pw = prm->cb_ctx; llcache->limit = prm->limit; llcache->minimum_lifetime = prm->minimum_lifetime; - llcache->bandwidth = prm->bandwidth; + llcache->minimum_bandwidth = prm->minimum_bandwidth; + llcache->maximum_bandwidth = prm->maximum_bandwidth; + llcache->time_quantum = prm->time_quantum; llcache->all_caught_up = true; LOG(("llcache initialising with a limit of %d bytes", llcache->limit)); diff --git a/content/llcache.h b/content/llcache.h index 1375759a2..1b7ba7dae 100644 --- a/content/llcache.h +++ b/content/llcache.h @@ -213,13 +213,22 @@ struct llcache_parameters { size_t limit; /**< The target upper bound for the RAM cache size */ size_t hysteresis; /**< The hysteresis around the target size */ - int minimum_lifetime; /**< The minimum lifetime to consider - * sending objects to backing store. - */ + /** The minimum lifetime to consider sending objects to backing store.*/ + int minimum_lifetime; - size_t bandwidth; /**< The maximum bandwidth to allow the - * backing store to use. - */ + /** The minimum bandwidth to allow the backing store to + * use in bytes/second + */ + size_t minimum_bandwidth; + + /** The maximum bandwidth to allow the backing store to use in + * bytes/second + */ + size_t maximum_bandwidth; + + /** The time quantum over which to calculate the bandwidth values + */ + unsigned long time_quantum; struct llcache_store_parameters store; }; diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 21fedfddf..cca80232b 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -72,17 +72,23 @@ /** default time between content cache cleans. */ #define HL_CACHE_CLEAN_TIME (2 * IMAGE_CACHE_CLEAN_TIME) -/** default minimum object time before object is pushed to backing store. */ -#define LLCACHE_MIN_DISC_LIFETIME (60 * 30) - -/** default maximum bandwidth for backing store writeout. */ -#define LLCACHE_MAX_DISC_BANDWIDTH (128 * 1024) - /** ensure there is a minimal amount of memory for source objetcs and * decoded bitmaps. */ #define MINIMUM_MEMORY_CACHE_SIZE (2 * 1024 * 1024) +/** default minimum object time before object is pushed to backing store. (s) */ +#define LLCACHE_STORE_MIN_LIFETIME (60 * 30) + +/** default minimum bandwidth for backing store writeout. (byte/s) */ +#define LLCACHE_STORE_MIN_BANDWIDTH (128 * 1024) + +/** default maximum bandwidth for backing store writeout. (byte/s) */ +#define LLCACHE_STORE_MAX_BANDWIDTH (1024 * 1024) + +/** default time quantum with which to calculate bandwidth (ms) */ +#define LLCACHE_STORE_TIME_QUANTUM (100) + static void netsurf_lwc_iterator(lwc_string *str, void *pw) { LOG(("[%3u] %.*s", str->refcnt, (int) lwc_string_length(str), lwc_string_data(str))); @@ -126,8 +132,10 @@ nserror netsurf_init(const char *messages, const char *store_path) .bg_clean_time = HL_CACHE_CLEAN_TIME, .llcache = { .cb = netsurf_llcache_query_handler, - .minimum_lifetime = LLCACHE_MIN_DISC_LIFETIME, - .bandwidth = LLCACHE_MAX_DISC_BANDWIDTH, + .minimum_lifetime = LLCACHE_STORE_MIN_LIFETIME, + .minimum_bandwidth = LLCACHE_STORE_MIN_BANDWIDTH, + .maximum_bandwidth = LLCACHE_STORE_MAX_BANDWIDTH, + .time_quantum = LLCACHE_STORE_TIME_QUANTUM, } }; struct image_cache_parameters image_cache_parameters = { -- cgit v1.2.3