Skip to contentSkip to conversation

mm: BadRAM support for broken memory

PATCH In review Rick van Rein 10 participants 18 messages Mar 2, 2008 – Mar 8, 2008 3 messages not in the archive

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: BadRAM support for broken memory

This is the latest version of the BadRAM patch, which makes it possible to run Linux on broken memory. The patch supports the use of a lesser grade of memory, which could be marketed more cheaply and which would thereby decrease the environmental stress caused by the process of (memory) chip manufacturing.

Over the years, feedback on this patch has invariably been positive and enthousiastic. The patch, even though not part of mainstream Linux, still managed to make lots of people happy:
- schools and other low-budget computer users
- people with partially defective RAM soldered onto laptop motherboards
- people with one faulty address due to wiring faults on their motherboard
- people who find it environmentally insane to toss out 99.99%-good hardware

The patch has been well-maintained over the years, mostly by volunteers who keep track of kernel updates. The submitters have changed over the years, but there have always been volunteers jumping in, sometimes within hours after a new kernel appeared, and mostly within a day. I have processed support requests and used them to learn and make the patch work optimally. It is obvious to me that the patch is in good demand, and I think it earns to be included in the mainstream kernel.

The current version supports ia32 and x86_64 architectures. Others would be unpractical to add on a patch outside mainstream Linux, but it ought to be straightforward to add support for other architectures as well.

For more information, read Documentation/badram.txt or visit the homepage for the patch, http://rick.vanrein.org/linux/badram/

arch/x86/configs/i386_defconfig +1 -0
diff -pruN linux-2.6.24.orig/arch/x86/configs/i386_defconfig linux-2.6.24/arch/x86/configs/i386_defconfig
@@ -198,6 +198,7 @@ CONFIG_DMIID=y
 # CONFIG_NOHIGHMEM is not set
 CONFIG_HIGHMEM4G=y
 # CONFIG_HIGHMEM64G is not set
+CONFIG_BADRAM=y
 CONFIG_PAGE_OFFSET=0xC0000000
 CONFIG_HIGHMEM=y
 CONFIG_ARCH_POPULATES_NODE_MAP=y
arch/x86/configs/x86_64_defconfig +1 -0
diff -pruN linux-2.6.24.orig/arch/x86/configs/x86_64_defconfig linux-2.6.24/arch/x86/configs/x86_64_defconfig
@@ -132,6 +132,7 @@ CONFIG_X86_CPUID=y
 CONFIG_X86_HT=y
 CONFIG_X86_IO_APIC=y
 CONFIG_X86_LOCAL_APIC=y
+CONFIG_BADRAM=y
 CONFIG_MTRR=y
 CONFIG_SMP=y
 CONFIG_SCHED_SMT=y
arch/x86/Kconfig +18 -0
diff -pruN linux-2.6.24.orig/arch/x86/Kconfig linux-2.6.24/arch/x86/Kconfig
@@ -813,6 +813,24 @@ config X86_PAE
 	  has the cost of more pagetable lookup overhead, and also
 	  consumes more pagetable space per process.
 
+
+config BADRAM
+	bool "Work around bad spots in RAM"
+	default y
+	help
+	  This small kernel extension makes it possible to use memory chips
+	  which are not entirely correct. It works by never allocating the
+	  places that are wrong. Those places are specified with the badram
+	  boot option to LILO. Read Documentation/badram.txt and/or visit
+	  http://home.zonnet.nl/vanrein/badram for information.
+
+	  This option co-operates well with a second boot option from LILO
+	  that starts memtest86, which is able to automatically produce the
+	  patterns for the commandline in case of memory trouble.
+
+	  It is safe to say 'Y' here, and it is advised because there is no
+	  performance impact.
+
 # Common NUMA Features
 config NUMA
 	bool "Numa Memory Allocation and Scheduler Support (EXPERIMENTAL)"
arch/x86/mm/init_32.c +42 -15

124 lines not on this page · raw message

arch/x86/mm/init_64.c +7 -1
diff -pruN linux-2.6.24.orig/arch/x86/mm/init_64.c linux-2.6.24/arch/x86/mm/init_64.c
@@ -63,7 +63,7 @@ DEFINE_PER_CPU(struct mmu_gather, mmu_ga
 
 void show_mem(void)
 {
-	long i, total = 0, reserved = 0;
+	long i, total = 0, reserved = 0, badram=0;
 	long shared = 0, cached = 0;
 	pg_data_t *pgdat;
 	struct page *page;
@@ -85,6 +85,8 @@ void show_mem(void)
 			total++;
 			if (PageReserved(page))
 				reserved++;
+			else if (PageBad(page))
+				badram++;
 			else if (PageSwapCache(page))
 				cached++;
 			else if (page_count(page))
@@ -93,6 +95,10 @@ void show_mem(void)
 	}
 	printk(KERN_INFO "%lu pages of RAM\n", total);
 	printk(KERN_INFO "%lu reserved pages\n",reserved);
+#ifdef CONFIG_BADRAM
+       printk(KERN_INFO "%lu pages of BadRAM\n",badram);
+#endif
+
 	printk(KERN_INFO "%lu pages shared\n",shared);
 	printk(KERN_INFO "%lu pages swap cached\n",cached);
 }
