Skip to content

Commit 997c136

Browse files
olafheringtorvalds
authored andcommitted
fs/proc/vmcore.c: add hook to read_from_oldmem() to check for non-ram pages
The balloon driver in a Xen guest frees guest pages and marks them as mmio. When the kernel crashes and the crash kernel attempts to read the oldmem via /proc/vmcore a read from ballooned pages will generate 100% load in dom0 because Xen asks qemu-dm for the page content. Since the reads come in as 8byte requests each ballooned page is tried 512 times. With this change a hook can be registered which checks wether the given pfn is really ram. The hook has to return a value > 0 for ram pages, a value < 0 on error (because the hypercall is not known) and 0 for non-ram pages. This will reduce the time to read /proc/vmcore. Without this change a 512M guest with 128M crashkernel region needs 200 seconds to read it, with this change it takes just 2 seconds. Signed-off-by: Olaf Hering <olaf@aepfle.de> Cc: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 98bc93e commit 997c136

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

fs/proc/vmcore.c

+49-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,46 @@ static u64 vmcore_size;
3535

3636
static struct proc_dir_entry *proc_vmcore = NULL;
3737

38+
/*
39+
* Returns > 0 for RAM pages, 0 for non-RAM pages, < 0 on error
40+
* The called function has to take care of module refcounting.
41+
*/
42+
static int (*oldmem_pfn_is_ram)(unsigned long pfn);
43+
44+
int register_oldmem_pfn_is_ram(int (*fn)(unsigned long pfn))
45+
{
46+
if (oldmem_pfn_is_ram)
47+
return -EBUSY;
48+
oldmem_pfn_is_ram = fn;
49+
return 0;
50+
}
51+
EXPORT_SYMBOL_GPL(register_oldmem_pfn_is_ram);
52+
53+
void unregister_oldmem_pfn_is_ram(void)
54+
{
55+
oldmem_pfn_is_ram = NULL;
56+
wmb();
57+
}
58+
EXPORT_SYMBOL_GPL(unregister_oldmem_pfn_is_ram);
59+
60+
static int pfn_is_ram(unsigned long pfn)
61+
{
62+
int (*fn)(unsigned long pfn);
63+
/* pfn is ram unless fn() checks pagetype */
64+
int ret = 1;
65+
66+
/*
67+
* Ask hypervisor if the pfn is really ram.
68+
* A ballooned page contains no data and reading from such a page
69+
* will cause high load in the hypervisor.
70+
*/
71+
fn = oldmem_pfn_is_ram;
72+
if (fn)
73+
ret = fn(pfn);
74+
75+
return ret;
76+
}
77+
3878
/* Reads a page from the oldmem device from given offset. */
3979
static ssize_t read_from_oldmem(char *buf, size_t count,
4080
u64 *ppos, int userbuf)
@@ -55,9 +95,15 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
5595
else
5696
nr_bytes = count;
5797

58-
tmp = copy_oldmem_page(pfn, buf, nr_bytes, offset, userbuf);
59-
if (tmp < 0)
60-
return tmp;
98+
/* If pfn is not ram, return zeros for sparse dump files */
99+
if (pfn_is_ram(pfn) == 0)
100+
memset(buf, 0, nr_bytes);
101+
else {
102+
tmp = copy_oldmem_page(pfn, buf, nr_bytes,
103+
offset, userbuf);
104+
if (tmp < 0)
105+
return tmp;
106+
}
61107
*ppos += nr_bytes;
62108
count -= nr_bytes;
63109
buf += nr_bytes;

include/linux/crash_dump.h

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ static inline void vmcore_unusable(void)
6666
if (is_kdump_kernel())
6767
elfcorehdr_addr = ELFCORE_ADDR_ERR;
6868
}
69+
70+
#define HAVE_OLDMEM_PFN_IS_RAM 1
71+
extern int register_oldmem_pfn_is_ram(int (*fn)(unsigned long pfn));
72+
extern void unregister_oldmem_pfn_is_ram(void);
73+
6974
#else /* !CONFIG_CRASH_DUMP */
7075
static inline int is_kdump_kernel(void) { return 0; }
7176
#endif /* CONFIG_CRASH_DUMP */

0 commit comments

Comments
 (0)