Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1711312imu; Tue, 6 Nov 2018 03:09:16 -0800 (PST) X-Google-Smtp-Source: AJdET5e6hW0Pm+/q5Sqif85XSPn7beEFZLHYlPVTxt1C8lBTTxG76WGEUKhu8XN0r5qWz5BjuT0V X-Received: by 2002:a63:525e:: with SMTP id s30-v6mr23588451pgl.436.1541502556751; Tue, 06 Nov 2018 03:09:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541502556; cv=none; d=google.com; s=arc-20160816; b=vkXfDk3eeFDHTjlnhSKn/NX5fefFAf/0pjLWHS+/Fm3OC3g1cDwvV35iI7qeqKA4YO N+RhJgpHmQmpSa/dNgdSWt7IbVFZf4zaDBLocfqYI0VM1sTTfNNl6O6RbHVOIq7HNGat O4qcJNaJDto2sZscrDFZgHNLRXjDMghLkgOj0ZO7jqTaO+adFnZ3BZPwcKFWdOtqpc3m o+D+uH24RKOSYY9IAg9nAIWc3TbKW6gTt/fQRofZuhntLUPqVlOb0vp6KPZ9pC37vuMO lVKEqIehWfHcbjM9R+PTJa9/vgyNSRae9f1Dplv2Wsu3OQ4134OaAvSjpkd/tcvf3LD5 NQvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:user-agent:message-id :references:cc:in-reply-to:from:to:content-transfer-encoding :mime-version; bh=h8atmvRJ+ZRMjNZI2D3/5p0GK+10kNe6xoabRh9oduc=; b=oB3vFMSlLuMCk9H8QbrrcXQnt/w7PC+lKWC8/phDU36ZbXEdh6GC/na+n6PgNsxBgC XLJQCh0PYXqGDBZ/kNOlbtoMwnt40vMG+/yFB2teECuW+2pZHruZkvdHUIORWSR2VRZu JJFRLptD63W7HFj1iZbrUkMd9/xH93LAAaJJXvMZYTNuqaUwIzIeQET84q65IiJ8ePD5 OfPC4s5I335fpOOr1nsRWcm8p9/s6DQqXOYUmjkgM6QTTqjlMagqrm5YazXfaiMzR61J t5iLS5r3l7b+R1AHPbAmgIkRyFoivKWkSuQjumW0U+wd44ktkm0qty3Dzr2JYhmKrIOm n72Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m5-v6si45346275pll.320.2018.11.06.03.09.01; Tue, 06 Nov 2018 03:09:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730421AbeKFUcd convert rfc822-to-8bit (ORCPT + 99 others); Tue, 6 Nov 2018 15:32:33 -0500 Received: from mail.fireflyinternet.com ([109.228.58.192]:55102 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726976AbeKFUcd (ORCPT ); Tue, 6 Nov 2018 15:32:33 -0500 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from localhost (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP (TLS) id 14370028-1500050 for multiple; Tue, 06 Nov 2018 11:07:01 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT To: Kuo-Hsin Yang , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org From: Chris Wilson In-Reply-To: <20181106093100.71829-1-vovoy@chromium.org> Cc: Kuo-Hsin Yang , Joonas Lahtinen , Peter Zijlstra , Andrew Morton , Dave Hansen , Michal Hocko References: <20181106093100.71829-1-vovoy@chromium.org> Message-ID: <154150241813.6179.68008798371252810@skylake-alporthouse-com> User-Agent: alot/0.6 Subject: Re: [PATCH v6] mm, drm/i915: mark pinned shmemfs pages as unevictable Date: Tue, 06 Nov 2018 11:06:58 +0000 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Kuo-Hsin Yang (2018-11-06 09:30:59) > The i915 driver uses shmemfs to allocate backing storage for gem > objects. These shmemfs pages can be pinned (increased ref count) by > shmem_read_mapping_page_gfp(). When a lot of pages are pinned, vmscan > wastes a lot of time scanning these pinned pages. In some extreme case, > all pages in the inactive anon lru are pinned, and only the inactive > anon lru is scanned due to inactive_ratio, the system cannot swap and > invokes the oom-killer. Mark these pinned pages as unevictable to speed > up vmscan. > > Export pagevec API check_move_unevictable_pages(). > > This patch was inspired by Chris Wilson's change [1]. > > [1]: https://patchwork.kernel.org/patch/9768741/ > > Cc: Chris Wilson > Cc: Joonas Lahtinen > Cc: Peter Zijlstra > Cc: Andrew Morton > Cc: Dave Hansen > Signed-off-by: Kuo-Hsin Yang > Acked-by: Michal Hocko # mm part > --- > Changes for v6: > Tweak the acked-by. > > Changes for v5: > Modify doc and comments. Remove the ifdef surrounding > check_move_unevictable_pages. > > Changes for v4: > Export pagevec API check_move_unevictable_pages(). > > Changes for v3: > Use check_move_lru_page instead of shmem_unlock_mapping to move pages > to appropriate lru lists. > > Changes for v2: > Squashed the two patches. > > Documentation/vm/unevictable-lru.rst | 6 +++++- > drivers/gpu/drm/i915/i915_gem.c | 28 ++++++++++++++++++++++++++-- > include/linux/swap.h | 4 +++- > mm/shmem.c | 2 +- > mm/vmscan.c | 22 +++++++++++----------- > 5 files changed, 46 insertions(+), 16 deletions(-) > > diff --git a/Documentation/vm/unevictable-lru.rst b/Documentation/vm/unevictable-lru.rst > index fdd84cb8d511..b8e29f977f2d 100644 > --- a/Documentation/vm/unevictable-lru.rst > +++ b/Documentation/vm/unevictable-lru.rst > @@ -143,7 +143,7 @@ using a number of wrapper functions: > Query the address space, and return true if it is completely > unevictable. > > -These are currently used in two places in the kernel: > +These are currently used in three places in the kernel: > > (1) By ramfs to mark the address spaces of its inodes when they are created, > and this mark remains for the life of the inode. > @@ -154,6 +154,10 @@ These are currently used in two places in the kernel: > swapped out; the application must touch the pages manually if it wants to > ensure they're in memory. > > + (3) By the i915 driver to mark pinned address space until it's unpinned. The > + amount of unevictable memory marked by i915 driver is roughly the bounded > + object size in debugfs/dri/0/i915_gem_objects. > + > > Detecting Unevictable Pages > --------------------------- > diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c > index 0c8aa57ce83b..c620891e0d02 100644 > --- a/drivers/gpu/drm/i915/i915_gem.c > +++ b/drivers/gpu/drm/i915/i915_gem.c > @@ -2381,12 +2381,25 @@ void __i915_gem_object_invalidate(struct drm_i915_gem_object *obj) > invalidate_mapping_pages(mapping, 0, (loff_t)-1); > } > > +/** > + * Move pages to appropriate lru and release the pagevec. Decrement the ref > + * count of these pages. > + */ > +static inline void check_release_pagevec(struct pagevec *pvec) > +{ > + if (pagevec_count(pvec)) { > + check_move_unevictable_pages(pvec); > + __pagevec_release(pvec); This gave disappointing syslatency results until I put a cond_resched() here and moved the one in put_pages_gtt to before the page alloc, see https://patchwork.freedesktop.org/patch/260332/ The last really nasty wart for syslatency is the spin in i915_gem_shrinker, for which I'm investigating https://patchwork.freedesktop.org/patch/260365/ All 3 patches together give very reasonable syslatency results! (So good that it's time to find a new worst case scenario!) The challenge for the patch as it stands, is who lands it? We can take it through drm-intel (for merging in 4.21) but need Andrew's ack on top of all to agree with that path. Or we split the patch and only land the i915 portion once we backmerge the mm tree. I think pushing the i915 portion through the mm tree is going to cause the most conflicts, so would recommend against that. -Chris