Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
pixelpipe_cache_pressure.h File Reference
#include "system/memory_pressure.h"
#include <glib.h>
#include <stddef.h>
#include <stdint.h>
+ Include dependency graph for pixelpipe_cache_pressure.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dt_pixelpipe_cache_pressure_t
 
struct  dt_pixelpipe_cache_pressure_monitor_t
 
struct  dt_pixelpipe_cache_pressure_sink_t
 

Macros

#define DT_PIXELPIPE_CACHE_PSI_WINDOW_US   ((gint64)2 * 1000 * 1000)
 
#define DT_PIXELPIPE_CACHE_PSI_SHED   0.10
 
#define DT_PIXELPIPE_CACHE_PSI_CALM   0.02
 
#define DT_PIXELPIPE_CACHE_PRESSURE_KEEP   SIZE_MAX
 

Typedefs

typedef struct dt_pixelpipe_cache_pressure_t dt_pixelpipe_cache_pressure_t
 
typedef struct dt_pixelpipe_cache_pressure_monitor_t dt_pixelpipe_cache_pressure_monitor_t
 
typedef struct dt_pixelpipe_cache_pressure_sink_t dt_pixelpipe_cache_pressure_sink_t
 

Functions

static size_t dt_pixelpipe_cache_pressure_floor (const dt_pixelpipe_cache_pressure_t *p)
 
static size_t dt_pixelpipe_cache_pressure_mark_top (const dt_pixelpipe_cache_pressure_t *p)
 
static void dt_pixelpipe_cache_pressure_init (dt_pixelpipe_cache_pressure_t *p, const size_t plan)
 
static size_t dt_pixelpipe_cache_pressure_budget (const dt_pixelpipe_cache_pressure_t *p)
 
static size_t dt_pixelpipe_cache_pressure_cap (const dt_pixelpipe_cache_pressure_t *p)
 
static size_t dt_pixelpipe_cache_pressure_reported (const dt_pixelpipe_cache_pressure_t *p, const size_t current)
 
static size_t dt_pixelpipe_cache_pressure_shed_target (const dt_pixelpipe_cache_pressure_t *p, const double share, const size_t current)
 
static void dt_pixelpipe_cache_pressure_after_shed (dt_pixelpipe_cache_pressure_t *p, const size_t before, const size_t after)
 
static gboolean dt_pixelpipe_cache_pressure_relax (dt_pixelpipe_cache_pressure_t *p)
 
void dt_pixelpipe_cache_pressure_monitor_init (dt_pixelpipe_cache_pressure_monitor_t *m, size_t plan)
 
void dt_pixelpipe_cache_pressure_watch_start (dt_pixelpipe_cache_pressure_monitor_t *m, void(*wake)(void *user), void *user)
 
void dt_pixelpipe_cache_pressure_watch_stop (dt_pixelpipe_cache_pressure_monitor_t *m)
 
size_t dt_pixelpipe_cache_pressure_react (dt_pixelpipe_cache_pressure_monitor_t *m, const dt_pixelpipe_cache_pressure_sink_t *sink)
 
void dt_pixelpipe_cache_pressure_triggered (dt_pixelpipe_cache_pressure_monitor_t *m, const dt_pixelpipe_cache_pressure_sink_t *sink)
 

Macro Definition Documentation

◆ DT_PIXELPIPE_CACHE_PRESSURE_KEEP

#define DT_PIXELPIPE_CACHE_PRESSURE_KEEP   SIZE_MAX

Definition at line 60 of file pixelpipe_cache_pressure.h.

◆ DT_PIXELPIPE_CACHE_PSI_CALM

#define DT_PIXELPIPE_CACHE_PSI_CALM   0.02

Definition at line 56 of file pixelpipe_cache_pressure.h.

◆ DT_PIXELPIPE_CACHE_PSI_SHED

#define DT_PIXELPIPE_CACHE_PSI_SHED   0.10

Definition at line 54 of file pixelpipe_cache_pressure.h.

◆ DT_PIXELPIPE_CACHE_PSI_WINDOW_US

#define DT_PIXELPIPE_CACHE_PSI_WINDOW_US   ((gint64)2 * 1000 * 1000)

Definition at line 51 of file pixelpipe_cache_pressure.h.

