mm/vmpressure.c

1,

What is vmpressure level?

The levels are defined like this: The "low" level means that the system is reclaiming memory for new allocations. Monitoring this reclaiming activity might be useful for maintaining cache level. Upon notification, the program (typically "Activity Manager") might analyze vmstat and act in advance (i.e. prematurely shutdown unimportant services).

The "medium" level means that the system is experiencing medium memory pressure, the system might be making swap, paging out active file caches, etc. Upon this event applications may decide to further analyze vmstat/zoneinfo/memcg or internal memory usage statistics and free any resources that can be easily reconstructed or re-read from a disk.

The "critical" level means that the system is actively thrashing, it is about to out of memory (OOM) or even the in-kernel OOM killer is on its way to trigger. Applications should do whatever they can to help the system. It might be too late to consult with vmstat or any other statistics, so it's advisable to take an immediate action.

2,

static struct vmpressure global_vmpressure;

static unsigned long vmpressure_win = SWAP_CLUSTER_MAX * 16;

crash64> p vmpressure_win

vmpressure_win = $1 = 512

crash64> p global_vmpressure

global_vmpressure = $2 = {

scanned = 0,

reclaimed = 0,

void vmpressure_global(gfp_t gfp, unsigned long scanned,
                unsigned long reclaimed)
{
        struct vmpressure *vmpr = &global_vmpressure;
        unsigned long pressure;
...

        vmpr->scanned += scanned;
        vmpr->reclaimed += reclaimed;

        if (!current_is_kswapd())
                vmpr->stall += scanned;
...
        scanned = vmpr->scanned;
        reclaimed = vmpr->reclaimed;
        spin_unlock(&vmpr->sr_lock);

        if (scanned < vmpressure_win)
                return;
...

        pressure = vmpressure_calc_pressure(scanned, reclaimed);
...
        vmpressure_notify(pressure);
}
static unsigned long vmpressure_calc_pressure(unsigned long scanned,
                                                    unsigned long reclaimed)
{
        unsigned long scale = scanned + reclaimed;
        unsigned long pressure;

        /*
         * We calculate the ratio (in percents) of how many pages were
         * scanned vs. reclaimed in a given time frame (window). Note that
         * time is in VM reclaimer's "ticks", i.e. number of pages
         * scanned. This makes it possible to set desired reaction time
         * and serves as a ratelimit.
         */
        pressure = scale - (reclaimed * scale / scanned);
        pressure = pressure * 100 / scale;

        pr_debug("%s: %3lu  (s: %lu  r: %lu)\n", __func__, pressure,
                 scanned, reclaimed);

        return pressure;
}

pressure = 100*(scanned-reclaimed)/scanned

results matching ""

    No results matching ""