arch/x86/mm/pgtable_32.c +6 -1
diff -pruN linux-2.6.24.orig/arch/x86/mm/pgtable_32.c linux-2.6.24/arch/x86/mm/pgtable_32.c
@@ -26,7 +26,7 @@
 
 void show_mem(void)
 {
-	int total = 0, reserved = 0;
+	int total = 0, reserved = 0, badram = 0;
 	int shared = 0, cached = 0;
 	int highmem = 0;
 	struct page *page;
@@ -48,6 +48,8 @@ void show_mem(void)
 				highmem++;
 			if (PageReserved(page))
 				reserved++;
+			if (PageBad(page))
+				badram++;
 			else if (PageSwapCache(page))
 				cached++;
 			else if (page_count(page))
@@ -58,6 +60,9 @@ void show_mem(void)
 	printk(KERN_INFO "%d pages of RAM\n", total);
 	printk(KERN_INFO "%d pages of HIGHMEM\n", highmem);
 	printk(KERN_INFO "%d reserved pages\n", reserved);
+#ifdef CONFIG_BADRAM
+	printk(KERN_INFO "%d pages of badRAM\n", badram);
+#endif
 	printk(KERN_INFO "%d pages shared\n", shared);
 	printk(KERN_INFO "%d pages swap cached\n", cached);
 
CREDITS +10 -0
diff -pruN linux-2.6.24.orig/CREDITS linux-2.6.24/CREDITS
@@ -2840,6 +2840,16 @@ S: 6 Karen Drive
 S: Malvern, Pennsylvania 19355
 S: USA
 
+N: Rick van Rein
+E: [email protected]
+W: http://rick.vanrein.org/
+D: Memory, the BadRAM subsystem dealing with statically challanged RAM modules.
+S: Haarlebrink 5
+S: 7544 WP  Enschede
+S: The Netherlands
+P: 1024D/89754606  CD46 B5F2 E876 A5EE 9A85  1735 1411 A9C2 8975 4606
+
+
 N: Stefan Reinauer
 E: [email protected]
 W: http://www.freiburg.linux.de/~stepan/
Documentation/badram.txt +275 -0

275 lines not on this page · raw message

Documentation/kernel-parameters.txt +3 -0
diff -pruN linux-2.6.24.orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
@@ -35,6 +35,7 @@ parameter is applicable:
 	APIC	APIC support is enabled.
 	APM	Advanced Power Management support is enabled.
 	AX25	Appropriate AX.25 support is enabled.
+	BADRAM	Support for faulty RAM chips is enabled.
 	BLACKFIN Blackfin architecture is enabled.
 	DRM	Direct Rendering Management support is enabled.
 	EDD	BIOS Enhanced Disk Drive Services (EDD) is enabled
@@ -322,6 +323,8 @@ and is between 256 and 4096 characters. 
 
 	autotest	[IA64]
 
+	badram=		[BADRAM] Avoid allocating faulty RAM addresses.
+
 	baycom_epp=	[HW,AX25]
 			Format: <io>,<mode>
 
Documentation/memory.txt +11 -0
diff -pruN linux-2.6.24.orig/Documentation/memory.txt linux-2.6.24/Documentation/memory.txt
@@ -18,11 +18,22 @@ systems.
 	   as you add more memory.  Consider exchanging your 
            motherboard.
 
+	4) A static discharge or production fault causes a RAM module
+	  to have (predictable) errors, usually meaning that certain
+	  bits cannot be set or reset. Instead of throwing away your
+	  RAM module, you may read /usr/src/linux/Documentation/badram.txt
+	  to learn how to detect, locate and circuimvent such errors
+	  in your RAM module.
+
+
+
 All of these problems can be addressed with the "mem=XXXM" boot option
 (where XXX is the size of RAM to use in megabytes).  
 It can also tell Linux to use less memory than is actually installed.
 If you use "mem=" on a machine with PCI, consider using "memmap=" to avoid
 physical address space collisions.
+If this helps, read Documentation/badram.txt to learn how to
+find and circumvent memory errors.
 
 See the documentation of your boot loader (LILO, loadlin, etc.) about
 how to pass options to the kernel.
