From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBF1EC2D0A3 for ; Sat, 7 Nov 2020 01:58:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B587620825 for ; Sat, 7 Nov 2020 01:58:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B587620825 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AC0E16B0036; Fri, 6 Nov 2020 20:58:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A72326B005D; Fri, 6 Nov 2020 20:58:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9875A6B0068; Fri, 6 Nov 2020 20:58:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 697516B0036 for ; Fri, 6 Nov 2020 20:58:30 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1A5CB1EE6 for ; Sat, 7 Nov 2020 01:58:30 +0000 (UTC) X-FDA: 77455962780.16.owl54_3c06c7c272d7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id EA3A0100E6903 for ; Sat, 7 Nov 2020 01:58:29 +0000 (UTC) X-HE-Tag: owl54_3c06c7c272d7 X-Filterd-Recvd-Size: 3677 Received: from r3-21.sinamail.sina.com.cn (r3-21.sinamail.sina.com.cn [202.108.3.21]) by imf16.hostedemail.com (Postfix) with SMTP for ; Sat, 7 Nov 2020 01:58:27 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([123.123.27.62]) by sina.com with ESMTP id 5FA5FF3E0003370E; Sat, 7 Nov 2020 09:58:25 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 31451628790 From: Hillf Danton To: Rik van Riel Cc: hughd@google.com, 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 Subject: Re: [PATCH 2/2] mm,thp,shm: limit gfp mask to no more than specified Date: Sat, 7 Nov 2020 09:58:11 +0800 Message-Id: <20201107015811.8708-1-hdanton@sina.com> In-Reply-To: <0f50046d0195d857bf7dc5a61db0a59795c3e06b.camel@surriel.com> References: <20201105191508.1961686-1-riel@surriel.com> <20201106030511.396-1-hdanton@sina.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, 06 Nov 2020 12:53:33 -0500 Rik van Riel wrote: > On Fri, 2020-11-06 at 11:05 +0800, Hillf Danton wrote: > > On Thu, 5 Nov 2020 14:15:08 -0500 > > > 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; > > > } > > >=20 > > > +/* > > > + * 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 =3D __GFP_IO | __GFP_FS | __GFP_RECLAIM; > > > + gfp_t denyflags =3D __GFP_NOWARN | __GFP_NORETRY; > > > + gfp_t result =3D huge_gfp & ~allowflags; > > > + > > > + /* > > > + * Minimize the result gfp by taking the union with the deny > > > flags, > > > + * and the intersection of the allow flags. > > > + */ > > > + result |=3D (limit_gfp & denyflags); > > > > Currently NORETRY is always set regardless of i915 and if it's > > determined in 1/2 then the i915 thing can be done like > > > > return huge_gfp | (limit_gfp & __GFP_RECLAIM); >=20 > No, if __GFP_KSWAPD_RECLAIM or __GFP_DIRECT_RECLAIM are > not set in either huge_gfp or limit_gfp, we want to ensure > the resulting gfp does not have it set, either. That means huge_gfp can play game without i915 considered if __GFP_RECLAIM is determined in 1/2 too. Then things become simpler because we have no need to check limit_gfp from the begining. >=20 > Your suggested change > would result in __GFP_KSWAPD_RECLAIM > or __GFP_DIRECT_RECLAIM getting set if it was set in either > of the input gfp variables, which is probably not the desired > behavior. It makes sense on if we could not determine __GFP_RECLAIM without i915 considered. Now it is safe to ignore it.