Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2848497rwd; Fri, 26 May 2023 12:10:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5vfwwTy3NyP0uOEcdOyHukz7zFXIII4X+DqH4nRUP8inrh6NPHDjYOrPDdwDgpbW54VtZn X-Received: by 2002:a05:6a00:c8e:b0:64f:3fc8:5d3a with SMTP id a14-20020a056a000c8e00b0064f3fc85d3amr5254649pfv.16.1685128237810; Fri, 26 May 2023 12:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685128237; cv=none; d=google.com; s=arc-20160816; b=YoI8E3c9Y7gCAXcVi7/HAXqwRtLUGnRq+v3qTrA8bSjzIJT0/T3acLFN4EmIea3nk1 gwgDGrw7CILeVXHvoGr1VididOf9IeZOrZDHmH8FvKOEhz1pbHDEtXuTG7swY2dEPKDw kc2ycXf9TyUax7TORiZsXWadwrgLTQ+A8MOD9uWUcOJX2l7GXIPcrLJ1As/ENpNSFbdd 71/VvDbVQWIFydhhIx4bsRYMWm2R7t9PlawHdvCaYmbphqh6YkmiiS4Iwik/Rmv5n0lP qCHb5PvOREg5sjOGQ0KzfvN9up7diUv/JyUSnwr0HX6tN91xEJnI+RqBVU8dcQ/txqWs fIBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1cJq9zIs0nZ+a+dTmYQ4RE64ai18LNw3YMg66oEGC+o=; b=gDnM1wmayg5Ba/p6FGvLi3TzOnhYiVjJoH13cxKnxnizc/kmPaaQD9G02aQ4mtFflC 6frVp6Q10zl2+kBGdR7f8OPSVi5o/F5tBQcSTEuFlPU07LqCd6FvePokItzEsM+kW4b6 NwEWgrW69W2WTIDfO0u9We8ZA0nt30QbBz+mfEbaDW7M3vXCu+RHUILTqRxztVxvnU+n KYKKG2WYmU1bsb0K3PjZfHAAWxIoTVHIwIZMhLKNE904bISeUldasp6rVfwyUM+8vEK4 ZjwHVeYoDJ8sSQ7l07l+QdOK8idzjO/YE1dkQcC1NbE/N0Vg/bOuaRv5i1XlNBS+EvO+ YnDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=BoDyrS3q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r12-20020aa7962c000000b0064d72c6eab6si2694117pfg.274.2023.05.26.12.10.24; Fri, 26 May 2023 12:10:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=BoDyrS3q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242836AbjEZSqg (ORCPT + 99 others); Fri, 26 May 2023 14:46:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242793AbjEZSqe (ORCPT ); Fri, 26 May 2023 14:46:34 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28865125 for ; Fri, 26 May 2023 11:46:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=1cJq9zIs0nZ+a+dTmYQ4RE64ai18LNw3YMg66oEGC+o=; b=BoDyrS3q49eYTzYXMZ+EQJdZQ7 XsFEfXiEGufp692c5s6T3VqZOR19XZXZwCdeHmaE5NRNcJ0x3YGH1IR5hBdWvXpbCi75VF1aE8jCo UDRT2dLssfTd6LUv8fHprvJV4ga0idQGoomgMfuKcwGZdTh5Z4hI9Bk0ptFrU2xYMfEO/AoJ0BY9T hRqSx8shvhkP3giwTuNDvQ5o9hqrrim4nRHfoLJUcq1SWGxXyb5TIxQMiSjiOxU5bBf0rFrouoqEY GpAC+0PqXTJE/Xk/5K7E9AJRTEpGaixlUa2olPvY9Th1ECbj8ZViZJleR5NiMxxt364zC11dAiRvj 5zkLNQ/g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1q2cS8-0032fH-28; Fri, 26 May 2023 18:46:16 +0000 Date: Fri, 26 May 2023 19:46:16 +0100 From: Matthew Wilcox To: David Hildenbrand Cc: Khalid Aziz , Steven Sistare , akpm@linux-foundation.org, ying.huang@intel.com, mgorman@techsingularity.net, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Khalid Aziz Subject: Re: [PATCH v4] mm, compaction: Skip all non-migratable pages during scan Message-ID: References: <20230525191507.160076-1-khalid.aziz@oracle.com> <60367660-f4a3-06dc-4d17-4dbdc733ef74@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 26, 2023 at 06:46:15PM +0200, David Hildenbrand wrote: > On 26.05.23 18:44, Matthew Wilcox wrote: > > On Fri, May 26, 2023 at 09:44:34AM -0600, Khalid Aziz wrote: > > > > Oh, I think I found it! pin_user_pages_remote() is called by > > > > vaddr_get_pfns(). If these are the pages you're concerned about, > > > > then the efficient way to do what you want is simply to call > > > > folio_maybe_dma_pinned(). Far more efficient than the current mess > > > > of total_mapcount(). > > > > > > vfio pinned pages triggered this change. Wouldn't checking refcounts against > > > mapcount provide a more generalized way of detecting non-migratable pages? > > > > Well, you changed the comment to say that we were concerned about > > long-term pins. If we are, than folio_maybe_dma_pinned() is how to test > > for long-term pins. If we want to skip pages which are short-term pinned, > > then we need to not change the comment, and keep using mapcount/refcount > > differences. > > > > folio_maybe_dma_pinned() is all about FOLL_PIN, not FOLL_LONGTERM. But according to our documentation, FOLL_LONGTERM implies FOLL_PIN. Anyway, right now, the code skips any pages which are merely FOLL_GET, so we'll skip fewer pages if we do only skip the FOLL_PIN ones, regardless if we'd prefer to only skip the FOLL_LONGTERM ones. > folio_maybe_dma_pinned() would skip migrating any page that has more than > 1024 references. (shared libraries?) True, but maybe we should be skipping any page with that many mappings, given how disruptive it is to the rest of the system to unmap a page from >1024 processes.