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 B4749C77B7A for ; Fri, 26 May 2023 18:50:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4269D900003; Fri, 26 May 2023 14:50:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D6AE900002; Fri, 26 May 2023 14:50:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29F9A900003; Fri, 26 May 2023 14:50:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1B080900002 for ; Fri, 26 May 2023 14:50:27 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E05C980F62 for ; Fri, 26 May 2023 18:50:26 +0000 (UTC) X-FDA: 80833296852.04.88C007E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 95BB8180010 for ; Fri, 26 May 2023 18:50:24 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZkprI5nk; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685127024; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Iv1rySWpJ3wV63UZEQURnsupoRRaDiB4keiWDoZznIA=; b=5kMaOrInt8D1bVSaoMDF+Yg2H+90YPitSvizqPZtg/SSGqYUHamu7DZKky4HQwStIer1LP N/vsS6C2feFzD38rUgxnAOYIKY/RYtfzxp25V4IjQpjtrvqS9G5ld2REsspZAADUz+yk4N BD8pMXxlQQeifGsAv5ZdKZxiklKumHQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685127024; a=rsa-sha256; cv=none; b=kRvNkYpc+ksfbK61xXpoF7KmF9c5GtztSiJqtKr3E75FpDBl6e8kXtQSRLP9pPXuvyHFn7 MGM8exALVrYja1IELQuDQWiX3suYypkEHIUKQV+STPwnb9nIVmEcuiG8sPNQ/Mq6QuST0H qUARnN8Lsry37hWqTWBWSO0n/C+bjoI= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZkprI5nk; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685127023; 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=Iv1rySWpJ3wV63UZEQURnsupoRRaDiB4keiWDoZznIA=; b=ZkprI5nkrAJe3RyzuIQFKljscWsOom6UAYWW1u9lcubDruFAY6xWOb9mvE/Qp/5y3xAWML 9o798ddRtf/ze+AX/ZbI89gUhEMXGFBbpqAfM3gZl4qx8WSctYF1F4ahe7DqF++wflhyfx Wth8OE5qdUgeQeoC22bODA6WMNqgzgE= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-562-L6A1IxHzMuWyxY65FEcy5A-1; Fri, 26 May 2023 14:50:22 -0400 X-MC-Unique: L6A1IxHzMuWyxY65FEcy5A-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-30a88ed463eso443412f8f.0 for ; Fri, 26 May 2023 11:50:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685127021; x=1687719021; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Iv1rySWpJ3wV63UZEQURnsupoRRaDiB4keiWDoZznIA=; b=BI0OTavq8+nflW4MO00HjDkFVJ55pr6T4zEgx2RTyZ3ynkjOjuCa8ISrWuPZWqrlbC uZreASIOUapQtK2tMGoRSwD/h4cGYagaWtndK+D2Lt+bFA+PvRpBZJHtFi4AO0udHjTY q9l3Ui2VWU+P/Y1u37VDps/E2bhzAIfJyk20UaoITsBDsjAlFxEKX28BTR9fawMHdti/ duaI4fvW4Km857xq6dg/Sa85sWiUjdfodaMdGkqKooCa7JAHuimcpAoR8shTd+pgC7o3 RPfP1zJus473sj5hLbh8Le2bNBPX4joUf1108nZSDLwVu/BkHGRJI37FVbfTX7bSOTFj MJ5w== X-Gm-Message-State: AC+VfDw3aDXAFmwEOayJKOS7DkE0TJwVjTzBWSLWrgjvr+GeyBpYJhjN 8mQEwC6NGFHWut9I5uuCroP1XpMG5P5T9SH2X3Jx8DyNaB/Z+pX9Ffga1rzRhVMePy8NfO4vs0/ evPYlWh3yoN4= X-Received: by 2002:a5d:4692:0:b0:306:3912:a7f0 with SMTP id u18-20020a5d4692000000b003063912a7f0mr1821714wrq.50.1685127021405; Fri, 26 May 2023 11:50:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5AHGb2j2bC1dzW1ck3vYSHMHeI+g1bm2+xdrB6+cWUAioBUBvLaZef/1lx9/GXfgiMT/QPeg== X-Received: by 2002:a5d:4692:0:b0:306:3912:a7f0 with SMTP id u18-20020a5d4692000000b003063912a7f0mr1821696wrq.50.1685127021032; Fri, 26 May 2023 11:50:21 -0700 (PDT) Received: from ?IPV6:2003:d8:2f2e:ae00:f2e3:50e0:73f7:451? (p200300d82f2eae00f2e350e073f70451.dip0.t-ipconnect.de. [2003:d8:2f2e:ae00:f2e3:50e0:73f7:451]) by smtp.gmail.com with ESMTPSA id z13-20020adfd0cd000000b003048477729asm5796307wrh.81.2023.05.26.11.50.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 May 2023 11:50:20 -0700 (PDT) Message-ID: Date: Fri, 26 May 2023 20:50:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v4] mm, compaction: Skip all non-migratable pages during scan To: Matthew Wilcox 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 References: <20230525191507.160076-1-khalid.aziz@oracle.com> <60367660-f4a3-06dc-4d17-4dbdc733ef74@oracle.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 95BB8180010 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: uhaxkpo9crr4f4jiqd9pshsd5if3u8xn X-HE-Tag: 1685127024-771273 X-HE-Meta: U2FsdGVkX19chJ55MVWQumsXriAaA2wrL4idRfgucAJWl5PuhN8VxPESXyWbiEyP8/RohfWgkp3tAkLCX7LgWDtBgGc8gCNATaJCr/j5FWmXs+qwmfpneiudnl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VexzulX+Re8UcC/ERqFg3ggOVEahvtQd7MuP6cUNhZo6PJHGkYivpdOM2bKc74Un5ekg/xZvH8qSEm33INFLSJ4aGpOGQYqbozJMImAHugr05SD4Wz+uc5YeeiAleQICR5lUIciZR4Bf7yGU1PHq4evErl2RkjYg+K5yR+JHVZ5iOtByrbDKldDeZnh7+XpHo 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 26.05.23 20:46, Matthew Wilcox wrote: > 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. Yes. But folio_maybe_dma_pinned() will indicate both, long-term pins and short-term pins. There really is no way to distinguish both, unfortunately. > 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. > So any user with 1024 processes can fragment physical memory? :/ Sorry, I'd like to minimize the usage of folio_maybe_dma_pinned(). It's all suboptimal but let's not try to make it worse. -- Thanks, David / dhildenb