Skip to content
Permalink
Browse files
Ask LocalStorage database to free as much memory as possible on memor…
…y pressure

https://bugs.webkit.org/show_bug.cgi?id=225109

Reviewed by Geoffrey Garen.

Source/WebCore:

Add releaseMemory() function to SQLiteDatabase that calls sqlite3_db_release_memory()
to free as much memory as possible.

* platform/sql/SQLiteDatabase.cpp:
(WebCore::SQLiteDatabase::releaseMemory):
* platform/sql/SQLiteDatabase.h:

Source/WebKit:

Ask LocalStorage database to free as much memory as possible on memory pressure.
Some of the strings in the database can be large and we don't want SQLite to be
holding on to those for performance reason when we are under memory pressure.

This seems to be a ~1.75% improvement on PLUM/nytimes-home and a ~1% improvement
on PLUM/wikipedia, sadly not enough to show an impact on the overal PLUM score.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::lowMemoryHandler):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/WebStorage/LocalStorageDatabase.cpp:
(WebKit::LocalStorageDatabase::handleLowMemoryWarning):
* NetworkProcess/WebStorage/LocalStorageDatabase.h:
* NetworkProcess/WebStorage/StorageArea.cpp:
(WebKit::StorageArea::handleLowMemoryWarning):
* NetworkProcess/WebStorage/StorageArea.h:
* NetworkProcess/WebStorage/StorageManagerSet.cpp:
(WebKit::StorageManagerSet::handleLowMemoryWarning):
* NetworkProcess/WebStorage/StorageManagerSet.h:


Canonical link: https://commits.webkit.org/237075@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@276648 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Apr 27, 2021
1 parent 342b7d0 commit 4b1a68cc9190e1c7032a6e5e4a1c881530cb9819
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 1 deletion.
@@ -1,3 +1,17 @@
2021-04-27 Chris Dumez <cdumez@apple.com>

Ask LocalStorage database to free as much memory as possible on memory pressure
https://bugs.webkit.org/show_bug.cgi?id=225109

Reviewed by Geoffrey Garen.

Add releaseMemory() function to SQLiteDatabase that calls sqlite3_db_release_memory()
to free as much memory as possible.

* platform/sql/SQLiteDatabase.cpp:
(WebCore::SQLiteDatabase::releaseMemory):
* platform/sql/SQLiteDatabase.h:

2021-04-27 Brent Fulgham <bfulgham@apple.com>

[iOS] [GPU] The UI process should issue the mach sandbox extension to 'com.apple.AGXCompilerService'
@@ -635,4 +635,12 @@ void SQLiteDatabase::removeCollationFunction(const String& collationName)
sqlite3_create_collation_v2(m_db, collationName.utf8().data(), SQLITE_UTF8, nullptr, nullptr, nullptr);
}

void SQLiteDatabase::releaseMemory()
{
if (!m_db)
return;

sqlite3_db_release_memory(m_db);
}

} // namespace WebCore
@@ -146,6 +146,8 @@ class SQLiteDatabase {

WEBCORE_EXPORT static void setIsDatabaseOpeningForbidden(bool);

WEBCORE_EXPORT void releaseMemory();

private:
static int authorizerFunction(void*, int, const char*, const char*, const char*, const char*);

@@ -1,3 +1,30 @@
2021-04-27 Chris Dumez <cdumez@apple.com>

Ask LocalStorage database to free as much memory as possible on memory pressure
https://bugs.webkit.org/show_bug.cgi?id=225109

Reviewed by Geoffrey Garen.

Ask LocalStorage database to free as much memory as possible on memory pressure.
Some of the strings in the database can be large and we don't want SQLite to be
holding on to those for performance reason when we are under memory pressure.

This seems to be a ~1.75% improvement on PLUM/nytimes-home and a ~1% improvement
on PLUM/wikipedia, sadly not enough to show an impact on the overal PLUM score.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::lowMemoryHandler):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/WebStorage/LocalStorageDatabase.cpp:
(WebKit::LocalStorageDatabase::handleLowMemoryWarning):
* NetworkProcess/WebStorage/LocalStorageDatabase.h:
* NetworkProcess/WebStorage/StorageArea.cpp:
(WebKit::StorageArea::handleLowMemoryWarning):
* NetworkProcess/WebStorage/StorageArea.h:
* NetworkProcess/WebStorage/StorageManagerSet.cpp:
(WebKit::StorageManagerSet::handleLowMemoryWarning):
* NetworkProcess/WebStorage/StorageManagerSet.h:

