Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cocoa] Temporarily wake up remote process if outgoing IPC message queue becomes too large #13340

Conversation

cdumez
Copy link
Contributor

@cdumez cdumez commented May 1, 2023

5183343

[Cocoa] Temporarily wake up remote process if outgoing IPC message queue becomes too large
https://bugs.webkit.org/show_bug.cgi?id=256181

Reviewed by Ben Nham.

Temporarily wake up remote process if outgoing IPC message queue becomes too
large, to avoid potentially bad memory growth when the remote process is
suspended.

This currently only works for AuxiliaryProcessProxy, so IPC from the UIProcess
to child processes. However, we may want to consider extending this to IPC
from the network process to WebProcesses in a follow-up.

In the current proposal, we wake up the destination process for 3 seconds when
its outgoing message queue has reached 1024 messages. We do so at most once
every 30 seconds.

* Source/WebKit/Platform/IPC/Connection.cpp:
(IPC::Connection::setOutgoingMessageQueueIsGrowingLargeCallback):
(IPC::Connection::invalidate):
(IPC::Connection::sendMessage):
* Source/WebKit/Platform/IPC/Connection.h:
* Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:
(WebKit::AuxiliaryProcessProxy::AuxiliaryProcessProxy):
(WebKit::AuxiliaryProcessProxy::didFinishLaunching):
(WebKit::AuxiliaryProcessProxy::outgoingMessageQueueIsGrowingLarge):
* Source/WebKit/UIProcess/AuxiliaryProcessProxy.h:

Canonical link: https://commits.webkit.org/263570@main

966aea0

Misc iOS, tvOS & watchOS macOS Linux Windows
❌ πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ›  gtk
βœ… πŸ§ͺ ios-wk2-wpt   πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  tv-sim
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@cdumez cdumez self-assigned this May 1, 2023
@cdumez cdumez added the WebKit2 Bugs relating to the WebKit2 API layer label May 1, 2023
@cdumez cdumez force-pushed the 256181_AuxiliaryProcessProxy_wake_up_remote_process_for_ipc branch from 17a41bd to 9e5d96d Compare May 1, 2023 21:59
#endif

constexpr size_t largeOutgoingMessageQueueCountThreshold { 500 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest picking 1024 to match MACH_PORT_QLIMIT_LARGE. So basically in the worst case this will trigger after ~2048 messages if the receiver process is suspended (1024 will be stuck in the Mach IPC queue and 1024 will be stuck in m_outgoingMessages.

I also realize this only applies to UIProcess at the moment, but when running some LocalStorage benchmarks, I was easily able to see message queues of size ~3k-4k in NetworkProcess even without the receiver process being suspended. So we may need to consider upping this limit so that it doesn't become too noisy. But I think we can start with this limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will up to 1024 for now. We can up if we becomes too noisy later. But it won't be more than once every 30 seconds so I am not too worried about noise at the moment.

, 0
#endif
);
m_outgoingMessageQueueIsGrowingLargeCallback();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be called outside of the block that holds the lock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@cdumez cdumez force-pushed the 256181_AuxiliaryProcessProxy_wake_up_remote_process_for_ipc branch from 9e5d96d to 7ad9257 Compare May 1, 2023 22:54
@cdumez cdumez requested a review from geoffreygaren May 1, 2023 23:24
Copy link
Contributor

@bnham bnham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

if (shouldNotifyOfQueueGrowingLarge) {
RELEASE_LOG_ERROR(IPC, "Connection::sendMessage(): Too many messages (%lu) in the queue to remote PID: %d, notifying client", outgoingMessagesCount
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: %zu for size_t

@cdumez cdumez force-pushed the 256181_AuxiliaryProcessProxy_wake_up_remote_process_for_ipc branch from 7ad9257 to 966aea0 Compare May 1, 2023 23:41
@cdumez cdumez added the merge-queue Applied to send a pull request to merge-queue label May 2, 2023
…eue becomes too large

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

Reviewed by Ben Nham.

Temporarily wake up remote process if outgoing IPC message queue becomes too
large, to avoid potentially bad memory growth when the remote process is
suspended.

This currently only works for AuxiliaryProcessProxy, so IPC from the UIProcess
to child processes. However, we may want to consider extending this to IPC
from the network process to WebProcesses in a follow-up.

In the current proposal, we wake up the destination process for 3 seconds when
its outgoing message queue has reached 1024 messages. We do so at most once
every 30 seconds.

* Source/WebKit/Platform/IPC/Connection.cpp:
(IPC::Connection::setOutgoingMessageQueueIsGrowingLargeCallback):
(IPC::Connection::invalidate):
(IPC::Connection::sendMessage):
* Source/WebKit/Platform/IPC/Connection.h:
* Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:
(WebKit::AuxiliaryProcessProxy::AuxiliaryProcessProxy):
(WebKit::AuxiliaryProcessProxy::didFinishLaunching):
(WebKit::AuxiliaryProcessProxy::outgoingMessageQueueIsGrowingLarge):
* Source/WebKit/UIProcess/AuxiliaryProcessProxy.h:

Canonical link: https://commits.webkit.org/263570@main
@webkit-commit-queue webkit-commit-queue force-pushed the 256181_AuxiliaryProcessProxy_wake_up_remote_process_for_ipc branch from 966aea0 to 5183343 Compare May 2, 2023 02:14
@webkit-commit-queue
Copy link
Collaborator

Committed 263570@main (5183343): https://commits.webkit.org/263570@main

Reviewed commits have been landed. Closing PR #13340 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 5183343 into WebKit:main May 2, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit2 Bugs relating to the WebKit2 API layer
Projects
None yet
4 participants