mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
linux-user: Do not align brk with host page size
do_brk() minimizes calls into target_mmap() by aligning the address
with host page size, which is potentially larger than the target page
size. However, the current implementation of this optimization has two
bugs:
- The start of brk is rounded up with the host page size while brk
advertises an address aligned with the target page size as the
beginning of brk. This makes the beginning of brk unmapped.
- Content clearing after mapping is flawed. The size to clear is
specified as HOST_PAGE_ALIGN(brk_page) - brk_page, but brk_page is
aligned with the host page size so it is always zero.
This optimization actually has no practical benefit. It makes difference
when brk() is called multiple times with values in a range of the host
page size. However, sophisticated memory allocators try to avoid to
make such frequent brk() calls. For example, glibc 2.37 calls brk() to
shrink the heap only when there is a room more than 128 KiB. It is
rare to have a page size larger than 128 KiB if it happens.
Let's remove the optimization to fix the bugs and make the code simpler.
Fixes: 86f04735ac
("linux-user: Fix brk() to release pages")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1616
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-Id: <20230802071754.14876-7-akihiko.odaki@daynix.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
cb9d5d1fda
commit
2aea137a42
2 changed files with 14 additions and 44 deletions
|
@ -3679,8 +3679,8 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
|
|||
* to mmap pages in this space.
|
||||
*/
|
||||
if (info->reserve_brk) {
|
||||
abi_ulong start_brk = HOST_PAGE_ALIGN(info->brk);
|
||||
abi_ulong end_brk = HOST_PAGE_ALIGN(info->brk + info->reserve_brk);
|
||||
abi_ulong start_brk = TARGET_PAGE_ALIGN(info->brk);
|
||||
abi_ulong end_brk = TARGET_PAGE_ALIGN(info->brk + info->reserve_brk);
|
||||
target_munmap(start_brk, end_brk - start_brk);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue