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=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 768C6C433DF for ; Wed, 24 Jun 2020 23:20:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 069572078D for ; Wed, 24 Jun 2020 23:20:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="dKlIDqIO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 069572078D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 592686B0005; Wed, 24 Jun 2020 19:20:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5423B6B0007; Wed, 24 Jun 2020 19:20:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 431326B0008; Wed, 24 Jun 2020 19:20:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id 2B2676B0005 for ; Wed, 24 Jun 2020 19:20:51 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 78C02180AD822 for ; Wed, 24 Jun 2020 23:20:50 +0000 (UTC) X-FDA: 76965677460.02.balls39_120a88726e48 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 6149030000D08FC8 for ; Wed, 24 Jun 2020 23:20:50 +0000 (UTC) X-HE-Tag: balls39_120a88726e48 X-Filterd-Recvd-Size: 5836 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Wed, 24 Jun 2020 23:20:49 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id q198so3662485qka.2 for ; Wed, 24 Jun 2020 16:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=50l5Dv+6ZxPyVzpp0Gvp+/OZMC9Zz2ShDuxO8n/e6qc=; b=dKlIDqIO1zKZ5/r3LEEqIIdXXMvKWYtqZh7kuJcGaewZfIiKKHCMQINMIvisSlXQH1 xWmHbqQ+xmEOXDLfwSjs4SKukimSGWgCe/tn2h3unn/czaeRTH4VfyNkvG3t6OyCmhTX 8rymFqCr5v6Csjrxd+jyQEE4grQgfTRkyG76KizeQJcPdm6g687B1vDC1dHlYPLJy9EM wS751PjIZpPmXB9jpDk8F5kPJ7qUyxAr7I3yxxFFMpjYI6iMqvS7haf+GQt1A0NXBM2e WVNmFKTUOvehhDhTGPeD79nZ4NVgUdQXLXxz8/RTDA2tr+ZdNsK37lM1U+8haZ7Hb2wa LAFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=50l5Dv+6ZxPyVzpp0Gvp+/OZMC9Zz2ShDuxO8n/e6qc=; b=R/Tqzi2MkgrUUAZ0dcktVnAmr3TWX9HVVKBX3oPOiSXlGSuryFonMUlv1R/Yc7YMxf gikJXnn45W1rlVDtomJwRnjDkVoZtZbBMld3Er9dzbiv712e8i7xowi9674U2oisG5A+ svAh4EJaan6VJzTO45OpNxjefXM6ujpNYJ9OtBgI1RxmqndMdiFUKOIyxg8WlEF/4r9H +DmRqlYDdzWg7n3FLRi0///2p+UT+MGC+ZtH9fFBkyXZRMkID+tYoV37wrKG2xoCOM1y XglXGKyJslqYiLwNOo/D/Kiq0JGJwqocZM9+FC7sWIMglYDavMur+1GX4gHnszGyCIv4 KHdw== X-Gm-Message-State: AOAM531cT00qcdLpZgo6mcrKzYmB12V4Kvl9HKTKR4jKAMOq/j5NaSxP TP6W+0Ay5/09AZdNKOMY7hNmlg== X-Google-Smtp-Source: ABdhPJwJc/5vcM8iqN/INyrOnQzJ0qVecIjg2WtX4ifSmsVgC0ZMiY8O/7SJAPB5rKpjXVNlBg2h0g== X-Received: by 2002:a37:9a96:: with SMTP id c144mr25764049qke.207.1593040849174; Wed, 24 Jun 2020 16:20:49 -0700 (PDT) Received: from ziepe.ca ([206.223.160.26]) by smtp.gmail.com with ESMTPSA id a28sm4047194qko.45.2020.06.24.16.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 16:20:48 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.93) (envelope-from ) id 1joEhD-00DqBT-Fa; Wed, 24 Jun 2020 20:20:47 -0300 Date: Wed, 24 Jun 2020 20:20:47 -0300 From: Jason Gunthorpe To: John Hubbard Cc: Chris Wilson , linux-mm@kvack.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, Andrew Morton , Jan Kara , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Claudio Imbrenda , "Kirill A . Shutemov" Subject: Re: [PATCH] mm: Skip opportunistic reclaim for dma pinned pages Message-ID: <20200624232047.GP6578@ziepe.ca> References: <20200624191417.16735-1-chris@chris-wilson.co.uk> <20200624192116.GO6578@ziepe.ca> <44708b2e-479f-7d58-fe01-29cfd6c70bdb@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44708b2e-479f-7d58-fe01-29cfd6c70bdb@nvidia.com> X-Rspamd-Queue-Id: 6149030000D08FC8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 Wed, Jun 24, 2020 at 01:47:23PM -0700, John Hubbard wrote: > On 2020-06-24 12:21, Jason Gunthorpe wrote: > > On Wed, Jun 24, 2020 at 08:14:17PM +0100, Chris Wilson wrote: > > > A general rule of thumb is that shrinkers should be fast and effective. > > > They are called from direct reclaim at the most incovenient of times when > > > the caller is waiting for a page. If we attempt to reclaim a page being > > > pinned for active dma [pin_user_pages()], we will incur far greater > > > latency than a normal anonymous page mapped multiple times. Worse the > > > page may be in use indefinitely by the HW and unable to be reclaimed > > > in a timely manner. > > > > A pinned page can't be migrated, discarded or swapped by definition - > > it would cause data corruption. > > > > So, how do things even get here and/or work today at all? I think the > > explanation is missing something important. > > > > Well, those activities generally try to unmap the page, and > have to be prepared to deal with failure to unmap. From my reading, > it seemed very clear. I think Yang explained it - the page is removed from the mappings but freeing it does not happen because page_ref_freeze() does not succeed due to the pin. Presumably the mappings can reconnect to the same physical page if it is re-faulted to avoid any data corruption. So, the issue here is the mappings are trashed while the page remains - and trashing the mapping triggers a mmu notifier which upsets i915. > What's less clear is why the comment and the commit description > only talk about reclaim, when there are additional things that call > try_to_unmap(), including: > > migrate_vma_unmap() > split_huge_page_to_list() --> unmap_page() It looks like the same unmap first then abort if the refcount is still elevated design as shrink_page_list() ? > I do like this code change, though. And I *think* it's actually safe to > do this, as it stays away from writeback or other filesystem activity. > But let me double check that, in case I'm forgetting something. It would be nice to have an explanation why it is OK now to change it.. I don't know, but could it be that try_to_unmap() has to be done before checking the refcount as each mapping is included in the refcount? ie we couldn't know a DMA pin was active in advance? Now that we have your pin stuff we can detect a DMA pin without doing all the unmaps? Jason