aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2025-08-03 15:02:41 +0200
committerRodrigo Arias Mallo <rodarima@gmail.com>2025-08-11 21:43:10 +0200
commit1a885c25f7ad7eb217d9b2f0ab477ab1b7be6433 (patch)
tree25b8a6c130e4925ca448cc0f035887bfe9c2b613
parentc3431cc169a7bc24dcff845aeda3f7f30a8ad1fa (diff)
Add about:dicache for decompressed image cache
The dicache holds the decompressed buffers for each image and it often is the main cause for memory consumption in Dillo. The current algorithm for evicting entries waits until a image has no references and at least three pages were opened before removing the entry.
-rw-r--r--src/cache.c2
-rw-r--r--src/dicache.c56
-rw-r--r--src/dicache.h14
3 files changed, 71 insertions, 1 deletions
diff --git a/src/cache.c b/src/cache.c
index 7ee9d9d7..5a852167 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -427,6 +427,8 @@ static int Cache_internal_url(CacheEntry_t *entry)
if (strcmp(URL_PATH(entry->Url), "cache") == 0) {
s = Cache_stats();
+ } else if (strcmp(URL_PATH(entry->Url), "dicache") == 0) {
+ s = a_Dicache_stats();
}
if (s != NULL) {
diff --git a/src/dicache.c b/src/dicache.c
index e53fb011..e83d2d72 100644
--- a/src/dicache.c
+++ b/src/dicache.c
@@ -2,7 +2,7 @@
* File: dicache.c
*
* Copyright 2000-2007 Jorge Arellano Cid <jcid@dillo.org>
- * Copyright 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
+ * Copyright 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -191,6 +191,14 @@ static void Dicache_remove(const DilloUrl *Url, int version)
dFree(entry);
}
+static int Dicache_is_last_ref(DICacheEntry *entry)
+{
+ if (entry->v_imgbuf)
+ return a_Imgbuf_last_reference(entry->v_imgbuf);
+
+ return 0;
+}
+
/**
* Unrefs the counter of a dicache entry (it counts cache clients).
* If there're no clients and no imgbuf, remove the entry.
@@ -599,3 +607,49 @@ void a_Dicache_freeall(void)
}
dList_free(CachedIMGs);
}
+
+Dstr *a_Dicache_stats(void)
+{
+ long bytesCached = 0L;
+ Dstr *s = dStr_new(
+ "<!DOCTYPE HTML>\n"
+ "<html>\n"
+ "<head><title>Decompressed Image Cache</title></head>\n"
+ "<body>\n");
+
+ int n = dList_length(CachedIMGs);
+ dStr_sprintfa(s, "<h1>Decompressed Image Cache (%d)</h1>\n", n);
+
+ dStr_append(s, "<table>\n");
+ dStr_append(s, "<tr>\n");
+ dStr_append(s, "<th><span title='Survival Counter'>S</span></th>\n");
+ dStr_append(s, "<th><span title='Last Reference'>L</span></th>\n");
+ dStr_append(s, "<th>Area</th>\n");
+ dStr_append(s, "<th>Size</th>\n");
+ dStr_append(s, "<th>URL</th>\n");
+ dStr_append(s, "</tr>\n");
+ for (int i = 0; i < n; i++) {
+ DICacheEntry *e = dList_nth_data(CachedIMGs, i);
+ dStr_append(s, "<tr>\n");
+ dStr_sprintfa(s, "<td style='text-align:right'>%hd</td>", e->SurvCleanup);
+ dStr_sprintfa(s, "<td style='text-align:right'>%d</td>", Dicache_is_last_ref(e));
+ dStr_sprintfa(s, "<td style='text-align:right'>%ux%u</td>", e->width, e->height);
+ dStr_sprintfa(s, "<td style='text-align:right'>%.2f KiB</td>\n",
+ e->TotalSize / 1024.0f);
+ dStr_sprintfa(s, "<td><a href='%s'>", URL_STR(e->url));
+ dStr_shorten(s, URL_STR(e->url), 60);
+ dStr_append(s, "</a></td>\n");
+ dStr_append(s, "</tr>\n");
+ bytesCached += (long) e->TotalSize;
+ }
+ dStr_append(s, "</table>\n");
+ float mb = (float) bytesCached / (1024.0f * 1024.0f);
+
+ dStr_sprintfa(s, "<p>Total cached: %.2f MiB</p>\n", mb);
+
+ dStr_append(s,
+ "</body>\n"
+ "</html>\n");
+
+ return s;
+}
diff --git a/src/dicache.h b/src/dicache.h
index e0f49dfb..815dcf6a 100644
--- a/src/dicache.h
+++ b/src/dicache.h
@@ -1,3 +1,15 @@
+/*
+ * File: dicache.c
+ *
+ * Copyright 2000-2007 Jorge Arellano Cid <jcid@dillo.org>
+ * Copyright 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ */
+
#ifndef __DICACHE_H__
#define __DICACHE_H__
@@ -9,6 +21,7 @@ extern "C" {
#include "bitvec.h"
#include "image.hh"
#include "cache.h"
+#include "dlib/dlib.h"
/** Symbolic name to request the last version of an image */
#define DIC_Last -1
@@ -76,6 +89,7 @@ DICacheEntry* a_Dicache_ref(const DilloUrl *Url, int version);
void a_Dicache_unref(const DilloUrl *Url, int version);
void a_Dicache_cleanup(void);
void a_Dicache_freeall(void);
+Dstr *a_Dicache_stats(void);
#ifdef __cplusplus