Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp97583imm; Tue, 16 Oct 2018 18:49:14 -0700 (PDT) X-Google-Smtp-Source: ACcGV62HhGe8evUBuZtSae6qJ/rGv8aNBsGbRS7NPfAVmq7rKCXH5UdcIuXY35kut8Lmcv/AbpgV X-Received: by 2002:a17:902:b696:: with SMTP id c22-v6mr24063321pls.37.1539740954415; Tue, 16 Oct 2018 18:49:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539740954; cv=none; d=google.com; s=arc-20160816; b=l5EKQ6LFZ7oBvwYg5rEPinxuS3mU/lAVHZL0q9w5pjS0tazBUecejnz8h5p69WLKXr s2djFU7vTJBodpdEBtrYwn+AOLlcCMIWJApH3u56aoczu/6FyO2cYWm5F82+SgfwN9rV fNG9leNiRsc8PVl50BEd2YNhn92hpUDRIzTIuNGu/aFus3cHmxXWgN9rzAIKPyQ2BQ7q Ray9fxkzsRTqz39e6p+E4IVBv+UsplKayv0TdXTTpKan12l4xzhSRFIE2qUATTY+AzFb lUlN97shgc6PGHVRTBARlo7ZuI7S/GfhcG7B9bf1GFgcACotcNkA9rEEj3sKbG0bQTFT yU7w== 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=b4/mJam0D1fhRUlyqVCwxK8d3kEQAgqNaK05DHLC8H0=; b=bWDUPXMiXTF82daYNOURF82oTNKVFvYQ6dNtqz/WURAqxoOekSni/Eu3VSEOq08Bkr OMCIDxdq21URWvmlCG8ElX8zFbiQLGkWa3Pgf6PfkILMhq/yYk9BNhMtKNywGLwEuMm1 c/TwLbUmjQNLJAYQMlbWqxa/C1zkEXVX2FY3vLlNVOKen+t62hdxZOhBkFWcu75ReePS Xu5l86ajyzPoScMexzudxcrAnDHSGmqD8hcxt07843cWWEVGNAaNLtKN06/K0mXdng4a ZJ0gnZVjKs3INV0/v2wdNh083yczGGJsKvLGBddQuTC1j9mDhlmw+l6xVevJsAerqqn2 A0gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b="gPvh6/GS"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id o30-v6si15641944pgb.386.2018.10.16.18.48.57; Tue, 16 Oct 2018 18:49:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b="gPvh6/GS"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727260AbeJQJlm (ORCPT + 99 others); Wed, 17 Oct 2018 05:41:42 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:10489 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726210AbeJQJll (ORCPT ); Wed, 17 Oct 2018 05:41:41 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 16 Oct 2018 18:48:21 -0700 Received: from HQMAIL101.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 16 Oct 2018 18:48:24 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 16 Oct 2018 18:48:24 -0700 Received: from [10.2.167.215] (172.20.13.39) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 17 Oct 2018 01:48:23 +0000 Subject: Re: [PATCH 4/6] mm: introduce page->dma_pinned_flags, _count To: Jan Kara , Dave Chinner CC: Matthew Wilcox , Michal Hocko , Christopher Lameter , Jason Gunthorpe , Dan Williams , , Andrew Morton , LKML , linux-rdma , References: <20181012060014.10242-1-jhubbard@nvidia.com> <20181012060014.10242-5-jhubbard@nvidia.com> <20181013035516.GA18822@dastard> <7c2e3b54-0b1d-6726-a508-804ef8620cfd@nvidia.com> <20181013230124.GB18822@dastard> <20181016085102.GB18918@quack2.suse.cz> From: John Hubbard X-Nvconfidentiality: public Message-ID: Date: Tue, 16 Oct 2018 18:48:23 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20181016085102.GB18918@quack2.suse.cz> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL101.nvidia.com (172.20.187.10) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1539740901; bh=b4/mJam0D1fhRUlyqVCwxK8d3kEQAgqNaK05DHLC8H0=; h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=gPvh6/GSAXbWNCowYe4KAQjnUnW5aDWuxE6PJWdW8aIRiIl05z6Co3ecpR+Mt4ttS 9cWhuDneyBmZi1FRwzi6YYKDa9RfhLlRDLVz/krw3Im8gNWLOxSxVFHamcHH7++XI2 EaTW8AKwVFU8myZ/9n4wdXzT09EpuXj1sGeB9zU5Q/HhZFu3ZP8/otlbjys9+hqpAJ o81b8KlSxZKn0dt1MDTTLZymhiI6ohs2EZqKw2UyNq63HAA39xGqOBdVgAvVSPfv6r uyFQaZlRq2/WbXffPgtT3mqZpVAQNMJP67iYXtVWRmIG4DPy5xRs8iRSB91Yn1H3L5 Q1ltLPefL50GQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/16/18 1:51 AM, Jan Kara wrote: > On Sun 14-10-18 10:01:24, Dave Chinner wrote: >> On Sat, Oct 13, 2018 at 12:34:12AM -0700, John Hubbard wrote: >>> On 10/12/18 8:55 PM, Dave Chinner wrote: >>>> On Thu, Oct 11, 2018 at 11:00:12PM -0700, john.hubbard@gmail.com wrote: >>>>> From: John Hubbard >>> [...] >>>>> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h >>>>> index 5ed8f6292a53..017ab82e36ca 100644 >>>>> --- a/include/linux/mm_types.h >>>>> +++ b/include/linux/mm_types.h >>>>> @@ -78,12 +78,22 @@ struct page { >>>>> */ >>>>> union { >>>>> struct { /* Page cache and anonymous pages */ >>>>> - /** >>>>> - * @lru: Pageout list, eg. active_list protected by >>>>> - * zone_lru_lock. Sometimes used as a generic list >>>>> - * by the page owner. >>>>> - */ >>>>> - struct list_head lru; >>>>> + union { >>>>> + /** >>>>> + * @lru: Pageout list, eg. active_list protected >>>>> + * by zone_lru_lock. Sometimes used as a >>>>> + * generic list by the page owner. >>>>> + */ >>>>> + struct list_head lru; >>>>> + /* Used by get_user_pages*(). Pages may not be >>>>> + * on an LRU while these dma_pinned_* fields >>>>> + * are in use. >>>>> + */ >>>>> + struct { >>>>> + unsigned long dma_pinned_flags; >>>>> + atomic_t dma_pinned_count; >>>>> + }; >>>>> + }; >>>> >>>> Isn't this broken for mapped file-backed pages? i.e. they may be >>>> passed as the user buffer to read/write direct IO and so the pages >>>> passed to gup will be on the active/inactive LRUs. hence I can't see >>>> how you can have dual use of the LRU list head like this.... >>>> >>>> What am I missing here? >>> >>> Hi Dave, >>> >>> In patch 6/6, pin_page_for_dma(), which is called at the end of get_user_pages(), >>> unceremoniously rips the pages out of the LRU, as a prerequisite to using >>> either of the page->dma_pinned_* fields. >> >> How is that safe? If you've ripped the page out of the LRU, it's no >> longer being tracked by the page cache aging and reclaim algorithms. >> Patch 6 doesn't appear to put these pages back in the LRU, either, >> so it looks to me like this just dumps them on the ground after the >> gup reference is dropped. How do we reclaim these page cache pages >> when there is memory pressure if they aren't in the LRU? > > Yeah, that's a bug in patch 6/6 (possibly in ClearPageDmaPinned). It should > return the page to the LRU from put_user_page(). > Yes. Ugh, the LRU handling in this series is definitely not all there yet: probably need to track (in the page->dma_pinned_flags) which LRU (if any) each page was taken from. It's hard to say exactly what the active/inactive/unevictable list should be when DMA is done and put_user_page*() is called, because we don't know if some device read, wrote, or ignored any of those pages. Although if put_user_pages_dirty() is called, that's an argument for "active", at least. And maybe this will all be pointless if the DIRECT_IO performance test, that Christoph requested, shows that LRU operations are too expensive here, anyway. I wonder if we should just limit this to 64-bit arches and find a real page flag...well, let's see what the testing shows first I suppose. -- thanks, John Hubbard NVIDIA