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 15CDEC77B7E for ; Thu, 25 May 2023 20:45:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94E3D900003; Thu, 25 May 2023 16:45:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 904F4900002; Thu, 25 May 2023 16:45:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EC4F900003; Thu, 25 May 2023 16:45:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6E503900002 for ; Thu, 25 May 2023 16:45:54 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3B8F5C0D5E for ; Thu, 25 May 2023 20:45:54 +0000 (UTC) X-FDA: 80829959028.09.B64D48A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id DC76F180019 for ; Thu, 25 May 2023 20:45:51 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=pSLzkSTg; spf=none (imf06.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685047552; 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=SBmKO8aSIQFep/NI9A33SHF1dRQ/pJp/iFl292SxJdw=; b=uKyDolT/CaMa0KJjSTSbCZm4NGCR4RoJ0hKbRfbRZ3oP0o9v3WSVqqc+Wi9AkLs7EJzVUF IRAu3be39t6ZNKa5ijCtUIof1VTlAvOY8AkpPDI5h8bxbnyFPwTmaSt9w3/ZH/znDDt1V7 Q57iEQw/XA3NcPKexYBGqKfRoAvt7Kc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685047552; a=rsa-sha256; cv=none; b=fQmy/X8G5ZNKiw0Nt4ZQtm8ItB8l1T9bU5VnTCfrisKUjE6rKfg07XovJF++srosp15nfe EXQ6UwBYkfbbKbxNV4ctJ593ec5fSiUQJNWPg0I7kAulK14UnFcMt7ZJ06GgLzJ3ooLqUl beiZSSGr6BKEtaMNuSvflrJT/FJB+k4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=pSLzkSTg; spf=none (imf06.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=SBmKO8aSIQFep/NI9A33SHF1dRQ/pJp/iFl292SxJdw=; b=pSLzkSTgiRLP8DJyWeeqovKscL JqUYhwsn25Sm4ZgWYHJj7m1U3gKzVopniqtlr/tysys/dDmdWkde7HLtc/cIx81KyybalNl3QBfoV mX17ra6xv/3timmBT4ryBoLdfQAhSvBN8klq5n+YfTdGnZTW9rA2zSVlg0B8tgZAP6mTDq6Xm5pEW IhN7zs9bmPrc7ZvIq7C0BjvPhFUyaVepC3UDsD4auY0sFcpsC3eRjm/2lORybUtFEgsykt7DsiW1A 5PYx4MtHXib70Kv3W/YoFowaEjuz8lH0PCbFT9SsFjNMijwH65VFt4gAwaABuRYj6VjosLmvqz9ti r+vXXZPQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1q2Hq2-00D9v5-Ge; Thu, 25 May 2023 20:45:34 +0000 Date: Thu, 25 May 2023 21:45:34 +0100 From: Matthew Wilcox To: Steven Sistare Cc: Khalid Aziz , akpm@linux-foundation.org, david@redhat.com, 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: DC76F180019 X-Rspam-User: X-Stat-Signature: 1j5hx9nih15n6oofzmgsqud4jp3qaajw X-Rspamd-Server: rspam03 X-HE-Tag: 1685047551-145324 X-HE-Meta: U2FsdGVkX19C7Gi5V7FnHTdLxIoniKs1biq6NWMiTtN1hpNcbumsYt1AU3UbPw/dLQrTUJnuH5Yr0E4pofBeIgSZhhJT5Rq9fcXitDokds8KlXvyDwdIsISLAxyP2KwChUV7i51MTbdJ0MaF3xwiWUTfXjS68qwOnLlvDCNsNgbIvsweKkr6DlK4psrgrvsy+3ilQLvOw6sUD+oCHImJEzWngOszTrtfXQ0ivRuCkcZV6a/Yp02EgID9Ax+KfzRfJ0YG3Wt5RyYJqbfeunBM4hNdxcW3WEbQ4m8v/nmcPp2OFgCQdWTNZmJR9UPxYoc2LFwQzdudvjXjzEE+Tqu/81otcu2zXSchYqfZVg3pmI5KyKtURilFCtZVenXIixXaCiggR7hNeJWHE2IX1vFbl5M+7kfrlwORossK7MOPMnulEU5tdHdqVvKldmKmQV2n8mxFwwNSSWXmh2Zli/WPOCTBhl1uj8L0NUmeBJLjJYfE+dQBsrBKaO4x+0U5JrPKksJW1vZVkju+Nh0HoaoxOSU2f28gtrGHxiqqfidI4m3m2ThlFG4OHlhGdtRDJOi0DzU9W/E0pOCwIOsnmGO2HPzR7FrT7iScqBWuIwZ8o3GUlIKuDCP7/HxSVfBqDcfdvw31n7tUafIdsPdpQ58dwUmU9qQMLHKSQ+Nh02vMb5FBpQR/XQ8NI4SpPePQII0YUsMC30rWRhA/71gMGtZv7I2cRpid7bsaS38VUZlc2LFnGrqxAFveYyfreKZZ7Jjs0rvKMBVU3BXLAHdSFbo4SIIio9PCl0w74eDzIedr0biAAUabQwu5SGVwWpBBZTQ1ocG/Gthok2+hP69+1/49Dq64z8QTNwpah+62vOxVry1rV0QkGOl9dHRhHedMusx8dS+LuRSTnwqP74IhHoJPd2nxbjbF2bh9m77cKDMu0ktf+99a85/QKM1FD83wPHVcrgMt05QfRNqAjzZI5Lt A79lpTDf psW87MOPp+J879+pf2FUHtP/ovTbq/zyIpUjVjwIn3G5k/rAqhLtcS7DYTzKt3o04UOUWPxkA++0lRd60DUfXdZZEYEBPwL+z0dlSZWGK1bRIeq0TPqGRhV7uvarmKDsML7JKuSujxaFC8SA= 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 Thu, May 25, 2023 at 04:15:07PM -0400, Steven Sistare wrote: > On 5/25/2023 3:58 PM, Matthew Wilcox wrote: > > On Thu, May 25, 2023 at 01:15:07PM -0600, Khalid Aziz wrote: > >> diff --git a/mm/compaction.c b/mm/compaction.c > >> index 5a9501e0ae01..b548e05f0349 100644 > >> --- a/mm/compaction.c > >> +++ b/mm/compaction.c > >> @@ -764,6 +764,42 @@ static bool too_many_isolated(pg_data_t *pgdat) > >> return too_many; > >> } > >> > >> +/* > >> + * Check if this base page should be skipped from isolation because > >> + * it has extra refcounts that will prevent it from being migrated. > >> + * This code is inspired by similar code in migrate_vma_check_page(), > >> + * can_split_folio() and folio_migrate_mapping() > >> + */ > >> +static inline bool page_has_extra_refs(struct page *page, > >> + struct address_space *mapping) > >> +{ > >> + unsigned long extra_refs; > >> + struct folio *folio; > >> + > >> + /* > >> + * Skip this check for pages in ZONE_MOVABLE or MIGRATE_CMA > >> + * pages that can not be long term pinned > >> + */ > >> + if (is_zone_movable_page(page) || is_migrate_cma_page(page)) > >> + return false; > >> + > >> + folio = page_folio(page); > >> + > >> + /* > >> + * caller holds a ref already from get_page_unless_zero() > >> + * which is accounted for in folio_expected_refs() > >> + */ > >> + extra_refs = folio_expected_refs(mapping, folio); > >> + > >> + /* > >> + * This is an admittedly racy check but good enough to determine > >> + * if a page is pinned and can not be migrated > >> + */ > >> + if ((folio_ref_count(folio) - extra_refs) > folio_mapcount(folio)) > >> + return true; > >> + return false; > >> +} > >> + > >> /** > >> * isolate_migratepages_block() - isolate all migrate-able pages within > >> * a single pageblock > >> @@ -992,12 +1028,12 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, > >> goto isolate_fail; > > > > Just out of shot, we have ... > > > > if (unlikely(!get_page_unless_zero(page))) > > > > This is the perfect opportunity to use folio_get_nontail_page() instead. > > You get back the folio without having to cast the pointer yourself > > or call page_folio(). Now you can use a folio throughout your new > > function, saving a call to compound_head(). > > > > For a followup patch, everything in this loop below this point can use > > the folio ... that's quite a lot of change. > > > >> /* > >> - * Migration will fail if an anonymous page is pinned in memory, > >> - * so avoid taking lru_lock and isolating it unnecessarily in an > >> - * admittedly racy check. > >> + * Migration will fail if a page has extra refcounts > >> + * from long term pinning preventing it from migrating, > >> + * so avoid taking lru_lock and isolating it unnecessarily. > >> */ > > > > Isn't "long term pinning" the wrong description of the problem? Long term > > pins suggest to me FOLL_LONGTERM. I think this is simple short term > > pins that we care about here. > > vfio pins are held for a long time - Steve So this is a third sense of "pinned pages" that is neither what filesystems nor the mm means by pinned pages, but whatever it is that vfio means by pinned pages? If only "pin" weren't such a desirable word. Can somebody explain to me in small words what a vfio pin looks like because I've tried reading vfio_iommu_type1_pin_pages() and I don't recognise anything there that looks like pinning in either of the other two senses.