Skip to content

Commit

Permalink
Speed up the session invocation time of "flattened" format dumpfiles
Browse files Browse the repository at this point in the history
created by the makedumpfile(8) facility.  When sorting the blocks of
memory by their intended ELF or compressed kdump file offsets, the
patch replaces the bubble-sort method that is currently used with an
insertion sort method.
([email protected])
  • Loading branch information
Dave Anderson committed Apr 29, 2015
1 parent 7f3731a commit d304aab
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions makedumpfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ store_flat_data_array(char *file, struct flat_data **fda)
{
int result = FALSE, fd;
int64_t offset_fdh;
int64_t offset_report = 0;
unsigned long long num_allocated = 0;
unsigned long long num_stored = 0;
unsigned long long sort_idx;
unsigned long long size_allocated;
struct flat_data *ptr = NULL, *cur, *new;
struct makedumpfile_data_header fdh;
Expand Down Expand Up @@ -100,11 +102,34 @@ store_flat_data_array(char *file, struct flat_data **fda)
break;
}
cur = ptr + num_stored;
sort_idx = num_stored;
while (sort_idx) {
new = ptr + --sort_idx;
if (new->off_rearranged >= fdh.offset) {
cur->off_flattened = new->off_flattened;
cur->off_rearranged = new->off_rearranged;
cur->buf_size = new->buf_size;
cur = new;
} else {
if (CRASHDEBUG(1) && sort_idx + 1 != num_stored) {
fprintf(fp,
"makedumpfile: Moved from %lld to %lld\n",
num_stored, sort_idx + 1);
}
break;
}
}
cur->off_flattened = offset_fdh + sizeof(fdh);
cur->off_rearranged = fdh.offset;
cur->buf_size = fdh.buf_size;
num_stored++;

if (CRASHDEBUG(1) && (fdh.offset >> 30) > (offset_report >> 30)) {
fprintf(fp, "makedumpfile: At %lld GiB\n",
(ulonglong)(fdh.offset >> 30));
offset_report = fdh.offset;
}

/* seek for next makedumpfile_data_header. */
if (lseek(fd, fdh.buf_size, SEEK_CUR) < 0) {
error(INFO, "%s: seek error (flat format)\n", file);
Expand All @@ -121,35 +146,6 @@ store_flat_data_array(char *file, struct flat_data **fda)
return num_stored;
}

static void
sort_flat_data_array(struct flat_data **fda, unsigned long long num_fda)
{
unsigned long long i, j;
struct flat_data tmp, *cur_i, *cur_j;

for (i = 0; i < num_fda - 1; i++) {
for (j = i + 1; j < num_fda; j++) {
cur_i = *fda + i;
cur_j = *fda + j;

if (cur_i->off_rearranged < cur_j->off_rearranged)
continue;

tmp.off_flattened = cur_i->off_flattened;
tmp.off_rearranged = cur_i->off_rearranged;
tmp.buf_size = cur_i->buf_size;

cur_i->off_flattened = cur_j->off_flattened;
cur_i->off_rearranged = cur_j->off_rearranged;
cur_i->buf_size = cur_j->buf_size;

cur_j->off_flattened = tmp.off_flattened;
cur_j->off_rearranged = tmp.off_rearranged;
cur_j->buf_size = tmp.buf_size;
}
}
}

static int
read_all_makedumpfile_data_header(char *file)
{
Expand All @@ -161,8 +157,6 @@ read_all_makedumpfile_data_header(char *file)
if (retval < 0)
return FALSE;

sort_flat_data_array(&fda, num);

afd.num_array = num;
afd.array = fda;

Expand Down

0 comments on commit d304aab

Please sign in to comment.