Skip to content
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

Use a stack size slightly smaller than 1MB #935

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ matrix:
- os: osx
before_install:
- HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install ccache
- ulimit -n 1024 # increase the open files limit from the default of 512
env:
- NPROC=2
allow_failures:
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ ifneq ($(USE_LIBBACKTRACE), 0)
deps: | libbacktrace
endif

# maximum stack size (in bytes) mirroring Android limits
NIM_PARAMS := $(NIM_PARAMS) -d:stack_size=1000000

#- deletes and recreates "beacon_chain.nims" which on Windows is a copy instead of a proper symlink
update: | update-common
rm -f beacon_chain.nims && \
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ make -j$(nproc) NIMFLAGS="-d:release" USE_MULTITAIL=yes eth2_network_simulation
make USE_LIBBACKTRACE=0 # expect the resulting binaries to be 2-3 times slower
```

- show (some) C compiler warnings:

```bash
make NIMFLAGS="-d:cwarnings" beacon_node
```

- publish a book using [mdBook](https://github.com/rust-lang/mdBook) from sources in "docs/" to GitHub pages:

```bash
Expand Down
4 changes: 4 additions & 0 deletions beacon_chain/beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import
sync_protocol, request_manager, keystore_management, interop, statusbar,
sync_manager, validator_duties, validator_api, attestation_aggregation

when defined(posix):
import posix

const
genesisFile* = "genesis.ssz"
timeToInitNetworkingBeforeGenesis = chronos.seconds(30)
Expand Down Expand Up @@ -1119,6 +1122,7 @@ programMain:

setupMainProc(config.logLevel)

## handle command line arguments
case config.cmd
of createTestnet:
var
Expand Down
37 changes: 32 additions & 5 deletions config.nims
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import strutils

if defined(release):
switch("nimcache", "nimcache/release/$projectName")
else:
switch("nimcache", "nimcache/debug/$projectName")

const stack_size {.intdefine.}: int = 0
when defined(stack_size):
when defined(gcc):
# conservative compile-time estimation for single functions
switch("passC", "-Werror=stack-usage=" & $stack_size)
when defined(posix):
# limit the stack at runtime, on POSIX systems
switch("import", "stew/rlimits")
when defined(windows):
switch("passL", "-Wl,--stack," & $stack_size)

if defined(windows):
# disable timestamps in Windows PE headers - https://wiki.debian.org/ReproducibleBuilds/TimestampsInPEBinaries
switch("passL", "-Wl,--no-insert-timestamp")
# increase stack size
switch("passL", "-Wl,--stack,8388608")
# https://github.com/nim-lang/Nim/issues/4057
--tlsEmulation:off
if defined(i386):
Expand Down Expand Up @@ -59,9 +70,25 @@ else:
--stacktrace:on
--linetrace:on

# the default open files limit is too low on macOS (512), breaking the
# "--debugger:native" build. It can be increased with `ulimit -n 1024`.
if not defined(macosx):
var canEnableDebuggingSymbols = true
if defined(macosx):
# The default open files limit is too low on macOS (512), breaking the
# "--debugger:native" build. It can be increased with `ulimit -n 1024`.
let openFilesLimitTarget = 1024
var openFilesLimit = 0
try:
openFilesLimit = staticExec("ulimit -n").strip(chars = Whitespace + Newlines).parseInt()
if openFilesLimit < openFilesLimitTarget:
echo "Open files limit too low to enable debugging symbols and lightweight stack traces."
echo "Increase it with \"ulimit -n " & $openFilesLimitTarget & "\""
canEnableDebuggingSymbols = false
except:
echo "ulimit error"
# We ignore this resource limit on Windows, where a default `ulimit -n` of 256
# in Git Bash is apparently ignored by the OS, and on Linux where the default of
# 1024 is good enough for us.

if canEnableDebuggingSymbols:
# add debugging symbols and original files and line numbers
--debugger:native

Expand Down
9 changes: 9 additions & 0 deletions nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# can't do this in "config.nims", probably due to parsing order
@if cwarnings:
@if windows:
gcc.options.always = "-mno-ms-bitfields -Wno-discarded-qualifiers -Wno-incompatible-pointer-types"
@else:
gcc.options.always = "-Wno-discarded-qualifiers -Wno-incompatible-pointer-types"
@end
@end

2 changes: 1 addition & 1 deletion vendor/nim-stew
Submodule nim-stew updated 1 files
+29 −0 stew/rlimits.nim