Linker performance related to swap space?

后端 未结 3 1461
鱼传尺愫
鱼传尺愫 2021-02-02 06:34

Sometimes it\'s handy to mock up something with a little C program that uses a big chunk of static memory. I noticed after changing to Fedora 15 the program took a long

3条回答
  •  长发绾君心
    2021-02-02 06:47

    I don't observe this behavior (with Debian/Sid/AMD64 on a 8Gb desktop, gcc 4.6.2, binutils gold ld (GNU Binutils for Debian 2.22) 1.11). Here is the changed program (displaying its memory map with pmap).

    #include 
    #include 
    #include 
    #define M 1000000
    #define GIANT_SIZE (2000*M)
    size_t g_arr[GIANT_SIZE];
    int main( int argc, char **argv){   
      int i;
      char cmd[80];
      for(i = 0; i<10; i++){
          printf("This should be zero: %d\n",g_arr[i*1000]);
      }
      sprintf (cmd, "pmap %d", (int)getpid());
      system(cmd);
      exit(0);
    }
    

    Here is its compilation:

    % time gcc -v -O big.c -o big
    Using built-in specs.
    COLLECT_GCC=/usr/bin/gcc-4.6.real
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.2-4' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
    Thread model: posix
    gcc version 4.6.2 (Debian 4.6.2-4) 
    COLLECT_GCC_OPTIONS='-v' '-O' '-o' 'big' '-mtune=generic' '-march=x86-64'
     /usr/lib/gcc/x86_64-linux-gnu/4.6/cc1 -quiet -v -imultilib . -imultiarch x86_64-linux-gnu big.c -quiet -dumpbase big.c -mtune=generic -march=x86-64 -auxbase big -O -version -o /tmp/ccWThBP5.s
    GNU C (Debian 4.6.2-4) version 4.6.2 (x86_64-linux-gnu)
        compiled by GNU C version 4.6.2, GMP version 5.0.2, MPFR version 3.1.0, MPC version 0.9
    warning: MPFR header version 3.1.0 differs from library version 3.1.0-p3.
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
    ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/include"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/lib/gcc/x86_64-linux-gnu/4.6/include
     /usr/local/include
     /usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
     /usr/include/x86_64-linux-gnu
     /usr/include
    End of search list.
    GNU C (Debian 4.6.2-4) version 4.6.2 (x86_64-linux-gnu)
        compiled by GNU C version 4.6.2, GMP version 5.0.2, MPFR version 3.1.0, MPC version 0.9
    warning: MPFR header version 3.1.0 differs from library version 3.1.0-p3.
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    Compiler executable checksum: 4b128876859f8f310615c7040fa3cb67
    COLLECT_GCC_OPTIONS='-v' '-O' '-o' 'big' '-mtune=generic' '-march=x86-64'
     as --64 -o /tmp/ccm7905b.o /tmp/ccWThBP5.s
    COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/
    LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../:/lib/:/usr/lib/
    COLLECT_GCC_OPTIONS='-v' '-O' '-o' 'big' '-mtune=generic' '-march=x86-64'
     /usr/lib/gcc/x86_64-linux-gnu/4.6/collect2 --build-id --no-add-needed --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o big /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. /tmp/ccm7905b.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o
    gcc -v -O big.c -o big  0.07s user 0.01s system 90% cpu 0.089 total
    

    and its execution:

      % time ./big
     This should be zero: 0
     This should be zero: 0
     This should be zero: 0
     This should be zero: 0
     This should be zero: 0
     This should be zero: 0
     This should be zero: 0
     This should be zero: 0
     This should be zero: 0
     This should be zero: 0
     8835:   ./big
     0000000000400000      4K r-x--  /home/basile/tmp/big
     0000000000401000      4K rw---  /home/basile/tmp/big
     0000000000402000 15625000K rw---    [ anon ]
     00007f2d15a44000   1512K r-x--  /lib/x86_64-linux-gnu/libc-2.13.so
     00007f2d15bbe000   2048K -----  /lib/x86_64-linux-gnu/libc-2.13.so
     00007f2d15dbe000     16K r----  /lib/x86_64-linux-gnu/libc-2.13.so
     00007f2d15dc2000      4K rw---  /lib/x86_64-linux-gnu/libc-2.13.so
     00007f2d15dc3000     20K rw---    [ anon ]
     00007f2d15dc8000    124K r-x--  /lib/x86_64-linux-gnu/ld-2.13.so
     00007f2d15fb4000     12K rw---    [ anon ]
     00007f2d15fe4000     12K rw---    [ anon ]
     00007f2d15fe7000      4K r----  /lib/x86_64-linux-gnu/ld-2.13.so
     00007f2d15fe8000      4K rw---  /lib/x86_64-linux-gnu/ld-2.13.so
     00007f2d15fe9000      4K rw---    [ anon ]
     00007ffff5b5b000    132K rw---    [ stack ]
     00007ffff5bff000      4K r-x--    [ anon ]
     ffffffffff600000      4K r-x--    [ anon ]
      total         15628908K
     ./big  0.00s user 0.00s system 0% cpu 0.004 total
    

    I believe that installing a recent GCC (e.g. a GCC 4.6) with a binutils Gold linker is significant for such programs.

    I don't hear any swapping involved.

提交回复
热议问题