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=-2.0 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 A56F8C433C1 for ; Tue, 23 Mar 2021 12:21:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2723A619B1 for ; Tue, 23 Mar 2021 12:21:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2723A619B1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 92B406B0189; Tue, 23 Mar 2021 08:21:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B2436B018B; Tue, 23 Mar 2021 08:21:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 705866B018C; Tue, 23 Mar 2021 08:21:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id 505276B0189 for ; Tue, 23 Mar 2021 08:21:36 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 08ABA4FEC for ; Tue, 23 Mar 2021 12:21:36 +0000 (UTC) X-FDA: 77951049792.12.EC6D9C2 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf28.hostedemail.com (Postfix) with ESMTP id A9A8820001D6 for ; Tue, 23 Mar 2021 12:21:34 +0000 (UTC) Received: by mail-ed1-f51.google.com with SMTP id bf3so23228551edb.6 for ; Tue, 23 Mar 2021 05:21:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=+l1FkHneCCxWHd7Lw55HE5rWouIsqHp49qYTvqtcL2k=; b=c8HZ4UuxI4tMpK3bfOLxR2mpo2MYKjvUiQ3fDpVE+daGCpuplamrRZQkT+MrcWUDbE 5fyesazaC9swWYpVAsVh4bjZCtwWMyo/tYRDg8l+MScxBoss1amGb4MNmqBlxAzSsGPY gOG1OA3nzcmgdlOYVNV3GxkgtZojqXbIgReIqXgqpyfywJ5+hzVa7c24OFzgdgVYRkTY X8zseP4vAQZp4vxpZJollDELEll+ZMamuzK23/jJ7yRb7Ifi+XvjIer9ZwRemGYQ315T /DXnwlr8mzNHEe9AYR+J/Jv2FPEsCyxQ60Uf8yJ6Uv1DjSraOu2v18Vtd+YfcHVagmnn UdKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=+l1FkHneCCxWHd7Lw55HE5rWouIsqHp49qYTvqtcL2k=; b=koI1G86wdi0QObpUsXxyltlSfQo5Otjefvwu7gXw6iugyhpfGwNQ/+Ow+ZugAQyQLi r/7JaV+0ya/YPO9mGlAuQh63EYIIXXg6+m9POVbDwvdrB+DeGTymcOkmLmma/z7TiT17 FQmnQcRWpGZCNiCuQ0GvG7cOZfL2umezTLa6ja2tz+E3KQB5FIQq/h+124RADvHymXcG kzrDdCG3/+VFO0Bwlqx5XX9riXpS93r2hTSw32U6IJVD5Lv2a9WacE1fqzhgWDsvFJpx xolRiDEAuiACr6i1QZmGg0/azffVga9lVjYjCH06ANR900IAWbKlKkzetHAGpzDgVV1u /OmA== X-Gm-Message-State: AOAM532CXWOihH9M14i04BAhxYLKZUYFzkV0IxbUGL5/GFhfqZcVvJ9A l6UmjGiasWCmrp2HG2p0PK8= X-Google-Smtp-Source: ABdhPJzVRLqp4Hqmn/EMxIcWHlx0cmTl0G2L+0FrDyPfaGc6f7BT8Nm5ZnhhEkfP/NS62yrvo8DYwg== X-Received: by 2002:aa7:c850:: with SMTP id g16mr4274306edt.324.1616502094239; Tue, 23 Mar 2021 05:21:34 -0700 (PDT) Received: from ?IPv6:2a02:908:1252:fb60:fdcd:4dd1:a1af:a7ec? ([2a02:908:1252:fb60:fdcd:4dd1:a1af:a7ec]) by smtp.gmail.com with ESMTPSA id p24sm12790444edt.5.2021.03.23.05.21.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Mar 2021 05:21:33 -0700 (PDT) Subject: Re: [PATCH] drm/ttm: stop warning on TT shrinker failure To: Michal Hocko Cc: Matthew Wilcox , dri-devel , Linux MM , amd-gfx list , Dave Chinner , Leo Liu References: <20210322140548.GN1719932@casper.infradead.org> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: <75ff80c5-a054-d13d-85c1-0040addb45d2@gmail.com> Date: Tue, 23 Mar 2021 13:21:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Stat-Signature: ymaq4uwsn6kwsz4gszcatoq6dp7dymcm X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A9A8820001D6 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=mail-ed1-f51.google.com; client-ip=209.85.208.51 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616502094-661509 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: Am 23.03.21 um 13:04 schrieb Michal Hocko: > On Tue 23-03-21 12:48:58, Christian K=C3=B6nig 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=C3=B6nig wrote: > [...] >>>>> My only concern is that if I could rely on memalloc_no* being used = 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. >> The question is if this is also guaranteed the other way around? >> >> In other words if somebody calls get_free_page(GFP_NOFS) are the conte= xt >> 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? But what happens if you don't have noio scope and somebody calls=20 get_free_page(GFP_NOFS)? Is then the noio scope added automatically? And is it possible that the=20 shrinker gets called without noio scope even we would need it? >>>> I think this is where I don't get yet what Christian tries to do: We >>>> really shouldn't do different tricks and calling contexts between di= rect >>>> reclaim and kswapd reclaim. Otherwise very hard to track down bugs a= re >>>> pretty much guaranteed. So whether we use explicit gfp flags or the >>>> context apis, result is exactly the same. >> Ok let us recap what TTMs TT shrinker does here: >> >> 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 = grab 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. Thanks, exactly that was one thing I was absolutely not sure about. And=20 yes I agree that this is really tricky. Ideally I would like to be able to trigger swapping out the shmem page I=20 allocated immediately after doing the copy. This way I would only need a single page for the whole shrink operation=20 at any given time. > Also note that if the allocation cannot succeed it will not trigger rec= laim > again because you are already called from the reclaim context. > >> 4. Free the not swapable/reclaimable pages. >> >> 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_N= OIO. > 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 t= o > emulate a GFP_NO* allocation context and see how shrinker behaves? Please be as dense as you need to be :) I think Daniel and I only have a very rough understanding of the memory=20 management details here, but we need exactly that knowledge to get the=20 GPU memory management into the shape we want it to be. Thanks, Christian.