为什么`dd`映射200M的虚拟地址空间?

为什么`dd`映射200M的虚拟地址空间?
  1. sudo atop -R
  2. dd if=/dev/zero of=/dev/null # in a background tab

在 中atop,键入m内存详细信息。键入/dd要搜索的dd.结果:

PID TID MINFLT MAJFLT VSTEXT VSLIBS VDATA VSTACK VSIZE RSIZE PSIZE VGROW RGROW SWAPSZ RUID EUID MEM CMD 1/1
...
29041 - 93 0 56K 1456K 176K 136K 210.0M 832K 255K 210.0M 832K 0K alan-sys alan-sys 0% dd

让我们把这些列删减到我最好奇的部分:

PID VSTEXT VSLIBS VDATA VSTACK VSIZE RSIZE PSIZE VGROW RGROW SWAPSZ
...
29041 56K 1456K 176K 136K 210.0M 832K 255K 210.0M 832K 0K

这个210M VSIZE有什么用?


$ rpm -q --whatprovides $(which dd)
coreutils-8.30-6.fc29.x86_64

答案1

这不是堆内存分配。它是区域设置信息的虚拟映射文件。映射的文件是/usr/lib/locale/locale-archive.它归包所有glibc-all-langpacks。即,这可能是不同语言的消息文件。

$ gdb dd
...
(gdb) break main
Breakpoint 1 at 0x29c0: file ../src/dd.c, line 2380.
(gdb) run if=/dev/zero of=/dev/null
Starting program: /usr/bin/dd if=/dev/zero of=/dev/null
warning: Loadable section ".note.gnu.property" outside of ELF segments

Breakpoint 1, main (argc=3, argv=0x7fffffffd3b8) at ../src/dd.c:2380
2380    {
(gdb)  break mmap
Breakpoint 2 at 0x7ffff7ecd070: file ../sysdeps/unix/sysv/linux/mmap64.c, line 41.
(gdb) cont
Continuing.

Breakpoint 2, __GI___mmap64 (addr=addr@entry=0x0, len=len@entry=217742304, prot=prot@entry=1, flags=flags@entry=2, fd=fd@entry=3, 
    offset=offset@entry=0) at ../sysdeps/unix/sysv/linux/mmap64.c:41
41  {
(gdb) break munmap
Breakpoint 3 at 0x7ffff7ecd150: file ../sysdeps/unix/syscall-template.S, line 78.
(gdb) cont
Continuing.
^C
Program received signal SIGINT, Interrupt.
(gdb) info proc mappings
process 30592
Mapped address spaces:

          Start Addr           End Addr       Size     Offset objfile
      0x555555554000     0x555555556000     0x2000        0x0 /usr/bin/dd
      0x555555556000     0x555555562000     0xc000     0x2000 /usr/bin/dd
      0x555555562000     0x555555567000     0x5000     0xe000 /usr/bin/dd
      0x555555567000     0x555555568000     0x1000    0x12000 /usr/bin/dd
      0x555555568000     0x555555569000     0x1000    0x13000 /usr/bin/dd
      0x555555569000     0x55555558a000    0x21000        0x0 [heap]
      0x7fffeae2d000     0x7ffff7dd5000  0xcfa8000        0x0 /usr/lib/locale/locale-archive
...
(gdb) exit

相关内容