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

1019 Коммитов

Автор SHA1 Сообщение Дата
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
Aaron Patterson 8525603c72
Revert "Fix transient heap mode"
This reverts commit 87253d047c.

Revert "Implement `Process.warmup`"

This reverts commit ba6ccd8714.
2023-04-04 12:59:14 -07:00
Jean Boussier ba6ccd8714 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-04-04 19:49:08 +02:00
Nobuyoshi Nakada 1d529f382c
PID cache is never cleared where `fork` is not used 2023-04-04 11:29:57 +09:00
Nobuyoshi Nakada 3e7d1cbceb Cache pid itself instead of converted VALUE 2023-03-24 14:22:02 +09:00
Jean Boussier 3563e1383f thread_pthread.c: Use a `fork_gen` to protect against fork instead of getpid()
[Feature #19443]

Until recently most libc would cache `getpid()` so this was a cheap check to make.

However as of glibc version 2.25 the PID cache is removed and calls to getpid() always
invoke the actual system call which significantly degrades the performance of existing applications.

The reason glibc removed the cache is that some libraries were bypassing fork(2)
by issuing system calls themselves, causing stale cache issues.

That isn't a concern for Ruby as bypassing MRI's primitive for forking would
render the VM unusable, so we can safely cache the PID.
2023-03-23 09:08:19 +00:00
Peter Zhu 3210130993 Suppress a compiler warning on GCC in process.c
rb_pid_t is 32 bits on some platforms, which will cause a warning on GCC
due to POSFIXABLE always returning true.

    include/ruby/internal/arithmetic/fixnum.h:43:31: warning: comparison is always true due to limited range of data type [-Wtype-limits]
2023-03-22 17:25:18 -04:00
Nobuyoshi Nakada 758e4db551
Mark cached pid if necessary 2023-03-20 18:08:05 +09:00
Jean Boussier 1db8951d3a Cache `Process.pid`
[Feature #19443]

It's not uncommon for database client and similar network libraries
to protect themselves from Process.fork by regularly checking Process.pid

Until recently most libc would cache `getpid()` so this was a cheap
check to make.

However as of glibc version 2.25 the PID cache is removed and calls to
`getpid()` always invoke the actual system call which significantly degrades
the performance of existing applications.

The reason glibc removed the cache is that some libraries were bypassing
`fork(2)` by issuing system calls themselves, causing stale cache issues.

That isn't a concern for Ruby as bypassing MRI's primitive for forking
would render the VM unusable, so we can safely cache the PID.
2023-03-20 08:21:23 +00:00
Samuel Williams 7fd53eeb46
Remove SIGCHLD `waidpid`. (#7527)
* Remove `waitpid_lock` and related code.

* Remove un-necessary test.

* Remove `rb_thread_sleep_interruptible` dead code.
2023-03-15 19:48:27 +13:00
Samuel Williams ac65ce16e9
Revert SIGCHLD changes to diagnose CI failures. (#7517)
* Revert "Remove special handling of `SIGCHLD`. (#7482)"

This reverts commit 44a0711eab.

* Revert "Remove prototypes for functions that are no longer used. (#7497)"

This reverts commit 4dce12bead.

* Revert "Remove SIGCHLD `waidpid`. (#7476)"

This reverts commit 1658e7d966.

* Fix change to rjit variable name.
2023-03-14 20:07:59 +13:00
Samuel Williams 4dce12bead
Remove prototypes for functions that are no longer used. (#7497) 2023-03-10 23:38:09 +13:00
Samuel Williams 86d38b4520
Accept `sleep(nil)` as sleep forever. (#7484) 2023-03-10 16:40:05 +13:00
Samuel Williams 1658e7d966
Remove SIGCHLD `waidpid`. (#7476)
* Remove `waitpid_lock` and related code.

* Remove un-necessary test.

* Remove `rb_thread_sleep_interruptible` dead code.
2023-03-09 16:05:47 +13:00
Takashi Kokubun 9ad19069f9 Remove obsoleted functions in rjit.c 2023-03-07 23:59:50 -08:00
Takashi Kokubun b67f07fa2c Get rid of MJIT's special fork 2023-03-07 23:08:57 -08:00
Takashi Kokubun 23ec248e48 s/mjit/rjit/ 2023-03-06 23:44:01 -08:00
Takashi Kokubun 2e875549a9 s/MJIT/RJIT/ 2023-03-06 23:44:01 -08:00
zverok 01509f344a [DOC] Restore Process module doc lost due to RDoc update 2023-02-19 22:32:52 +02:00
Maciek Rząsa 50c6cabadc
[DOC] Change formatting in the exec docs
The last part of the sentence was accidentally put in enumeration, It
made an impression that it's one of the rules, not the result of
applying the rules.
2022-11-19 11:38:16 +09:00
S-H-GAMELINKS 1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Hiroshi SHIBATA 6b0b326ef2 Followed up 796069b288 2022-09-22 11:35:28 +09:00
David Carlier 796069b288 getrlimit adding RLIMIT_NPTS constant. 2022-09-21 18:07:59 +09:00
Koichi ITO e3b178066b [DOC] Tweak the doc for `Process.kill` signature
Replacing `...` with `*pids` seems to clarify the expected variadic arguments.

Note that the expected arguments are two or more with a signal and pids.
That is, the method must have at least one pid, which cannot be omitted:

```console
% ruby -e 'Process.kill(0)'
-e:1:in `kill': wrong number of arguments (given 1, expected 2+) (ArgumentError)
        from -e:1:in `<main>'
```
2022-09-21 15:21:27 +09:00
Nobuyoshi Nakada 55e540f7ab
Ignore EPERM which means already being process-leader 2022-09-20 11:12:11 +09:00
Nobuyoshi Nakada ae07336529 Reduce fork calls in daemon
The forked child process is a grandchild process from the viewpoint of
the process which invoked the caller process.  That means the child is
detached at that point, and it does not need to fork twice.
2022-09-19 15:34:16 +09:00
Takashi Kokubun aa8a3b2358
MJIT: Do not hang after forking with threads
First, rb_mjit_fork should call rb_thread_atfork to stop threads after
fork in the child process. Unfortunately, we cannot use rb_fork_ruby to
prevent this kind of mistakes because MJIT needs special handling of
waiting_pid and mjit_pause/resume.

Second, mjit_waitpid_finished should be checked regardless of
trap_interrupt. It doesn't seem like the flag is not set when SIGCHLD is
handled for an MJIT child process.
2022-09-11 09:09:05 +09:00
Takashi Kokubun f6d569b7c0
Call appropriate hooks on MJIT's fork
This takes care of signal_self_pipe and other things.
2022-09-04 18:22:25 -07:00
Nobuyoshi Nakada b2205cd45c Short-circuit `Process._fork` 2022-08-12 16:57:56 +09:00
Nobuyoshi Nakada e545cfad20
Stop using casted `rb_syswait` as `proc_syswait`
The argument of `rb_syswait` is now `rb_pid_t` which may differ from
`int`.  Also it is an undefined behavior to take the result of casted
void function (in `rb_protect`).
2022-08-07 00:02:38 +09:00
Nobuyoshi Nakada f245b425af
Fix the sizes comparison
`proc_syswait` will be called with a `VALUE` argument.
2022-08-06 23:56:44 +09:00
Ivo Anjo 74817f3d37
[DOC] Process._fork does not get called by Process.daemon
As discussed in [Bug #18911], I'm adding some documentation to
`Process._fork` to clarify that it is not expected to cover
calls to `Process.daemon`.

[Bug #18911]: https://bugs.ruby-lang.org/issues/18911

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
2022-08-05 18:40:48 +09:00
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Nobuyoshi Nakada 5e66525e41
[DOC] Document `Process::Tms` 2022-06-28 20:19:05 +09:00
Nobuyoshi Nakada a58611dfb1 Allow to just warn as bool expected, without an exception 2022-06-20 19:35:12 +09:00