• Chris Wilson's avatar
    drm/i915: Start writeback from the shrinker · 2d6692e6
    Chris Wilson authored
    When we are called to relieve mempressue via the shrinker, the only way
    we can make progress is either by discarding unwanted pages (those
    objects that userspace has marked MADV_DONTNEED) or by reclaiming the
    dirty objects via swap. As we know that is the only way to make further
    progress, we can initiate the writeback as we invalidate the objects.
    This means the objects we put onto the inactive anon lru list are
    already marked for reclaim+writeback and so will trigger a wait upon the
    writeback inside direct reclaim, greatly improving the success rate of
    direct reclaim on i915 objects.
    
    The corollary is that we may start a slow swap on opportunistic
    mempressure from the likes of the compaction + migration kthreads. This
    is limited by those threads only being allowed to shrink idle pages, but
    also that if we reactivate the page before it is swapped out by gpu
    activity, we only page the cost of repinning the page. The cost is most
    felt when an object is reused after mempressure, which hopefully
    excludes the latency sensitive tasks (as we are just extending the
    impact of swap thrashing to them).
    
    Apparently this is not the first time we've had this idea. Back in
    commit 5537252b ("drm/i915: Invalidate our pages under memory
    pressure") we wanted to start writeback but settled on invalidate after
    Hugh Dickins warned us about a possibility of a deadlock within shmemfs
    if we started writeback from shrink_slab. Looking at the callchain,
    using writeback from i915_gem_shrink should be equivalent to the pageout
    also employed by shrink_slab, i.e. it should not be any riskier afaict.
    
    v2: Leave mmapings intact. At this point, the only mmapings of our
    objects will be via CPU mmaps on the shmemfs filp, which are
    out-of-scope for our LRU tracking. Instead leave those pages to the
    inactive anon LRU page list for aging and pageout as normal.
    
    v3: Be selective on which paths trigger writeback, in particular
    excluding paths shrinking just to reclaim vm space (e.g. mmap, vmap
    reapers) and avoid starting writeback on the entire process space from
    within the pm freezer.
    
    References: https://bugs.freedesktop.org/show_bug.cgi?id=108686Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
    Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
    Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
    Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
    Cc: Matthew Auld <matthew.auld@intel.com>
    Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
    Cc: Michal Hocko <mhocko@suse.com>
    Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> #v1
    Link: https://patchwork.freedesktop.org/patch/msgid/20190420115539.29081-1-chris@chris-wilson.co.uk
    2d6692e6
i915_gem_shrinker.c 18 KB