Skip to content

Commit

Permalink
Revert "Merge pull request #10736 from xavierleroy/bigger-stack"
Browse files Browse the repository at this point in the history
This reverts commit 6c2fb7b, reversing
changes made to b6aa64e.
  • Loading branch information
xavierleroy committed Nov 29, 2021
1 parent 3fa2cfc commit 01c6f16
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 80 deletions.
3 changes: 0 additions & 3 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ OCaml 4.14.0
- #10730, 10731: Fix bug in `Obj.reachable_words` causing a slowdown when called
multiple time (Alain Frisch, report by ygrek, review by Xavier Leroy)

- #10736: Try to increase the maximal stack size for native-code applications
(Xavier Leroy, review by Damien Doligez)

### Code generation and optimizations:

- #10578: Increase the number of integer registers used for
Expand Down
4 changes: 2 additions & 2 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +731,13 @@ AS_CASE([$host],
flexlink_flags="-chain $flexdll_chain -stack 16777216"],
[x86_64-w64-mingw32],
[flexdll_chain='mingw64'
flexlink_flags="-chain $flexdll_chain -stack 67108864"],
flexlink_flags="-chain $flexdll_chain -stack 33554432"],
[i686-pc-windows],
[flexdll_chain='msvc'
flexlink_flags="-merge-manifest -stack 16777216"],
[x86_64-pc-windows],
[flexdll_chain='msvc64'
flexlink_flags="-x64 -merge-manifest -stack 67108864"])
flexlink_flags="-x64 -merge-manifest -stack 33554432"])

AS_IF([test x"$supports_shared_libraries" != 'xfalse'], [
AC_MSG_CHECKING([for flexdll sources])
Expand Down
39 changes: 2 additions & 37 deletions manual/src/cmds/native.etex
Original file line number Diff line number Diff line change
Expand Up @@ -206,48 +206,13 @@ the following environment variables are also consulted:
\begin{options}
\item["OCAMLRUNPARAM"] Same usage as in "ocamlrun"
(see section~\ref{s:ocamlrun-options}), except that option "l"
is ignored. (How to control the stack size is explained in
section~\ref{s:native:stacksize}.)
is ignored (the operating system's stack size limit
is used instead).
\item["CAMLRUNPARAM"] If "OCAMLRUNPARAM" is not found in the
environment, then "CAMLRUNPARAM" will be used instead. If
"CAMLRUNPARAM" is not found, then the default values will be used.
\end{options}

\section{s:native:stacksize}{Size of the stack}

Native-code executables produced by the "ocamlopt" compiler use the
stack managed by the operating system to implement function calls in
non-tail positions. The system stack grows on demand up to a certain
size limit maintained by the operating system. We now explain how this
size limit is determined and can be controlled.

\begin{unix}
Linux, macOS, and other Unix-like operating systems maintain two
limits for the stack size: a current limit and a hard limit. These
limits can be modified (as long as the hard limit is not exceeded)
with the "ulimit -s" shell command or the "setrlimit" system call.
At start-up, executables generated by "ocamlopt" try to set a
comfortable limit for the stack size, as follows:
\begin{itemize}
\item If the current limit is already at the hard limit, as happens if
a "ulimit -s" command was issued in the shell that starts the
executable, the stack size limit is unchanged.
\item If the hard limit is ``unlimited'', as in many Linux
distributions, the stack size limit is raised to 1 Gibytes for 64-bit
platforms and 16 Mibytes for 32-bit platforms.
\item Otherwise, the stack size limit is raised to the hard limit.
For example, this gives a limit of 64 Mibytes under macOS and 512
Mibytes under FreeBSD 64 bits.
\end{itemize}
\end{unix}

\begin{windows}
By default, the maximal size of the system stack is 64 Mibytes for 64-bit
executables and 16 Mibytes for 32-bit executables. It cannot be
changed dynamically. It can be changed at link-time by passing the
appropriate "-stack" option to the "flexlink" linker.
\end{windows}

\section{s:compat-native-bytecode}{Compatibility with the bytecode compiler}

This section lists the known incompatibilities between the bytecode
Expand Down
3 changes: 0 additions & 3 deletions runtime/caml/osdeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ extern char_os *caml_secure_getenv(char_os const *var);
cannot be determined, return -1. */
extern int caml_num_rows_fd(int fd);

/* Try to increase the size of the native stack */
extern void caml_increase_native_stack_size(void);

#ifdef _WIN32

extern int caml_win32_rename(const wchar_t *, const wchar_t *);
Expand Down
1 change: 0 additions & 1 deletion runtime/startup_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ value caml_startup_common(char_os **argv, int pooling)
if (!caml_startup_aux(pooling))
return Val_unit;

caml_increase_native_stack_size();
caml_init_frame_descriptors();
caml_init_locale();
#if defined(_MSC_VER) && __STDC_SECURE_LIB__ >= 200411L
Expand Down
28 changes: 0 additions & 28 deletions runtime/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include <errno.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "caml/config.h"
#if defined(SUPPORT_DYNAMIC_LINKING) && !defined(BUILDING_LIBCAMLRUNS)
#define WITH_DYNAMIC_LINKING
Expand Down Expand Up @@ -436,29 +434,3 @@ int caml_num_rows_fd(int fd)
return -1;
#endif
}

void caml_increase_native_stack_size(void)
{
#ifdef RLIMIT_STACK
struct rlimit lim;
rlim_t newlim;
if (getrlimit(RLIMIT_STACK, &lim) == -1) return;
newlim = lim.rlim_max;
if (newlim == RLIM_INFINITY) {
#ifdef ARCH_SIXTYFOUR
newlim = 1024*1024*1024; /* 1G */
#else
newlim = 16*1024*1024; /* 16M */
#endif
}
if (lim.rlim_cur >= newlim) return;
lim.rlim_cur = newlim;
if (setrlimit(RLIMIT_STACK, &lim) == -1) {
caml_gc_message(0x08, "Failed to increase native stack size\n");
} else {
caml_gc_message(0x08, "Increased native stack size to "
"%"ARCH_INT64_PRINTF_FORMAT"u\n",
(ARCH_UINT64_TYPE) newlim);
}
#endif
}
4 changes: 0 additions & 4 deletions runtime/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,3 @@ CAMLexport clock_t caml_win32_clock(void)
clocks_per_sec = INT64_LITERAL(10000000U) / (ULONGLONG)CLOCKS_PER_SEC;
return (clock_t)(total / clocks_per_sec);
}

void caml_increase_native_stack_size(void)
{
}

0 comments on commit 01c6f16

Please sign in to comment.