7 ms·
Hah, check out that malloc page for OpenBSD for how you configure malloc globally (to e.g. enable debugging): you create a /etc/malloc.conf which is a symbolic
by Erwin 17y ago
Hah, check out that malloc page for OpenBSD for how you configure malloc globally (to e.g. enable debugging): you create a /etc/malloc.conf which is a symbolic link to a non-existant file the name of which determines options, e.g. "G<" to enable extra malloc debugging and half the cache size!
- rbanffy 17y agoThis debugging method seems like an ugly hack. Why not use a plain text file that could be read when the program (or the computer) starts with options written in human-readable form? Assuming it is a short file, it would require only one block read (the block pointed to by the directory entry). The broken symlink method may be faster (one less disk read, a lot less parsing overhead) but is much less human-friendly. And the added speed would only be meaningful if the file got checked more often than at program start.
- amalcon 17y agoIt would also never hurt most users at all, as the standard configuration (no file) is the same for both.
- silentbicycle 17y agoIf you're having to debug something carefully with malloc, the readability of a list of single-letter flags is probably not a big deal. (I'm not sure why the symlink filename is used, though.) The code is in /usr/src/lib/libc/stdlib/malloc.c . I didn't know OpenBSD's malloc was under the "beer-ware license". :)
- cperciva 17y agoWhy not use a plain text file that could be read when the program (or the computer) starts with options written in human-readable form? Reading a symlink is one system call. Reading a file is three or more system calls. There is an overhead cost for each system call -- and if you're going to be doing something for almost every process, you might as well be as efficient as possible.
- rbanffy 17y agoExcept that if you were using a text file, you use different flags or turn it on or off on a per executable file basis checked on process start and would not have to re-parse the symlink every time you malloc something.
- cperciva 17y agoThe symlink is only checked when malloc is first called.
- rbanffy 17y agoThen why parsing a human-readable file that could, conceivably, activate a much richer debugging option-set is such a huge overhead as to make the symlink way a better option? Is the setting system-wide or process-wide? Sorry, but I just can't see why it would be a better option.
- silentbicycle 17y agoIt's checked when malloc initializes, so the startup cost for a more complex method would have to be paid by nearly every process system-wide.
- antonovka 17y agoThat's a feature of phkmalloc (written by Poul-Henning Kamp) that was brought forward into jemalloc (used by FreeBSD and Firefox/Windows, among others) and OpenBSD's malloc (written by Otto Moerbeek et al, borrowing from phkmalloc) As cperciva already noted below, readlink() is one syscall, whereas reading and parsing a configuration file is many syscalls and much more code. This is malloc we're talking about here, not general purpose user-configurable software.