Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp726346pxb; Thu, 5 Nov 2020 11:17:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoKcnsWXEA5BOjj56QhEykECbK7CQWBBqI6BgCTZ1xZYHYqN8NND+f+1zAqt1e5WEUE5gb X-Received: by 2002:a17:906:944f:: with SMTP id z15mr4021974ejx.111.1604603872647; Thu, 05 Nov 2020 11:17:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604603872; cv=none; d=google.com; s=arc-20160816; b=ymHCk8XDPx9IY240PKFWqIQ1DkZLTGB+has57i7nBUHfsv9dwGPsrvExr8GA9T0jq9 3H3u9d8/BSZmSgesjJytpxTKvx7TlUgsVpTyhnqTwkz3lJY0me5M5nN8BlW377tmU31+ kgfk5vzDBWGexN2oKj6+xKkewYTBovFp8sPl1P0ZphFALUJLgZuyLZmQgOI89wTg/XnL cEgsrA4ZJzIJEz4UPw35cx3gvHYWnXkqdFr7PHGWnLsfn76zkdyr0chYdhJI0sIpbyBZ bXiL5XZPG4Ps0YF7gg119idG65syijialIK2Jc5jsCDZZzVbkTdXdH8K7Q7cDlbl0gs4 DAkw== 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; bh=LyZuSYZHIk8Wq1XHPLT4vnZYqFZhdpgNtHgq0pbpHas=; b=BY2aehh5KDPql7apHho3WGOr8VQ9bQwkjF4a0rFnl5FvwjB+6r6a0ENzPQR7R0NOQy AaAvWD3clwadH99tDlWX57mn5SQXQ+pnBujO56vfZDg89xQoxdA4lzIj/1TDmNUsvg/P PIQBB6HQtigTCgeGaoWvoiJ0cToNeGv9UfqD3anwH7Xt66CFmBa0cDTQTtCfijGZ6mOV u5Ps0QVjvaRaXWv7RMdLCYZjOC+tdhC5Vo0hGWSHNaVS/hbF2/plu7UBOzkRXhBcXuRu 4zAVgpkIHAn0PK9zwh4vBfDpJIPJ6SfPNa4bEJ3RdPoJF5aZuAvNN58Sku/ZkqD9rdZ4 fkZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi9si2632972edb.4.2020.11.05.11.17.30; Thu, 05 Nov 2020 11:17:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732043AbgKETPZ (ORCPT + 99 others); Thu, 5 Nov 2020 14:15:25 -0500 Received: from shelob.surriel.com ([96.67.55.147]:60598 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732013AbgKETPY (ORCPT ); Thu, 5 Nov 2020 14:15:24 -0500 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kakj1-00048T-FN; Thu, 05 Nov 2020 14:15:11 -0500 From: Rik van Riel To: hughd@google.com Cc: xuyu@linux.alibaba.com, akpm@linux-foundation.org, mgorman@suse.de, aarcange@redhat.com, willy@infradead.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, linux-mm@kvack.org, vbabka@suse.cz, mhocko@suse.com, Rik van Riel Subject: [PATCH 2/2] mm,thp,shm: limit gfp mask to no more than specified Date: Thu, 5 Nov 2020 14:15:08 -0500 Message-Id: <20201105191508.1961686-3-riel@surriel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201105191508.1961686-1-riel@surriel.com> References: <20201105191508.1961686-1-riel@surriel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: riel@shelob.surriel.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Matthew Wilcox pointed out that the i915 driver opportunistically allocates tmpfs memory, but will happily reclaim some of its pool if no memory is available. Make sure the gfp mask used to opportunistically allocate a THP is always at least as restrictive as the original gfp mask. Signed-off-by: Rik van Riel Suggested-by: Matthew Wilcox --- mm/shmem.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 6c3cb192a88d..ee3cea10c2a4 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1531,6 +1531,26 @@ static struct page *shmem_swapin(swp_entry_t swap, gfp_t gfp, return page; } +/* + * Make sure huge_gfp is always more limited than limit_gfp. + * Some of the flags set permissions, while others set limitations. + */ +static gfp_t limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp) +{ + gfp_t allowflags = __GFP_IO | __GFP_FS | __GFP_RECLAIM; + gfp_t denyflags = __GFP_NOWARN | __GFP_NORETRY; + gfp_t result = huge_gfp & ~allowflags; + + /* + * Minimize the result gfp by taking the union with the deny flags, + * and the intersection of the allow flags. + */ + result |= (limit_gfp & denyflags); + result |= (huge_gfp & limit_gfp) & allowflags; + + return result; +} + static struct page *shmem_alloc_hugepage(gfp_t gfp, struct shmem_inode_info *info, pgoff_t index) { @@ -1889,6 +1909,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, alloc_huge: huge_gfp = vma_thp_gfp_mask(vma); + huge_gfp = limit_gfp_mask(huge_gfp, gfp); page = shmem_alloc_and_acct_page(huge_gfp, inode, index, true); if (IS_ERR(page)) { alloc_nohuge: -- 2.25.4