r/programming • u/unixbhaskar • Apr 03 '23
Every 7.8μs your computer’s memory has a hiccup
https://blog.cloudflare.com/every-7-8us-your-computers-memory-has-a-hiccup/1.2k
u/Druffilorios Apr 03 '23
My whole PC lives inside a try catch block
433
u/BlueCrystalFlame Apr 03 '23
Every PC is actually just a Java virtual machine.
276
Apr 03 '23
This but unironically. Your CPU is a massive superscalar state machine that pretends to be a dumb one-instruction-at-a-time machine but behind the scenes may replace, combine, reorder, or simultaneously execute them to get you the best performance. Compared to something that was just a straightforward implementation of x86/64 it might as well be a virtual machinie.
63
u/BigHandLittleSlap Apr 04 '23
It's even more abstracted than that! The memory subsystem lies to processes, telling them that they have "all of memory" available to them, mapped from "0x0". This is virtual memory, which the processor remaps using a "page table" to the physical addresses.
Similarly, many old CPU instructions are basically just emulated now, broken down into modern instructions using "microcode", which is a bit like a Java VM processing bytecode using a giant switch table into real machine instructions.
Even operating system kernels are "lied to" by the CPU "Ring -1" hypervisors, which emulate a "real physical machine" that actually doesn't exist except in software.
And then... the hypervisors are lied to by the code running below them in the "Ring -2" protection level called "System Management Mode" (SMM). This is firmware code that gets a region of unreadable, unwriteable memory and can "pause the world" and do anything it wants. It can change fan speeds, set processor bus voltages, whatever.
2
Apr 04 '23
Memory paging is off by default on all x86 compatible CPUs. It won't start lying to you unless you specifically tell it to. Until then you aren't presented with a linear address space. You have to use segments and offsets to access memory. It is one of the first thing OS kernels have to set up. Switching into protected mode, setting up the memory paging tables and then possibly switching into 64bit mode.
4
u/BigHandLittleSlap Apr 05 '23
Don’t confuse “swap” (page file) with virtual memory, which is implemented with “page tables” and is always on in all modern operating systems.
MS DOS was the last popular OS that didn’t use virtual memory. Also old versions of Novell NetWare, if I remember correctly…
→ More replies (2)→ More replies (42)5
u/lenkite1 Apr 04 '23
Aren't we losing performance by the old instruction-at-a-time abstraction then ? ie can performance be improved by creating a better interface for this sophisticated CPU state machine that modern OS's and software can leverage more effectively ?
8
u/thejynxed Apr 04 '23
We can and we will. Intel made a valiant but misguided attempt at it that led to things like SPECTRE.
5
6
Apr 04 '23
Yes, that is more or less what a GPU is/does. If your execution path is potentially very complex, keeping track of all that becomes very difficult to manage, which is why GPUs are mostly used for very parallelizable operations like linear algebra instead of as general purpose computing platforms.
3
Apr 04 '23
Technically yes, practically ehhhhhh.
The problem is twofold:
It's very hard to generate optimized code to drive the architecture exactly: Itanic VLIW experiment failed because of that. Complilers got better by then but still.
Once you have your magical compiler that can perfectly use the hardware.... what if you want to improve hardware?. If old code doesn't get recompiled it will work suboptimally
The "compiler in CPU" approach basically optimizes the incoming instruction stream to fit the given CPU so the CPU vendor is free to change the architecture and any improvement there will automatically be used by any code, old or new.
A new architecture making it easier to generate assembly that is internally compiled onto uops would prove some improvements, but backward compatibility is important feature, and a lot of that gains can also be achieved with just adding specialized instructions that make utilizing whole CPU easier for some task (like whole slew of SIMD) instructions.
1
u/Yoddel_Hickory Apr 07 '23
Itanium was a bit more like that, but that put a lot more work on the plate of compilers.
126
u/Tyler_Zoro Apr 03 '23
My entire life is a poorly implemented JVM running inside CommonLisp.
54
u/Laladelic Apr 03 '23
You're lucky, mine is a chrome browser running JS with way too many tabs
23
u/todo_add_username Apr 03 '23
Oh you are lucky! Mine is segfault
17
u/-Redstoneboi- Apr 03 '23
Oh you are lucky! Mine is <infinite loop reading garbled data and personal information beyond the end of the buffer>
"Oh sorry I'm oversharing..."
4
8
4
2
Apr 04 '23
and the CL is interpreted as Perl oneliner
1
3
u/vplatt Apr 03 '23 edited Apr 04 '23
Within a simulation we call reality running on a UniversalOS that supports our perceptions of space and time. This is otherwise known as RealityVM, which is a joke of a name to be sure.
The author was quite specific about the starting parameters and swarmily claimed this set of parameters was so dissimilar to any other working parameters they had heretofore seen that we the occupants would never be able to figure out the full set of parameters nor the functions that generate an infinite series of allowed parameters for the RealityVM. All of this together would make it seem as if the creator must be God.
This is a very good joke indeed if you ask me. A developer that thinks they're a god? Hilarious!
1
u/IAmRoot Apr 04 '23
Javascript VM, actually. See the Birth and Death of Javascript, it's history from 1995 to 2035: https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript
→ More replies (3)1
19
u/metaltyphoon Apr 03 '23
Try catch superior, checkmate Result<T> religious nuts.
31
4
1
136
u/Agent7619 Apr 03 '23
Isn't this the problem we have been waiting for the holy grail MRAM to solve for the last 40 years?
172
u/vriemeister Apr 03 '23 edited Apr 03 '23
No, but MRAM would fix it. SRAM also fixes it but we choose to use DRAM because it's cheaper/smaller.
1GB of SRAM takes up the same space on a chip as 16GB of DRAM. Would you give up 80% of your ram for a 1% speed increase?
134
u/papaja7312 Apr 03 '23
SRAM is much, much faster than DRAM. Like 5x faster. That's why we use it for caches. It doesn't change the fact, that DRAM is way, way cheaper. That's why we use it for general storage.
13
u/snet0 Apr 04 '23
Can you even make use of that speed increase when it's not located directly adjacent to the CPU?
1
u/Uberhipster Apr 05 '23
part of the reason it is fast is the size constraint
it would take more time to look up in SRAM if it had 16 times more data to lookup (if for now other reason then that it would need to be 16 times its 1GB physical size to accommodate 16GB of data)
14
Apr 03 '23
I mean we can get single chip 16DRAM, it's just expensive, so if there's a legit need, yeah?
But also with ssd technology advances we might just DMA drives that work in tandem with the CPU within a computing generation, I think we technically already have them.
24
u/StabbyPants Apr 03 '23
no.
why spend all that power and board space for a few percent bump in performance? data locality means that you can get most of the advantage with a much smaller cache in front of main memory, and then spend the money and power budget somewhere that gives more advantage
15
u/Hofstee Apr 03 '23
Anecdotally, see how something like the X3D Ryzen CPUs don't mega-outperform their non-X3D counterparts on most workloads despite having significantly larger caches (yes clock speeds do slightly affect the results).
Though when your workload does benefit from that kind of thing (games, hpc, etc.) the gains that can be had are impressive.
7
u/StabbyPants Apr 03 '23
linus tech tips did a review on that - it seems heavily dependent on processor firmware and other stuff to achieve its advantages, so the results being mixed make sense. the epyc 7502 runs about 128M cache against 2G/socket or thereabouts. it's a server part, so likely benefits more from the L3 cache size
5
u/Hofstee Apr 03 '23
Definitely. I just meant it more as practical evidence that current CPU cache sizes are where they are for a reason, and making them larger won't magically make every single workload faster.
3
Apr 03 '23
If there's a legitimate need for an increase in speed that takes priority over power and board space, that's reason enough?
I just answered the question, I'm not arguing against anyone else's in head hypotheticals.
3
u/StabbyPants Apr 03 '23
the point is that you won't get that increase in speed, so it can't take priority over power or board space - you spend your budget on that speed bump from a faster processor, or more cores
→ More replies (5)0
0
Apr 03 '23
[deleted]
11
u/Xipher Apr 03 '23
When you want to step that up another notch you use it for TCAM and oh look there goes another kilowatt.
5
u/Pancho507 Apr 03 '23
Yes but dram still has life left to it and is field proven so why take the relatively high risk of using it? And it has lower densities and is designed by less well known companies
111
u/yozharius Apr 03 '23
Can somebody explain why is the whole chip getting stalled if only a fraction of memory is being refreshed?
221
u/Godd2 Apr 03 '23 edited Apr 03 '23
Refreshing a row engages the same mechanism used to read/write memory, so if a row of bits is being refreshed, you can't read/write anything. It's the same reason you can't read two different addresses at the same time.
There is a small "hack" here, and that is that if you read some memory, that action refreshes the whole row of bits, aka "reading is refreshing". So if you made your own circuit with DRAM (not off-the-shelf DDR), you could hypothetically interact with it without refreshing if you know you'll be reading from it enough.
This is actually how the sprite memory in the NES works. The PPU (graphics chip) reads all of sprite memory every single scanline, so it doesn't have any built-in refresh mechanism. When Nintendo made the European version, they actually had to add refresh because the slower 50Hz television standard had a vblank period (time between frames) so long that the sprite DRAM would decay in that time. But the American and Japanese 60Hz standard didn't have that problem.
Modern DDR needs to guarantee generic random access with no decay, so they just refresh each row constantly to make sure.
55
u/StabbyPants Apr 03 '23
modern dram is far more complex than this - it's pipelined and has multiple banks, plus cache levels - not having access to main ram doesn't matter if the contents are in L2, as they often are, and the delay of a DRAM refresh is overshadowed by fetch latency
16
u/WaitForItTheMongols Apr 03 '23
Are you sure about that?
The NES only used SRAM as far as I can tell. The PPU's RAM is U4. Several chips were used for this throughout the NES lifespan, but they're all 16 Kbit (2k x 8-bit) SRAM.
Was the sprite DRAM baked into the PPU, or what? I'm unclear about what was stored on U4, it might just be nametables.
35
u/Godd2 Apr 03 '23
Yes, 256 bytes of DRAM is baked into the PPU (64 sprites at 4 bytes per sprite). The PPU scans through every Y coordinate of the sprites during tile render to find up to 8 sprites, and it would then grab the graphics for those 8 sprites in hblank before the start of the next scanline. This is why there was so much sprite flicker on the NES, the PPU could only render 8 of the 64 sprites per scanline (games would do fancy things like reorder the sprites in memory so that different ones were picked over time).
Both of the 2k chips are SRAM like you said, but the sprite memory is not stored in that 2k memory chip, which was used for 2 screens of background tile data (1k each). If a game wanted more than 2 screens of graphics loaded at the same time, they would have to supply their own memory on cart, which some games did (e.g. Gauntlet and Napoleon Senki).
7
u/oscar_the_couch Apr 03 '23 edited Apr 03 '23
in this particular example, clflush also writes anything in the cache that has been modified back to memory. unless context switching has been disabled, i'm pretty sure clflush should be writing back to memory (which would also refresh it) on every run through the loop.
the frequency he's looking for is 7812ns, so 100ns should be more than fine for that
also, his sampling interval ends up being more than 100ns because the loop is taking more than 100ns each run through. you can't preprocess your way into a shorter sampling interval (at least, not in a way that would give you greater resolution on the Nyquist rate). his actual sampling interval is closer to about 140ns.
i'm pretty sure that should still be sufficient here because the delay introduced acts like frequency modulation and would just imperceptibly shift the frequency spike on the FFT.
i think this still ends up working because clflush can't write to memory while a refresh is happening, and in those intervals you have clflush time + refresh instead of just clflush.
6
u/wrosecrans Apr 03 '23
The earliest Sun workstations skimped on the cost of a proper memory controller by doing RAM refresh in software. As soon as the CPU booted, there was a refresh loop in the ROM that would start reading through all memory. And once you booted into the OS the kernel took over refreshing the RAM, including the RAM the kernel itself was loaded into, which was pretty hilarious.
2
u/gay_for_glaceons Apr 04 '23
As someone who grew up on MS-DOS, the thought of that is absolutely terrifying. If you had a restriction like that back on DOS, you'd have ended up with every single program developer being responsible for making sure they're still reading all the RAM frequently enough without any delay during the entire time their program is running. None of the terribly written software of the time would've worked at all if they had to do that.
4
u/danielcw189 Apr 03 '23
When Nintendo made the European version, they actually had to add refresh because the slower 50Hz television standard had a vblank period (time between frames) so long that the sprite DRAM would decay in that time
That is a nice tidbit of info I have not heard about before. Thanks.
Does it have any side-effects?
and by the way: do you happen to know why the European NES runs at a lower CPU-clock?
5
u/Godd2 Apr 03 '23
Does it have any side-effects?
You mean like in terms of using it? I haven't made any PAL NES games/roms, so I really don't know, but I think you can still do OAMDMA whenever you want.
do you happen to know why the European NES runs at a lower CPU-clock?
The best info I have on that is from the nesdev wiki which said they could have divided the new master clock by 15 just like the Dendy does, but that they chose to keep the same circuit design and just divide by 16 instead.
1
u/danielcw189 Apr 04 '23
Thanks
Does it have any side-effects?
You mean like in terms of using it?
Like, does the refresh stall the CPU if it wants to read or write in that moment?
1
u/fmux418 Apr 04 '23
I think it's not about the CPU clock speed but about the screen refresh rate of the different tv standards. The European PAL standard refreshes the picture at a frequency of 50Hz, while elsewhere 60Hz are used (I believe it's called SECAM). The early Nintendo consoles did a lot of stuff based on what the CRT ray did, for example you could only write to graphics memory during the time the ray was travelling from bottom right to top left on the screen. This interval is called a vblank.
In fact, some write operations could also take place during the hblank interval, when the ray travels from one end of a line to the beginning of the next, which is much shorter. If I remember correctly, Mario Kart on the SNES switched off the ray for some time in the middle of the picture because the graphics were so complex they needed more time to produce them - that's why you have a thick black line there between the upper and lower parts of the screen :)
1
u/danielcw189 Apr 05 '23 edited Apr 05 '23
I think it's not about the CPU clock speed but about the screen refresh rate of the different tv standards.
I think you misunderstood my question or put it in a context that is not there.
The European PAL standard refreshes the picture at a frequency of 50Hz, while elsewhere 60Hz are used (I believe it's called SECAM)
SECAM was something else, used in France, for example.
Most places that use 60hz (actually more like 59.94hz) uses variants of NTSC, but for example Brazil used a PAL variant.
Most consoles did not exactly create the perfect framerate anyway.
34
u/driveawayfromall Apr 03 '23
My guess would be that refreshing the cell requires occupying the word and bit select lines, so you can’t perform read or writes using the same lines at the same time.
8
u/happyscrappy Apr 03 '23 edited Apr 03 '23
Surely it's not. (For micros) Ever since the 486 (especially DX2) and Motorola 68040 the instruction execution unit does not run in lock step with the bus. So you can keep running all the instructions you want as long as you don't need to access memory.
And now that it is much later than that we have memory controllers that can refresh one bank of memory while accessing another. Every memory chip has 4 banks. They come about because of the physical layout of the chip, The circuitry that accesses the RAM cells is in the middle, like the X and Y axes of a cartesian plot, as well as some circuitry around the outsize like a picture frame. Then the RAM cells are big arrays in the 4 quadrants of the cartesian plot. The circuitry along the axes divides the RAM into the 4 quadrants and those 4 quadrants are the 4 banks.
There is also the fact that the memory control lines (bus) is a bottleneck, you can't actually access anything on a chip while you are telling it to refresh a bank. But then after you start that refresh you can access the other banks while that one refreshes. Some memory controllers are good enough to do that, others just lock up all accesses while waiting.
→ More replies (2)-1
36
u/helix400 Apr 03 '23
This is very impressive. If anyone has ever had the thought of "I bet I could write code to obtain this hardware value", you get so frustrated because it's much harder than it seems.
290
u/denis-bazhenov Apr 03 '23
Just leave it here https://people.freebsd.org/~lstewart/articles/cpumemory.pdf
145
u/tubbana Apr 03 '23 edited May 02 '25
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
232
u/davispw Apr 03 '23
I am convinced I landed my dream job thanks to this. I was totally bombing one of my system design interviews. It was awful. I knew my answer was off track and the interviewer was feeding me help. Then I noticed a place where performance would be impacted by L3 row collisions and mentioned it. The tone changed. The interviewer stopped sounding frustrated. I got the job (and negotiated my salary up).
Once or twice a year, knowing about things like locality and cache layers is vaguely useful to me. Can’t say I’ve ever directly applied this knowledge but it can be useful to understand trade-offs made by other engineers who have.
120
u/The_Northern_Light Apr 03 '23
Yep, it's like learning higher math. You will never need every single piece of math you do know, but you open a lot of doors by being able to (even occasionally) recontextualize things in a way other people can't.
39
u/patentlyfakeid Apr 03 '23
... or by having incorporated it into the way you think and do things to start with.
6
u/PasDeDeux Apr 04 '23
This is how I feel every time I see someone who knows math way better than me solve a problem analytically that I would have just solved using numerical methods.
2
u/The_Northern_Light Apr 04 '23
Sure but let's not forget the value of numerics :) that's a very high leverage high value skill
37
u/applepy3 Apr 03 '23
I’ve had a similar situation in an interview - I was doing a question but needed to use C and wasn’t allowed to use the standard library because the interviewer thought I took “creative liberties” with my resume and wanted to check if I was full of shit. I had to reimplement hasty versions of the core data structures that I needed in the interview from scratch. I ran out of time to solve the main question but still got the job.
Sometimes just knowing how many turtles you’re standing on and how you can make the most of them is a valuable insight in itself.
16
u/Ameisen Apr 03 '23
I like being able to say that the register file in my VM fits cleanly into an L1 entry.
8
u/strong_scalp Apr 03 '23
Can you link more details on l3 collisions ? I want try to understand better
97
u/denis-bazhenov Apr 03 '23
There are so many interpretations of a word “need”.
If need is a strict requirement to get job done, then of course yes, you are right.
If need is a potentially useful information and guidance how to create software that fits modern hardware better, than I would say every developer who into this stuff, need it.
→ More replies (5)13
u/Dwedit Apr 03 '23
Cache is King. Work with the cache properly, and your code runs a lot faster. Keep accesses as sequential as possible.
You can do binary search trees contained within an array. You double the index and (possibly) add one to pick a child index. This keeps the top half of the tree living in cache the whole time.
4
u/GayMakeAndModel Apr 03 '23
The same would apply to the OP. It’s interesting knowing what goes on behind the abstractions, and it can even help you solve problems that would stump a majority of professional developers.
2
u/bidet_enthusiast Apr 04 '23
Having a basic understanding of the systems you use is important even if you live in higher level abstractions. Sometimes, abstractions break or actions at higher levels have unintended consequences at lower levels. It’s useful and (I would argue) important to be able to come down off the ladder and have a look around once in a while.
2
Apr 03 '23
Exactly. A Javascript web developer will never need to know anything in that paper. "Every" is absurdly silly in this context.
17
u/wocsom_xorex Apr 03 '23
Not sure why you’ve been downvoted, you’re totally right.
You don’t need to know shit about memory management and computer science to make a button for a scrum team that goes into some react site
22
u/o11c Apr 03 '23
Because memory is the single biggest reason that most programs are slow nowadays.
→ More replies (7)0
u/Spider_pig448 Apr 03 '23
Definitely. We need to stop thinking that every programmer needs to do everything and accept that this entire industry is about abstractions. You don't have to learn the foundations to build on what we have now.
25
u/JMBourguet Apr 03 '23
his entire industry is about abstractions
The issue is that they are all leaky.
→ More replies (1)12
u/TheRidgeAndTheLadder Apr 03 '23
Some of them sure.
But you could build a castle upon the foundation of TCP/IP. Many have.
The idea of pitching a tent on top of browser js engines makes me sweat.
Once the abstraction has "set" and the foundations are good, absolutely, developers can build with wild abandon
The problem is you need engineers to try and guess which abstraction layers are ready
4
u/Spider_pig448 Apr 03 '23
Sure, no need to go too crazy. But you can do things like build modern programs without knowing little endian vs big endien, or how floating point numbers are represented in binary, or how to do bitwise math. Any modern web developer doesn't need to know a single thing about how RAM functions, or how CPU caches are used. There will always be places for academics to learn the absolute fundamentals, but the only real thing "Every Programmer Should Know About Memory" these days is a fraction of what's in that paper.
4
u/TheRidgeAndTheLadder Apr 03 '23
Sure, no need to go too crazy. But you can do things like build modern programs without knowing little endian vs big endien, < I would put the line here > or how floating point numbers are represented in binary, or how to do bitwise math.
I agree with you in principal, but I disagree that the last two examples have been successfully abstracted away.
Any modern web developer doesn't need to know a single thing about how RAM functions, or how CPU caches are used. There will always be places for academics to learn the absolute fundamentals, but the only real thing "Every Programmer Should Know About Memory" these days is a fraction of what's in that paper.
I get where you're coming from, but webdevs demand progress, which means engineers need to understand the stack well enough to make improvements.
Definitely not a day one topic, but neither do I want to give the impression that we don't need to understand this stuff.
→ More replies (9)11
u/Prophetoflost Apr 03 '23
Not really, no. But then people build things like Slack, an IM app that takes 1GB of ram. Does it solve a particular problem - yes. Does it indirectly waste millions of person years? Also yes.
→ More replies (5)7
u/ShinyHappyREM Apr 03 '23
We need to stop thinking that every programmer needs to do everything and accept that this entire industry is about abstractions
https://www.joelonsoftware.com/2002/11/11/the-law-of-leaky-abstractions/
3
u/Spider_pig448 Apr 03 '23
The problem with this is that they are evaluating short-term abstractions and not long-term abstractions. Using STL string in C++ is a short term abstraction over char*. You might get lucky and have it Just Work everytime, but if you use it enough, you'll probably have to learn the fundamentals eventually. It takes years and years of improvements before we determine which abstractions are truly solid enough that the leaks have been worked out. C++ as an abstraction for assembly is one such example. No matter what my C++ code does, I will never have to abandon it and insert my own assembly. And there's no char* in Rust, so abstractions for other C++ concepts are here and baking now. Once we reach that point, there's no reason for the common developer to be learning assembly. We see the short-term abstractions of today and let it fool us into thinking that all programmers just have to keep learning the entire transistor stack, but they don't
1
u/thejynxed Apr 04 '23
Programmers not knowing Assembly is exactly why we have multi-gig programs to store 16-bit macro functions in the onboard memory of mice using up 250+ mb of reserved system memory.
3
u/Spider_pig448 Apr 04 '23
You mean
Programmers not knowing Assembly is exactly why we have programs to store macro functions in the onboard memory of mice
People spent time building new things instead of focusing on minimizing resource usage while hardware improvements make their work obsolete.
-1
u/strong_scalp Apr 03 '23
Can you list out what you think is top 10% most important to cover regarding system deisgn interview process ?
0
Apr 03 '23
[deleted]
33
u/happyscrappy Apr 03 '23
IMHO, any "programmer" that can't pass a test on the contents of the linked paper in their sleep is a dangerous poser.
That's silly. It's definitely not the case. Programming is specialized work now. There are plenty of people who do thinks like make websites that don't know any of that and really don't need to.
If you write in a managed language the hardware is already so far away that knowing about precharge times is not important.
Sure, know big O notation. That's going to get you a lot farther than trying to write "cache oblivious algorithms".
0
Apr 03 '23
[deleted]
8
u/happyscrappy Apr 03 '23
Everyone wants to go faster. But if you aren't equipped with even the most rudimentary knowledge required to begin to break down the abstractions that stand between you and the silicon, you are doomed to wander that solution space in complete darkness, often led by other charlatans.
That document does not contain the most rudimentary knowledge required to begin to break down the abstractions that stand between you and the silicon.
They all wanted a CPU with more cores or to get rid of the GIL
The information in that document is not going to get rid of the GIL. It won't even help you. It doesn't even describe the GIL.
Again, we are well past the bartender/dentist/pharmacist/doctor/barber specialization level of medicine.
No need for an again here. You already said this before and I read it. The issue that you're wrong.
There are a thousand other things to learn first which will make your code faster before you need to know about RAM precharge. All of those things will help you make a bigger improvement.
Even if that person is writing the website handling your private info?
There is nothing in that document which will improve how well a person handles your private info.
We should all strive to be as smart as the specialization that makes us all download 3 megs of minified JavaScript framework to render a blog page properly...
Correcting that use of 3MB of minified JavaScript framework will improve their site (and your experience with it) far more than knowing about RAM precharge.
So why is it you're hung up on knowing how RAM works?
1
13
u/svenz Apr 03 '23
Oh good grief. No need to channel your inner Ulrich Drepper. [1]
1: https://sourceware.org/bugzilla/show_bug.cgi?id=12518 for your amusement
1
-1
u/semitones Apr 03 '23 edited Feb 18 '24
Since reddit has changed the site to value selling user data higher than reading and commenting, I've decided to move elsewhere to a site that prioritizes community over profit. I never signed up for this, but that's the circle of life
7
u/overtoke Apr 03 '23
the article is named "What Every Programmer Should Know About Memory by Ulrich Drepper Red Hat, Inc"
24
u/P0indext3r Apr 03 '23
Nice read! For some more visualisation about DRAM a video about how does computer memory work? . Really helped me understand memory better by seeing it.
4
44
u/mebob85 Apr 03 '23
This is a great post, but…one of my pet peeves is people saying FFT when they just mean Fourier transform. It’s like saying quicksort instead of sort. Sure, almost always when you’re computing a discrete Fourier transform you’re using the FFT algorithm but still, it’s the algorithm and not the transform.
9
u/turunambartanen Apr 03 '23
I catch myself doing it. But FFT is just so much nicer to say and write than FT or Fourier transform. And the difference matters incredibly rarely.
7
u/gay_for_glaceons Apr 04 '23
There's a reason people read "TLA" as three-letter acronym and not two-letter acronym, and it's not just because TLA itself is a three-letter acronym. 2 letters are just too ambiguous and tend to be confusing. When I see FT I think Financial Times, or maybe FaceTime, or feet, or featuring, or any number of different things. FFT on the other hand is immediately recognizable as a distinct thing and I know exactly what you mean with it.
So basically, FFT is pronounced "Fourier transform". But the abbreviation is FFT. If France gets to cheat with their acronyms, we can too.
2
1
u/TheBB Apr 04 '23
Use DFT. Same rhythm as FFT.
Fourier transform without qualification generally means continuous Fourier transform.
4
u/debugs_with_println Apr 04 '23
Well technically its not the fourier transform either, its the discrete fourier transform. That sounds pedantic but the two are quite different (imo)!
→ More replies (1)1
7
u/hagenbuch Apr 04 '23 edited Apr 04 '23
Proud user of core memory around 1979! (AlphaLSI II).
We could turn off power in the middle of any operation, beefy capacitors would blow all the RAM into core memory and the machine would resume at the exact same letter, not lose any register content when power came back again. No glitches, no crashes.
I had never experienced this once in my later career.
6
u/Sebazzz91 Apr 03 '23
When the memory is hot (>85C) the memory retention time drops and the static refresh time halves to 32ms, and tREFI falls to 3906.25 ns.
Is this detected somehow? Is this a linear gradient between memory temperature and refresh time?
11
u/fiah84 Apr 03 '23
I don't know if it's linear, but overclockers have experienced this a thousand times over. You can have a configuration that seems stable and will continue to run as long as you have a fan pointed at it, then as soon as you turn off the fan it'll crash. As in, literally within a second. Of course that's only when running way out of spec, but I've seen it happen and backing down on the refresh timings is one way to make it stop
3
u/turunambartanen Apr 03 '23
They very likely put a temperature probe on the silicon and refresh twice as often once a certain temperature is reached. Something that is dirt cheap to put on the chip.
2
u/pantsofmagic Apr 04 '23
This is not automatic, the memory controller must be programmed to maintain the increased rate during normal operation. Also, self refresh isn't supported at high temps on traditional dram, though I believe lpddr can do it.
1
u/quentech Apr 04 '23
Is this detected somehow?
I'm not sure how universal it is, but my machines going back about 10 years have all reported each ram modules temperature - they must have a thermistor built in with a protocol for reporting the temp.
16
u/Dwedit Apr 03 '23
Well so much for those attempts at hiding the high precision timers from Javascript...
4
u/vqrs Apr 03 '23
Which on my data produces fairly boring vector like this
Why does estimate_linear only return ones and zeroes? That would only happen if no interpolation was needed, right, or they actually ran estimate_closest, no?
5
u/turunambartanen Apr 03 '23 edited Apr 03 '23
They could also interpolate first and cap to [0, 1] afterwards.
Edit: true, the pseudo code in the article must assume nearest neighbor or something. It does capping first and interpolation second.
Edit2: I don't know why I did that, but I looked it up in the actual code of their implementation and they use linear interpolation after cutoff, resulting in numbers between 0 and 1 in the data that is sent to the FFT then
1
u/vqrs Apr 03 '23 edited Apr 03 '23
But what you feed into linear interpolation is 0,0 or 0,1, or 1,0 or 1,1.
That doesn't usually result in zero or ones afterwards.
1
u/turunambartanen Apr 03 '23
Yes, it results in numbers between 0 and 1 as I've written in my second edit.
2
u/mallardtheduck Apr 04 '23
It's a lot better than in the early days when DRAM refresh happened externally to the RAM and took over the entire bus and even (on some systems) halted the CPU while it took place.
On the original IBM PC for example, DRAM refresh took approximately 5.6% of "bus time". If you were lucky, your code was running a complex instruction at the time (the PC didn't halt the CPU) and it had no impact, but most of the time it would at least stall an instruction fetch...
1
u/mehvermore Apr 03 '23
DRAM was a mistake.
22
u/Dwedit Apr 03 '23
If you like paying $100 for 8 megabytes of static RAM, then go ahead and continue to avoid DRAM.
Meanwhile, the false static ram ("Psuedo-static RAM", it's DRAM with the refresh details hidden away from you) is 5 bucks for 8 megabytes.
12
10
u/WhAtEvErYoUmEaN101 Apr 03 '23
On the other hand that would make the general populace have a greater hate against election apps
1
u/pantsofmagic Apr 04 '23
Another trick we use in the embedded world is that you can stack up a batch of refreshes at the same time. If you know you have some downtime you can send 8 refresh commands (burst refresh) and wait for them to finish, then do memory transfers for 8 times as long before needing it again. The trick is to get through the whole chip on time (as mentioned in the article) without violating any timing parameters.
1
1
u/geee001 Apr 05 '23
how to get this compiled in Windows? I've set up MSYS2 just for that, but hit a missing sys/personality.h, I could grab it somewhere but then a missing psersonality(), tried a few searches, it seems none of Mingw and cygwin provide that package (I suspect an equivalence of libc6-dev), not a linux person, a bit clueless now.
1
-1
u/fireflash38 Apr 03 '23
I enjoy seeing articles that span the gamut of low level C and some assembly instruction set commands up to analysis in python/numpy.
There's a reason python is killing it in science and stats circles: it's easy to do super complex things, quickly.
1.0k
u/dweeb_plus_plus Apr 03 '23
I've been an engineer for like 20 years now and I'm still amazed that this stuff works as well as it does every single day. Computers are amazing and the further down you dig the more "HOW THE EFF IS THIS HOUSE OF CARDS STANDING" you get.