aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded
AgeCommit message (Collapse)Author
2019-01-07Spawn prim_file helper as a system processJohn Högberg
2018-12-10Prepare releaseErlang/OTP
2018-12-03Update preloaded modulesHenrik Nord
2018-11-22Merge branch 'sverker/erts/atomics-counters/OTP-13468' into maintSverker Eriksson
AGAIN * sverker/erts/atomics-counters/OTP-13468: erts: Add counters:put/3
2018-11-21erts: Add counters:put/3Sverker Eriksson
2018-11-16Merge branch 'john/erts/defer-orphan-file-close/OTP-15421/ERIERL-261' into maintJohn Högberg
* john/erts/defer-orphan-file-close/OTP-15421/ERIERL-261: Fix broken assertion on monitor release Avoid closing files in gc/monitor callbacks
2018-11-15erts: Add new module 'counters'Sverker Eriksson
2018-11-15erts: Add new module 'atomics'Sverker Eriksson
2018-11-13Avoid closing files in gc/monitor callbacksJohn Högberg
Closing files in these callbacks could block scheduler progress and cause major system instability. We now defer these operations to a dedicated process instead. This process may in turn block forever and prevent further orphaned files from being closed, but it will keep the emulator itself from misbehaving.
2018-11-06Add a persistent term storageBjörn Gustavsson
Persistent terms are useful for storing Erlang terms that are never or infrequently updated. They have the following advantages: * Constant time access. A persistent term is not copied when it is looked up. The constant factor is lower than for ETS, and no locks are taken when looking up a term. * Persistent terms are not copied in garbage collections. * There is only ever one copy of a persistent term (until it is deleted). That makes them useful for storing configuration data that needs to be easily accessible by all processes. Persistent terms have the following drawbacks: * Updates are expensive. The hash table holding the keys for the persistent terms are updated whenever a persistent term is added, updated or deleted. * Updating or deleting a persistent term triggers a "global GC", which will schedule a heap scan of all processes to search the heap of all processes for the deleted term. If a process still holds a reference to the deleted term, the process will be garbage collected and the term copied to the heap of the process. This global GC can make the system less responsive for some time. Three BIFs (implemented in C in the emulator) is the entire interface to the persistent term functionality: * put(Key, Value) to store a persistent term. * get(Key) to look up a persistent term. * erase(Key) to delete a persistent term. There are also two additional BIFs to obtain information about persistent terms: * info() to return a map with information about persistent terms. * get() to return a list of a {Key,Value} tuples for all persistent terms. (The values are not copied.)
2018-10-22Merge branch 'raimo/tcp-close-while-send/maint/ERL-561/OTP-12242' into maintRaimo Niskanen
* raimo/tcp-close-while-send/maint/ERL-561/OTP-12242: Write test case Fix hanging gen_tcp send vs close race Conflicts: erts/preloaded/ebin/prim_inet.beam
2018-10-19Fix hanging gen_tcp send vs close raceRaimo Niskanen
While a gen_tcp send was in progress with filled buffers and slow receiver a close (from another process) would place the port in a half dead state so the port could not signal back to send, that waited for confirmation. The solution is to after some time (5 s) of waiting for send confirmation set a monitor on the port, which detects if the port becomes half dead due to close from another process. The close pending loop has also been improved to use the linger timeout for waiting, and to set a system timeout (arbitrarily selected 3 min) to not wait forever when the other end reads data s l o w l y (tarpitting, kind of).
2018-10-17Merge branch 'igor/tcp-nopush-ERL-698/OTP-15357' into maintJohn Högberg
* igor/tcp-nopush-ERL-698/OTP-15357: "cork" tcp socket around file:sendfile Add nopush TCP socket option
2018-10-11"cork" tcp socket around file:sendfileIgor Slepchin
This fixes 200ms delay on the last TCP segment when using file:sendfile/2 on Linux (ERL-698).
2018-10-11Add nopush TCP socket optionIgor Slepchin
This translates to TCP_CORK on Linux and TCP_NOPUSH on BSD. In effect, this acts as super-Nagle: no partial TCP segments are sent out until this option is turned off. Once turned off, all accumulated unsent data is sent out immediately. The latter is *not* the case on OSX, hence the implementation ignores "nopush" on OSX to reduce confusion.
2018-10-02Implement {netns,NS} option for inet:getifaddrs/1Raimo Niskanen
Also implement the same option for the legacy undocumented functions inet:getif/1,getiflist/1,ifget/2,ifset/2. The arity 1 functions had before this change got signatures that took a socket port that was used to do the needed syscall, so now the signature was extended to also take an option list with the only supported option {netns,Namespace}. The Socket argument variant remains unsupported. For inet:getifaddrs/1 the documentation file was changed to old style function name definition so be able to hide the Socket argument variant that is visible in the type spec. The arity 2 functions had got an option list as second argument. This list had to be partitioned into one list for the namespace option(s) and the other for the rest. The namespace option list was then fed to the already existing namespace support for socket opening, which places the socket in a namespace and hence made all these functions that in inet_drv.c used getsockopt() work without change. The functions that used getifaddrs() in inet_drv.c had to be changed in inet_drv.c to swap namespaces around the getifaddrs() syscall. This functionality was separated into a new function call_getifaddrs().
2018-09-18Merge branch 'sverker/erts/robustify-dist-entry-states/OTP-15297' into maintSverker Eriksson
* sverker/erts/robustify-dist-entry-states/OTP-15297: erts: Refactor port dist_entry & conn_id into PRTSD Remove ugly fail case macros Consolidate distribution entry state transitions erts: Fix bug in undocumented system_flag(scheduling_statistics)
2018-09-18Consolidate distribution entry state transitionsSverker Eriksson
* Make connection_id part of the distribution handle as {ConnId, DistEntry} in order for BIFs to verify correct connection. * Make distribution handle opaque to net_kernel. * Remove some unsafe lockless reads of DistEntry.flags * Change state ERTS_DE_STATE_EXITING to be more of an internal state that prevents erts from enqueue, encode or schedule new data to be sent. Otherwise it should behave like ERTS_DE_STATE_CONNECTED.
2018-09-17Merge branch 'raimo/receive-TOS-TCLASS/ERIERL-187/OTP-15145' into maintRaimo Niskanen
* raimo/receive-TOS-TCLASS/ERIERL-187/OTP-15145: Write testcases for recvtos and friends Fix term buffer overflow bug Fix documentation due to feedback Implement socket option recvtos and friends
2018-09-13Fix unsafe use of lists:reverse/1John Högberg
We said reverse/2 but used reverse/1 which is unsafe to use in preloaded modules. This didn't have any effect in practice as the affected functions weren't used before the code server was started, but it's still an error.
2018-09-04Implement socket option recvtos and friendsRaimo Niskanen
Implement socket options recvtclass, recvtos, recvttl and pktoptions. Document the implemented socket options, new types and message formats. The options recvtclass, recvtos and recvttl are boolean options that when activated (true) for a socket will cause ancillary data to be received through recvmsg(). That is for packet oriented sockets (UDP and SCTP). The required options for this feature were recvtclass and recvtos, and recvttl was only added to test that the ancillary data parsing handled multiple data items in one message correctly. These options does not work on Windows since ancillary data is not handled by the Winsock2 API. For stream sockets (TCP) there is no clear connection between a received packet and what is returned when reading data from the socket, so recvmsg() is not useful. It is possible to get the same ancillary data through a getsockopt() call with the IPv6 socket option IPV6_PKTOPTIONS, on Linux named IPV6_2292PKTOPTIONS after the now obsoleted RFC where it originated. (unfortunately RFC 3542 that obsoletes it explicitly undefines this way to get packet ancillary data from a stream socket) Linux also has got a way to get packet ancillary data for IPv4 TCP sockets through a getsockopt() call with IP_PKTOPTIONS, which appears to be Linux specific. This implementation uses a flag field in the inet_drv.c socket internal data that records if any setsockopt() call with recvtclass, recvtos or recvttl (IPV6_RECVTCLASS, IP_RECVTOS or IP_RECVTTL) has been activated. If so recvmsg() is used instead of recvfrom(). Ancillary data is delivered to the application by a new return tuple format from gen_udp:recv/2,3 containing a list of ancillary data tuples [{tclass,TCLASS} | {tos,TOS} | {ttl,TTL}], as returned by recvmsg(). For a socket in active mode a new message format, containing the ancillary data list, delivers the data in the same way. For gen_sctp the ancillary data is delivered in the same way, except that the gen_sctp return tuple format already contained an ancillary data list so there are just more possible elements when using these socket options. Note that the active mode message format has got an extra tuple level for the ancillary data compared to what is now implemented gen_udp. The gen_sctp active mode format was considered to be the odd one - now all tuples containing ancillary data are flat, except for gen_sctp active mode. Note that testing has not shown that Linux SCTP sockets deliver any ancillary data for these socket options, so it is probably not implemented yet. Remains to be seen what FreeBSD does... For gen_tcp inet:getopts([pktoptions]) will deliver the latest received ancillary data for any activated socket option recvtclass, recvtos or recvttl, on platforms where IP_PKTOPTIONS is defined for an IPv4 socket, or where IPV6_PKTOPTIONS or IPV6_2292PKTOPTIONS is defined for an IPv6 socket. It will be delivered as a list of ancillary data items in the same way as for gen_udp (and gen_sctp). On some platforms, e.g the BSD:s, when you activate IP_RECVTOS you get ancillary data tagged IP_RECVTOS with the TOS value, but on Linux you get ancillary data tagged IP_TOS with the TOS value. Linux follows the style of RFC 2292, and the BSD:s use an older notion. For RFC 2292 that defines the IP_PKTOPTIONS socket option it is more logical to tag the items with the tag that is the item's, than with the tag that defines that you want the item. Therefore this implementation translates all BSD style ancillary data tags to the corresponding Linux style data tags, so the application will only see the tags 'tclass', 'tos' and 'ttl' on all platforms.
2018-07-26Merge branch 'maint-21' into maintJohn Högberg
2018-07-18Fix node crash on passing bad arguments to file:read_file_info/2John Högberg
2018-07-09erts: Fix spec and docs for process_info 'monitored_by'Sverker Eriksson
to include ports and NIF resources. Added new opaque type 'nif_resource'.
2018-06-20Update system_info doc to include ets_countArtur Cygan
2018-06-18Update copyright yearHenrik Nord
2018-06-18Update preloaded modulesHenrik Nord
2018-06-04Merge branch 'sverker/erlang-memory-fix'Sverker Eriksson
* sverker/erlang-memory-fix: erts: Purge unused allocation types erts: Fix erlang:memory for 'processes' and 'processes_used'
2018-05-29erts: Improve contracts of zlibHans Bolinder
2018-05-28erts: Improve a contractHans Bolinder
2018-05-23Update preloadedSiri Hansen
2018-05-23Use system_time instead of monotonic_time as timestamp in loggerSiri Hansen
2018-05-22erts: Fix erlang:memory for 'processes' and 'processes_used'Sverker Eriksson
to include links and monitors which were lost at 4bc282d812cc2c49aa3e2d073e96c720f16aa270 where these fix_alloc types changed names.
2018-05-16Replace previous suspend in setnode/3Rickard Green
2018-05-16New process suspend implementation based on async signalingRickard Green
2018-05-07Update preloaded modulesBjörn Gustavsson
2018-05-07Merge pull request #1802 from michalmuskala/map-is-key-bifBjörn Gustavsson
Introduce is_map_key/2 guard BIF OTP-15037
2018-04-29Introduce is_map_key/2 guard BIFMichał Muskała
This complements the `map_get/2` guard BIF introduced in #1784. Rationale. `map_get/2` allows accessing map fields in guards, but it might be problematic in more complex guard expressions, for example: foo(X) when map_get(a, X) =:= 1 or is_list(X) -> ... The `is_list/1` part of the guard could never succeed since the `map_get/2` guard would fail the whole guard expression. In this situation, this could be solved by using `;` instead of `or` to separate the guards, but it is not possible in every case. To solve this situation, this PR proposes a `is_map_key/2` guard that allows to check if a map has key inside a guard before trying to access that key. When combined with `is_map/1` this allows to construct a purely boolean guard expression testing a value of a key in a map. Implementation. Given the use case motivating the introduction of this function, the PR contains compiler optimisations that produce optimial code for the following guard expression: foo(X) when is_map(X) and is_map_key(a, X) and map_get(a, X) =:= 1 -> ok; foo(_) -> error. Given all three tests share the failure label, the `is_map_key/2` and `is_map/2` tests are optimised away. As with `map_get/2` the `is_map_key/2` BIF is allowed in match specs.
2018-04-26Don't kill logger process until all other processes are deadSiri Hansen
2018-04-26Remove error_logger process and add logger processSiri Hansen
2018-04-25Update preloaded modulesBjörn Gustavsson
2018-04-25Merge branch 'map-get-bif' of git://github.com/michalmuskala/otpBjörn Gustavsson
* 'map-get-bif' of git://github.com/michalmuskala/otp: Introduce map_get guard-safe function OTP-15037
2018-04-24Merge pull request #1790 from jhogberg/john/erts/more-alloc-info/OTP-14961John Högberg
Improve memory instrumentation OTP-15024 OTP-14961
2018-04-24Introduce map_get guard-safe functionMichał Muskała
Rationale Today all compound data types except for maps can be deconstructed in guards. For tuples we have `element/2` and for lists `hd/1` and `tl/1`. Maps are completely opaque to guards. This means matching on maps can't be abstracted into macros, which is often done with repetitive guards. It also means that maps have to be always selected whole from ETS tables, even when only one field would be enough, which creates a potential efficiency issue. This PR introduces an `erlang:map_get/2` guard-safe function that allows extracting a map field in guard. An alternative to this function would be to introduce the syntax for extracting a value from a map that was planned in the original EEP: `Map#{Key}`. Even outside of guards, since this function is a guard-BIF it is more efficient than using `maps:get/2` (since it does not need to set up the stack), and more convenient from pattern matching on the map (compare: `#{key := Value} = Map, Value` to `map_get(key, Map)`). Performance considerations A common concern against adding this function is the notion that "guards have to be fast" and ideally execute in constant time. While there are some counterexamples (`length/1`), what is more important is the fact that adding those functions does not change in any way the time complexity of pattern matching - it's already possible to match on map fields today directly in patterns - adding this ability to guards will niether slow down or speed up the execution, it will only make certain programs more convenient to write. This first version is very naive and does not perform any optimizations.
2018-04-23erts: Rewrite memory instrumentationJohn Högberg
This commit replaces the old memory instrumentation with a new implementation that scans carriers instead of wrapping erts_alloc/erts_free. The old implementation could not extract information without halting the emulator, had considerable runtime overhead, and the memory maps it produced were noisy and lacked critical information. Since the new implementation walks through existing data structures there's no longer a need to start the emulator with special flags to get information about carrier utilization/fragmentation. Memory fragmentation is also easier to diagnose as it's presented on a per-carrier basis which eliminates the need to account for "holes" between mmap segments. To help track allocations, each allocation can now be tagged with what it is and who allocated it at the cost of one extra word per allocation. This is controlled on a per-allocator basis with the +M<S>atags option, and is enabled by default for binary_alloc and driver_alloc (which is also used by NIFs).
2018-04-16Deprecate erlang:get_stacktrace/0Björn Gustavsson
2018-04-10erts: Flush messages before doing init restartLukas Larsson
If messages are not flushed they would cause problems when the system is booting. For instance module load requests would be issued before the prim loader has been launched.
2018-03-23Merge branch 'rickard/signals/OTP-14589'Rickard Green
* rickard/signals/OTP-14589: Fix VM probes compilation Fix lock counting Fix signal order for is_process_alive Fix signal handling priority elevation
2018-03-23Merge branch 'john/erts/list-installed-nifs/OTP-14965'John Högberg
* john/erts/list-installed-nifs/OTP-14965: Add an option to ?MODULE:module_info/1 for listing NIFs Fix a misleading comment
2018-03-22Fix signal order for is_process_aliveRickard Green