Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp555049pxu; Thu, 26 Nov 2020 05:44:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJymegpKir5CCd6CYFCGEhXq0C9YXm6znYIXienRq4fHLeqThBQvakMovV/EBIINBXgp2CcZ X-Received: by 2002:a17:906:5cb:: with SMTP id t11mr2723440ejt.295.1606398264593; Thu, 26 Nov 2020 05:44:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606398264; cv=none; d=google.com; s=arc-20160816; b=J5JhQw7F/73kkzEXwsIX1za06wJvzq5aj9kV1MAa/tCAKRqyu/6asTp6X5Q7dcWjG8 BY4IXb9XG16femf1mLED2fGsid558psM0sZpK2PVn+Bc39xB6saxsFPRrnEoS3udZG0q W8XLj/SiActuoA3jHUOWoG7/satcdVvvpMKGKgeggmTwJDThNdRw/OP3l6AEO3ZXKcNH g1cuhvC+IDx/rDlY1oNvMxo18aVT/ShuJ8XsW2nj52yR5Qkqr9A0WBxgk+bL37IdsK6s gnn31ZtlxdDdlQDtlAT1q2ZN0UpSTItCUskmyhN2nTn77GQd3s5xI8HAof1NxYna5bz0 MMeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9tpQ2yN+EcMyN7hnntqz+RkMEw6hXQibeFRMrMM5L2s=; b=rqgECMvTKw4W3PqHhKree0Eia53OxCyX6lTOgBE7DUzKPULTNncMOcXbhtNwQ+TMsk GuSOAtJj0smw41ypjy1X6rTl0fxibf/7gUCfd273tqxhVjzg0QxoCHUOOGArmDW6IDyZ KAG7d2JzRqxOPYkpAcSL3CN942dRXt3cWw7F6GSYOvgZPWxvAHJg9g1kEth8XA+Ouflb lsnlkYQ5kZXaIkHPC3BcRZ/BFkzGynK+MpjwXixmJh5IHxWhNpo8NedVlWWqwekp14dU fsatJk5Ed/yOCSQ/bjcOIG28pX8GN97xb/vbKMbSXMq9Ingc3RIeYH2//f7rPo7C31TI a4sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ajTwHAYd; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gq17si2995785ejb.178.2020.11.26.05.44.01; Thu, 26 Nov 2020 05:44:24 -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; dkim=pass header.i=@suse.com header.s=susede1 header.b=ajTwHAYd; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390320AbgKZNkh (ORCPT + 99 others); Thu, 26 Nov 2020 08:40:37 -0500 Received: from mx2.suse.de ([195.135.220.15]:56436 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390022AbgKZNkh (ORCPT ); Thu, 26 Nov 2020 08:40:37 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1606398035; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9tpQ2yN+EcMyN7hnntqz+RkMEw6hXQibeFRMrMM5L2s=; b=ajTwHAYd5J0mqReqBekTnBlsHHrNFEO2eq6u4Ld8L6JTiJiyCw/6cPwlyL+/8n48mCToMO 9Fj6YnH2i8ERYfahSgxPKMouUumvsl2wEMjOv8qwNncauWTW6QbzM4Kca7A+6xWQxltQbk ddaiT31gMg3MoDiILTaN+MtEExvEZgY= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A1D05AC6A; Thu, 26 Nov 2020 13:40:35 +0000 (UTC) Date: Thu, 26 Nov 2020 14:40:34 +0100 From: Michal Hocko 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 Subject: Re: [PATCH 2/3] mm,thp,shm: limit gfp mask to no more than specified Message-ID: <20201126134034.GI31550@dhcp22.suse.cz> References: <20201124194925.623931-1-riel@surriel.com> <20201124194925.623931-3-riel@surriel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201124194925.623931-3-riel@surriel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 24-11-20 14:49:24, Rik van Riel wrote: > 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. I have brought this up in the previous version review and I feel my feedback hasn't been addressed. Please describe the expected behavior by those shmem users including GFP_KERNEL restriction which would make the THP flags incompatible. Is this a problem? Is there any actual problem if the THP uses its own set of flags? I am also not happy how those two sets of flags are completely detached and we can only expect surprises there. > 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 > -- Michal Hocko SUSE Labs