Skip to content

Make waiting_fd behaviour per-IO. #13127

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ioquatix
Copy link
Member

See #5384 for full context.

@ioquatix ioquatix requested review from ko1, akr, nobu and Copilot April 18, 2025 01:06
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the “waiting_fd” behavior so that waiting and blocking operations are managed per‑IO rather than via a global list. Key changes include:

  • Removing the global waiting_fd list initialization and associated memory‐size functions (e.g. in vm_core.h and vm.c).
  • Replacing the waiting_fd structure and its helper functions in thread.c with per‑IO blocking operation nodes.
  • Eliminating the thread_fd close test file, consistent with the new per‑IO design.

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vm_core.h Removed initialization of the global waiting_fds list.
vm.c Removed calls to rb_vm_memsize_waiting_fds in memory size reporting.
thread.c Commented out and removed waiting_fd structures/functions in favor of per‑IO nodes.
test/-ext-/thread_fd/test_thread_fd_close.rb Removed outdated test file no longer applicable under the new design.
io.c Updated blocking call APIs to accept an IO pointer instead of a raw file descriptor.
internal/* Updated function declarations and struct fields to reflect per‑IO blocking operations.
Files not reviewed (1)
  • ext/-test-/thread_fd/depend: Language not supported
Comments suppressed due to low confidence (2)

vm.c:3229

  • Verify that the new per‑IO blocking operations are correctly accounted for in the overall memory size calculations now that the global waiting_fd memory size contribution has been removed.
-        rb_vm_memsize_waiting_fds(&vm->waiting_fds) +

test/-ext-/thread_fd/test_thread_fd_close.rb:1

  • The removal of the thread_fd close test file reduces test coverage for FD closing behavior; please ensure that the per‑IO waiting/blocking operations introduced in this PR are adequately covered by other tests.
Entire file removed

@ioquatix ioquatix marked this pull request as draft April 18, 2025 01:09
@ioquatix ioquatix force-pushed the io-close-isolated branch 3 times, most recently from 9cba6ac to 5d85916 Compare April 18, 2025 01:25
@ioquatix ioquatix force-pushed the io-close-isolated branch 3 times, most recently from aa93db0 to a0aa5d2 Compare April 18, 2025 01:51

This comment has been minimized.

@ioquatix ioquatix force-pushed the io-close-isolated branch 14 times, most recently from 7976829 to bcd3524 Compare April 21, 2025 23:16
@ioquatix ioquatix marked this pull request as ready for review April 21, 2025 23:16
@ioquatix ioquatix force-pushed the io-close-isolated branch 5 times, most recently from b8795d1 to f18bd39 Compare April 22, 2025 12:22
@ioquatix ioquatix requested a review from Copilot April 22, 2025 23:15
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the Ruby VM’s waiting_fd behavior to operate on a per-IO basis. In doing so, the global waiting_fds list and its associated functions have been removed and replaced with per-IO blocking operations.

  • Remove waiting_fds initialization and memory size calculations in vm_core.h and vm.c.
  • Replace waiting_fd struct and functions in thread.c with a per-IO blocking_operations mechanism.
  • Update test cases and IO-related functions (in io.c, internal/io.h, etc.) to reflect the new behavior.

Reviewed Changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
vm_core.h, vm.c Removed waiting_fds handling and its memory reporting
thread.c Deleted waiting_fd struct and functions; introduced blocking_operations
test/ruby/test_io.rb Adjusted file descriptor range to match expected fd limits
io.c, internal/io.h Updated IO structure and related functions to support blocking_operations
internal/thread.h, gc.c Revised internal interfaces, GC marking, and thread IO close functionality
ext/-test-/thread_fd/* Removed redundant test extensions
Files not reviewed (2)
  • common.mk: Language not supported
  • ext/-test-/thread_fd/depend: Language not supported
Comments suppressed due to low confidence (3)

test/ruby/test_io.rb:3829

  • [nitpick] The adjustment of the range from (0..fd_setsize+1) to (0...fd_setsize) should be reviewed to ensure the test still covers the intended boundary conditions for file descriptor limits.
(0...fd_setsize).map {|i|

thread.c:1709

  • With the removal of the waiting_fd mechanism and the introduction of rb_mutex_synchronize in io_blocking_operation_release, please verify that this change does not introduce any race conditions during unblocking.
rb_fiber_scheduler_unblock(thread->scheduler, io->self, rb_fiberptr_self(fiber));

io.c:5688

  • [nitpick] The inclusion of the blocking_operations list in the memory size calculation is appropriate; please confirm that any future additions to the rb_io structure are also reflected in this computation to avoid memory under-reporting.
size += io->rbuf.capa;

@ioquatix ioquatix force-pushed the io-close-isolated branch from f18bd39 to a711798 Compare April 22, 2025 23:20
@ioquatix ioquatix force-pushed the io-close-isolated branch 4 times, most recently from a255ece to 498cf35 Compare April 30, 2025 06:22
@ioquatix ioquatix force-pushed the io-close-isolated branch from 498cf35 to 402685f Compare April 30, 2025 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant