Skip to content

Commit df1fd92

Browse files
HuangShijie2024lian-bo
authored andcommitted
diskdump: Optimize the boot time
1.) The vmcore file maybe very big. For example, I have a vmcore file which is over 23G, and the panic kernel had 767.6G memory, its max_sect_len is 4468736. Current code costs too much time to do the following loop: .............................................. for (i = 1; i < max_sect_len + 1; i++) { dd->valid_pages[i] = dd->valid_pages[i - 1]; for (j = 0; j < BITMAP_SECT_LEN; j++, pfn++) if (page_is_dumpable(pfn)) dd->valid_pages[i]++; .............................................. For my case, it costs about 56 seconds to finish the big loop. This patch moves the hweightXX macros to defs.h, and uses hweight64 to optimize the loop. For my vmcore, the loop only costs about one second now. 2.) Tests result: # cat ./commands.txt quit Before: #echo 3 > /proc/sys/vm/drop_caches; #time ./crash -i ./commands.txt /root/t/vmlinux /root/t/vmcore > /dev/null 2>&1 ............................ real 1m54.259s user 1m12.494s sys 0m3.857s ............................ After this patch: #echo 3 > /proc/sys/vm/drop_caches; #time ./crash -i ./commands.txt /root/t/vmlinux /root/t/vmcore > /dev/null 2>&1 ............................ real 0m55.217s user 0m15.114s sys 0m3.560s ............................ Signed-off-by: Huang Shijie <[email protected]>
1 parent bf24b45 commit df1fd92

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

defs.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4531,6 +4531,26 @@ struct machine_specific {
45314531
#define NUM_IN_BITMAP(bitmap, x) (bitmap[(x)/BITS_PER_LONG] & NUM_TO_BIT(x))
45324532
#define SET_BIT(bitmap, x) (bitmap[(x)/BITS_PER_LONG] |= NUM_TO_BIT(x))
45334533

4534+
static inline unsigned int __const_hweight8(unsigned long w)
4535+
{
4536+
return
4537+
(!!((w) & (1ULL << 0))) +
4538+
(!!((w) & (1ULL << 1))) +
4539+
(!!((w) & (1ULL << 2))) +
4540+
(!!((w) & (1ULL << 3))) +
4541+
(!!((w) & (1ULL << 4))) +
4542+
(!!((w) & (1ULL << 5))) +
4543+
(!!((w) & (1ULL << 6))) +
4544+
(!!((w) & (1ULL << 7)));
4545+
}
4546+
4547+
#define __const_hweight16(w) (__const_hweight8(w) + __const_hweight8((w) >> 8))
4548+
#define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))
4549+
#define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32))
4550+
4551+
#define hweight32(w) __const_hweight32(w)
4552+
#define hweight64(w) __const_hweight64(w)
4553+
45344554
/*
45354555
* precision lengths for fprintf
45364556
*/

diskdump.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ read_dump_header(char *file)
544544
ulong pfn;
545545
int i, j, max_sect_len;
546546
int is_split = 0;
547+
ulonglong tmp, *bitmap;
547548

548549
if (block_size < 0)
549550
return FALSE;
@@ -885,11 +886,16 @@ read_dump_header(char *file)
885886

886887
dd->valid_pages = calloc(sizeof(ulong), max_sect_len + 1);
887888
dd->max_sect_len = max_sect_len;
889+
890+
/* It is safe to convert it to (ulonglong *). */
891+
bitmap = (ulonglong *)dd->dumpable_bitmap;
888892
for (i = 1; i < max_sect_len + 1; i++) {
889893
dd->valid_pages[i] = dd->valid_pages[i - 1];
890-
for (j = 0; j < BITMAP_SECT_LEN; j++, pfn++)
891-
if (page_is_dumpable(pfn))
892-
dd->valid_pages[i]++;
894+
for (j = 0; j < BITMAP_SECT_LEN; j += 64, pfn += 64) {
895+
tmp = bitmap[pfn >> 6];
896+
if (tmp)
897+
dd->valid_pages[i] += hweight64(tmp);
898+
}
893899
}
894900

895901
return TRUE;

sbitmap.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,6 @@ struct sbitmapq_data {
4949

5050
static uint sb_flags = 0;
5151

52-
static inline unsigned int __const_hweight8(unsigned long w)
53-
{
54-
return
55-
(!!((w) & (1ULL << 0))) +
56-
(!!((w) & (1ULL << 1))) +
57-
(!!((w) & (1ULL << 2))) +
58-
(!!((w) & (1ULL << 3))) +
59-
(!!((w) & (1ULL << 4))) +
60-
(!!((w) & (1ULL << 5))) +
61-
(!!((w) & (1ULL << 6))) +
62-
(!!((w) & (1ULL << 7)));
63-
}
64-
65-
#define __const_hweight16(w) (__const_hweight8(w) + __const_hweight8((w) >> 8))
66-
#define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))
67-
#define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32))
68-
69-
#define hweight32(w) __const_hweight32(w)
70-
#define hweight64(w) __const_hweight64(w)
7152

7253
#define BIT(nr) (1UL << (nr))
7354

0 commit comments

Comments
 (0)