Typedef Documentation

◆ dt_pixelpipe_cache_pressure_monitor_t

◆ dt_pixelpipe_cache_pressure_sink_t

◆ dt_pixelpipe_cache_pressure_t

Function Documentation

◆ dt_pixelpipe_cache_pressure_after_shed()

static void dt_pixelpipe_cache_pressure_after_shed ( dt_pixelpipe_cache_pressure_t p,
const size_t  before,
const size_t  after 
)
inlinestatic

Record what a shed achieved: eviction took the footprint from before to after. The mark is where pressure struck, and the ceiling follows what is actually left – never under the floor, since the ceiling only steers allocations and shedding itself still goes lower while the pressure lasts.

Definition at line 137 of file pixelpipe_cache_pressure.h.

References dt_pixelpipe_cache_pressure_floor(), MAX, MIN, and p.

Referenced by _a_shed_lowers_the_budget_to_what_is_left(), _recovery_reaches_the_plan_without_a_jump(), _recovery_waits_under_the_mark(), _reported_budget_never_underflows_its_readers(), _shed(), and _the_budget_never_falls_under_the_floor().

◆ dt_pixelpipe_cache_pressure_budget()

◆ dt_pixelpipe_cache_pressure_cap()

static size_t dt_pixelpipe_cache_pressure_cap ( const dt_pixelpipe_cache_pressure_t p)
inlinestatic

The highest the ceiling may climb to until the mark recovers further.

Definition at line 105 of file pixelpipe_cache_pressure.h.

References MIN, and p.

Referenced by _recovery_waits_under_the_mark(), _starts_at_the_plan(), dt_pixelpipe_cache_pressure_react(), and dt_pixelpipe_cache_pressure_relax().

◆ dt_pixelpipe_cache_pressure_floor()

static size_t dt_pixelpipe_cache_pressure_floor ( const dt_pixelpipe_cache_pressure_t p)
inlinestatic

Below an eighth of the plan, shedding frees nothing worth having and the stall is somebody else's: the cache neither sheds nor lowers its budget.

Definition at line 76 of file pixelpipe_cache_pressure.h.

References p, and dt_pixelpipe_cache_pressure_t::plan.

Referenced by _an_empty_cache_is_not_the_cause(), _the_budget_never_falls_under_the_floor(), dt_pixelpipe_cache_pressure_after_shed(), and dt_pixelpipe_cache_pressure_shed_target().

◆ dt_pixelpipe_cache_pressure_init()

static void dt_pixelpipe_cache_pressure_init ( dt_pixelpipe_cache_pressure_t p,
const size_t  plan 
)
inlinestatic

◆ dt_pixelpipe_cache_pressure_mark_top()

static size_t dt_pixelpipe_cache_pressure_mark_top ( const dt_pixelpipe_cache_pressure_t p)
inlinestatic

The mark tops out here rather than at the plan, so that 7/8 of it MEETS the plan instead of the ceiling jumping the last eighth the moment the mark is full. The + 8 covers the integer division: without it, 7/8 of a full mark lands a few hundred bytes under the plan and the ceiling can never quite come home. Written this way, and not as plan * 8 / 7, because the multiplication overflows a 32-bit size_t for a plan of a few GiB.

Definition at line 86 of file pixelpipe_cache_pressure.h.

References p.

Referenced by _an_empty_cache_is_not_the_cause(), dt_pixelpipe_cache_pressure_init(), and dt_pixelpipe_cache_pressure_relax().

◆ dt_pixelpipe_cache_pressure_monitor_init()

void dt_pixelpipe_cache_pressure_monitor_init ( dt_pixelpipe_cache_pressure_monitor_t m,
size_t  plan 
)

A monitor for a cache planned at plan bytes: full budget, nothing measured, no watcher.

Definition at line 63 of file pixelpipe_cache_pressure.c.

References dt_pixelpipe_cache_pressure_init(), and m.

Referenced by dt_dev_pixelpipe_cache_init().

◆ dt_pixelpipe_cache_pressure_react()

size_t dt_pixelpipe_cache_pressure_react ( dt_pixelpipe_cache_pressure_monitor_t m,
const dt_pixelpipe_cache_pressure_sink_t sink 
)

