GNU make: should the number of jobs equal the number of CPU cores in a system?

后端 未结 10 1086
长情又很酷
长情又很酷 2020-12-07 10:13

There seems to be some controversy on whether the number of jobs in GNU make is supposed to be equal to the number of cores, or if you can optimize the build time by adding

10条回答
  •  天涯浪人
    2020-12-07 10:55

    I just got an Athlon II X2 Regor proc with a Foxconn M/B and 4GB of G-Skill memory.

    I put my 'cat /proc/cpuinfo' and 'free' at the end of this so others can see my specs. It's a dual core Athlon II x2 with 4GB of RAM.

    uname -a on default slackware 14.0 kernel is 3.2.45.
    

    I downloaded the next step kernel source (linux-3.2.46) to /archive4;

    extracted it (tar -xjvf linux-3.2.46.tar.bz2);

    cd'd into the directory (cd linux-3.2.46);

    and copied the default kernel's config over (cp /usr/src/linux/.config .);

    used make oldconfig to prepare the 3.2.46 kernel config;

    then ran make with various incantations of -jX.

    I tested the timings of each run by issuing make after the time command, e.g., 'time make -j2'. Between each run I 'rm -rf' the linux-3.2.46 tree and reextracted it, copied the default /usr/src/linux/.config into the directory, ran make oldconfig and then did my 'make -jX' test again.

    plain "make":

    real    51m47.510s
    user    47m52.228s
    sys     3m44.985s
    bob@Moses:/archive4/linux-3.2.46$
    

    as above but with make -j2

    real    27m3.194s
    user    48m5.135s
    sys     3m39.431s
    bob@Moses:/archive4/linux-3.2.46$
    

    as above but with make -j3

    real    27m30.203s
    user    48m43.821s
    sys     3m42.309s
    bob@Moses:/archive4/linux-3.2.46$
    

    as above but with make -j4

    real    27m32.023s
    user    49m18.328s
    sys     3m43.765s
    bob@Moses:/archive4/linux-3.2.46$
    

    as above but with make -j8

    real    28m28.112s
    user    50m34.445s
    sys     3m49.877s
    bob@Moses:/archive4/linux-3.2.46$
    

    'cat /proc/cpuinfo' yields:

    bob@Moses:/archive4$ cat /proc/cpuinfo
    processor       : 0
    vendor_id       : AuthenticAMD
    cpu family      : 16
    model           : 6
    model name      : AMD Athlon(tm) II X2 270 Processor
    stepping        : 3
    microcode       : 0x10000c8
    cpu MHz         : 3399.957
    cache size      : 1024 KB
    physical id     : 0
    siblings        : 2
    core id         : 0
    cpu cores       : 2
    apicid          : 0
    initial apicid  : 0
    fdiv_bug        : no
    hlt_bug         : no
    f00f_bug        : no
    coma_bug        : no
    fpu             : yes
    fpu_exception   : yes
    cpuid level     : 5
    wp              : yes
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmo
    v pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rd
    tscp lm 3dnowext 3dnow constant_tsc nonstop_tsc extd_apicid pni monitor cx16 p
    opcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowpre
    fetch osvw ibs skinit wdt npt lbrv svm_lock nrip_save
    bogomips        : 6799.91
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 48 bits physical, 48 bits virtual
    power management: ts ttp tm stc 100mhzsteps hwpstate
    
    processor       : 1
    vendor_id       : AuthenticAMD
    cpu family      : 16
    model           : 6
    model name      : AMD Athlon(tm) II X2 270 Processor
    stepping        : 3
    microcode       : 0x10000c8
    cpu MHz         : 3399.957
    cache size      : 1024 KB
    physical id     : 0
    siblings        : 2
    core id         : 1
    cpu cores       : 2
    apicid          : 1
    initial apicid  : 1
    fdiv_bug        : no
    hlt_bug         : no
    f00f_bug        : no
    coma_bug        : no
    fpu             : yes
    fpu_exception   : yes
    cpuid level     : 5
    wp              : yes
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmo
    v pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rd
    tscp lm 3dnowext 3dnow constant_tsc nonstop_tsc extd_apicid pni monitor cx16 p
    opcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowpre
    fetch osvw ibs skinit wdt npt lbrv svm_lock nrip_save
    bogomips        : 6799.94
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 48 bits physical, 48 bits virtual
    power management: ts ttp tm stc 100mhzsteps hwpstate
    

    'free' yields:

    bob@Moses:/archive4$ free
                 total       used       free     shared    buffers     cached
    Mem:       3991304    3834564     156740          0     519220    2515308
    

提交回复
热议问题