[tracker/wip/carlosg/release-memory: 1/5] libtracker-data: Add internal API to release TrackerDataManager memory
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/release-memory: 1/5] libtracker-data: Add internal API to release TrackerDataManager memory
- Date: Sun, 30 Aug 2020 21:32:04 +0000 (UTC)
commit a763f16a94e3c80dda4a5087d92aee28c86b1c9c
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Aug 30 19:25:09 2020 +0200
libtracker-data: Add internal API to release TrackerDataManager memory
This call frees all inactive readonly TrackerDBInterfaces, and ensures
that the readwrite one releases as much memory as possible (freeing
all cached prepared statements, and asking SQLite to do so).
src/libtracker-data/tracker-data-manager.c | 6 ++++
src/libtracker-data/tracker-data-manager.h | 2 ++
src/libtracker-data/tracker-db-interface-sqlite.c | 12 +++++++
src/libtracker-data/tracker-db-interface-sqlite.h | 1 +
src/libtracker-data/tracker-db-manager.c | 39 +++++++++++++++++++++++
src/libtracker-data/tracker-db-manager.h | 1 +
6 files changed, 61 insertions(+)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index fd02de2a8..a5e077041 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -5102,3 +5102,9 @@ tracker_data_manager_rollback_graphs (TrackerDataManager *manager)
{
g_clear_pointer (&manager->transaction_graphs, g_hash_table_unref);
}
+
+void
+tracker_data_manager_release_memory (TrackerDataManager *manager)
+{
+ tracker_db_manager_release_memory (manager->db_manager);
+}
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index dbd4d86fc..db8b4e509 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -105,6 +105,8 @@ guint tracker_data_manager_get_generation (TrackerDataManager *
void tracker_data_manager_rollback_graphs (TrackerDataManager *manager);
void tracker_data_manager_commit_graphs (TrackerDataManager *manager);
+void tracker_data_manager_release_memory (TrackerDataManager *manager);
+
G_END_DECLS
#endif /* __LIBTRACKER_DATA_MANAGER_H__ */
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c
b/src/libtracker-data/tracker-db-interface-sqlite.c
index 46b2aab46..cfedcd5ec 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -3726,3 +3726,15 @@ tracker_db_interface_detach_database (TrackerDBInterface *db_interface,
sqlite3_finalize (stmt);
return retval;
}
+
+gssize
+tracker_db_interface_sqlite_release_memory (TrackerDBInterface *db_interface)
+{
+ db_interface->select_stmt_lru.head = db_interface->select_stmt_lru.tail = NULL;
+ db_interface->select_stmt_lru.size = 0;
+ db_interface->update_stmt_lru.head = db_interface->update_stmt_lru.tail = NULL;
+ db_interface->update_stmt_lru.size = 0;
+ g_hash_table_remove_all (db_interface->dynamic_statements);
+
+ return (gssize) sqlite3_db_release_memory (db_interface->db);
+}
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.h
b/src/libtracker-data/tracker-db-interface-sqlite.h
index cdca629f5..6a8ffb235 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -93,6 +93,7 @@ gboolean tracker_db_interface_attach_database (TrackerD
gboolean tracker_db_interface_detach_database (TrackerDBInterface
*db_interface,
const gchar *name,
GError **error);
+gssize tracker_db_interface_sqlite_release_memory (TrackerDBInterface
*db_interface);
G_END_DECLS
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 6b3c4bdd7..5cc3cf997 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -1085,3 +1085,42 @@ tracker_db_manager_detach_database (TrackerDBManager *db_manager,
{
return tracker_db_interface_detach_database (iface, name, error);
}
+
+void
+tracker_db_manager_release_memory (TrackerDBManager *db_manager)
+{
+ TrackerDBInterface *iface;
+ gint i, len;
+
+ g_async_queue_lock (db_manager->interfaces);
+ len = g_async_queue_length_unlocked (db_manager->interfaces);
+
+ for (i = 0; i < len; i++) {
+ iface = g_async_queue_try_pop_unlocked (db_manager->interfaces);
+ if (!iface)
+ break;
+
+ if (tracker_db_interface_get_is_used (iface))
+ g_async_queue_push_unlocked (db_manager->interfaces, iface);
+ else
+ g_object_unref (iface);
+ }
+
+ if (g_async_queue_length_unlocked (db_manager->interfaces) < len) {
+ g_debug ("Freed %d readonly interfaces",
+ len - g_async_queue_length_unlocked (db_manager->interfaces));
+ }
+
+ if (db_manager->db.iface) {
+ gssize bytes;
+
+ bytes = tracker_db_interface_sqlite_release_memory (db_manager->db.iface);
+
+ if (bytes > 0) {
+ g_debug ("Freed %" G_GSSIZE_MODIFIER "d bytes from writable interface",
+ bytes);
+ }
+ }
+
+ g_async_queue_unlock (db_manager->interfaces);
+}
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index 486e337ba..5feb64b6f 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -92,6 +92,7 @@ gboolean tracker_db_manager_detach_database (TrackerDBManager
TrackerDBInterface *iface,
const gchar *name,
GError **error);
+void tracker_db_manager_release_memory (TrackerDBManager *db_manager);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]