include/asm-x86/page_32.h +1 -0
diff -pruN linux-2.6.24.orig/include/asm-x86/page_32.h linux-2.6.24/include/asm-x86/page_32.h
@@ -189,6 +189,7 @@ extern int page_is_ram(unsigned long pag
 #define pfn_valid(pfn)		((pfn) < max_mapnr)
 #endif /* CONFIG_FLATMEM */
 #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
+#define phys_to_page(x)         pfn_to_page((unsigned long)(x) >> PAGE_SHIFT)
 
 #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
 
include/asm-x86/page_64.h +1 -0
diff -pruN linux-2.6.24.orig/include/asm-x86/page_64.h linux-2.6.24/include/asm-x86/page_64.h
@@ -126,6 +126,7 @@ extern unsigned long __phys_addr(unsigne
 #endif
 
 #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
+#define phys_to_page(x)         pfn_to_page((unsigned long)(x) >> PAGE_SHIFT)
 #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
 #define pfn_to_kaddr(pfn)      __va((pfn) << PAGE_SHIFT)
 
include/linux/kernel.h +2 -0
diff -pruN linux-2.6.24.orig/include/linux/kernel.h linux-2.6.24/include/linux/kernel.h
@@ -164,6 +164,8 @@ extern int vsscanf(const char *, const c
 
 extern int get_option(char **str, int *pint);
 extern char *get_options(const char *str, int nints, int *ints);
+extern int get_longoption (char **str, long *plong);
+extern char *get_longoptions(const char *str, int nlongs, long *longs);
 extern unsigned long long memparse(char *ptr, char **retptr);
 
 extern int core_kernel_text(unsigned long addr);
include/linux/page-flags.h +12 -0
diff -pruN linux-2.6.24.orig/include/linux/page-flags.h linux-2.6.24/include/linux/page-flags.h
@@ -93,6 +93,9 @@
 /* PG_readahead is only used for file reads; PG_reclaim is only for writes */
 #define PG_readahead		PG_reclaim /* Reminder to do async read-ahead */
 
+#define PG_badram              20      /* BadRam page */
+
+
 /* PG_owner_priv_1 users should have descriptive aliases */
 #define PG_checked		PG_owner_priv_1 /* Used by some filesystems */
 #define PG_pinned		PG_owner_priv_1	/* Xen pinned pagetable */
@@ -108,6 +111,15 @@
 #define PG_uncached		31	/* Page has been mapped as uncached */
 #endif
 
+#ifdef CONFIG_BADRAM
+#define PageBad(page)          test_bit(PG_badram, &(page)->flags)
+#define PageSetBad(page)       set_bit(PG_badram, &(page)->flags)
+#define PageTestandSetBad(page)     test_and_set_bit(PG_badram, &(page)->flags)
+#else
+#define PageBad(page)          0
+#endif
+
+
 /*
  * Manipulation of page state flags
  */
lib/cmdline.c +66 -0

75 lines not on this page · raw message

mm/bootmem.c +2 -0
diff -pruN linux-2.6.24.orig/mm/bootmem.c linux-2.6.24/mm/bootmem.c
@@ -317,10 +317,12 @@ static unsigned long __init free_all_boo
 	pfn = PFN_DOWN(bdata->node_boot_start);
 	idx = bdata->node_low_pfn - pfn;
 	map = bdata->node_bootmem_map;
+#ifndef CONFIG_BADRAM /* no idea if this is really needed */
 	/* Check physaddr is O(LOG2(BITS_PER_LONG)) page aligned */
 	if (bdata->node_boot_start == 0 ||
 	    ffs(bdata->node_boot_start) - PAGE_SHIFT > ffs(BITS_PER_LONG))
 		gofast = 1;
+#endif
 	for (i = 0; i < idx; ) {
 		unsigned long v = ~map[i / BITS_PER_LONG];
 
mm/page_alloc.c +1 -0
diff -pruN linux-2.6.24.orig/mm/page_alloc.c linux-2.6.24/mm/page_alloc.c
@@ -10,6 +10,7 @@
  *  Reshaped it to be a zoned allocator, Ingo Molnar, Red Hat, 1999
  *  Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999
  *  Zone balancing, Kanoj Sarcar, SGI, Jan 2000
+ *  BadRAM handling, Rick van Rein, Feb 2001
  *  Per cpu hot/cold page lists, bulk allocation, Martin J. Bligh, Sept 2002
  *          (lots of bits borrowed from Ingo Molnar & Andrew Morton)
  */
@@ -540,9 +541,11 @@ static void __free_pages_ok(struct page 
 void fastcall __init __free_pages_bootmem(struct page *page, unsigned int order)
 {
 	if (order == 0) {
		__ClearPageReserved(page);

- set_page_count(page, 0);
- set_page_refcounted(page);
+ if(!PageBad(page)){
+ set_page_count(page, 0);
+ set_page_refcounted(page);
__free_page(page);
+ }
} else {
int loop;
@@ -4378,6 +4381,91 @@ EXPORT_SYMBOL(pfn_to_page);
EXPORT_SYMBOL(page_to_pfn);
#endif /* CONFIG_OUT_OF_LINE_PFN_TO_PAGE */

+
+#ifdef CONFIG_BADRAM
+
+/* Given a pointed-at address and a mask, increment the page so that the
+ * mask hides the increment. Return 0 if no increment is possible.
+ */
+static int __init next_masked_address (unsigned long *addrp, unsigned long mask) +{

+       unsigned long inc=1;
+       unsigned long newval = *addrp;
+       while (inc & mask)
+               inc += inc;
+       while (inc != 0) {
+               newval += inc;
+               newval &= ~mask;
+               newval |= ((*addrp) & mask);
+               if (newval > *addrp) {

+ *addrp = newval;
+ return 1;
+ }
+ do {
+ inc += inc;
+ } while (inc & ~mask);
+ while (inc & mask)
+ inc += inc;
+ }
+ return 0;
+}
+
+
+void __init badram_markpages (int argc, unsigned long *argv) {
+ unsigned long addr, mask;
+ while (argc-- > 0) {

+               addr = *argv++;
+               mask = (argc-- > 0) ? *argv++ : ~0L;
+               mask |= ~PAGE_MASK;     /* Optimalisation */
+               addr &= mask;           /* Normalisation */
+               do {

+ struct page *pg = phys_to_page(addr);
+ printk(KERN_DEBUG "%016lx =%016lx\n",
+ addr >> PAGE_SHIFT,
+ (unsigned long)(pg-mem_map));
+ if (PageTestandSetBad (pg))
+ reserve_bootmem (addr, PAGE_SIZE);
+ } while (next_masked_address (&addr,mask));
+ }
+}
+
+
+/*********** CONFIG_BADRAM: CUSTOMISABLE SECTION STARTS HERE *****************/ +/* Enter your custom BadRAM patterns here as pairs of unsigned long integers. */ +/* For more information on these F/M pairs, refer to Documentation/badram.txt */ +
+static unsigned long __initdata badram_custom[] = {
+ 0, /* Number of longwords that follow, as F/M pairs */
+};
+
+
+/*********** CONFIG_BADRAM: CUSTOMISABLE SECTION ENDS HERE *******************/ +
+static int __init badram_setup (char *str)
+{

+       unsigned long opts[3];
+       BUG_ON(!mem_map);
+       printk (KERN_INFO "PAGE_OFFSET=0x%08lx\n", PAGE_OFFSET);
+       printk (KERN_INFO "BadRAM option is %s\n", str);
+       if (*str++ == '=')

+ while ((str = get_longoptions (str, 3, (long *) opts), *opts)) {
+ printk (KERN_INFO " --> marking 0x%08lx, 0x%08lx [%ld]\n",
+ opts[1], opts[2], opts[0]);
+ badram_markpages (*opts, opts+1);
+ if (*opts == 1)
+ break;
+ };
+ badram_markpages (*badram_custom, badram_custom+1);
+ return 0;
+}
+
+__setup("badram", badram_setup);
+
+#endif /* CONFIG_BADRAM */
+
+
+
+
/* Return a pointer to the bitmap storing bits affecting a block of pages */ static inline unsigned long *get_pageblock_bitmap(struct zone *zone,
unsigned long pfn)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

Hi

in general,
Agreed with we need bad memory treatness.

Quoted 1 line

+#define PG_badram 20 /* BadRam page */

some architecture use PG_reserved for treat bad memory. Why do you want introduce new page flag?
for show_mem() improvement?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

Hello Kosaki,

Quoted 2 lines

in general,
Agreed with we need bad memory treatness.

Glad to hear that.

Quoted 4 lines
Quoted 1 line

+#define PG_badram 20 /* BadRam page */

some architecture use PG_reserved for treat bad memory. Why do you want introduce new page flag?

It is clearer to properly name a flag, I suppose.
Is the use that you are mentioning the intended, and only use of the flag? If not, I think it is clearer to use a separate flag instead of overloading one.

Quoted 1 line

for show_mem() improvement?

For code clarity.

Thanks,
-Rick

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw

Hi Rick

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

+#define PG_badram 20 /* BadRam page */

some architecture use PG_reserved for treat bad memory. Why do you want introduce new page flag?

It is clearer to properly name a flag, I suppose.
Is the use that you are mentioning the intended, and only use of the flag? If not, I think it is clearer to use a separate flag instead of overloading one.

hmmm
unfortunately flag bit of struct page is very valuable resource rather than diamond on current implementaion ;-)

if you can change to no introduce new page flag,
IMHO merge to mainline dramatically become easy.

Quoted 3 lines
Quoted 1 line

for show_mem() improvement?

For code clarity.

agreed with your code is clarify. but...

#4 lore raw
In reply to KOSAKI Motohiro
Quoted 10 lines · KOSAKI Motohiro

Hi

in general,
Agreed with we need bad memory treatness.

Quoted 1 line

+#define PG_badram 20 /* BadRam page */

some architecture use PG_reserved for treat bad memory. Why do you want introduce new page flag?
for show_mem() improvement?

I'd like to get rid of PG_reserved at some point. So I'd rather not overload it with more meanings ;)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 6 lines
Quoted 3 lines

some architecture use PG_reserved for treat bad memory. Why do you want introduce new page flag?
for show_mem() improvement?

I'd like to get rid of PG_reserved at some point. So I'd rather not overload it with more meanings ;)

really?

as far as I know, IA64 already use PG_reserved for bad memory. please see arch/ia64/kernel/mcs_drv.c#mca_page_isolate.

Doesn't it works on ia64 if your patch introduce?

- kosaki

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw
Quoted 7 lines · KOSAKI Motohiro
Quoted 6 lines
Quoted 3 lines

some architecture use PG_reserved for treat bad memory. Why do you want introduce new page flag?
for show_mem() improvement?

I'd like to get rid of PG_reserved at some point. So I'd rather not overload it with more meanings ;)

Quoted 6 lines

really?

as far as I know, IA64 already use PG_reserved for bad memory. please see arch/ia64/kernel/mcs_drv.c#mca_page_isolate.

Doesn't it works on ia64 if your patch introduce?

It doesn't really need to use PG_reserved there, no. It could use PG_bad for that instead.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
Quoted 7 lines
Quoted 4 lines

as far as I know, IA64 already use PG_reserved for bad memory. please see arch/ia64/kernel/mcs_drv.c#mca_page_isolate.

Doesn't it works on ia64 if your patch introduce?

It doesn't really need to use PG_reserved there, no. It could use PG_bad for that instead.

unfortunately that feature already merged to mainline. and i am not its developer, sorry ;)

- kosaki

#8 lore raw
In reply to Nick Piggin
Quoted 10 lines · On Mon, 3 Mar 2008 18:35:02 +1100 Nick Piggin <[email protected]> wrote:
Quoted 9 lines · KOSAKI Motohiro
Quoted 6 lines
Quoted 3 lines

some architecture use PG_reserved for treat bad memory. Why do you want introduce new page flag?
for show_mem() improvement?

I'd like to get rid of PG_reserved at some point. So I'd rather not overload it with more meanings ;)

really?

Quoted 8 lines
Quoted 4 lines

as far as I know, IA64 already use PG_reserved for bad memory. please see arch/ia64/kernel/mcs_drv.c#mca_page_isolate.

Doesn't it works on ia64 if your patch introduce?

It doesn't really need to use PG_reserved there, no. It could use PG_bad for that instead.

Hmm, it seems that it's necessary to rewrite ia64/mca code after PG_bad patch is merged.

Thanks,
-Kame

#9 lore raw
In reply to Rick van Rein
Quoted 22 lines · Rick van Rein

This is the latest version of the BadRAM patch, which makes it possible to run Linux on broken memory. The patch supports the use of a lesser grade of memory, which could be marketed more cheaply and which would thereby decrease the environmental stress caused by the process of (memory) chip manufacturing.

Over the years, feedback on this patch has invariably been positive and enthousiastic. The patch, even though not part of mainstream Linux, still managed to make lots of people happy:
- schools and other low-budget computer users
- people with partially defective RAM soldered onto laptop motherboards
- people with one faulty address due to wiring faults on their motherboard
- people who find it environmentally insane to toss out 99.99%-good hardware

The patch has been well-maintained over the years, mostly by volunteers who keep track of kernel updates. The submitters have changed over the years, but there have always been volunteers jumping in, sometimes within hours after a new kernel appeared, and mostly within a day. I have processed support requests and used them to learn and make the patch work optimally. It is obvious to me that the patch is in good demand, and I think it earns to be included in the mainstream kernel.

Quoted 6 lines

The current version supports ia32 and x86_64 architectures. Others would be unpractical to add on a patch outside mainstream Linux, but it ought to be straightforward to add support for other architectures as well.

For more information, read Documentation/badram.txt or visit the homepage for the patch, http://rick.vanrein.org/linux/badram/

This is a great feature for those of us who value their money more than a few hours of time as well. :-)

