Blame SOURCES/kexec-tools-2.0.4-makedumpfile-cache-Allocate-buffers-at-initialization-t.patch

ab224c
From 92563d7a7a5175ef78c4a94ee269b1b455331b4c Mon Sep 17 00:00:00 2001
ab224c
From: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
ab224c
Date: Tue, 17 Sep 2013 15:29:33 +0900
ab224c
Subject: [PATCH] [PATCH 1/2] cache: Allocate buffers at initialization to
ab224c
 detect malloc() failure.
ab224c
ab224c
malloc() is used in cache_alloc() but there's no check for it. If I
ab224c
added check in cache_alloc() directly, cache_alloc() needs to return
ab224c
one more error status and code gets somewhat complicated. Instead, I
ab224c
move malloc() in initial() to detect allocation failure at
ab224c
initialization. By this change, 8 buffers are allocated at the same
ab224c
time, no longer incrementally. However, 8 buffers are almost always
ab224c
used throughout execution. There's essential differnece from the
ab224c
incremental one.
ab224c
ab224c
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
ab224c
---
ab224c
 cache.c        | 29 ++++++++++++++++++++++-------
ab224c
 cache.h        |  1 +
ab224c
 makedumpfile.c |  3 +++
ab224c
 3 files changed, 26 insertions(+), 7 deletions(-)
ab224c
ab224c
diff --git a/makedumpfile-1.5.4/cache.c b/makedumpfile-1.5.4/cache.c
ab224c
index 3bea089..dad8d80 100644
ab224c
--- a/makedumpfile-1.5.4/cache.c
ab224c
+++ b/makedumpfile-1.5.4/cache.c
ab224c
@@ -18,6 +18,7 @@
ab224c
 
ab224c
 #include "makedumpfile.h"
ab224c
 #include "cache.h"
ab224c
+#include "print_info.h"
ab224c
 
ab224c
 struct cache_entry {
ab224c
 	unsigned long long paddr;
ab224c
@@ -36,6 +37,25 @@ static int avail = CACHE_SIZE;
ab224c
 
ab224c
 static struct cache used, pending;
ab224c
 
ab224c
+int
ab224c
+cache_init(void)
ab224c
+{
ab224c
+	void *bufptr;
ab224c
+	int i;
ab224c
+
ab224c
+	for (i = 0; i < CACHE_SIZE; ++i) {
ab224c
+		bufptr = malloc(info->page_size);
ab224c
+		if (bufptr == NULL) {
ab224c
+			ERRMSG("Can't allocate memory for cache. %s\n",
ab224c
+			       strerror(errno));
ab224c
+			return FALSE;
ab224c
+		}
ab224c
+		pool[i].bufptr = bufptr;
ab224c
+	}
ab224c
+
ab224c
+	return TRUE;
ab224c
+}
ab224c
+
ab224c
 static void
ab224c
 add_entry(struct cache *cache, struct cache_entry *entry)
ab224c
 {
ab224c
@@ -83,13 +103,8 @@ cache_alloc(unsigned long long paddr)
ab224c
 {
ab224c
 	struct cache_entry *entry = NULL;
ab224c
 
ab224c
-	if (avail) {
ab224c
-		void *bufptr = malloc(info->page_size);
ab224c
-		if (bufptr) {
ab224c
-			entry = &pool[--avail];
ab224c
-			entry->bufptr = bufptr;
ab224c
-		}
ab224c
-	}
ab224c
+	if (avail)
ab224c
+		entry = &pool[--avail];
ab224c
 
ab224c
 	if (!entry) {
ab224c
 		if (used.tail) {
ab224c
diff --git a/makedumpfile-1.5.4/cache.h b/makedumpfile-1.5.4/cache.h
ab224c
index f37d883..4730e12 100644
ab224c
--- a/makedumpfile-1.5.4/cache.h
ab224c
+++ b/makedumpfile-1.5.4/cache.h
ab224c
@@ -19,6 +19,7 @@
ab224c
 #ifndef _CACHE_H
ab224c
 #define _CACHE_H
ab224c
 
ab224c
+int cache_init(void);
ab224c
 void *cache_search(unsigned long long paddr);
ab224c
 void *cache_alloc(unsigned long long paddr);
ab224c
 void cache_add(unsigned long long paddr);
ab224c
diff --git a/makedumpfile-1.5.4/makedumpfile.c b/makedumpfile-1.5.4/makedumpfile.c
ab224c
index 1718f88..e01ff50 100644
ab224c
--- a/makedumpfile-1.5.4/makedumpfile.c
ab224c
+++ b/makedumpfile-1.5.4/makedumpfile.c
ab224c
@@ -3017,6 +3017,9 @@ out:
ab224c
 		DEBUG_MSG("Buffer size for the cyclic mode: %ld\n", info->bufsize_cyclic);
ab224c
 	}
ab224c
 
ab224c
+	if (!cache_init())
ab224c
+		return FALSE;
ab224c
+
ab224c
 	if (debug_info) {
ab224c
 		if (info->flag_sadump)
ab224c
 			(void) sadump_virt_phys_base();
ab224c
-- 
ab224c
1.8.3.1
ab224c