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=-5.3 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 0C3B3C433E6 for ; Mon, 8 Feb 2021 08:21:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 62B0A64E87 for ; Mon, 8 Feb 2021 08:21:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62B0A64E87 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A75F86B006E; Mon, 8 Feb 2021 03:21:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A000E6B0070; Mon, 8 Feb 2021 03:21:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C7C16B0071; Mon, 8 Feb 2021 03:21:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 71BAE6B006E for ; Mon, 8 Feb 2021 03:21:57 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 271BB180AD81A for ; Mon, 8 Feb 2021 08:21:57 +0000 (UTC) X-FDA: 77794407474.13.sense33_2712f52275fd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 05B3F18140B67 for ; Mon, 8 Feb 2021 08:21:56 +0000 (UTC) X-HE-Tag: sense33_2712f52275fd X-Filterd-Recvd-Size: 8125 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Mon, 8 Feb 2021 08:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612772515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DJj/eM72zDKRzFdR3uq7IOOzFEK9yZtZ/1IHJ8Iiu80=; b=T9FOA9eOG1+AFbwsOlJujTJ2rS5/iWA9VAhV4m/lcSb/vy8pxpkw8qtyLQc9QsoEQgYcUx 0LsgeiWsECraP8JSiA98bBEGI85xAkqvNYLcrDKJDOHfQB4+EGaJvxgtmH69XPFoJMsehO dZseg7mtbyvkavxW0WUBhr9CMu2Tipk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-346-wnE7NQ8nMlC-J6d6ylO5cA-1; Mon, 08 Feb 2021 03:21:51 -0500 X-MC-Unique: wnE7NQ8nMlC-J6d6ylO5cA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 805A4801962; Mon, 8 Feb 2021 08:21:49 +0000 (UTC) Received: from [10.36.113.240] (ovpn-113-240.ams2.redhat.com [10.36.113.240]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1004AE14E; Mon, 8 Feb 2021 08:21:42 +0000 (UTC) To: "Song Bao Hua (Barry Song)" , Matthew Wilcox Cc: "Wangzhou (B)" , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "linux-mm@kvack.org" , "linux-arm-kernel@lists.infradead.org" , "linux-api@vger.kernel.org" , Andrew Morton , Alexander Viro , "gregkh@linuxfoundation.org" , "jgg@ziepe.ca" , "kevin.tian@intel.com" , "jean-philippe@linaro.org" , "eric.auger@redhat.com" , "Liguozhu (Kenneth)" , "zhangfei.gao@linaro.org" , "chensihang (A)" References: <1612685884-19514-1-git-send-email-wangzhou1@hisilicon.com> <1612685884-19514-2-git-send-email-wangzhou1@hisilicon.com> <20210207213409.GL308988@casper.infradead.org> <20210208013056.GM308988@casper.infradead.org> From: David Hildenbrand Organization: Red Hat GmbH Subject: Re: [RFC PATCH v3 1/2] mempinfd: Add new syscall to provide memory pin Message-ID: Date: Mon, 8 Feb 2021 09:21:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: On 08.02.21 03:27, Song Bao Hua (Barry Song) wrote: >=20 >=20 >> -----Original Message----- >> From: owner-linux-mm@kvack.org [mailto:owner-linux-mm@kvack.org] On Be= half Of >> Matthew Wilcox >> Sent: Monday, February 8, 2021 2:31 PM >> To: Song Bao Hua (Barry Song) >> Cc: Wangzhou (B) ; linux-kernel@vger.kernel.o= rg; >> iommu@lists.linux-foundation.org; linux-mm@kvack.org; >> linux-arm-kernel@lists.infradead.org; linux-api@vger.kernel.org; Andre= w >> Morton ; Alexander Viro ; >> gregkh@linuxfoundation.org; jgg@ziepe.ca; kevin.tian@intel.com; >> jean-philippe@linaro.org; eric.auger@redhat.com; Liguozhu (Kenneth) >> ; zhangfei.gao@linaro.org; chensihang (A) >> >> Subject: Re: [RFC PATCH v3 1/2] mempinfd: Add new syscall to provide m= emory >> pin >> >> On Sun, Feb 07, 2021 at 10:24:28PM +0000, Song Bao Hua (Barry Song) wr= ote: >>>>> In high-performance I/O cases, accelerators might want to perform >>>>> I/O on a memory without IO page faults which can result in dramatic= ally >>>>> increased latency. Current memory related APIs could not achieve th= is >>>>> requirement, e.g. mlock can only avoid memory to swap to backup dev= ice, >>>>> page migration can still trigger IO page fault. >>>> >>>> Well ... we have two requirements. The application wants to not tak= e >>>> page faults. The system wants to move the application to a differen= t >>>> NUMA node in order to optimise overall performance. Why should the >>>> application's desires take precedence over the kernel's desires? An= d why >>>> should it be done this way rather than by the sysadmin using numactl= to >>>> lock the application to a particular node? >>> >>> NUMA balancer is just one of many reasons for page migration. Even on= e >>> simple alloc_pages() can cause memory migration in just single NUMA >>> node or UMA system. >>> >>> The other reasons for page migration include but are not limited to: >>> * memory move due to CMA >>> * memory move due to huge pages creation >>> >>> Hardly we can ask users to disable the COMPACTION, CMA and Huge Page >>> in the whole system. >> >> You're dodging the question. Should the CMA allocation fail because >> another application is using SVA? >> >> I would say no. >=20 > I would say no as well. >=20 > While IOMMU is enabled, CMA almost has one user only: IOMMU driver > as other drivers will depend on iommu to use non-contiguous memory > though they are still calling dma_alloc_coherent(). >=20 > In iommu driver, dma_alloc_coherent is called during initialization > and there is no new allocation afterwards. So it wouldn't cause > runtime impact on SVA performance. Even there is new allocations, > CMA will fall back to general alloc_pages() and iommu drivers are > almost allocating small memory for command queues. >=20 > So I would say general compound pages, huge pages, especially > transparent huge pages, would be bigger concerns than CMA for > internal page migration within one NUMA. >=20 > Not like CMA, general alloc_pages() can get memory by moving > pages other than those pinned. >=20 > And there is no guarantee we can always bind the memory of > SVA applications to single one NUMA, so NUMA balancing is > still a concern. >=20 > But I agree we need a way to make CMA success while the userspace > pages are pinned. Since pin has been viral in many drivers, I > assume there is a way to handle this. Otherwise, APIs like > V4L2_MEMORY_USERPTR[1] will possibly make CMA fail as there > is no guarantee that usersspace will allocate unmovable memory > and there is no guarantee the fallback path- alloc_pages() can > succeed while allocating big memory. >=20 Long term pinnings cannot go onto CMA-reserved memory, and there is=20 similar work to also fix ZONE_MOVABLE in that regard. https://lkml.kernel.org/r/20210125194751.1275316-1-pasha.tatashin@soleen.= com One of the reasons I detest using long term pinning of pages where it=20 could be avoided. Take VFIO and RDMA as an example: these things=20 currently can't work without them. What I read here: "DMA performance will be affected severely". That does=20 not sound like a compelling argument to me for long term pinnings.=20 Please find another way to achieve the same goal without long term=20 pinnings controlled by user space - e.g., controlling when migration=20 actually happens. For example, CMA/alloc_contig_range()/memory unplug are corner cases=20 that happen rarely, you shouldn't have to worry about them messing with=20 your DMA performance. --=20 Thanks, David / dhildenb