[PATCH resend] ramdisk: fix zeroed ramdisk pages on memory pressure



Andrew, this is a resend of a bugfix patch. Ramdisk seems a bit unmaintained,
so decided to sent the patch to you :-).
I have CCed Ted, who did work on the code in the 90s. I found no current
email address of Chad Page.

We have seen ramdisk based install systems, where some pages of mapped
libraries and programs were suddendly zeroed under memory pressure. This
should not happen, as the ramdisk avoids freeing its pages by keeping them
dirty all the time.

It turns out that there is a case, where the VM makes a ramdisk page clean,
without telling the ramdisk driver.
On memory pressure shrink_zone runs and it starts to run shrink_active_list.
There is a check for buffer_heads_over_limit, and if true, pagevec_strip is
called. pagevec_strip calls try_to_release_page. If the mapping has no
releasepage callback, try_to_free_buffers is called. try_to_free_buffers has
now a special logic for some file systems to make a dirty page clean, if all
buffers are clean. Thats what happened in our test case.

The solution is to provide a noop-releasepage callback for the ramdisk driver.
This avoids try_to_free_buffers for ramdisk pages.

To trigger the problem, you have to make buffer_heads_over_limit true, which
means:
- lower max_buffer_heads
or
- have a system with lots of high memory

Andrew, if there are no objections - please apply. The patch applies against
todays git.

Signed-off-by: Christian Borntraeger <borntraeger@xxxxxxxxxx>

---
drivers/block/rd.c | 13 +++++++++++++
1 files changed, 13 insertions(+)

Index: linux-2.6/drivers/block/rd.c
===================================================================
--- linux-2.6.orig/drivers/block/rd.c
+++ linux-2.6/drivers/block/rd.c
@@ -189,6 +189,18 @@ static int ramdisk_set_page_dirty(struct
return 0;
}

+/*
+ * releasepage is called by pagevec_strip/try_to_release_page if
+ * buffers_heads_over_limit is true. Without a releasepage function
+ * try_to_free_buffers is called instead. That can unset the dirty
+ * bit of our ram disk pages, which will be eventually freed, even
+ * if the page is still in use.
+ */
+static int ramdisk_releasepage(struct page *page, gfp_t dummy)
+{
+ return 0;
+}
+
static const struct address_space_operations ramdisk_aops = {
.readpage = ramdisk_readpage,
.prepare_write = ramdisk_prepare_write,
@@ -196,6 +208,7 @@ static const struct address_space_operat
.writepage = ramdisk_writepage,
.set_page_dirty = ramdisk_set_page_dirty,
.writepages = ramdisk_writepages,
+ .releasepage = ramdisk_releasepage,
};

static int rd_blkdev_pagecache_IO(int rw, struct bio_vec *vec, sector_t sector,
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • [PATCH 2.4] Use "sym53c8xx_2" as proc_name
    ... A month or so ago I wrote a patch against 2.6 that changed the proc_name ... module is inserted into the ramdisk. ... * Simple Wrapper to kernel PCI bus interface. ... To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: [PATCH 1/2] x86 boot: add E820_RESVD_KERN
    ... can you have setup_data and ebda at the same time? ... setup_data and ramdisk should be ok, ... the more sanity checks we do before relying on some crutial data, ... Which git-x86 head should I use to test the patch? ...
    (Linux-Kernel)
  • Re: [PATCH 1/2] x86 boot: add E820_RESVD_KERN
    ... can you have setup_data and ebda at the same time? ... setup_data and ramdisk should be ok, ... the more sanity checks we do before relying on some crutial data, ... Which git-x86 head should I use to test the patch? ...
    (Linux-Kernel)
  • Re: Initrd - cramfs image is not being recognized by 2.4.20 kernel
    ... >> I have a kernel built from kernel.org source. ... >> support for ramdisk, initial ramdisk, and cramfs. ... Is there not a specific patch for this in the Debian kernels? ...
    (Debian-User)
  • Re: [PATCH resend2] rd: fix data corruption on memory pressure
    ... we now have passed rc1. ... That means that Erics or Nicks rd rewrite is no ... We have seen ramdisk based install systems, ... It turns out that there is a case, where the VM makes a ramdisk page clean, ...
    (Linux-Kernel)