views:

40

answers:

3

I have recently gotten a faulty RAM and despite already finding out this I would like to try a much easier concept - write a program that would allocate faulty regions of RAM and never release them. It might not work well if they get allocated before the program runs, but it'd be much easier to reboot on failure than to build a kernel with patches.

So the question is:

  1. How to write a program that would allocate given sectors (or pages containing given sectors)
  2. and (if possible) report if it was successful.
+1  A: 

Check out BadRAM: it seems to do exactly what you want.

Steven Schlansker
You didn't click the "this" link, didn't you... ;) I linked to a modern version of badRAM-badMEM. I already considered it and thought it's requiring a bit too much work. That's why I thought of creating a non-perfect, but bearable solution. BUT if you have experience using badRAM or badMEM with newest kernels - let me know.
naugtur
@naugtur: It's got patches as recent as 2.6.28 and I did click the "this" link. Since it's a separate project from what you linked I thought I'd link it to you... and it's almost certain that using an already-written kernel module will be easier than rolling your own.
Steven Schlansker
Thanks for pointing it out. I thought badMEM was a continuation of badRAM, but it's just a kind of fork. And I didn't want to mess with kernel at all, but do an experiment and write an app and hope no bad sectors are used while system boots. (I gave you +1 for the link to badram already)
naugtur
I think you'll find that one way or another you're going to have to mess with the kernel - by default it won't let you have a specific physical address. You'll need at the very least a special system call, kernel module, or other hack.
Steven Schlansker
+2  A: 

This will problematic. To understand why, you have to understand the relation between physical and virtual memory.

On any modern Operating System, programs will get a very large address space for themselves, with the remainder of the address space being used for the OS itself. Other programs are simply invisible: there's no address at which they're found. How is this possible? Simple: processes use virtual addresses. A virtual address does not correspond directly to physical RAM. Instead, there's an address translation table, managed by the OS. When your process runs, the table only contains mappings for RAM that's allocated to you.

Now, that implies that the OS decides what physical RAM is allocated to your program. It can (and will) change that at runtimke. For instance, swapping is implemented using the same mechanism. When swapping out, a page of RAM is written to disk, and its mapping deleted from the translation table. When you try to use the virtual address, the OS detects the missing mapping, restores the page from disk to RAM, and puts back a mapping. It's unlikely that you get back the same page of physical RAM, but the virtual address doesn't change during the whole swap-out/swap-in. So, even if you happened to allocate a page of bad memory, you couldn't keep it. Programs don't own RAM, they own a virtual address space.

Now, Linux does offer some specific kernel functions that allocate memory in a slightly different way, but it seems that you want to bypass the kernel entirely. You can find a much more detailed description in http://lwn.net/images/pdf/LDD3/ch08.pdf

MSalters
Thank you. I was aware of relation between physical and virtual memory, but I didn't take swapping into account. The paper looks interesting. But it looks like compiling a kernel might be less of a trouble...
naugtur
A: 

Well, it's not an answer on how to write a program, but it fixes the issue whitout compiling a kernel:

Use memmap or mem parameters: http://gquigs.blogspot.com/2009/01/bad-memory-howto.html

I will edit this answer when I get it running and give details.

naugtur