2021-04-27 Don Olmstead <don.olmstead@sony.com>

[CMake] Don't use FORWARDING_HEADERS_DIR for GTK WebKit headers
@@ -309,6 +309,8 @@ void NetworkProcess::lowMemoryHandler(Critical critical)
networkSession.clearPrefetchCache();
});

m_storageManagerSet->handleLowMemoryWarning();

#if ENABLE(SERVICE_WORKER)
for (auto& swServer : m_swServers.values())
swServer->handleLowMemoryWarning();
@@ -549,7 +549,7 @@ class NetworkProcess : public AuxiliaryProcess, private DownloadManager::Client,
HashMap<PAL::SessionID, std::unique_ptr<NetworkSession>> m_networkSessions;
HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>> m_networkStorageSessions;

RefPtr<StorageManagerSet> m_storageManagerSet;
Ref<StorageManagerSet> m_storageManagerSet;

#if PLATFORM(COCOA)
void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
@@ -362,4 +362,10 @@ bool LocalStorageDatabase::databaseIsEmpty()
return !query.getColumnInt(0);
}

void LocalStorageDatabase::handleLowMemoryWarning()
{
if (m_database.isOpen())
m_database.releaseMemory();
}

} // namespace WebKit
@@ -59,6 +59,8 @@ class LocalStorageDatabase : public RefCounted<LocalStorageDatabase> {
// Will block until all pending changes have been written to disk.
void close();

void handleLowMemoryWarning();

private:
LocalStorageDatabase(Ref<WorkQueue>&&, Ref<LocalStorageDatabaseTracker>&&, const WebCore::SecurityOriginData&);

@@ -227,4 +227,10 @@ void StorageArea::close()
m_localStorageDatabase->close();
}

void StorageArea::handleLowMemoryWarning()
{
if (m_localStorageDatabase)
m_localStorageDatabase->handleLowMemoryWarning();
}

} // namespace WebKit
@@ -73,6 +73,8 @@ class StorageArea : public CanMakeWeakPtr<StorageArea> {
void syncToDatabase();
void close();

void handleLowMemoryWarning();

private:
void dispatchEvents(IPC::Connection::UniqueID sourceConnection, StorageAreaImplIdentifier, const String& key, const String& oldValue, const String& newValue, const String& urlString) const;

@@ -129,6 +129,15 @@ void StorageManagerSet::removeConnection(IPC::Connection& connection)
});
}

void StorageManagerSet::handleLowMemoryWarning()
{
ASSERT(RunLoop::isMain());
m_queue->dispatch([this, protectedThis = makeRef(*this)] {
for (auto& storageArea : m_storageAreas.values())
storageArea->handleLowMemoryWarning();
});
}

void StorageManagerSet::waitUntilTasksFinished()
{
ASSERT(RunLoop::isMain());
@@ -57,6 +57,7 @@ class StorageManagerSet : public IPC::Connection::WorkQueueMessageReceiver {
void addConnection(IPC::Connection&);
void removeConnection(IPC::Connection&);

void handleLowMemoryWarning();
void waitUntilTasksFinished();
void waitUntilSyncingLocalStorageFinished();
void suspend(CompletionHandler<void()>&&);

0 comments on commit 4b1a68c

Please sign in to comment.