Skip to content

Conversation

@kpamnany
Copy link
Member

We've observed mbedtls_ssl_read and mbedtls_ssl_write show up in CPU profiles while also seeing long GC time-to-safepoint. These ccalls call back into Julia (f_send and f_recv), during which GC should be able to run. But I can't tell if, for large enough reads or writes, there could be a long interval without reaching a GC safepoint.

Adding GC-safe regions around the ccalls will let GC run even if a thread is busy inside. Since c_send and c_recv are @cfunctions, they will do the right thing wrt GC safety.

Ref: JuliaLang/julia#51574

This is a temporary fix; when JuliaLang/julia#49933 lands, this should be changed to do whatever that requires.

If a reviewer knows for certain that a thread won't remain inside the ccall without calling back into Julia for multiple seconds, then this PR can be discarded.

@kpamnany kpamnany requested a review from vchuravy October 26, 2023 21:12
@kpamnany kpamnany force-pushed the kp/gc-safe-some-ccalls branch from 4c90bee to 34be0ef Compare October 26, 2023 21:17
@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Merging #265 (9d9a5a5) into master (e84f973) will increase coverage by 0.36%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #265      +/-   ##
==========================================
+ Coverage   73.49%   73.86%   +0.36%     
==========================================
  Files          12       12              
  Lines         732      750      +18     
==========================================
+ Hits          538      554      +16     
- Misses        194      196       +2     
Files Coverage Δ
src/ssl.jl 71.88% <100.00%> (+1.03%) ⬆️

@kpamnany kpamnany requested review from quinnj and vtjnash November 2, 2023 14:04
@kpamnany kpamnany force-pushed the kp/gc-safe-some-ccalls branch from 82eabdc to 9d9a5a5 Compare November 3, 2023 00:12
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

LGTM

@kpamnany
Copy link
Member Author

kpamnany commented Nov 3, 2023

The CI failures for Julia nightly are:

ERROR: LoadError: conversion to pointer not defined for Base.CodeUnits{UInt8, String}

They're coming from crypt! in cipher.jl here, which I haven't touched in this PR.

@kpamnany kpamnany merged commit 90bcfa1 into master Nov 3, 2023
@kpamnany kpamnany deleted the kp/gc-safe-some-ccalls branch November 3, 2023 16:30
@vtjnash
Copy link
Member

vtjnash commented Nov 3, 2023

There are so many random pointer calls here that only serve to ensure incorrectness and serve no other value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants