Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2050340pxu; Tue, 24 Nov 2020 15:54:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6CcEN/GCDHS2NAvWfyb05HJvaOx7u2koT0V3U0rvKxFGAvjNWo5zEjGDj8LSmKVGIdWta X-Received: by 2002:a05:6402:176e:: with SMTP id da14mr980857edb.245.1606262063117; Tue, 24 Nov 2020 15:54:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606262063; cv=none; d=google.com; s=arc-20160816; b=ORpzkk0Cbvl0sfhZxNyq0e0dEIHJg1//yEy6eFq4tH/7J9lzPU040Sj2NHqKrW+aS/ 19hCg1koJZeC2I8Qs6fKNg/sBLRCorRr4RmV7rZ80UnMeY5xtb/VwISf6gKV7e6uq0s3 Tbm9qRvCSjRNei6L58akbDzffBTsv+tju9w0GuCeQSe+ei0pclU/umaesMg5xXqDksA2 xV/r3WfAFmIE0Nd+HKTvQI3FZ/iDbiVQXH9ZG7odB0f2NeA9PI3+G8ffxmHqjb/7QsoA RQpdZQC7YNd1iGyirSTg4pRJN66SuONxyKS8gYSR9uQ3PUZWr00g8+2JRBCg7dvXp69Z pZ7Q== 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=DXmN+5utJGYwbYDCxyuOE9GTUd/O5W7xzBSBUEErUejXhjpQ/1QYD0J5TKSUev6vl3 jsa0p+RiOLEqb8gCTtHheEZFXMU+tN2yE+Z8tkED92tQS5H1mSZXmycjrXvLI/FJPskP Unu8MGA8QjZtetsfurQmRELG7cpmTG6mlG+pnj1MnmJpRi1yCiWfSasrnT6hFJAPEkiX +uCwpC5KxePxLvLos4t2kgDHzXAB9Tj880tY/9hMzWFuzMnjcdTUOkj0eVRXmCV4evE7 Uj0m26vUkXp8tJDd4HjrUo/X55gj8+RjdTlChqMV+r9BhU6TnrrQIlDI7IuVLRtRfs5d lwdQ== 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 hb37si282070ejc.174.2020.11.24.15.54.00; Tue, 24 Nov 2020 15:54:23 -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 S1728338AbgKXTtp (ORCPT + 99 others); Tue, 24 Nov 2020 14:49:45 -0500 Received: from shelob.surriel.com ([96.67.55.147]:36790 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726447AbgKXTtl (ORCPT ); Tue, 24 Nov 2020 14:49:41 -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 1kheJc-0006wM-3G; Tue, 24 Nov 2020 14:49:28 -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/3] mm,thp,shm: limit gfp mask to no more than specified Date: Tue, 24 Nov 2020 14:49:24 -0500 Message-Id: <20201124194925.623931-3-riel@surriel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201124194925.623931-1-riel@surriel.com> References: <20201124194925.623931-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