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 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 5A081C2D0E4 for ; Mon, 23 Nov 2020 09:01:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BA3F220731 for ; Mon, 23 Nov 2020 09:01:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="lCOXuryy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA3F220731 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 36C206B0072; Mon, 23 Nov 2020 04:01:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 31C366B0073; Mon, 23 Nov 2020 04:01:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20ACD6B0074; Mon, 23 Nov 2020 04:01:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id E79976B0072 for ; Mon, 23 Nov 2020 04:01:32 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7F2598249980 for ; Mon, 23 Nov 2020 09:01:32 +0000 (UTC) X-FDA: 77515089624.16.copy36_3b1181f27364 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 5B63C100E691E for ; Mon, 23 Nov 2020 09:01:32 +0000 (UTC) X-HE-Tag: copy36_3b1181f27364 X-Filterd-Recvd-Size: 5422 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Nov 2020 09:01:31 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1606122090; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=fjl5UMVuuyoQfqRCTSDt5soHTVWO5X8L91E971LLf0Y=; b=lCOXuryyJ+Vg74cLIHGG5VUmLp6mJJX5LYrnHYpwgsbBw/rJKy838IqLG35tdwexQ3e7EA 0HhQXbrNl3gjoNFoRXqZzMo2rgb5XEtz2PyEyjvxP01tiyquIxDq/X2zAfRwxpfD2xWFuT 0du1567VfjVs+Qux8IeR0lVdoEMNLo8= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 485BFAD57; Mon, 23 Nov 2020 09:01:30 +0000 (UTC) Date: Mon, 23 Nov 2020 10:01:29 +0100 From: Michal Hocko To: Pavel Tatashin Cc: linux-mm , Andrew Morton , Vlastimil Babka , LKML , David Hildenbrand , Oscar Salvador , Dan Williams , Sasha Levin , Tyler Hicks , Joonsoo Kim , sthemmin@microsoft.com Subject: Re: Pinning ZONE_MOVABLE pages Message-ID: <20201123090129.GD27488@dhcp22.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 20-11-20 15:27:46, Pavel Tatashin wrote: > Recently, I encountered a hang that is happening during memory 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. Long term or effectively time unbound pinning on zone movable is fundamentaly broken. The sole reason of ZONE_MOVABLE existence is to guarantee migrateability. If the cosumer of this memory cannot guarantee that then it shouldn't use __GFP_MOVABLE in the first place. > Kernel keeps trying to > hot-remove them, but refcnt never gets to zero, so we are looping > until the hardware watchdog kicks in. Yeah, the existing offlining behavior doesn't stop trying because the current implementation of the migration cannot tell a diffence between short and long term failures. Maybe the recent ref count for long term pinning can be used to help out there. Anyway, I am wondering what do you mean by watchdog firing. The operation should trigger neither of soft, hard or hung detectors. > 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. > > The solution is for dpdk to allocate pages from a zone below > ZONE_MOVAVLE, i.e. ZONE_NORMAL/ZONE_HIGHMEM, but this is not possible. > There is no user interface that we have that allows applications to > select what zone the memory should come from. Our existing interface is __GFP_MOVABLE. It is a responsibility of the driver to know whether the resulting memory is migratable. Users shouldn't even have to think about that. > I've spoken with Stephen Hemminger, and he said that DPDK is moving in > the direction of using transparent huge pages instead of HugeTLBs, > which means that we need to allow at least anonymous, and anonymous > transparent huge pages to come from non-movable zones on demand. You can migrate before pinning. > Here is what I am proposing: > 1. Add a new flag that is passed through pin_user_pages_* down to > fault handlers, and allow the fault handler to allocate from a > non-movable zone. gup already tries to deal with long term pins on CMA regions and migrate to a non CMA region. Have a look at __gup_longterm_locked. Migrating of the movable zone sounds like a reasonable solution to me. > 2. Add an internal move_pages_zone() similar to move_pages() syscall > but instead of migrating to a different NUMA node, migrate pages from > ZONE_MOVABLE to another zone. > Call move_pages_zone() on demand prior to pinning pages from > vfio_pin_map_dma() for instance. Why is the existing migration API insufficient? > 3. Perhaps, it also makes sense to add madvise() flag, to allocate > pages from non-movable zone. When a user application knows that it > will do DMA mapping, and pin pages for a long time, the memory that it > allocates should never be migrated or hot-removed, so make sure that > it comes from the appropriate place. > The benefit of adding madvise() flag is that we won't have to deal > with slow page migration during pin time, but the disadvantage is that > we would need to change the user interface. No, the MOVABLE_ZONE like other zone types are internal implementation detail of the MM. I do not think we want to expose that to the userspace and carve this into stone. -- Michal Hocko SUSE Labs