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=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 38A3CC433C1 for ; Tue, 23 Mar 2021 12:04:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A4A756191C for ; Tue, 23 Mar 2021 12:04:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4A756191C Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 237F66B017F; Tue, 23 Mar 2021 08:04:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20ED36B0181; Tue, 23 Mar 2021 08:04:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D8E26B0182; Tue, 23 Mar 2021 08:04:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0078.hostedemail.com [216.40.44.78]) by kanga.kvack.org (Postfix) with ESMTP id E911E6B017F for ; Tue, 23 Mar 2021 08:04:15 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A1648180AD82F for ; Tue, 23 Mar 2021 12:04:15 +0000 (UTC) X-FDA: 77951006070.32.2C42C59 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf24.hostedemail.com (Postfix) with ESMTP id BB0B0A00084B for ; Tue, 23 Mar 2021 12:04:10 +0000 (UTC) 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=1616501049; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hlDvHobKzx0p3BSIH1iU7GaUAE5bHJz9NOdKDiruEDw=; b=JJdQSwDPmNu+V+SFxAJz0cPaoRDt9+YJVooaeTdADIzQtvY2KJCZpaE2tXGKWGNSnSEAWd zvILv2OrSuG9HDHAaaYqWPzTo6gVgGKgUPDHYccFUkocI7EgIcKKwG+x7B9sVu0LOHcAGt zASxfaswP7AZmwCpPzsp3jmdlxBiQJk= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E06ACAD38; Tue, 23 Mar 2021 12:04:08 +0000 (UTC) Date: Tue, 23 Mar 2021 13:04:03 +0100 From: Michal Hocko To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: Matthew Wilcox , dri-devel , Linux MM , amd-gfx list , Dave Chinner , Leo Liu Subject: Re: [PATCH] drm/ttm: stop warning on TT shrinker failure Message-ID: References: <20210322140548.GN1719932@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: BB0B0A00084B X-Stat-Signature: nfz3fs93iq5zzhs41nz31ec3goynoeyk Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616501050-98949 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 Tue 23-03-21 12:48:58, Christian K=F6nig wrote: > Am 23.03.21 um 12:28 schrieb Daniel Vetter: > > On Tue, Mar 23, 2021 at 08:38:33AM +0100, Michal Hocko wrote: > > > On Mon 22-03-21 20:34:25, Christian K=F6nig wrote: [...] > > > > My only concern is that if I could rely on memalloc_no* being use= d we could > > > > optimize this quite a bit further. > > > Yes you can use the scope API and you will be guaranteed that _any_ > > > allocation from the enclosed context will inherit GFP_NO* semantic. >=20 > The question is if this is also guaranteed the other way around? >=20 > In other words if somebody calls get_free_page(GFP_NOFS) are the contex= t > flags set as well? gfp mask is always restricted in the page allocator. So say you have noio scope context and call get_free_page/kmalloc(GFP_NOFS) then the scope would restrict the allocation flags to GFP_NOIO (aka drop __GFP_IO). For further details, have a look at current_gfp_context and its callers. Does this answer your question? > > > I think this is where I don't get yet what Christian tries to do: W= e > > > really shouldn't do different tricks and calling contexts between d= irect > > > reclaim and kswapd reclaim. Otherwise very hard to track down bugs = are > > > pretty much guaranteed. So whether we use explicit gfp flags or the > > > context apis, result is exactly the same. >=20 > Ok let us recap what TTMs TT shrinker does here: >=20 > 1. We got memory which is not swapable because it might be accessed by = the > GPU at any time. > 2. Make sure the memory is not accessed by the GPU and driver need to g= rab a > lock before they can make it accessible again. > 3. Allocate a shmem file and copy over the not swapable pages. This is quite tricky because the shrinker operates in the PF_MEMALLOC context so such an allocation would be allowed to completely deplete memory unless you explicitly mark that context as __GFP_NOMEMALLOC. Also note that if the allocation cannot succeed it will not trigger reclaim again because you are already called from the reclaim context. > 4. Free the not swapable/reclaimable pages. >=20 > The pages we got from the shmem file are easily swapable to disk after = the > copy is completed. But only if IO is not already blocked because the > shrinker was called from an allocation restricted by GFP_NOFS or GFP_NO= IO. Sorry for being dense here but I still do not follow the actual problem (well, except for the above mentioned one). Is the sole point of this to emulate a GFP_NO* allocation context and see how shrinker behaves?=20 --=20 Michal Hocko SUSE Labs