mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-01 00:58:39 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									98bc93e505
								
							
						
					
					
						commit
						997c136f51
					
				
					 2 changed files with 54 additions and 3 deletions
				
			
		|  | @ -35,6 +35,46 @@ static u64 vmcore_size; | ||||||
| 
 | 
 | ||||||
| static struct proc_dir_entry *proc_vmcore = NULL; | static struct proc_dir_entry *proc_vmcore = NULL; | ||||||
| 
 | 
 | ||||||
|  | /*
 | ||||||
|  |  * Returns > 0 for RAM pages, 0 for non-RAM pages, < 0 on error | ||||||
|  |  * The called function has to take care of module refcounting. | ||||||
|  |  */ | ||||||
|  | static int (*oldmem_pfn_is_ram)(unsigned long pfn); | ||||||
|  | 
 | ||||||
|  | int register_oldmem_pfn_is_ram(int (*fn)(unsigned long pfn)) | ||||||
|  | { | ||||||
|  | 	if (oldmem_pfn_is_ram) | ||||||
|  | 		return -EBUSY; | ||||||
|  | 	oldmem_pfn_is_ram = fn; | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  | EXPORT_SYMBOL_GPL(register_oldmem_pfn_is_ram); | ||||||
|  | 
 | ||||||
|  | void unregister_oldmem_pfn_is_ram(void) | ||||||
|  | { | ||||||
|  | 	oldmem_pfn_is_ram = NULL; | ||||||
|  | 	wmb(); | ||||||
|  | } | ||||||
|  | EXPORT_SYMBOL_GPL(unregister_oldmem_pfn_is_ram); | ||||||
|  | 
 | ||||||
|  | static int pfn_is_ram(unsigned long pfn) | ||||||
|  | { | ||||||
|  | 	int (*fn)(unsigned long pfn); | ||||||
|  | 	/* pfn is ram unless fn() checks pagetype */ | ||||||
|  | 	int ret = 1; | ||||||
|  | 
 | ||||||
|  | 	/*
 | ||||||
|  | 	 * Ask hypervisor if the pfn is really ram. | ||||||
|  | 	 * A ballooned page contains no data and reading from such a page | ||||||
|  | 	 * will cause high load in the hypervisor. | ||||||
|  | 	 */ | ||||||
|  | 	fn = oldmem_pfn_is_ram; | ||||||
|  | 	if (fn) | ||||||
|  | 		ret = fn(pfn); | ||||||
|  | 
 | ||||||
|  | 	return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /* Reads a page from the oldmem device from given offset. */ | /* Reads a page from the oldmem device from given offset. */ | ||||||
| static ssize_t read_from_oldmem(char *buf, size_t count, | static ssize_t read_from_oldmem(char *buf, size_t count, | ||||||
| 				u64 *ppos, int userbuf) | 				u64 *ppos, int userbuf) | ||||||
|  | @ -55,9 +95,15 @@ static ssize_t read_from_oldmem(char *buf, size_t count, | ||||||
| 		else | 		else | ||||||
| 			nr_bytes = count; | 			nr_bytes = count; | ||||||
| 
 | 
 | ||||||
| 		tmp = copy_oldmem_page(pfn, buf, nr_bytes, offset, userbuf); | 		/* If pfn is not ram, return zeros for sparse dump files */ | ||||||
| 		if (tmp < 0) | 		if (pfn_is_ram(pfn) == 0) | ||||||
| 			return tmp; | 			memset(buf, 0, nr_bytes); | ||||||
|  | 		else { | ||||||
|  | 			tmp = copy_oldmem_page(pfn, buf, nr_bytes, | ||||||
|  | 						offset, userbuf); | ||||||
|  | 			if (tmp < 0) | ||||||
|  | 				return tmp; | ||||||
|  | 		} | ||||||
| 		*ppos += nr_bytes; | 		*ppos += nr_bytes; | ||||||
| 		count -= nr_bytes; | 		count -= nr_bytes; | ||||||
| 		buf += nr_bytes; | 		buf += nr_bytes; | ||||||
|  |  | ||||||
|  | @ -66,6 +66,11 @@ static inline void vmcore_unusable(void) | ||||||
| 	if (is_kdump_kernel()) | 	if (is_kdump_kernel()) | ||||||
| 		elfcorehdr_addr = ELFCORE_ADDR_ERR; | 		elfcorehdr_addr = ELFCORE_ADDR_ERR; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | #define HAVE_OLDMEM_PFN_IS_RAM 1 | ||||||
|  | extern int register_oldmem_pfn_is_ram(int (*fn)(unsigned long pfn)); | ||||||
|  | extern void unregister_oldmem_pfn_is_ram(void); | ||||||
|  | 
 | ||||||
| #else /* !CONFIG_CRASH_DUMP */ | #else /* !CONFIG_CRASH_DUMP */ | ||||||
| static inline int is_kdump_kernel(void) { return 0; } | static inline int is_kdump_kernel(void) { return 0; } | ||||||
| #endif /* CONFIG_CRASH_DUMP */ | #endif /* CONFIG_CRASH_DUMP */ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Olaf Hering
						Olaf Hering