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 73EDBC433E1 for ; Tue, 23 Mar 2021 11:49:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CBEEC619C0 for ; Tue, 23 Mar 2021 11:49:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBEEC619C0 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 61A526B016F; Tue, 23 Mar 2021 07:49:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CA9B6B0171; Tue, 23 Mar 2021 07:49:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F5456B0172; Tue, 23 Mar 2021 07:49:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 1F1E76B016F for ; Tue, 23 Mar 2021 07:49:02 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D5D2018021CBC for ; Tue, 23 Mar 2021 11:49:01 +0000 (UTC) X-FDA: 77950967682.31.E481E24 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by imf27.hostedemail.com (Postfix) with ESMTP id 518EF80192DA for ; Tue, 23 Mar 2021 11:49:00 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id u5so26587148ejn.8 for ; Tue, 23 Mar 2021 04:49:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=yBNZMhnlRz+OQ/oRguhqxLcJ0EOnKr6E58EZZvdRp0g=; b=t+n2lXQf2Sg9x5rF2NF+g9GXkxxP2DOtdxOwUrORgbEqcvMNuGugpxOljZXO2buwf/ teK7VazupoitxXwWEAZ5lDX//kHwdOWfIWQ1nn9JZGBm5btBN59vFoScXn+P6dyT58s8 xaooaHqyIXJBt42jsr6XTdseMq+qIBZamQlMGlIDypWYYDS4Le7zXiox4IMSe2gsVDwI cYIdiepRayKthmCAIhoYul5O6a6YkfmTd6+EzRYVev7f/cPzfT3Vs4bds6eYAHkpEh1d p0KbZOMi0KTP86IoALJikva00rCthVYgIZMC/heAAPXC0ds2EurHMkgThiC2IVIvrcjv B/Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=yBNZMhnlRz+OQ/oRguhqxLcJ0EOnKr6E58EZZvdRp0g=; b=ZJGyd9kgrvntg0oYL9xOTlxJJ8Bo3CefypOXoV5ujDOK791xIDOLa97D2OiIuXNMOM KpsLsaq90/srtxoOEhH5rmjET/zW5sMh5K7eNInyNuQgGI4PCc3qYDdvGM6smOsAeAva MeiHlldk6p8rn/eYDVkRCgNxWq6q8jnk3hi4CbUJxT9huHynDKDu0e0KJl1Jldbaab/B unPNsgby3bSdpqplbHoCuZYTHyOVo+UrF7RQe1wSy3cFbCYC+apHv0pLbBRiLZNYPYSn Lz+MygLanOk9T6fcm0xWlSWkMJw+2TUwhziXERFVHBkx9Xfe0oNkvt9LLfVPTxd/6rxs qVOQ== X-Gm-Message-State: AOAM5336f3HpxUkHD2dXNuGkQ9AZbA1V6gnXcEZV1Qdu+P/vU6JTgEj4 bI6Hl9UEQprEkEtyOONWqnc= X-Google-Smtp-Source: ABdhPJzOuz7nv4wb+1Q/OtBMpyRjoe3hnF2WLHVvU/z8S8l3W/4ovIGyNTg/h7jFbjoQL9nN49wEJw== X-Received: by 2002:a17:906:d797:: with SMTP id pj23mr4538672ejb.367.1616500140065; Tue, 23 Mar 2021 04:49:00 -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 k12sm12919809edr.60.2021.03.23.04.48.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Mar 2021 04:48:59 -0700 (PDT) Subject: Re: [PATCH] drm/ttm: stop warning on TT shrinker failure To: Michal Hocko , Matthew Wilcox , dri-devel , Linux MM , amd-gfx list , Dave Chinner , Leo Liu References: <1ae415c4-8e49-5183-b44d-bc92088657d5@gmail.com> <20210322140548.GN1719932@casper.infradead.org> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: Date: Tue, 23 Mar 2021 12:48:58 +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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 518EF80192DA X-Stat-Signature: b8zbzxapmut7sri5o951h6roe5nfjiq8 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf27; identity=mailfrom; envelope-from=""; helo=mail-ej1-f42.google.com; client-ip=209.85.218.42 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616500140-486113 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 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: >>> Am 22.03.21 um 18:02 schrieb Daniel Vetter: >>>> On Mon, Mar 22, 2021 at 5:06 PM Michal Hocko wrote= : >>>>> On Mon 22-03-21 14:05:48, Matthew Wilcox wrote: >>>>>> On Mon, Mar 22, 2021 at 02:49:27PM +0100, Daniel Vetter wrote: >>>>>>> On Sun, Mar 21, 2021 at 03:18:28PM +0100, Christian K=C3=B6nig wr= ote: >>>>>>>> Am 20.03.21 um 14:17 schrieb Daniel Vetter: >>>>>>>>> On Sat, Mar 20, 2021 at 10:04 AM Christian K=C3=B6nig >>>>>>>>> wrote: >>>>>>>>>> Am 19.03.21 um 20:06 schrieb Daniel Vetter: >>>>>>>>>>> On Fri, Mar 19, 2021 at 07:53:48PM +0100, Christian K=C3=B6ni= g wrote: >>>>>>>>>>>> Am 19.03.21 um 18:52 schrieb Daniel Vetter: >>>>>>>>>>>>> On Fri, Mar 19, 2021 at 03:08:57PM +0100, Christian K=C3=B6= nig wrote: >>>>>>>>>>>>>> Don't print a warning when we fail to allocate a page for = swapping things out. >>>>>>>>>>>>>> >>>>>>>>>>>>>> Also rely on memalloc_nofs_save/memalloc_nofs_restore inst= ead of GFP_NOFS. >>>>>>>>>>>>> Uh this part doesn't make sense. Especially since you only = do it for the >>>>>>>>>>>>> debugfs file, not in general. Which means you've just compl= etely broken >>>>>>>>>>>>> the shrinker. >>>>>>>>>>>> Are you sure? My impression is that GFP_NOFS should now work= much more out >>>>>>>>>>>> of the box with the memalloc_nofs_save()/memalloc_nofs_resto= re(). >>>>>>>>>>> Yeah, if you'd put it in the right place :-) >>>>>>>>>>> >>>>>>>>>>> But also -mm folks are very clear that memalloc_no*() family = is for dire >>>>>>>>>>> situation where there's really no other way out. For anything= where you >>>>>>>>>>> know what you're doing, you really should use explicit gfp fl= ags. >>>>>>>>>> My impression is just the other way around. You should try to = avoid the >>>>>>>>>> NOFS/NOIO flags and use the memalloc_no* approach instead. >>>>>>>>> Where did you get that idea? >>>>>>>> Well from the kernel comment on GFP_NOFS: >>>>>>>> >>>>>>>> * %GFP_NOFS will use direct reclaim but will not use any file= system >>>>>>>> interfaces. >>>>>>>> * Please try to avoid using this flag directly and instead us= e >>>>>>>> * memalloc_nofs_{save,restore} to mark the whole scope which >>>>>>>> cannot/shouldn't >>>>>>>> * recurse into the FS layer with a short explanation why. All= allocation >>>>>>>> * requests will inherit GFP_NOFS implicitly. >>>>>>> Huh that's interesting, since iirc Willy or Dave told me the oppo= site, and >>>>>>> the memalloc_no* stuff is for e.g. nfs calling into network layer= (needs >>>>>>> GFP_NOFS) or swap on top of a filesystems (even needs GFP_NOIO I = think). >>>>>>> >>>>>>> Adding them, maybe I got confused. >>>>>> My impression is that the scoped API is preferred these days. >>>>>> >>>>>> https://www.kernel.org/doc/html/latest/core-api/gfp_mask-from-fs-i= o.html >>>>>> >>>>>> I'd probably need to spend a few months learning the DRM subsystem= to >>>>>> have a more detailed opinion on whether passing GFP flags around e= xplicitly >>>>>> or using the scope API is the better approach for your situation. >>>>> yes, in an ideal world we would have a clearly defined scope of the >>>>> reclaim recursion wrt FS/IO associated with it. I've got back to >>>>> https://lore.kernel.org/amd-gfx/20210319140857.2262-1-christian.koe= nig@amd.com/ >>>>> and there are two things standing out. Why does ttm_tt_debugfs_shri= nk_show >>>>> really require NOFS semantic? And why does it play with >>>>> fs_reclaim_acquire? >>>> It's our shrinker. shrink_show simply triggers that specific shrinke= r >>>> asking it to shrink everything it can, which helps a lot with testin= g >>>> without having to drive the entire system against the OOM wall. >> Yes I figured that much. But... >> >>>> fs_reclaim_acquire is there to make sure lockdep understands that th= is >>>> is a shrinker and that it checks all the dependencies for us like if >>>> we'd be in real reclaim. There is some drop caches interfaces in pro= c >>>> iirc, but those drop everything, and they don't have the fs_reclaim >>>> annotations to teach lockdep about what we're doing. >> ... I really do not follow this. You shouldn't really care whether thi= s >> is a reclaim interface or not. Or maybe I just do not understand this.= .. > We're heavily relying on lockdep and fs_reclaim to make sure we get it = all > right. So any drop caches interface that isn't wrapped in fs_reclaim > context is kinda useless for testing. Plus ideally we want to only hit = our > own paths, and not trash every other cache in the system. Speed matters= in > CI. > >>> To summarize the debugfs code is basically to test if that stuff real= ly >>> works with GFP_NOFS. >> What do you mean by testing GFP_NOFS. Do you mean to test that GFP_NOF= S >> context is sufficiently powerful to reclaim enough objects due to some >> internal constrains? >> >>> 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 context=20 flags set as well? >> 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 dire= ct >> 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. Ok let us recap what TTMs TT shrinker does here: 1. We got memory which is not swapable because it might be accessed by=20 the GPU at any time. 2. Make sure the memory is not accessed by the GPU and driver need to=20 grab a lock before they can make it accessible again. 3. Allocate a shmem file and copy over the not swapable pages. 4. Free the not swapable/reclaimable pages. The pages we got from the shmem file are easily swapable to disk after=20 the copy is completed. But only if IO is not already blocked because the=20 shrinker was called from an allocation restricted by GFP_NOFS or GFP_NOIO= . Regards, Christian. > -Daniel