Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1005013ybt; Wed, 24 Jun 2020 17:13:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwp8ltW1d9j2NrDYGYjsg+gobqiRMT0K/DuEKP+mAM/5dgQvNQIm/JwzrV6QQHENwCuUJJ X-Received: by 2002:a50:a721:: with SMTP id h30mr29542115edc.153.1593043996067; Wed, 24 Jun 2020 17:13:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593043996; cv=none; d=google.com; s=arc-20160816; b=dmt/vfxV4pwsZawUML+nWz+BdcXvj5prGV5bAGfvuyOX/jRQ4A1safe/s4jIiRPspF WNIB4Oh+hreQBNHQS/qg4WBgudHYAnTZ8MHZ7uqePRN6s1UUKDp6jQTHceocuYBAfKDZ BElfX4N4NHFIqIv820eZyE05dj7KLroPuSWDfG9JSuG4wP0MHxjA3BuPPDr2N+39XD90 39t/XfOm9pkNqYwvN2VkuiS6RvzOI3ovrFw71LCZxz/Gc5Oq122KP4N4CwuvJSUmoFkP OxX2gVkoCHw8D3D8nBQ5z0DHHhOXDs1twKRZaE9gM8vGI2q/jPJD0YmVINDaa2RhZdhh GVtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=HgfzVvVqN21hLMs0lCHOTEd/EC0i4XdyaUbWxeMoOfA=; b=rv32xfcnpgz9No7B85It6bL47bncyUq2g7CaXCr7s+5y6DRUysa0471CnWqNimKBFQ 2w8pg5z0q3z30kRXoMp3DwZnhBPJbCPzbaorl9NSaNwh9d3ib8Q/EDCLV7aVwmTX6Kos 9nRJfwtdaoixNNLykeHaYVtEPoyFbFunuDnU9noIPxcTsBnkF3DkHZtQQoa+mNHZXK8x 0kDLlZmu3rCBj864POomTHrN0Y85w70d4LVW6ePZfeA1cwtD6cy7hw918GF0YaYp4TJL CvlDXqZvJF03lBC5Hgr0AsUfuSZaUMpxgZfNAZvMZl41MYEGc7th19PqdbcJi2YcyPGj iGyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=BzwIdhXh; 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=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p4si5801860edq.201.2020.06.24.17.12.52; Wed, 24 Jun 2020 17:13:16 -0700 (PDT) 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=@nvidia.com header.s=n1 header.b=BzwIdhXh; 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=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388963AbgFYALf (ORCPT + 99 others); Wed, 24 Jun 2020 20:11:35 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:12433 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388412AbgFYALe (ORCPT ); Wed, 24 Jun 2020 20:11:34 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 24 Jun 2020 17:11:21 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Wed, 24 Jun 2020 17:11:34 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Wed, 24 Jun 2020 17:11:34 -0700 Received: from [10.2.59.206] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 25 Jun 2020 00:11:30 +0000 Subject: Re: [PATCH] mm: Skip opportunistic reclaim for dma pinned pages To: Jason Gunthorpe CC: Chris Wilson , , , , "Andrew Morton" , Jan Kara , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Claudio Imbrenda , "Kirill A . Shutemov" References: <20200624191417.16735-1-chris@chris-wilson.co.uk> <20200624192116.GO6578@ziepe.ca> <44708b2e-479f-7d58-fe01-29cfd6c70bdb@nvidia.com> <20200624232047.GP6578@ziepe.ca> From: John Hubbard Message-ID: <887ac706-65f0-3089-b51b-47aabf7d3847@nvidia.com> Date: Wed, 24 Jun 2020 17:11:30 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200624232047.GP6578@ziepe.ca> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1593043882; bh=HgfzVvVqN21hLMs0lCHOTEd/EC0i4XdyaUbWxeMoOfA=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=BzwIdhXhJaR4a1GFOREXvpV6vUVM0xoljaj4gyGV2TZqstSNPlA0ceFN6s9KnFBdE iH/boJYVyAOCocaXJ1GaY8MFDkY3XmDaWzguouPg/G5bCA7EMIsi76lhhdcj7zWsy1 XxFw8VvTeWEvK8lVKxA3Rmxa7MWeAdYQZPwvUgg86Kf8VWTQ72tk4LhlnTWgJAFMke G56/gtNQ+7U9O3rOBvgPxoAsdVr8oAzhJXMTS/KO9TdyvLTuXwR6BUlUvdAYg/Xorh UNuwyyk6SdwNfzBalWj6udbUWgd/aDchn8JWAgxcaCAuAaKmQbGuu3R6Te/OBRqkQ8 shubp1yPfhMOA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-24 16:20, Jason Gunthorpe wrote: ... > 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() ? Yes. I was just wondering why the documentation here seems to ignore the other, non-reclaim cases. Anyway, though... > >> 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. ...OK, I've checked, and I like it a little bit less now. Mainly for structural reasons, though. I think it would work correctly. But here's a concern: try_to_unmap() should only fail to unmap if there is a reason to not unmap. Having a page be pinned for dma is a reason to not *free* a page, and it's also a reason to be careful about writeback and page buffers for writeback and such. But I'm not sure that it's a reason to fail to remove mappings. True, most (all?) of the reasons that we remove mappings, generally are for things that are not allowed while a page is dma-pinned...at least, today. But still, there's nothing fundamental about a mapping that should prevent it from coming or going while a page is undergoing dma. So, it's merely a convenient, now-misnamed location in the call stack to fail out. That's not great. It might be better, as Jason hints at below, to fail out a little earlier, instead. That would lead to a more places to call page_maybe_dma_pinned(), but that's not a real problem, because it's still a small number of places. After writing all of that...I don't feel strongly about it, because TTU is kind of synonymous with "I'm about to do a dma-pin-unfriendly operation". Maybe some of the more experienced fs or mm people have strong opinions one way or the other? > > It would be nice to have an explanation why it is OK now to change > it.. Yes. Definitely good to explain that in the commit log. I think it's triggered by the existence of page_maybe_dma_pinned(). Until that was added, figuring out if dma was involved required basically just guesswork. Now we have a way to guess much more accurately. :) > > 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? > Once something calls pin_user_page*(), then the pages will be marked as dma-pinned, yes. So no, there is no need to wait until try_to_unmap() to find out. A final note: depending on where page_maybe_dma_pinned() ends up getting called, this might prevent a fair number of the problems that Jan originally reported [1], and that I also reported separately! Well, not all of the problems, and only after the filesystems get converted to call pin_user_pages() (working on that next), but...I think it would actually avoid the crash our customer reported back in early 2018. Even though we don't have the full file lease + pin_user_pages() solution in place. That's because reclaim is what triggers the problems that we saw. And with this patch, we bail out of reclaim early. [1] https://www.spinics.net/lists/linux-mm/msg142700.html thanks, -- John Hubbard NVIDIA