
Malloc Geiger Counter - mkeeter
https://github.com/laserallan/malloc_geiger
======
chroem-
Here I was hoping this was something about repurposing RAM as an actual geiger
counter by measuring radiation-induced bit flips.

~~~
s9w
Actually me too. I did write a program a while back to investigate the rumors
about this though. Spoiler alert: Doesn't really happen.
([https://github.com/s9w/MCC](https://github.com/s9w/MCC))

~~~
apankrat
Bit flips in RAM happen often enough to be an issue.

I make a desktop program with a sizeable installation base and it uses a form
paged on-disk storage for larger data sets. The code has a fair amount of
asserts in it and one specific assert would keep failing in a very tiny
percentage of the cases. I kept reviewing the code and scratching my head
before finally adding some extra logging for this case.

Lo and behold, in all failed cases an argument passed to a function had one of
the bits set for no apparent reason. I.e. the offsets of pages in the cache
would be:

    
    
        00000000000000 ...
        00000000100000 ...
        00000000200000 ...
        00000000300000 ...
    

But the args would come in as

    
    
        80000000100000
        00040000200000
        01000000300000
        ...
    

Followed up with the people who reported these, asked to run an overnight RAM
test and ALL of them found issues with their RAM. That was quite an eye-
opener.

~~~
andi999
Were all the machines which reported that in the same building (your software
could been used in house). If so, better check for radiation levels, for
health risks; I have never seen a RAM test fail actually (apart from a
completely broken chip)

~~~
edwintorok
As mentioned below it can deteriorate over time. A while ago I had a RAM stick
fail. I noticed because GCC started segfaulting randomly and I haven't
upgraded GCC recently. Sure enough a memtest revealed the fault. I think it
didn't have enough cooling.

I only purchased RAM with heatsinks since then, and I didn't have such
problems anymore (also my latest case has much better airflow)

~~~
hinkley
I unplugged the wrong power cable once, and thereafter the RAID controller on
that machine would report degradation after the system was running for a
while. Finally ran a RAM error check, one bit in most of a stick was flipped.
The last stick. So once the machine was all spooled up for a while, I’d get
errors.

This is also how I learned 3ware was using RAM instead of its own memory. What
is he point of hardware RAID if main memory can screw it up?

I have also heard of people swapping hardware on a defective machine only to
learn that the power supply was bad, sending noise or brown power to the
system. Swap in a new power supply and the components start to behave
themselves.

------
modeless
Sometimes I miss being able to hear the hard disk read heads moving around. It
was a surprisingly accurate way to tell what your computer was up to. Someone
must have made a simulation of this, right?

~~~
throwaway_pdp09
I have old spinny disks and it is a VERY, VERY simple and useful feedback for
DB work to hear it fighting itself.

As an aside I get the feeling software is being written more and more to
assume SSDs. Starting up visual studio from fresh on my machine will thrash
the disk. Disk read is roughly (average) 2MB/sec throughout. Disk queue length
will hit 10 several times. It takes 4 mins 50 secs (290 seconds) before the
disk will calm down - I just timed it. Total mem for the process when all's
finished - 204MB! That's all!

My feeling is the VS code is spawning many threads which are each fighting
each other for the disk. It's really, really poor.

~~~
GordonS
While Visual Studio is undoubtedly a great IDE, it's biggest issue for me
always been performance, especially when paired with ReSharper - this has been
the case even before SSDs were ubiquitous.

Honestly, I'd strongly recommend you get an SSD - prices are really cheap
nowadays.

~~~
throwaway_pdp09
Is VS a great IDE. It's laggy, it's too 'helpful' eg. it's going to add a
close bracket if you type an open bracket unless you tell it not to, in which
case it's a bitch to customise (took me 20 mins to find that option) and no
luck so far if I want to adjust eg. menu & tab font to make them larger.

It can do refactoring etc. and has context-sensitive help/completions but
honestly I work in emacs because it offers so much more - except the high-
level refactoring etc. Omnisharp works, sort of... VS just isn't as good as
emacs in many, many basic ways.

Anyway, I'll look at SSDs and stop nattering about editors.

~~~
GordonS
I do think it's a great IDE, apart from the lag - though that is obviously a
big issue.

In fact, after working with VS for years and getting more and more annoyed by
the lag, I tried JetBrains Rider - I'm a total convert, it's one of my
favourite ever pieces of software! The UI takes a bit of getting used to if
you've been using VS for a long time, but not that much. Plus there's an
excellent dark theme that is quite close to VS's.

Rider is absolutely stuffed with features and config switches - it's close to
feature parity with VS, with VS able to do a few things Rider can't, and vice-
versa. Rider absolutely flies by comparison to VS, and is more stable too. Oh,
and edit-and-continue "just works" in Rider, whereas I've always found it
problematic in VS.

After getting an SSD, trying Rider is my next suggestion :)

~~~
throwaway_pdp09
I really don't like VS. I did use jetbrains and whoa! Nice!. I'll check out
Rider, which is totally new to me (thanks).

The thing about "I do think [VS] a great IDE" is you haven't experienced emacs
so you don't know what can be. What emacs is bad at: all the things VS is good
at, the high-level code 'understanding'. But honestly for
writing/modifying/moving around/various other stuff, emacs is just so
astonishingly comfortable when you get used to it. It's not "I don't need to
use the mouse", more "I barely need to think about it". And then you've got
stackable clipboard, registers, macros from heaven, regexps that just work, so
much more...

And perhaps best of all, it's written by programmers for programmers. VS feels
like management have been involved in featuritis and "UI/UX experts" as they
think of themselves but aren't, have been allowed out of their cage too often.

I'll not recommend you try emacs, it's a lot of investment but if you could
get emacs to do high-level stuff as well as the low-level... Right, time for
me to stop hijacking this thread!

------
phonethrowaway
Here's a similar thing I did once...

[https://github.com/gordol/ld_preload-
sounds](https://github.com/gordol/ld_preload-sounds)

Generates WAV output by hooking malloc() and read().

You can totally hear the standard libraries loading in, I started this thing
on a whim of silliness...

It started out as just 38 lines of code.

[https://github.com/gordol/ld_preload-
sounds/commit/2d51b3e7b...](https://github.com/gordol/ld_preload-
sounds/commit/2d51b3e7bf857fdc5b594ea61f3b90f087fe7ef5)

------
aeturnum
I think projects like this, which try to give normally invisible qualities of
software some corporeal existence, are really important. Obviously this is too
course-grained for diagnosing specific problems, but in environments like our
phones or our full desktop environments, being able to turn on feedback about
what is taking resources and how has the potential to help us build general
feelings about particular ecosystems.

------
usr1106
I have been Linux only for 10 years, so I cannot try.

I have used similar tricks with gdb to play a sound when some high-level
function is called, can be really useful. However, for malloc I would expect
it to be called so often that a human cannot hear the difference. Or the
program needs to measure the rate and select the tone according to the rate.
Of course it depends on the program, but at least if there is enough
allocation to be worried.

~~~
spot5010
I love the idea of using sound as a mechanism for debugging code. It works
wonderfully in other areas. I used to run a complex atomic physics experiment
in graduate school which involved a series of steps repeated over and over
again, with slight changes in the sequence every time. Over time I got really
attuned to the sound of the machine: the clicking of shutters, hissing of
valves, a annoying 10kHz note that was generated by an amplifier driving AC
currents, etc. and could easily tell by ear if something was off (which
happened a lot!). I would also use sound to tune control loops by sending the
error signal to a speaker or earphones and listen to the noise. It
complemented a signal analyzer wonderfully.

Can gdb be configured to somehow “hum” a program by converting a series of
operations into sound and we can hear our programs in action? No idea how to
go about it though, and how to convert operations happening at the CPU clock
rate into the audible regime, but seems like it’s worth exploring.

------
euske
This is actually a brilliant idea.

If you change the pitch by the allocated chunk size (maybe in log scale) or
use different sound for free(), someone could be actually detecting memory
leaks just by listening to the app.

~~~
dkersten
I was thinking that it’s useful in games or other applications where you don’t
want to malloc at arbitrary times (eg in games you might malloc once in
startup or on level start and then reuse that memory instead). Many
applications with real-time requirements often work similarly (eg high
frequency trading), so this would be a fun check to make sure your application
is well behaved.

I like the idea of changing pitch by size and also representing frees, but I’m
not sure it would be useful to find memory leaks since there’s no real way of
matching them up in any non trivial application.

~~~
mypalmike
When I worked at a major game developer, our custom allocation library handled
this more directly: malloc would crash the program if called during normal
gameplay.

~~~
dkersten
Hah, that's certainly one way to do it!

------
YesThatTom2
People did this with network utilization decades ago:
[https://www.usenix.org/techsessionssummary/peep-network-
aura...](https://www.usenix.org/techsessionssummary/peep-network-auralizer-
monitoring-your-network-sound)

~~~
lucasvr_br
I loved the paper! The technique its authors present is more elaborated,
though: they mix different sounds extracted from nature, such as birds and
wind, and allow mixing different streams to create something pleasant to a
sysadmin's ears. I liked this paragraph in special:

"Due to copyright limitations on existing natural sound collections, Prof.
Couch has spent many hours with a Telinga parabolic nature microphone and Sony
DAT or digital minidisc recorder in search of the perfect bird."

Thanks for sharing this paper!

------
andi999
While some say here that they are disappointed that this isnt abour
radioactivity, for me it was the opposite. Wheb reading the headline I
thought, oh no not another one of those, wondering though how you can get
malloc in.

Read it, and I think this is actually a great new idea.

------
bregma
Back in the day sysadmins would just hooks up the least-significant address
line to a speaker. That way they could monitor the mainframe aurally while
reading and drinking coffee instead of watching the bank of flashing lights.

------
nemo1618
Here's a version for Go:
[https://github.com/lukechampine/geiger](https://github.com/lukechampine/geiger)

------
peter_d_sherman
What a strange, but interesting, idea!

The broader idea here is that there are probably an infinite number of
creative ways -- to measure different aspects of what software does, and to
instrument that output in different creative ways that can be experienced via
human senses (in this case, via sound).

------
lucasvr_br
This is really cool! It just occurred to me that the same approach would work
to identify non-sequential reads from applications that access data from
disk/tape. Thanks a lot for sharing this project with us :-)

------
fizixer
Thanks goodness this is not a renaming/rediscovery/attribution-hijacking of a
well-known and old concept (reference count, allocation count, etc.),
something every other person these days seems be engaged in.

------
olliej
well I'm sure as hell not using this on any Haskell* code (imagine we apply
the malloc sound effect to generic allocation)

* Any GC'd language really, JS, Java w/generics etc

~~~
chrisseaton
> well I'm sure as hell not using this on any Haskell* code

I think this is literally already a feature in Haskell, except it beeps on GC
rather than allocation.

[https://downloads.haskell.org/~ghc/latest/docs/html/users_gu...](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/runtime_control.html#rts-
options-for-hackers-debuggers-and-over-interested-souls)

~~~
1f60c
That's cool, but could you tell me how to use it?

When I try

    
    
      ghc -B hello.hs
    

I get an error

    
    
      Missing file: ./settings

.

If I then

    
    
      touch settings platformConstants
    

the error changes to

    
    
      Can't parse "./settings"

.

What am I supposed to put in this settings file? I'm but a Haskell noob, and
this is the first time I've heard of it.

EDIT:

I found it! The correct command is

    
    
      ghc hello.hs +RTS -B

.

I can't seem to get it to beep on macOS, though.

~~~
chrisseaton
It just prints \a - it's up to your Terminal what it does with that.

Does print "\a" work in your terminal?

~~~
1f60c
Yes, it does, but my terminal's "silent bell" feature had been enabled. I
disabled it, and it worked, though only while compiling, and _not_ during
runtime, strangely enough.