I would very much like to see this patch in mainline -- I've used it to allow use of a marginally bad RAM stick in my home workstation/fileserver, with great results (i.e. my FS never went belly-up).

There have been times when I was reluctant to report bugs in a BadMEM patched kernel, due to the patching, as well as times when I would have liked to have stuck with my distro's kernel, but couldn't, 'cause I needed to patch BadRAM in.

I haven't used BadRAM in a minute, nor read the patch. ISTR that one argument that has been historically made against this sort of thing is that it would make bug reports unreliable. But we have the taint mechanism now, so that shouldn't be a showstopper -- if that's the only argument, then set a new taint flag, please.

I've added a akpm to the CC list.

--
Joseph Fannin
[email protected]

#10 lore raw

Hello,

Quoted 2 lines

This is a great feature for those of us who value their money more than a few hours of time as well. :-)

That's how it's most often used, indeed. I do value the environmental aspect as well: the potential for memory manufacturers (say, for the $100 laptop) to ship out their broken memories at a low cost, thereby delivering more products for a given amount of toxic waste created in the chip etching process.

Quoted 1 line

I would very much like to see this patch in mainline

Many, many people want to. I've been asked about it a lot, but always lacked the time to figure out how.

Quoted 3 lines

ISTR that one
argument that has been historically made against this sort of thing is that it would make bug reports unreliable.

