makedumpfile: Add --non-mmap option to disable mmap() manually

This is a backport of the following upstream commit:

commit a895dc8
Author: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Date:   Thu Dec 12 16:40:12 2013 +0900

    [PATCH] Add --non-mmap option to disable mmap() manually.

    When --non-mmap option is specified, makedumpfile doesn't use
    mmap() even if /proc/vmcore supports mmap().

    Signed-off-by: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>

Having this patch, user can switch between mmap() and read() when
accessing vmcore. Whenever user feels necessary to use readmem on vmcore
(buggy code in mmap path, debug purpose, etc.), --non-mmap can do this
favor.

Signed-off-by: WANG Chao <chaowang@redhat.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
WANG Chao 2014-01-07 14:53:59 +08:00
parent 778ab7d0c4
commit 89a4cb24e0
2 changed files with 163 additions and 0 deletions

View File

@ -0,0 +1,161 @@
From a895dc8f2a17f7dac9d3d63de1cea4720557625d Mon Sep 17 00:00:00 2001
From: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Date: Thu, 12 Dec 2013 16:40:12 +0900
Subject: [PATCH 1/2] [PATCH] Add --non-mmap option to disable mmap() manually.
When --non-mmap option is specified, makedumpfile doesn't use
mmap() even if /proc/vmcore supports mmap().
Signed-off-by: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
---
makedumpfile.8 | 11 +++++++++++
makedumpfile.c | 29 +++++++++++++++++++----------
makedumpfile.h | 9 +++++++++
print_info.c | 6 ++++++
4 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/makedumpfile-1.5.4/makedumpfile.8 b/makedumpfile-1.5.4/makedumpfile.8
index f50a011..227b6f7 100644
--- a/makedumpfile-1.5.4/makedumpfile.8
+++ b/makedumpfile-1.5.4/makedumpfile.8
@@ -395,6 +395,17 @@ If you feel the cyclic mode is too slow, please try this mode.
# makedumpfile \-\-non\-cyclic \-d 31 \-x vmlinux /proc/vmcore dumpfile
.TP
+\fB\-\-non\-mmap\fR
+Never use \fBmmap(2)\fR to read \fIVMCORE\fR even if it supports \fBmmap(2)\fR.
+Generally, reading \fIVMCORE\fR with \fBmmap(2)\fR is faster than without it,
+so ordinary users don't need to specify this option.
+This option is mainly for debugging.
+.br
+.B Example:
+.br
+# makedumpfile \-\-non\-mmap \-d 31 \-x vmlinux /proc/vmcore dumpfile
+
+.TP
\fB\-\-xen-syms\fR \fIXEN-SYMS\fR
Specify the \fIXEN-SYMS\fR with debug information to analyze the xen's memory usage.
This option extracts the part of xen and domain-0.
diff --git a/makedumpfile-1.5.4/makedumpfile.c b/makedumpfile-1.5.4/makedumpfile.c
index 600fb5d..b3af28b 100644
--- a/makedumpfile-1.5.4/makedumpfile.c
+++ b/makedumpfile-1.5.4/makedumpfile.c
@@ -272,7 +272,7 @@ update_mmap_range(off_t offset, int initial) {
static int
is_mapped_with_mmap(off_t offset) {
- if (info->flag_usemmap
+ if (info->flag_usemmap == MMAP_ENABLE
&& offset >= info->mmap_start_offset
&& offset < info->mmap_end_offset)
return TRUE;
@@ -320,7 +320,7 @@ read_from_vmcore(off_t offset, void *bufptr, unsigned long size)
{
const off_t failed = (off_t)-1;
- if (info->flag_usemmap) {
+ if (info->flag_usemmap == MMAP_ENABLE) {
if (!read_with_mmap(offset, bufptr, size)) {
ERRMSG("Can't read the dump memory(%s) with mmap().\n",
info->name_memory);
@@ -3175,14 +3175,14 @@ out:
if (info->dump_level & DL_EXCLUDE_FREE)
setup_page_is_buddy();
- if (!initialize_mmap()) {
- /* this kernel does not support mmap of vmcore */
- DEBUG_MSG("Kernel can't mmap vmcore, using reads.\n");
- info->flag_usemmap = FALSE;
+ if (info->flag_usemmap == MMAP_TRY && initialize_mmap()) {
+ DEBUG_MSG("mmap() is available on the kernel.\n");
+ info->flag_usemmap = MMAP_ENABLE;
} else {
- DEBUG_MSG("read %s with mmap()\n", info->name_memory);
- info->flag_usemmap = TRUE;
- }
+ DEBUG_MSG("The kernel doesn't support mmap(),");
+ DEBUG_MSG("read() will be used instead.\n");
+ info->flag_usemmap = MMAP_DISABLE;
+ }
return TRUE;
}
@@ -8947,6 +8947,7 @@ static struct option longopts[] = {
{"non-cyclic", no_argument, NULL, OPT_NON_CYCLIC},
{"cyclic-buffer", required_argument, NULL, OPT_CYCLIC_BUFFER},
{"eppic", required_argument, NULL, OPT_EPPIC},
+ {"non-mmap", no_argument, NULL, OPT_NON_MMAP},
{0, 0, 0, 0}
};
@@ -8972,7 +8973,12 @@ main(int argc, char *argv[])
* By default, makedumpfile works in constant memory space.
*/
info->flag_cyclic = TRUE;
-
+
+ /*
+ * By default, makedumpfile try to use mmap(2) to read /proc/vmcore.
+ */
+ info->flag_usemmap = MMAP_TRY;
+
info->block_order = DEFAULT_ORDER;
message_level = DEFAULT_MSG_LEVEL;
while ((opt = getopt_long(argc, argv, "b:cDd:EFfg:hi:lpRvXx:", longopts,
@@ -9069,6 +9075,9 @@ main(int argc, char *argv[])
case OPT_NON_CYCLIC:
info->flag_cyclic = FALSE;
break;
+ case OPT_NON_MMAP:
+ info->flag_usemmap = MMAP_DISABLE;
+ break;
case OPT_XEN_VMCOREINFO:
info->flag_read_vmcoreinfo = 1;
info->name_vmcoreinfo = optarg;
diff --git a/makedumpfile-1.5.4/makedumpfile.h b/makedumpfile-1.5.4/makedumpfile.h
index 517e16e..fe88eff 100644
--- a/makedumpfile-1.5.4/makedumpfile.h
+++ b/makedumpfile-1.5.4/makedumpfile.h
@@ -128,6 +128,14 @@ enum {
MADDR_XEN
};
+/*
+ * State of mmap(2)
+ */
+enum {
+ MMAP_DISABLE,
+ MMAP_TRY,
+ MMAP_ENABLE,
+};
static inline int
test_bit(int nr, unsigned long addr)
@@ -1741,6 +1749,7 @@ struct elf_prstatus {
#define OPT_NON_CYCLIC OPT_START+10
#define OPT_CYCLIC_BUFFER OPT_START+11
#define OPT_EPPIC OPT_START+12
+#define OPT_NON_MMAP OPT_START+13
/*
* Function Prototype.
diff --git a/makedumpfile-1.5.4/print_info.c b/makedumpfile-1.5.4/print_info.c
index d7a8600..90b6cee 100644
--- a/makedumpfile-1.5.4/print_info.c
+++ b/makedumpfile-1.5.4/print_info.c
@@ -196,6 +196,12 @@ print_usage(void)
MSG(" same as v1.4.4 or before.\n");
MSG(" If you feel the cyclic mode is too slow, please try this mode.\n");
MSG("\n");
+ MSG(" [--non-mmap]:\n");
+ MSG(" Never use mmap(2) to read VMCORE even if it supports mmap(2).\n");
+ MSG(" Generally, reading VMCORE with mmap(2) is faster than without it,\n");
+ MSG(" so ordinary users don't need to specify this option.\n");
+ MSG(" This option is mainly for debugging.\n");
+ MSG("\n");
MSG(" [--xen-syms XEN-SYMS]:\n");
MSG(" Specify the XEN-SYMS to analyze Xen's memory usage.\n");
MSG("\n");
--
1.8.4.2

View File

@ -92,6 +92,7 @@ Patch610: kexec-tools-2.0.4-makedumpfile-cache-Reuse-entry-in-pending-list.patch
Patch612: kexec-tools-2.0.4-makedumpfile-Understand-v3.11-rc4-dmesg.patch Patch612: kexec-tools-2.0.4-makedumpfile-Understand-v3.11-rc4-dmesg.patch
Patch613: kexec-tools-2.0.4-makedumpfile-Assign-non-printable-value-as-short-option.patch Patch613: kexec-tools-2.0.4-makedumpfile-Assign-non-printable-value-as-short-option.patch
Patch614: kexec-tools-2.0.4-makedumpfile-Add-help-and-man-message-for-help.patch Patch614: kexec-tools-2.0.4-makedumpfile-Add-help-and-man-message-for-help.patch
Patch615: kexec-tools-2.0.4-makedumpfile-Add-non-mmap-option-to-disable-mmap-manually.patch
%description %description
kexec-tools provides /sbin/kexec binary that facilitates a new kexec-tools provides /sbin/kexec binary that facilitates a new
@ -137,6 +138,7 @@ tar -z -x -v -f %{SOURCE19}
%patch302 -p1 %patch302 -p1
%patch613 -p1 %patch613 -p1
%patch614 -p1 %patch614 -p1
%patch615 -p1
tar -z -x -v -f %{SOURCE13} tar -z -x -v -f %{SOURCE13}