Граф коммитов

1053 Коммитов

Автор SHA1 Сообщение Дата
Takashi Kokubun 6e46a363a8 merge revision(s) a7ff264477105b5dc0ade6facad4176a1b73df0b: [Backport #20393]
Don't clear pending interrupts in the parent process. (#10365)
2024-05-29 11:46:33 -07:00
JP Camara 8782e02138 KQueue support for M:N threads
* Allows macOS users to use M:N threads (and technically FreeBSD, though it has not been verified on FreeBSD)

* Include sys/event.h header check for macros, and include sys/event.h when present

* Rename epoll_fd to more generic kq_fd (Kernel event Queue) for use by both epoll and kqueue

* MAP_STACK is not available on macOS so conditionall apply it to mmap flags

* Set fd to close on exec

* Log debug messages specific to kqueue and epoll on creation

* close_invalidate raises an error for the kqueue fd on child process fork. It's unclear rn if that's a bug, or if it's kqueue specific behavior

Use kq with rb_thread_wait_for_single_fd

* Only platforms with `USE_POLL` (linux) had changes applied to take advantage of kernel event queues. It needed to be applied to the `select` so that kqueue could be properly applied

* Clean up kqueue specific code and make sure only flags that were actually set are removed (or an error is raised)

* Also handle kevent specific errnos, since most don't apply from epoll to kqueue

* Use the more platform standard close-on-exec approach of `fcntl` and `FD_CLOEXEC`. The io-event gem uses `ioctl`, but fcntl seems to be the recommended choice. It is also what Go, Bun, and Libuv use

* We're making changes in this file anyways - may as well fix a couple spelling mistakes while here

Make sure FD_CLOEXEC carries over in dup

* Otherwise the kqueue descriptor should have FD_CLOEXEC, but doesn't and fails in assert_close_on_exec
2023-12-20 16:23:38 +09:00
Victor Shepelev 570d7b2c3e
[DOC] Adjust some new features wording/examples. (#9183)
* Reword Range#overlap? docs last paragraph.

* Docs: add explanation about Queue#freeze

* Docs: Add :rescue event docs for TracePoint

* Docs: Enhance Module#set_temporary_name documentation

* Docs: Slightly expand Process::Status deprecations

* Fix MatchData#named_captures rendering glitch

* Improve Dir.fchdir examples

* Adjust Refinement#target docs
2023-12-14 23:01:48 +02:00
Jean Boussier 9ae6ee5a59 Embed exec_arg objects
They are very ephemeral, so avoiding the malloc churn
is desirable.
2023-11-22 13:04:21 +01:00
Jean Boussier 751d4b9913 Make Process::Status embedded
These are not very common, but they're very easy to convert.
2023-11-21 16:54:24 +01:00
Burdette Lamar d80009d169
[DOC] RDoc for module Process (#8847) 2023-11-08 09:26:27 -05:00
Nobuyoshi Nakada 9059d42c41
Align comment [ci skip] 2023-11-06 14:43:35 +09:00
Koichi Sasada be1bbd5b7d M:N thread scheduler for Ractors
This patch introduce M:N thread scheduler for Ractor system.

In general, M:N thread scheduler employs N native threads (OS threads)
to manage M user-level threads (Ruby threads in this case).
On the Ruby interpreter, 1 native thread is provided for 1 Ractor
and all Ruby threads are managed by the native thread.

From Ruby 1.9, the interpreter uses 1:1 thread scheduler which means
1 Ruby thread has 1 native thread. M:N scheduler change this strategy.

Because of compatibility issue (and stableness issue of the implementation)
main Ractor doesn't use M:N scheduler on default. On the other words,
threads on the main Ractor will be managed with 1:1 thread scheduler.

There are additional settings by environment variables:

`RUBY_MN_THREADS=1` enables M:N thread scheduler on the main ractor.
Note that non-main ractors use the M:N scheduler without this
configuration. With this configuration, single ractor applications
run threads on M:1 thread scheduler (green threads, user-level threads).

`RUBY_MAX_CPU=n` specifies maximum number of native threads for
M:N scheduler (default: 8).

This patch will be reverted soon if non-easy issues are found.

[Bug #19842]
2023-10-12 14:47:01 +09:00
Nobuyoshi Nakada 457971f4e2
[DOC] State the precision of `Process.times` as platform-defined
Remove the bad example that can lead to misunderstanding as if this
precision is defined in Ruby.
2023-10-03 14:42:47 +09:00
Burdette Lamar f9490110e1
[DOC] Another example for spawn (#8575) 2023-10-01 19:37:40 -04:00
BurdetteLamar 84312e688f [DOC] Fix minor inconsistencies 2023-09-27 14:42:50 -04:00
Peter Zhu 154bd04ee2 [DOC] Fix link in process.c 2023-09-26 11:28:36 -04:00
BurdetteLamar a40ab12768 [DOC] Refactor doc in process.c 2023-09-26 11:26:19 -04:00
Jean Boussier efe2822708 Process.warmup: invoke `malloc_trim` if available
Similar to releasing free GC pages, releasing free malloc pages
reduce the amount of page faults post fork.
2023-09-15 17:45:21 +02:00
Nobuyoshi Nakada 998ae7c3f3
[Bug #19868] Deprecate `Process::Status#&` and `Process::Status#>>` 2023-09-14 15:26:25 +09:00
Nobuyoshi Nakada b6de0a6c69
[Bug #19868] Suggest other Process::Status method for `&` and `>>`
`Process::Status#&` and `Process::Status#>>` are provided only for
the backward compatibility with older Ruby than 1.8 where `$?` was
a `Fixnum`, and the knowledge about internals of system dependent
macros is necessary to use them.  Modern programs and libraries
should not need these methods.
2023-09-14 14:57:57 +09:00
Nobuyoshi Nakada efe5e6e8d0
Negative value to Process::Status method for compatibility 2023-09-14 14:38:14 +09:00
Burdette Lamar 5edabd1cd5
[DOC] RDoc for Process::Status (#8416) 2023-09-12 16:31:31 -04:00
Nobuyoshi Nakada ac65fc833d
[DOC] Fix up Process::Status#>> 2023-09-07 10:05:10 +09:00
Burdette Lamar 54274b8c65
[DOC] Rdoc for Process::Status (#8386) 2023-09-06 18:26:11 -04:00
Burdette Lamar a17a1cd535
[DOC] Fix for RDoc for Process.kill (#8370) 2023-09-05 12:53:11 -04:00
Nobuyoshi Nakada 5b157997e2
[DOC] Fix up markup 2023-09-05 21:09:41 +09:00
Nobuyoshi Nakada 7c8932365f
[DOC] Fix signal list
- Signal names can be symbols, as stated above.
- Supported signals and those values are platform dependent.
- Key sequences to send signal are configurable.
- Fix description of signal 0.

Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2023-09-05 20:36:45 +09:00
Burdette Lamar c9af911489
[DOC] RDoc for process.c (#8366) 2023-09-04 21:16:48 -04:00
Burdette Lamar 40ab77eb3d
[DOC] Process doc (#8363) 2023-09-03 15:36:51 -04:00
BurdetteLamar 3602e253e7 [DOC] RDoc for process.c 2023-09-02 19:46:35 -04:00
Burdette Lamar ef4dab6983
[DOC] RDoc for process.c (#8358) 2023-09-02 11:43:10 -04:00
Burdette Lamar cfcb4a4e26
[DOC] RDoc for process.c (#8353) 2023-09-02 09:04:04 -04:00
Burdette Lamar 84fa8ae84e
[DOC] RDoc for #spawn (#8342) 2023-08-31 14:02:09 -04:00
Burdette Lamar eb3d94f4ba
[DOC] RDoc for Kernel#system (#8309) 2023-08-31 09:06:11 -04:00
Samuel Williams e46e48d690
Expose `rb_process_status_wait` and hide `rb_process_status_waitv`. (#8316) 2023-08-29 22:24:55 +12:00
Samuel Williams 901b6d9c50
Validate the typed data before dereferencing the internal struct. (#8315) 2023-08-29 20:04:14 +12:00
Burdette Lamar 1cc700907d
[DOC] More on method exec (#8302) 2023-08-27 13:39:18 -04:00
Peter Zhu b7237e3bbd Free all empty heap pages in Process.warmup
This commit adds `free_empty_pages` which frees all empty heap pages and
moves the number of pages freed to the allocatable pages counter. This
is used in Process.warmup to improve performance because page
invalidation from copy-on-write is slower than allocating a new page.
2023-08-27 09:39:29 -04:00
Burdette Lamar f9aea75747
[DOC] RDoc for Process (#8282) 2023-08-24 17:41:43 -04:00
Burdette Lamar 75c9c2c431
[DOC] Process doc (#8279) 2023-08-24 13:46:14 -04:00
Bo Anderson 84a12d6578 Fix compile error on older systems without clock_get* 2023-08-24 19:09:06 +09:00
Burdette Lamar 7e0d2c6143
[DOC] RDoc for Process (#8253) 2023-08-23 23:21:44 -04:00
Burdette Lamar 589c01c411
[DOC] RDoc for Process (#8179) 2023-08-07 09:51:03 -04:00
Burdette Lamar 533dcb8e52
RDoc for module Process (#8141) 2023-07-31 21:44:56 -04:00
Nobuyoshi Nakada 8b390a456c
[DOC] Update description of `Process.daemon` arguments
These arguments can only be `true` or `false` now.  Also add markups.
2023-08-01 01:47:19 +09:00
Jean Boussier 9b405a18be Process.warmup: precompute strings coderange
This both save time for when it will be eventually needed,
and avoid mutating heap pages after a potential fork.

Instrumenting some large Rails app, I've witnessed up to
58% of String instances having their coderange still unknown.
2023-07-26 11:41:23 +02:00
Jean Boussier fa30b99c34 Implement Process.warmup
[Feature #18885]

For now, the optimizations performed are:

  - Run a major GC
  - Compact the heap
  - Promote all surviving objects to oldgen

Other optimizations may follow.
2023-07-17 11:20:15 +02:00
Nobuyoshi Nakada c8d0470bb0
Use `File::NULL` instead of hard coded null device names 2023-07-10 19:21:47 +09:00
Samuel Williams a218ed5692
Hide the usage of `rb_io_t` where possible. (#7880)
This retries the compatible parts of the previously reverted PR so we can continue to update related code without breaking backwards compatibility.
2023-06-01 14:23:30 +09:00
NARUSE, Yui 85dcc4866d Revert "Hide most of the implementation of `struct rb_io`. (#6511)"
This reverts commit 18e55fc1e1.

fix [Bug #19704]
https://bugs.ruby-lang.org/issues/19704
This breaks compatibility for extension libraries. Such changes
need a discussion.
2023-06-01 08:43:22 +09:00
Samuel Williams 18e55fc1e1
Hide most of the implementation of `struct rb_io`. (#6511)
* Add rb_io_path and rb_io_open_descriptor.

* Use rb_io_open_descriptor to create PTY objects

* Rename FMODE_PREP -> FMODE_EXTERNAL and expose it

FMODE_PREP I believe refers to the concept of a "pre-prepared" file, but
FMODE_EXTERNAL is clearer about what the file descriptor represents and
aligns with language in the IO::Buffer module.

* Ensure that rb_io_open_descriptor closes the FD if it fails

If FMODE_EXTERNAL is not set, then it's guaranteed that Ruby will be
responsible for closing your file, eventually, if you pass it to
rb_io_open_descriptor, even if it raises an exception.

* Rename IS_EXTERNAL_FD -> RUBY_IO_EXTERNAL_P

* Expose `rb_io_closed_p`.

* Add `rb_io_mode` to get IO mode.

---------

Co-authored-by: KJ Tsanaktsidis <ktsanaktsidis@zendesk.com>
2023-05-30 10:02:40 +09:00
Nobuyoshi Nakada 7f7a8fa555
Put `rb_fork` back into process.c
Now, calling `rb_fork` directly breaks the PID cache and the timer
thread, so must use `rb_fork_ruby` or similar instead.
2023-05-21 23:00:27 +09:00
Nobuyoshi Nakada 3612b1bed8 [Feature #19590] Show the invalid clock argument
Include the failed clock argument in the error message from
`Process.clock_gettime` and `Process.clock_getres`.
2023-04-13 14:07:27 +09:00
Daniel DeLorme 4b100f75d2 [DOC] Clarify behavior of abort() with no argument
Since Ruby 2.7 it prints the message and backtrace of $!

Fixes [Bug #19578]
2023-04-05 07:37:07 -07:00