Actually it's broken memory that makes reports unreliable, not the patch :)

After the right set of broken addresses has been applied, the whole system runs as reliably as any other system. And I hope people have the wits to mistrust a system for a while after they've plugged in broken DIMMs ;-)

Quoted 2 lines

mechanism now, so that shouldn't be a showstopper -- if that's the only argument, then set a new taint flag, please.

I doubt that'll be necessary, but yes, it'd be a way out. Thanks.

Cheers,
-Rick

#11 lore raw
In reply to Rick van Rein

Hi!

Quoted 5 lines

This is the latest version of the BadRAM patch, which makes it possible to run Linux on broken memory. The patch supports the use of a lesser grade of memory, which could be marketed more cheaply and which would thereby decrease the environmental stress caused by the process of (memory) chip manufacturing.

What is wrong with mem=exactmap?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#12 lore raw

Hi!

Quoted 7 lines
Quoted 5 lines

This is the latest version of the BadRAM patch, which makes it possible to run Linux on broken memory. The patch supports the use of a lesser grade of memory, which could be marketed more cheaply and which would thereby decrease the environmental stress caused by the process of (memory) chip manufacturing.

What is wrong with mem=exactmap?

Agghh,
I had forgotten that.

you are right, may be.

#13 lore raw
Quoted 8 lines · KOSAKI Motohiro

Hi!

Quoted 6 lines
Quoted 5 lines

This is the latest version of the BadRAM patch, which makes it possible to run Linux on broken memory. The patch supports the use of a lesser grade of memory, which could be marketed more cheaply and which would thereby decrease the environmental stress caused by the process of (memory) chip manufacturing.

Quoted 6 lines
Quoted 1 line

What is wrong with mem=exactmap?

Agghh,
I had forgotten that.

you are right, may be.

More importantly:

	memmap=<size>$<len>

already allows you to knock arbitrary holes in the memory map.

-hpa

#14 lore raw
Quoted 7 lines · H. Peter Anvin

More importantly:

    memmap=<size>$<len>

already allows you to knock arbitrary holes in the memory map.

Sorry for the repeats. I just came off a long flight and didn't remember I had already responded to this thread.

-hpa

#15 lore raw
In reply to Rick van Rein
Quoted 5 lines · On Sun, 2 Mar 2008 13:42:21 +0000 Rick van Rein wrote:

