Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp402130imm; Wed, 17 Oct 2018 02:00:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Y6h2CeHRfch65o+krU79u3Pwd+y0AKTFmYvsb2pJEd0Ln5fYbEv65VYKee8hb3fwOCdHP X-Received: by 2002:a17:902:720b:: with SMTP id ba11-v6mr24691368plb.199.1539766800033; Wed, 17 Oct 2018 02:00:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539766800; cv=none; d=google.com; s=arc-20160816; b=F7PLPGDe4QunGHUakKc5+PyVG7U3dDFhRub3ylfa6AzYVoT8XSRnWZ5EMOmgX29DH8 2uf0VDjTLIkcHt522ZLjFJZnGWdJ2RgQcMjBikD7wGJUOq4+XOeu6sUd+2ZNhWDzHSXJ 8HtWvqYEmwoRPLfos22bxS6hPg0e77g3D841UL80UbrHozAPxZeDa/IIFeM8swlVe1JZ rgalJhypMYWg8gGx9hLB6BU+CSaZs94QGZIWNfcyiR0KUXfbnd3Pv8eDE5ItQcvuT7SY Bmz14MjyMr2Jls6FwYwl3YggaOLEhZDNBJCJgkCq7epnLcT/LUtf4ASw2Fg02kMU0fbJ gG3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uD+DH1P0SFFdY+Fa3qAgij6eAcAFeaVCmZBUuVfGQX4=; b=C0V7hOJipmaA4pxbiwWihMg1LKmigv/KrQ3Ly5LwMM1zhvsiqXWLbkSpMyprRHQeZ6 SoZpyUxMo//9EPGnA9xymSos+1sUulYcgQxot7MNhtB2mAm6bqNFv6H0p0M6RvPCJhX3 bdY5oQQqaMB9zQwAQO3GIfndEhyHHC7N4MhwNMg8R8YoAABPh8ht/2jpB/xxc5QgGPDQ Y6mmI1LelmDmhD08TIPjzDpBXyKId6mDp3Bbmh14uTs2mXoT6/FrS6I1ECpwqJNCA2Yu 4WG2g++58c24hrzbZJW3Hx43w54BiPXl2NqObfxj5u3uubSRdqVT1f5PF2vnv/nOoa7X eGjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KWht7aTR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w18-v6si17499370pfg.70.2018.10.17.01.59.44; Wed, 17 Oct 2018 01:59:59 -0700 (PDT) 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; dkim=pass header.i=@chromium.org header.s=google header.b=KWht7aTR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727196AbeJQQxh (ORCPT + 99 others); Wed, 17 Oct 2018 12:53:37 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36279 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726768AbeJQQxg (ORCPT ); Wed, 17 Oct 2018 12:53:36 -0400 Received: by mail-pf1-f196.google.com with SMTP id l81-v6so12873697pfg.3 for ; Wed, 17 Oct 2018 01:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uD+DH1P0SFFdY+Fa3qAgij6eAcAFeaVCmZBUuVfGQX4=; b=KWht7aTRlkiKCBtRfVeJNsP4i4VUhahGY5ijojCW63jtUpOs4tO1YQPPfBRq28ztKf pwbjKA+NcHMq8buohff8sKTcAm83Kq4FsjvkNQ8NruvsG8+UC9EEZTm1B4i1M1GZzYKV /TGgaHI/3co+Gf+NZmGh6yKSrf0Lb5Ptunwso= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uD+DH1P0SFFdY+Fa3qAgij6eAcAFeaVCmZBUuVfGQX4=; b=a7kYSUbkXi/Ev5Sz4Xd+Nbwn6C+TRIAksg+uhZEtXYlEHQJx+VMxbmzy//ZEMaWIsH SHf9ahJvLocuBwi32YMIRzHLOO6Ds27GaxuKMQX9aJ90n4M1ZBvsvMdqFjEXrEoWB2gf QN8WZMZVgC0BGLcD/H5SyLEAJO/1ir5IpHXuAw/+Z1LHRyTBhBju2iM77LaknVjBQ8vy vsT6YA7VMci5IlO44YRLSsZYh6vBxYP2ZiAvGsx5GZPWL59TeTbxe745pTBWi24fBjlC pPz9OrLVJkt4Hdiab1eHCPOKIPlgBl4WRYc/Nd30FS7IrMuTEe28GrG8VIPx5hHe29p8 VVQA== X-Gm-Message-State: ABuFfogQUGOTGztErFLpRcc+50gLyY8oqieKhBVBXcwlwng5QiUao9CX ImDzBxnstHfNumtjYdjn8bB/ X-Received: by 2002:a63:5c1f:: with SMTP id q31-v6mr23803403pgb.452.1539766734448; Wed, 17 Oct 2018 01:58:54 -0700 (PDT) Received: from vovoy-z840.tpe.corp.google.com ([2401:fa00:1:b:d89e:cfa6:3c8:e61b]) by smtp.gmail.com with ESMTPSA id 84-v6sm28477983pfs.108.2018.10.17.01.58.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 01:58:53 -0700 (PDT) From: Kuo-Hsin Yang To: vovoy@chromium.org Cc: akpm@linux-foundation.org, chris@chris-wilson.co.uk, corbet@lwn.net, dave.hansen@intel.com, hoegsberg@chromium.org, hughd@google.com, intel-gfx@lists.freedesktop.org, joonas.lahtinen@linux.intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, marcheu@chromium.org, mhocko@suse.com, peterz@infradead.org Subject: [PATCH v2] shmem, drm/i915: mark pinned shmemfs pages as unevictable Date: Wed, 17 Oct 2018 16:58:01 +0800 Message-Id: <20181017085801.220742-1-vovoy@chromium.org> X-Mailer: git-send-email 2.19.1.331.ge82ca0e54c-goog In-Reply-To: <20181016174300.197906-1-vovoy@chromium.org> References: <20181016174300.197906-1-vovoy@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. By exporting shmem_unlock_mapping, drivers can: 1. mark a shmemfs address space as unevictable with mapping_set_unevictable(), pages in the address space will be moved to unevictable list in vmscan. 2. mark an address space as evictable with mapping_clear_unevictable(), and move these pages back to evictable list with shmem_unlock_mapping(). This patch was inspired by Chris Wilson's change [1]. [1]: https://patchwork.kernel.org/patch/9768741/ Signed-off-by: Kuo-Hsin Yang --- Changes for v2: Squashed the two patches. Documentation/vm/unevictable-lru.rst | 4 +++- drivers/gpu/drm/i915/i915_gem.c | 8 ++++++++ mm/shmem.c | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Documentation/vm/unevictable-lru.rst b/Documentation/vm/unevictable-lru.rst index fdd84cb8d511..a812fb55136d 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,8 @@ 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. + Detecting Unevictable Pages --------------------------- diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index fcc73a6ab503..e0ff5b736128 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2390,6 +2390,7 @@ i915_gem_object_put_pages_gtt(struct drm_i915_gem_object *obj, { struct sgt_iter sgt_iter; struct page *page; + struct address_space *mapping; __i915_gem_object_release_shmem(obj, pages, true); @@ -2409,6 +2410,10 @@ i915_gem_object_put_pages_gtt(struct drm_i915_gem_object *obj, } obj->mm.dirty = false; + mapping = file_inode(obj->base.filp)->i_mapping; + mapping_clear_unevictable(mapping); + shmem_unlock_mapping(mapping); + sg_free_table(pages); kfree(pages); } @@ -2551,6 +2556,7 @@ static int i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj) * Fail silently without starting the shrinker */ mapping = obj->base.filp->f_mapping; + mapping_set_unevictable(mapping); noreclaim = mapping_gfp_constraint(mapping, ~__GFP_RECLAIM); noreclaim |= __GFP_NORETRY | __GFP_NOWARN; @@ -2664,6 +2670,8 @@ static int i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj) err_pages: for_each_sgt_page(page, sgt_iter, st) put_page(page); + mapping_clear_unevictable(mapping); + shmem_unlock_mapping(mapping); sg_free_table(st); kfree(st); diff --git a/mm/shmem.c b/mm/shmem.c index 446942677cd4..d1ce34c09df6 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -786,6 +786,7 @@ void shmem_unlock_mapping(struct address_space *mapping) cond_resched(); } } +EXPORT_SYMBOL_GPL(shmem_unlock_mapping); /* * Remove range of pages and swap entries from radix tree, and free them. @@ -3874,6 +3875,7 @@ int shmem_lock(struct file *file, int lock, struct user_struct *user) void shmem_unlock_mapping(struct address_space *mapping) { } +EXPORT_SYMBOL_GPL(shmem_unlock_mapping); #ifdef CONFIG_MMU unsigned long shmem_get_unmapped_area(struct file *file, -- 2.19.1.331.ge82ca0e54c-goog