OSDN Git Service

mem-prealloc: optimize large guest startup
authorbauerchen <bauerchen@tencent.com>
Tue, 11 Feb 2020 09:10:35 +0000 (17:10 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 25 Feb 2020 08:18:01 +0000 (09:18 +0100)
commit037fb5eb3941c80a2b7c36a843e47207ddb004d4
tree996d02a0c4e3ec1fa92b0ca3838430c48e56edcf
parent920d557e5ae58671d335acbcfba3f9a97a02911c
mem-prealloc: optimize large guest startup

[desc]:
    Large memory VM starts slowly when using -mem-prealloc, and
    there are some areas to optimize in current method;

    1、mmap will be used to alloc threads stack during create page
    clearing threads, and it will attempt mm->mmap_sem for write
    lock, but clearing threads have hold read lock, this competition
    will cause threads createion very slow;

    2、methods of calcuating pages for per threads is not well;if we use
    64 threads to split 160 hugepage,63 threads clear 2page,1 thread
    clear 34 page,so the entire speed is very slow;

    to solve the first problem,we add a mutex in thread function,and
    start all threads when all threads finished createion;
    and the second problem, we spread remainder to other threads,in
    situation that 160 hugepage and 64 threads, there are 32 threads
    clear 3 pages,and 32 threads clear 2 pages.

[test]:
    320G 84c VM start time can be reduced to 10s
    680G 84c VM start time can be reduced to 18s

Signed-off-by: bauerchen <bauerchen@tencent.com>
Reviewed-by: Pan Rui <ruippan@tencent.com>
Reviewed-by: Ivan Ren <ivanren@tencent.com>
[Simplify computation of the number of pages per thread. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
util/oslib-posix.c