From: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
To: kumagai-atsushi@mxc.nes.nec.co.jp
Cc: kexec@lists.infradead.org, ptesarik@suse.cz
Subject: [PATCH 1/2] cache: allocate buffers at initialization to detect malloc() failure
Date: Tue, 17 Sep 2013 15:29:33 +0900 [thread overview]
Message-ID: <20130917062933.4671.99911.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20130917062606.4671.40617.stgit@localhost6.localdomain6>
malloc() is used in cache_alloc() but there's no check for it. If I
added check in cache_alloc() directly, cache_alloc() needs to return
one more error status and code gets somewhat complicated. Instead, I
move malloc() in initial() to detect allocation failure at
initialization. By this change, 8 buffers are allocated at the same
time, no longer incrementally. However, 8 buffers are almost always
used throughout execution. There's essential differnece from the
incremental one.
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
---
cache.c | 29 ++++++++++++++++++++++-------
cache.h | 1 +
makedumpfile.c | 3 +++
3 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/cache.c b/cache.c
index 3bea089..dad8d80 100644
--- a/cache.c
+++ b/cache.c
@@ -18,6 +18,7 @@
#include "makedumpfile.h"
#include "cache.h"
+#include "print_info.h"
struct cache_entry {
unsigned long long paddr;
@@ -36,6 +37,25 @@ static int avail = CACHE_SIZE;
static struct cache used, pending;
+int
+cache_init(void)
+{
+ void *bufptr;
+ int i;
+
+ for (i = 0; i < CACHE_SIZE; ++i) {
+ bufptr = malloc(info->page_size);
+ if (bufptr == NULL) {
+ ERRMSG("Can't allocate memory for cache. %s\n",
+ strerror(errno));
+ return FALSE;
+ }
+ pool[i].bufptr = bufptr;
+ }
+
+ return TRUE;
+}
+
static void
add_entry(struct cache *cache, struct cache_entry *entry)
{
@@ -83,13 +103,8 @@ cache_alloc(unsigned long long paddr)
{
struct cache_entry *entry = NULL;
- if (avail) {
- void *bufptr = malloc(info->page_size);
- if (bufptr) {
- entry = &pool[--avail];
- entry->bufptr = bufptr;
- }
- }
+ if (avail)
+ entry = &pool[--avail];
if (!entry) {
if (used.tail) {
diff --git a/cache.h b/cache.h
index f37d883..4730e12 100644
--- a/cache.h
+++ b/cache.h
@@ -19,6 +19,7 @@
#ifndef _CACHE_H
#define _CACHE_H
+int cache_init(void);
void *cache_search(unsigned long long paddr);
void *cache_alloc(unsigned long long paddr);
void cache_add(unsigned long long paddr);
diff --git a/makedumpfile.c b/makedumpfile.c
index 1718f88..e01ff50 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -3017,6 +3017,9 @@ out:
DEBUG_MSG("Buffer size for the cyclic mode: %ld\n", info->bufsize_cyclic);
}
+ if (!cache_init())
+ return FALSE;
+
if (debug_info) {
if (info->flag_sadump)
(void) sadump_virt_phys_base();
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2013-09-17 6:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-17 6:29 [PATCH 0/2] cache: fix cache logic not go into invalid state HATAYAMA Daisuke
2013-09-17 6:29 ` HATAYAMA Daisuke [this message]
2013-09-17 6:29 ` [PATCH 2/2] cache: reuse entry in pending list HATAYAMA Daisuke
2013-09-19 0:53 ` [PATCH 0/2] cache: fix cache logic not go into invalid state HATAYAMA Daisuke
2013-09-19 8:18 ` Atsushi Kumagai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130917062933.4671.99911.stgit@localhost6.localdomain6 \
--to=d.hatayama@jp.fujitsu.com \
--cc=kexec@lists.infradead.org \
--cc=kumagai-atsushi@mxc.nes.nec.co.jp \
--cc=ptesarik@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox