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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 4E355C63777 for ; Fri, 20 Nov 2020 21:54:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 80E4E22254 for ; Fri, 20 Nov 2020 21:54:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="X7MLb6Q6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80E4E22254 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B8A886B005C; Fri, 20 Nov 2020 16:54:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B13F76B005D; Fri, 20 Nov 2020 16:54:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DA706B0068; Fri, 20 Nov 2020 16:54:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 6A6ED6B005C for ; Fri, 20 Nov 2020 16:54:34 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 10685180ACC36 for ; Fri, 20 Nov 2020 21:54:34 +0000 (UTC) X-FDA: 77506151268.30.cub14_5715b3a2734e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id E36A7180B3C83 for ; Fri, 20 Nov 2020 21:54:33 +0000 (UTC) X-HE-Tag: cub14_5715b3a2734e X-Filterd-Recvd-Size: 6467 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Nov 2020 21:54:33 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id bo9so9153579ejb.13 for ; Fri, 20 Nov 2020 13:54:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=BdGxZHHmNWUjxqYGOe+E7s2xXNJsvySUdvnv2lEf71E=; b=X7MLb6Q6fRECqWHpGN/RhKmYjHYauDLrSBvyd3prItB4mnb08UyJgAUVNo7NujpNDb kUaFG/GtH+ofG3FrxNu4EsTUDLUWtQ8HMEKRcMkZvEGkJP+SYaYMtSK/GP13TrP78HNB OGHs2r/zoDEfWLprdi64t0CfJQwI/miuV7r3NlEsXYMne1Y7NQLujpcX6FVi0sjmt8yJ RNt3qI2W5xvpe7EZg9JLzt1D67oSCCdb/nQNp29/WtbOxGrRH0vmc+dKy2uFSBEvSORd Ne4RW1OcCI+1n9QMw+Gk4dEes4uWXz/cpuPpZHaopPiWhiZnj1I69mf/vxEdJqwBFcHP 76Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=BdGxZHHmNWUjxqYGOe+E7s2xXNJsvySUdvnv2lEf71E=; b=DjsKO0B1vc7n2RZk2iU9TehmPpaXK31gMrJInRi53nQR2nVlLgyUZnMNM9hywcBx1r m8i8HnEVwHN3e9TpVlCCQk2W3OTfm1/Px0ZpQKurdIhdAPtK6wJn5WtNEeIfoOOvWiC6 Ee10G9hmZ1CpCSCOadpry8bWS91DpziiK7QT5VeVlBFFqs9XO8X9Xszdfphjzn4uq4eM 274c1F8e+1UPMsyeNt9NcmTymtihJQcCpOGOwoQs2HfvnNOEXM8x+ey1gcOIZdPSAinR pKHQqa2DVie1FZloY7i6TogoTZdq2rKCyHYBPrtQYBAGBh/IugLtwCV8fuOWSBdxQAsj XGNg== X-Gm-Message-State: AOAM53237bzRd+he8ly7D2yuOi75/dyT7cuyJIUeeVLhFqTjoSXHTO1G 6m462GxDpmBgK+SFi6bvBoS+PhX7UPxDC7+GDORFew== X-Google-Smtp-Source: ABdhPJyE2b/0YtawlbtxEUnWGo0jKy4x0sab3BacEj+0/c6kKxXAnmdvCPHRiJBllOsf974BtGexofusrunUiAvykHo= X-Received: by 2002:a17:906:1458:: with SMTP id q24mr36056793ejc.541.1605909272243; Fri, 20 Nov 2020 13:54:32 -0800 (PST) MIME-Version: 1.0 References: <20201120211707.GC4327@casper.infradead.org> <9C8F0E5D-2D42-4BA5-A5B5-9E049E1BE862@redhat.com> In-Reply-To: <9C8F0E5D-2D42-4BA5-A5B5-9E049E1BE862@redhat.com> From: Pavel Tatashin Date: Fri, 20 Nov 2020 16:53:56 -0500 Message-ID: Subject: Re: Pinning ZONE_MOVABLE pages To: David Hildenbrand Cc: Matthew Wilcox , linux-mm , Andrew Morton , Vlastimil Babka , LKML , Michal Hocko , Oscar Salvador , Dan Williams , Sasha Levin , Tyler Hicks , Joonsoo Kim , sthemmin@microsoft.com Content-Type: text/plain; charset="UTF-8" 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 Fri, Nov 20, 2020 at 4:34 PM David Hildenbrand wrote: > > > > Am 20.11.2020 um 22:17 schrieb Matthew Wilcox : > > > > =EF=BB=BFOn Fri, Nov 20, 2020 at 09:59:24PM +0100, David Hildenbrand wr= ote: > >> > >>>> Am 20.11.2020 um 21:28 schrieb Pavel Tatashin : > >>> > >>> =EF=BB=BFRecently, I encountered a hang that is happening during memo= ry hot > >>> remove operation. It turns out that the hang is caused by pinned user > >>> pages in ZONE_MOVABLE. > >>> > >>> Kernel expects that all pages in ZONE_MOVABLE can be migrated, but > >>> this is not the case if a user applications such as through dpdk > >>> libraries pinned them via vfio dma map. Kernel keeps trying to > >>> hot-remove them, but refcnt never gets to zero, so we are looping > >>> until the hardware watchdog kicks in. > >>> > >>> We cannot do dma unmaps before hot-remove, because hot-remove is a > >>> slow operation, and we have thousands for network flows handled by > >>> dpdk that we just cannot suspend for the duration of hot-remove > >>> operation. > >>> > >> > >> Hi! > >> > >> It=E2=80=98s a known problem also for VMs using vfio. I thought about = this some while ago an came to the same conclusion: before performing long-= term pinnings, we have to migrate pages off the movable zone. After that, i= t=E2=80=98s too late. > > > > We can't, though. VMs using vfio pin their entire address space (right= ?) > > so we end up with basically all of the !MOVABLE memory used for VMs and > > the MOVABLE memory goes unused (I'm thinking about the case of a machin= e > > which only hosts VMs and has nothing else to do with its memory). In > > that case, the sysadmin is going to reconfigure ZONE_MOVABLE away, and > > now we just don't have any ZONE_MOVABLE. So what's the point? > > When the guest is using an vIOMMU, it will only pin what=E2=80=98s curren= tly mapped by the guest into the vIOMMU. Otherwise: yes. Right, not all guest memory needs to be pinned, so ZONE_MOVABLE can still be used for a vast amount of allocations. > > If you assume all memory will be used for VMs with vfio, then yes: no ZON= E_MOVABLE, no memory hotunplug. If its=E2=80=98s only some VMs, it=E2=80=98= s a different story. Sounds like in such an extreme case it is reasonable to assume no hot-plug. But, when you have 8G, and need to remove 2G movable zone, but can't guarantee it even if you have 6G of free mem, this is unreasonable. > > > > > ZONE_MOVABLE can also be pinned by mlock() and other such system calls. > > Mlocked pages can be migrated, no? They are simply not swappable iirc. Yes, mlocked they are simply in memory, but the content of the pages can be migrated to a different place in RAM. > > > The kernel needs to understand that ZONE_MOVABLE memory may not actuall= y > > be movable, and skip the unmovable stuff. > > > > Then you don=E2=80=98t have unplug guarantees. Memory unplug broken by de= sign. Then there is no point in optimizing that case at all and tell custom= ers =E2=80=9Evfio and memory hotunplug is incompatible=E2=80=9C. The only u= gly thing is the endless loop. Right, if memory in ZONE_MOVABLE is not guaranteed to be movable, we can never guarantee memory hot-remove even when we have a lot of free memory to migrate to. >