This is the latest version of the BadRAM patch, which makes it possible to run Linux on broken memory. The patch supports the use of a lesser grade of memory, which could be marketed more cheaply and which would thereby decrease the environmental stress caused by the process of (memory) chip manufacturing.

Patch needs to be made against (i.e., applyable against) the latest linus-mainline kernel, not a few-weeks old kernel.
Of course, you could be lucky and it applies to either one.

Documentation/badram.txt line 6

Quoted 10 lines

diff -pruN linux-2.6.24.orig/Documentation/badram.txt linux-2.6.24/Documentation/badram.txt

Documentation/badram.txt +6 -0
@@ -0,0 +1,275 @@
+INFORMATION ON USING BAD RAM MODULES
+====================================
+
+
+Initial checks
+       If you experience RAM trouble, first read /usr/src/linux/memory.txt

Incorrect path. Insert "Documentation/". But we usually don't include the full path (i.e., drop "/usr/src/linux" or say
"read Documentation/memory.txt in the kernel source tree".

Quoted 18 lines
Documentation/badram.txt +18 -0
+       and try out the mem=4M trick to see if at least some initial parts
+       of your RAM work well. The BadRAM routines halt the kernel in panic
+       if the reserved area of memory (containing kernel stuff) contains
+       a faulty address.
+
+Running a RAM checker
+       The memory checker is not built into the kernel, to avoid delays at
+       runtime. If you experience problems that may be caused by RAM, run
+       a good RAM checker, such as
+               http://reality.sgi.com/cbrady_denver/memtest86
+       The output of a RAM checker provides addresses that went wrong. In
+       the 32 MB chip with 512 faulty bits mentioned above, the errors were
+       found in the 8MB-16MB range (the DIMM was in slot #0) at addresses
+               xxx42f4
+               xxx62f4
+               xxxc2f4
+               xxxe2f4
+       and the error was a "sticky 1 bit", a memory bit that stayed "1" no

Documentation/badram.txt line 66

Quoted 10 lines
Documentation/badram.txt +10 -0
+       matter what was written to it. The regularity of this pattern
+       suggests the death of a buffer at the output stages of a row on one of
+       the chips. I expect such regularity to be commonplace. Finding this
+       regularity currently is human effort, but it should not be hard to
+       alter a RAM checker to capture it in some sort of pattern, possibly
+       the BadRAM patterns described below.
+
+       By the way, if you manage to get hold of memtest86 version 2.3 or
+       beyond, you can configure the printing mode to produce BadRAM patterns,
+       which find out exactly what you must enter on the LILO: commandline,

Drop ":".

Quoted 19 lines
Documentation/badram.txt +19 -0
+       except that you shouldn't mention the added spacing. That means that
+       you can skip the following step, which saves you a *lot* of work.
+
+       Also by the way, if your machine has the ISA memory gap in the 15M-16M
+       range unstoppable, Linux can get in trouble. One way of handling that
+       situation is by specifying the total memory size to Linux with a boot
+       parameter mem=... and then to tell it to treat the 15M-16M range as
+       faulty with an additional boot parameter, for instance:
+               mem=24M badram=0x00f00000,0xfff00000
+       if you installed 24MB of RAM in total.
+
+
+Capturing errors in a pattern
+       Instead of manually providing all 512 errors to the kernel, it's nicer
+       to generate a pattern. Since the regularity is based on address decoding
+       software, which generally takes certain bits into account and ignores
+       others, we shall provide a faulty address F, together with a bit mask M
+       that specifies which bits must be equal to F. In C code, an address A
+       is faulty if and only if

Documentation/badram.txt line 104

Quoted 10 lines
Documentation/badram.txt +10 -0
+               (F & M) == (A & M)
+       or alternately (closer to a hardware implementation):
+               ~((F ^ A) & M)
+       In the example 32 MB chip, we had the faulty addresses in 8MB-16MB:
+               xxx42f4         ....0100....
+               xxx62f4         ....0110....
+               xxxc2f4         ....1100....
+               xxxe2f4         ....1110....
+       The second column represents the alternating hex digit in binary form.
+       Apperantly, the first and one-but last binary digit can be anything,

Apparently
s/one-but last/next to last/ ?

Documentation/badram.txt line 117

Quoted 13 lines
Documentation/badram.txt +13 -0
+       so the binary mask for that part is 0101. The mask for the part after
+       this is 0xfff, and the part before should select anything in the range
+       8MB-16MB, or 0x00800000-0x01000000; this is done with a bitmask
+       0xff80xxxx. Combining these partial masks, we get:
+               F=0x008042f4    M=0xff805fff
+       That covers everything for this DIMM; for more complicated failing
+       DIMMs, or for a combination of multiple failing DIMMs, it can be
+       necessary to set up a number of such F/M pairs.
+
+Rebooting Linux
+       Now that these patterns are known (and double-checked, the calculations
+       are highly error-prone... it would be neat to test them in the RAM
+       checker...) we simply restart Linux with these F/M pairs as a parameter

End above sentence with period (".").

Documentation/badram.txt line 121

Quoted 4 lines
Documentation/badram.txt +4 -0
+       If you normally boot as follows:
+              LILO: linux
+       you should now boot with
+              LILO: linux badram=0x008042f4,0xff805fff

Does the choice of bootloader matter?

Documentation/badram.txt line 129

Quoted 8 lines
Documentation/badram.txt +8 -0
+       or perhaps by mentioning more F/M pairs in an order F0,M0,F1,M1,...
+       When you provide an odd number of arguments to badram, the default mask
+       0xffffffff (only one address matched) is applied to the pattern.
+
+       Beware of the commandline length. At least up to LILO version 0.21,
+       the commandline is cut off after the 78th character; later versions
+       may go as far as the kernel goes, namely 255 characters. In no way is
+       it possible to enter more than 10 numbers to the badram boot option.

x86 command line length is now 2048.
I don't know if bootloaders can handle that.

Documentation/badram.txt line 135

Quoted 5 lines
Documentation/badram.txt +5 -0
+       When the kernel now boots, it should not give any trouble with RAM.
+       Mind you, this is under the assumption that the kernel and its data
+       storage do not overlap an erroneous part. If this happens, and the
+       kernel does not choke on it right away, it will stop with a panic.
+       You will need to provide a RAM where the initial, say 2MB, is faultless

End with period (".").

Quoted 6 lines
Documentation/badram.txt +6 -0
+
+       Now look up your memory status with
+              dmesg | grep ^Memory:
+       which prints a single line with information like
+               Memory: 158524k/163840k available
+                       (940k kernel code,

Documentation/badram.txt

Quoted 10 lines
Documentation/badram.txt +9 -0
+                       412k reserved,
+                       1856k data,
+                       60k init,
+                       0k highmem,
+                       2048k BadRAM)
 
+Known Bugs
+       LILO is known to cut off commandlines which are too long. For the
+       lilo-0.21 distribution, a commandline may not exceed 78 characters,
+       while actually, 255 would be possible [on x86, kernel 2.2.16].

Ancient kernel alert.

Documentation/badram.txt line 226

Quoted 12 lines
Documentation/badram.txt +12 -0
+       LILO does _not_ report too-long commandlines, but the error will
+       show up as either a panic at boot time, stating
+               panic: BadRAM page in initial area
+       or the dmesg line starting with Memory: will mention an unpredicted
+       number of kilobytes. (Note that the latter number only includes
+       errors in accessed memory.)
+
+Future Possibilities
+       It would be possible to use even more of the faulty RAMs by employing
+       them for slabs. The smaller allocation granularity of slabs makes it
+       possible to throw out just, say, 32 bytes surrounding an error. This
+       would mean that the example DIMM only looses 16kB instead of 2MB.

loses

Quoted 14 lines
Documentation/badram.txt +14 -0
+       It might even be possible to allocate the slabs in such a way that,
+       where possible, the remaining bytes in a slab structure are allocated
+       around the error, reducing the RAM loss to 0 in the optimal situation!
+
+       However, this yield is somewhat faked: It is possible to provide 512
+       pages of 32-byte slabs, but it is not certain that anyone would use
+       that many 32-byte slabs at any time.
+
+       A better solution might be to alter the page allocation for a slab to
+       have a preference for BadRAM pages, and given those a special treatment.
+       This way, the BadRAM would be spread over all the slabs, which seems
+       more likely to be a `true' pay-off. This would yield more overhead at
+       slab allocation time, but on the other hand, by the nature of slabs,
+       such allocations are made as rare as possible, so it might not matter

Documentation/badram.txt line 250

Quoted 10 lines
Documentation/badram.txt +10 -0
+       that much. I am uncertain where to go.
+
+       Many suggestions have been made to insert a RAM checker at boot time;
+       since this would leave the time to do only very meager checking, it
+       is not a reasonable option; we already have a BIOS doing that in most
+       systems!
+
+       It would be interesting to integrate this functionality with the
+       self-verifying nature of ECC RAM. These memories can even distinguish
+       between recorable and unrecoverable errors! Such memory has been

recoverable

Documentation/kernel-parameters.txt and is between 256 and 4096 characters. · line 326

Quoted 13 lines
Documentation/badram.txt +4 -0
+       handled in older operating systems by `testing' once-failed memory
+       blocks for a while, by placing only (reloadable) program code in it.
+       Unfortunately, I possess no faulty ECC modules to work this out.
+

diff -pruN linux-2.6.24.orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt

Documentation/kernel-parameters.txt +1 -0
@@ -322,6 +323,8 @@ and is between 256 and 4096 characters. 
 
 	autotest	[IA64]
 
+	badram=		[BADRAM] Avoid allocating faulty RAM addresses.

See Documentation/badram.txt for parameter details.

Quoted 8 lines
Documentation/kernel-parameters.txt +1 -0
+
 	baycom_epp=	[HW,AX25]
 			Format: <io>,<mode>
 

diff -pruN linux-2.6.24.orig/Documentation/memory.txt linux-2.6.24/Documentation/memory.txt

Documentation/memory.txt systems. · line 25

Quoted 8 lines
Documentation/memory.txt +5 -0
@@ -18,11 +18,22 @@ systems.
 	   as you add more memory.  Consider exchanging your 
            motherboard.
 
+	4) A static discharge or production fault causes a RAM module
+	  to have (predictable) errors, usually meaning that certain
+	  bits cannot be set or reset. Instead of throwing away your
+	  RAM module, you may read /usr/src/linux/Documentation/badram.txt
+	  to learn how to detect, locate and circuimvent such errors