Close the window since the last measurement and act on it: shed past the threshold, let the budget climb back under it, do nothing in between. Returns the bytes shed.

Definition at line 133 of file pixelpipe_cache_pressure.c.

References _shed(), _shed_too_soon(), _window_share(), DT_DEBUG_MEMORY, DT_DEBUG_PIPECACHE, dt_pixelpipe_cache_pressure_budget(), dt_pixelpipe_cache_pressure_cap(), dt_pixelpipe_cache_pressure_relax(), DT_PIXELPIPE_CACHE_PSI_CALM, DT_PIXELPIPE_CACHE_PSI_SHED, DT_PIXELPIPE_CACHE_PSI_WINDOW_US, dt_print(), and m.

Referenced by _pressure_react_locked().

◆ dt_pixelpipe_cache_pressure_relax()

static gboolean dt_pixelpipe_cache_pressure_relax ( dt_pixelpipe_cache_pressure_t p)
inlinestatic

One calm window: the mark recovers by 1/1024 of the plan and the ceiling by 1/32, up to the cap. TRUE when the ceiling actually moved, which is the only thing worth logging.

Definition at line 146 of file pixelpipe_cache_pressure.h.

References dt_pixelpipe_cache_pressure_cap(), dt_pixelpipe_cache_pressure_mark_top(), FALSE, MIN, p, and TRUE.

Referenced by _recovery_reaches_the_plan_without_a_jump(), _recovery_waits_under_the_mark(), and dt_pixelpipe_cache_pressure_react().

◆ dt_pixelpipe_cache_pressure_reported()

static size_t dt_pixelpipe_cache_pressure_reported ( const dt_pixelpipe_cache_pressure_t p,
const size_t  current 
)
inlinestatic

The budget to report outward (tiling plans against it): never under what is held, since the readers compute max - current unsigned.

Definition at line 112 of file pixelpipe_cache_pressure.h.

References dt_pixelpipe_cache_pressure_budget(), MAX, and p.

Referenced by _reported_budget_never_underflows_its_readers(), _starts_at_the_plan(), and dt_dev_pixelpipe_cache_get_usage().

◆ dt_pixelpipe_cache_pressure_shed_target()

static size_t dt_pixelpipe_cache_pressure_shed_target ( const dt_pixelpipe_cache_pressure_t p,
const double  share,
const size_t  current 
)
inlinestatic

The footprint to evict down to for a window share of which was fully stalled, while holding current bytes – a quarter of it, half when the stall is severe, and at least 256 MiB so a nearly-empty cache is not shed one byte at a time. DT_PIXELPIPE_CACHE_PRESSURE_KEEP when the stall is under the threshold, or when the cache holds too little to be the cause.

Definition at line 122 of file pixelpipe_cache_pressure.h.

References dt_pixelpipe_cache_pressure_floor(), DT_PIXELPIPE_CACHE_PRESSURE_KEEP, DT_PIXELPIPE_CACHE_PSI_SHED, MAX, and p.

Referenced by _an_empty_cache_is_not_the_cause(), _shed(), and _sheds_a_share_of_what_is_held().

◆ dt_pixelpipe_cache_pressure_triggered()

void dt_pixelpipe_cache_pressure_triggered ( dt_pixelpipe_cache_pressure_monitor_t m,
const dt_pixelpipe_cache_pressure_sink_t sink 
)

The kernel raised a trigger: shed now, without waiting for a window of ours to close.

Definition at line 157 of file pixelpipe_cache_pressure.c.

References _shed(), _shed_too_soon(), _window_share(), DT_PIXELPIPE_CACHE_PSI_SHED, DT_PIXELPIPE_CACHE_PSI_WINDOW_US, m, and MAX.

Referenced by _pressure_wake().

◆ dt_pixelpipe_cache_pressure_watch_start()

◆ dt_pixelpipe_cache_pressure_watch_stop()

void dt_pixelpipe_cache_pressure_watch_stop ( dt_pixelpipe_cache_pressure_monitor_t m)

Join that thread. Nothing the sink touches may go away before this returns.

Definition at line 181 of file pixelpipe_cache_pressure.c.

References dt_memory_pressure_watch_stop(), and m.

Referenced by dt_dev_pixelpipe_cache_cleanup().