Opened 4 years ago

Closed 4 months ago

Last modified 4 months ago

#62554 closed enhancement (fixed)

Let ports specify expected memory use per job

Reported by: ryandesign (Ryan Carsten Schmidt) Owned by: jmroot (Joshua Root)
Priority: Normal Milestone: MacPorts 2.10.0
Component: base Version:
Keywords: Cc: cooljeanius (Eric Gallager)
Port:

Description

MacPorts sets the default value of build.jobs via this code from portbuild.tcl:

proc portbuild::build_getjobs {args} {
    global buildmakejobs
    set jobs $buildmakejobs
    # if set to '0', use the number of cores for the number of jobs
    if {$jobs == 0} {
        try -pass_signal {
            set jobs [sysctl hw.activecpu]
        } catch {{*} eCode eMessage} {
            set jobs 2
            ui_warn "failed to determine the number of available CPUs (probably not supported on this platform)"
            ui_warn "defaulting to $jobs jobs, consider setting buildmakejobs to a nonzero value in macports.conf"
        }

        try -pass_signal {
            set memsize [sysctl hw.memsize]
            if {$jobs > $memsize / (1024 * 1024 * 1024) + 1} {
                set jobs [expr {$memsize / (1024 * 1024 * 1024) + 1}]
            }
        } catch {*} {}
    }
    if {![string is integer -strict $jobs] || $jobs <= 1} {
        set jobs 1
    }
    return $jobs
}

In other words it uses the number of active hyperthreaded CPU cores or the amount of RAM in GiB plus one, whichever is less. The assumption is that each job will not need more than about 1 GiB of RAM.

This assumption is wrong for some ports like py-tensorflow. Instead of making those ports recreate the above calculation to arrive at an acceptable number of jobs, let's make the assumption configurable. Introduce a new port option (perhaps build.expected_memory_use_per_job) set to a default value of 1024. Use it in the above calculation and let ports override it so that py-tensorflow could set it to e.g. 2560 instead.

Change History (4)

comment:1 Changed 3 years ago by cooljeanius (Eric Gallager)

Cc: cooljeanius added

comment:2 Changed 4 months ago by jmroot (Joshua Root)

Owner: set to jmroot
Resolution: fixed
Status: newclosed

In 86c02d3b1a4caba0573116954479a7119e4542fb/macports-base (master):

Add build.mem_per_job option

Specifies how many MiB of memory each parallel build job is expected to
use, and is used to limit the default number of build.jobs to avoid
exhausting memory.

Closes: #62554

comment:3 Changed 4 months ago by jmroot (Joshua Root)

Milestone: MacPorts Future

comment:4 Changed 4 months ago by jmroot (Joshua Root)

Milestone: MacPorts FutureMacPorts 2.10.0
Note: See TracTickets for help on using tickets.