circumvent

include/asm-x86/page_32.h extern int page_is_ram(unsigned long pag · line 192

Quoted 11 lines
Documentation/memory.txt +3 -0
+	  in your RAM module.
+
+

diff -pruN linux-2.6.24.orig/include/asm-x86/page_32.h linux-2.6.24/include/asm-x86/page_32.h

include/asm-x86/page_32.h +1 -0
@@ -189,6 +189,7 @@ extern int page_is_ram(unsigned long pag
 #define pfn_valid(pfn)		((pfn) < max_mapnr)
 #endif /* CONFIG_FLATMEM */
 #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
+#define phys_to_page(x)         pfn_to_page((unsigned long)(x) >> PAGE_SHIFT)

Use tab(s), not spaces.

include/asm-x86/page_64.h extern unsigned long __phys_addr(unsigne · line 129

Quoted 11 lines
include/asm-x86/page_32.h +0 -0
 #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
 

diff -pruN linux-2.6.24.orig/include/asm-x86/page_64.h linux-2.6.24/include/asm-x86/page_64.h

include/asm-x86/page_64.h +1 -0
@@ -126,6 +126,7 @@ extern unsigned long __phys_addr(unsigne
 #endif
 
 #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
+#define phys_to_page(x)         pfn_to_page((unsigned long)(x) >> PAGE_SHIFT)

Ditto.

Quoted 10 lines
include/asm-x86/page_64.h +0 -0
 #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
 #define pfn_to_kaddr(pfn)      __va((pfn) << PAGE_SHIFT)
 

diff -pruN linux-2.6.24.orig/mm/page_alloc.c linux-2.6.24/mm/page_alloc.c

mm/page_alloc.c +0 -0
@@ -4378,6 +4381,91 @@ EXPORT_SYMBOL(pfn_to_page);
 EXPORT_SYMBOL(page_to_pfn);
 #endif /* CONFIG_OUT_OF_LINE_PFN_TO_PAGE */
 

mm/page_alloc.c EXPORT_SYMBOL(pfn_to_page); · line 4393

Quoted 10 lines
mm/page_alloc.c +10 -0
+
+#ifdef CONFIG_BADRAM
+
+
+void __init badram_markpages (int argc, unsigned long *argv) {
+       unsigned long addr, mask;
+       while (argc-- > 0) {
+               addr = *argv++;
+               mask = (argc-- > 0) ? *argv++ : ~0L;
+               mask |= ~PAGE_MASK;     /* Optimalisation */

Optimisation ?

Quoted 10 lines
mm/page_alloc.c +10 -0
+               addr &= mask;           /* Normalisation */
+               do {
+                       struct page *pg = phys_to_page(addr);
+                       printk(KERN_DEBUG "%016lx =%016lx\n",
+                                       addr >> PAGE_SHIFT,
+                                       (unsigned long)(pg-mem_map));
+                       if (PageTestandSetBad (pg))
+                               reserve_bootmem (addr, PAGE_SIZE);
+               } while (next_masked_address (&addr,mask));
+       }

mm/page_alloc.c EXPORT_SYMBOL(pfn_to_page); · line 4413

Quoted 10 lines
mm/page_alloc.c +10 -0
+}
+
+
+
+static int __init badram_setup (char *str)
+{
+       unsigned long opts[3];
+       BUG_ON(!mem_map);
+       printk (KERN_INFO "PAGE_OFFSET=0x%08lx\n", PAGE_OFFSET);
+       printk (KERN_INFO "BadRAM option is %s\n", str);

No space after function name (2x).

mm/page_alloc.c EXPORT_SYMBOL(pfn_to_page); · line 4424

Quoted 11 lines
mm/page_alloc.c +11 -0
+       if (*str++ == '=')
+               while ((str = get_longoptions (str, 3, (long *) opts), *opts)) {
+                       printk (KERN_INFO "   --> marking 0x%08lx, 0x%08lx  [%ld]\n",
+                                       opts[1], opts[2], opts[0]);
+                       badram_markpages (*opts, opts+1);
+                       if (*opts == 1)
+                               break;
+               };
+       badram_markpages (*badram_custom, badram_custom+1);
+       return 0;
+}

---
~Randy

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 6 lines
Quoted 1 line

How is this different from:

	memmap=<size>$<len>

... ?

it's the inverse? When we identify bad areas of RAM, we really want to "punch holes" into the existing memory map. So 'badram=' or 'excludemem=' would be nicer and easier to use.

Or extend 'memmap=' with an inverse parameter: memmap=!0x10000000$1M would exclude a 1MB region at 256MB physical.

My understanding is that the $-form (as opposed to the @-form or #-form) is exactly that:

memmap=nn[KMG]$ss[KMG]
[KNL,ACPI] Mark specific memory as reserved. Region of memory to be used, from ss to ss+nn.

"Reserved" usually means "don't use as either memory or free address space".

-hpa

#20 lore raw
Quoted 18 lines · H. Peter Anvin
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

How is this different from:

	memmap=<size>$<len>
Quoted 9 lines
Quoted 1 line

... ?

it's the inverse? When we identify bad areas of RAM, we really want to "punch holes" into the existing memory map. So 'badram=' or 'excludemem=' would be nicer and easier to use.

Or extend 'memmap=' with an inverse parameter: memmap=!0x10000000$1M would exclude a 1MB region at 256MB physical.

My understanding is that the $-form (as opposed to the @-form or #-form) is exactly that:

Quoted 6 lines

memmap=nn[KMG]$ss[KMG]
[KNL,ACPI] Mark specific memory as reserved. Region of memory to be used, from ss to ss+nn.

"Reserved" usually means "don't use as either memory or free address space".

ah - thanks - didnt know that!

i guess there might still be badram syntax details that might be worth merging, but "memmap=" looks a lot more complete than what i thought it to be.

Ingo