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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEDD0C43334 for ; Sat, 18 Jun 2022 09:33:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21AD26B0078; Sat, 18 Jun 2022 05:33:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CB056B007B; Sat, 18 Jun 2022 05:33:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06B616B007D; Sat, 18 Jun 2022 05:33:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E608A6B0078 for ; Sat, 18 Jun 2022 05:33:10 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id B8CB680170 for ; Sat, 18 Jun 2022 09:33:10 +0000 (UTC) X-FDA: 79590842940.05.527AAD3 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by imf14.hostedemail.com (Postfix) with ESMTP id 6550F100080 for ; Sat, 18 Jun 2022 09:33:10 +0000 (UTC) Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-317a66d62dfso785607b3.7 for ; Sat, 18 Jun 2022 02:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Z0T2DhVRfdza3u7Hv/gMF8uaCaWYLQxsRMrZYAVQe+E=; b=hhOwVI2grUzcFZ0ZVRIzkXvpwrmX74i616R9TXr/QGGLafVdd6PqZPYq8cCpnbAguu eobuXZNnjB/K9lF43LKAw5hwh39dVDNxoRIQslaCf2rNMQrrZZpirfugII2o4q9yOtZl qmhJeIOfC58MR4YJg10Ph1hBVP9XOCirm4VEGWG+Bf4A/p7flbedOymFWXD8O7Gordti c+XD/cLUBMrsaadj8++He3td3LVG+hgJ0zQ/LSEo8aYftTQPolWNol3hNhe7db6lAMpA JDd8nfrVBcZ8VElsTPoFEclc4ta4nwZq4jL8bnfaUa4nuktELN+GCS6+9UA8RuMQ63dy Sa3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Z0T2DhVRfdza3u7Hv/gMF8uaCaWYLQxsRMrZYAVQe+E=; b=gIAn6Tndj/VjSnFMV+xjpEeaw++I4DVBIBLd2ERsur/rbggFbo3zoHW7qilDqd2/hV 8BwTeQdhFxAOds/HvHhuCKk/GR9ydmlPVjjKwY2FH2ZL2E+Y3Qh1Y5gyYewtqf19Jwus CzgHdG6pi0akAE8eVDkxSxrKgcv1vxBaJXVZ9Y6AmHFzMiWS/cycXsvud6ipiRpmUSzn 9fvlBWabVX28/wcfrELWHxKifjy8mQ6W3HLCSOBV0PGSelpmIGaO33T75omLSoKz2ATw cZIn3HfAjo2UcupL8FyIh5/ZKEmtJ+g1Zry6s7zStXE4ueNg4pRoIdKwnlIMLBNB3ine Mwnw== X-Gm-Message-State: AJIora8lsWPD0F9w0rnmmTv926wHEIJH/oaroYTzz+oawcRTUoGzad5Z saf+MA4Nsqkxhc+aLiZL19VlYKYoWJALT0ru7gc= X-Google-Smtp-Source: AGRyM1vn2cH6zGfArfaosFc+y9vfluuDeE8YyIEY6QF6n7KxHF4JLzJuPADGF0ikBubxdlhb5eiyviROp85UPabBXiQ= X-Received: by 2002:a81:7c42:0:b0:317:7789:85aa with SMTP id x63-20020a817c42000000b00317778985aamr12095755ywc.93.1655544789470; Sat, 18 Jun 2022 02:33:09 -0700 (PDT) MIME-Version: 1.0 References: <20220531200041.24904-1-alex.sierra@amd.com> <20220531200041.24904-2-alex.sierra@amd.com> <3ac89358-2ce0-7d0d-8b9c-8b0e5cc48945@redhat.com> <02ed2cb7-3ad3-8ffc-6032-04ae1853e234@amd.com> In-Reply-To: <02ed2cb7-3ad3-8ffc-6032-04ae1853e234@amd.com> From: Oded Gabbay Date: Sat, 18 Jun 2022 12:32:42 +0300 Message-ID: Subject: Re: [PATCH v5 01/13] mm: add zone device coherent type memory support To: "Sierra Guiza, Alejandro (Alex)" Cc: David Hildenbrand , Jason Gunthorpe , rcampbell@nvidia.com, Matthew Wilcox , "Kuehling, Felix" , apopple@nvidia.com, amd-gfx list , linux-xfs@vger.kernel.org, linux-mm , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Maling list - DRI developers , Andrew Morton , linux-ext4@vger.kernel.org, Christoph Hellwig Content-Type: text/plain; charset="UTF-8" ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hhOwVI2g; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of oded.gabbay@gmail.com designates 209.85.128.182 as permitted sender) smtp.mailfrom=oded.gabbay@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655544790; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Z0T2DhVRfdza3u7Hv/gMF8uaCaWYLQxsRMrZYAVQe+E=; b=xNkukm8aMxSOwsr5cSWU43e1cj2P8doqX8SYHksSIn+00gdbYaqVea+7HyDhUxGDdeoz74 trgOy4ZsI/lRGDWHKEL7CpzpvAJPh7jjj30vs7NGSMlH2TqO62uKyiWrcM0mjTNZR5O8I1 S2NA7xAytIT2saEwcQwP49bqQ8Xun9k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655544790; a=rsa-sha256; cv=none; b=XfFvnRUpFv2d9DKqkOh5KU1vaR7d6IVxuGIi9ZzEr8d3ZfOtQwhiC9N1DGjwayxxISa170 +xbt3M9afUYJRXup+N4EPqn12t8wkls9djJg0aq8FFJH70oEgs30wz/2u4oL+ogTEub2Oy NTHdS/pzndDsO0kkFWXGtW9knz39EM8= X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6550F100080 X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hhOwVI2g; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of oded.gabbay@gmail.com designates 209.85.128.182 as permitted sender) smtp.mailfrom=oded.gabbay@gmail.com X-Stat-Signature: qmxto5dgchik7fcfc7tyy4obbob65k3x X-HE-Tag: 1655544790-466499 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 Fri, Jun 17, 2022 at 8:20 PM Sierra Guiza, Alejandro (Alex) wrote: > > > On 6/17/2022 4:40 AM, David Hildenbrand wrote: > > On 31.05.22 22:00, Alex Sierra wrote: > >> Device memory that is cache coherent from device and CPU point of view. > >> This is used on platforms that have an advanced system bus (like CAPI > >> or CXL). Any page of a process can be migrated to such memory. However, > >> no one should be allowed to pin such memory so that it can always be > >> evicted. > >> > >> Signed-off-by: Alex Sierra > >> Acked-by: Felix Kuehling > >> Reviewed-by: Alistair Popple > >> [hch: rebased ontop of the refcount changes, > >> removed is_dev_private_or_coherent_page] > >> Signed-off-by: Christoph Hellwig > >> --- > >> include/linux/memremap.h | 19 +++++++++++++++++++ > >> mm/memcontrol.c | 7 ++++--- > >> mm/memory-failure.c | 8 ++++++-- > >> mm/memremap.c | 10 ++++++++++ > >> mm/migrate_device.c | 16 +++++++--------- > >> mm/rmap.c | 5 +++-- > >> 6 files changed, 49 insertions(+), 16 deletions(-) > >> > >> diff --git a/include/linux/memremap.h b/include/linux/memremap.h > >> index 8af304f6b504..9f752ebed613 100644 > >> --- a/include/linux/memremap.h > >> +++ b/include/linux/memremap.h > >> @@ -41,6 +41,13 @@ struct vmem_altmap { > >> * A more complete discussion of unaddressable memory may be found in > >> * include/linux/hmm.h and Documentation/vm/hmm.rst. > >> * > >> + * MEMORY_DEVICE_COHERENT: > >> + * Device memory that is cache coherent from device and CPU point of view. This > >> + * is used on platforms that have an advanced system bus (like CAPI or CXL). A > >> + * driver can hotplug the device memory using ZONE_DEVICE and with that memory > >> + * type. Any page of a process can be migrated to such memory. However no one > > Any page might not be right, I'm pretty sure. ... just thinking about special pages > > like vdso, shared zeropage, ... pinned pages ... > > Hi David, > > Yes, I think you're right. This type does not cover all special pages. > I need to correct that on the cover letter. > Pinned pages are allowed as long as they're not long term pinned. > > Regards, > Alex Sierra What if I want to hotplug this device's coherent memory, but I do *not* want the OS to migrate any page to it ? I want to fully-control what resides on this memory, as I can consider this memory "expensive". i.e. I don't have a lot of it, I want to use it for specific purposes and I don't want the OS to start using it when there is some memory pressure in the system. Oded > > > > >> + * should be allowed to pin such memory so that it can always be evicted. > >> + * > >> * MEMORY_DEVICE_FS_DAX: > >> * Host memory that has similar access semantics as System RAM i.e. DMA > >> * coherent and supports page pinning. In support of coordinating page > >> @@ -61,6 +68,7 @@ struct vmem_altmap { > >> enum memory_type { > >> /* 0 is reserved to catch uninitialized type fields */ > >> MEMORY_DEVICE_PRIVATE = 1, > >> + MEMORY_DEVICE_COHERENT, > >> MEMORY_DEVICE_FS_DAX, > >> MEMORY_DEVICE_GENERIC, > >> MEMORY_DEVICE_PCI_P2PDMA, > >> @@ -143,6 +151,17 @@ static inline bool folio_is_device_private(const struct folio *folio) > > In general, this LGTM, and it should be correct with PageAnonExclusive I think. > > > > > > However, where exactly is pinning forbidden? > > Long-term pinning is forbidden since it would interfere with the device > memory manager owning the > device-coherent pages (e.g. evictions in TTM). However, normal pinning > is allowed on this device type. > > Regards, > Alex Sierra > > >