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 2FF93C77B7E for ; Thu, 25 May 2023 19:59:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A397900004; Thu, 25 May 2023 15:59:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4530A900002; Thu, 25 May 2023 15:59:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34231900004; Thu, 25 May 2023 15:59:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 250B2900002 for ; Thu, 25 May 2023 15:59:04 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D3F16403EA for ; Thu, 25 May 2023 19:59:03 +0000 (UTC) X-FDA: 80829840966.14.6B1F353 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 7DA5A1C0015 for ; Thu, 25 May 2023 19:59:00 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=oLpgFZXK; spf=none (imf20.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=1685044742; 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=RwpqfGGYax+pT0MfFhzfIhAN71y4/MDvl/Gv7NEcip0=; b=ujLbIALZJhbXdIsi63feoP7YeEKE1GaGspPGMay+CNmh5hUm+Z5k0U1eurPSwHay85SEwx y8KIhWCrkXoVWYfSf6Dowb/3csx74QRzqUrY36MFBulmJ2EEP+wuhlODxPzI4FBuDdDiLw 0AGy/Gjf24TI3QF1uHSIF118wxSZnOo= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=oLpgFZXK; spf=none (imf20.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685044742; a=rsa-sha256; cv=none; b=WsgMm+BNqUdR1QVPvEBb7xWA1/rKHxuYpqafrkTy1CEf15RdNTKU3Q6S2qmckBbUB35pzJ iNOGzFWnbsj0p6N8UE5cSvLQNfkBlbvjKVkNe4uMzpZM6He7s156BVYUjYPDlaP4aBZftm IVUe0axon8Ir8D+YfLg6xHtDhE22qzU= 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=RwpqfGGYax+pT0MfFhzfIhAN71y4/MDvl/Gv7NEcip0=; b=oLpgFZXKkrtYOWRAbCHp7PQRav lquzf2zcJ26RmpzS5UFAL8NT3JPGzYq63xAMI1M3GfGZ9i1WH1t904bDMUDPQVQu/riz1mhMNWERz TOgqASQ+QbDvnsuNvwinwMCLYKtZgxFcO6cnRurXhmjrtmCPWcU8eJtgQ/6Sb+vq63l8qdIsLH8QG hY4ZTHrcleIeQTeMQvBgjt+i1xe7UPfmm5ZMlQkhpATEBiHF91EoNbRUEclX5uA/P6kGg9AUeH7E7 1i5doJchK0ufkm2guGo/zW81XeC2GjBZnpMq47JHJ3srZ5AhsAmc1G3F4BJXnC4q4Qp5xuISpjNxo lYgqBbEA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1q2H6k-00CVtH-EG; Thu, 25 May 2023 19:58:46 +0000 Date: Thu, 25 May 2023 20:58:46 +0100 From: Matthew Wilcox To: Khalid Aziz Cc: akpm@linux-foundation.org, steven.sistare@oracle.com, 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: <20230525191507.160076-1-khalid.aziz@oracle.com> X-Rspamd-Queue-Id: 7DA5A1C0015 X-Rspam-User: X-Stat-Signature: w4wcxw4f7fmrr9wurxi3tmc9qhaaip53 X-Rspamd-Server: rspam01 X-HE-Tag: 1685044740-870670 X-HE-Meta: U2FsdGVkX19xswax7AHF1qj+MKpRs7svOfCVZgWXhs99t9nl/9+YDjsX5EzXGU81SjALlg3lV899mZszv/phs3C69gPf1qxqHmqa/H+K2QBf5XX3qCEeOTJQJFaf7Kg2BbXQjmsN32gmDhNNuQSxJpD0z21G/OwhRMgXkbNw9DLcTYh6ay+jLJ/AyVuj+0r2pfJkZ+t5vijULZ6tGLcebFZFV/zceE9IG6YQSz5/fkKRX1B35luFze04NIP+xMHo4R1k/FEos/JQcgK/W8q3qITv6quwN3S5UtrV9LKaLPjV32tiDSfECa3y86Iewvx05fepRFKVwpVPBJ/qC53AyviZncvyumOY9BYEAsMjzz7v/0+Vh9gcY0+drNnnJzROqx8kU6wRXvEeudVm9UFuoE65UrJR9euc07dipq0yPjnGP2u+cJ/kKw/tvDQDm/EuWcX8afsEs0QhJ+vNre10riikvygL0L2ZQGkbAr6UTa3BDiqyqx/7vY35Ly+ywGSgF4zftD1LiwNiQXhh2y44U5zfo665MrOWy/x9l5Eg41iORBkwd1Cfk7kkvpN+GOQpIzZC55U0Rwl3y1nkFXTvv6y6ToTdCiL7VJM4P0K70PZsgfSw6ZhC9AaAb9UbxlYt/P9rvLkfdZ7o0TgOJzUkT0Dt2U7Oh4sGJJLgf4hEVxH0P4q+jB+4xdHUL8lPIGOP75TFoJRBBF3WiY4wu1jAbvZUvqV/C3JXc5WSIxDobixqB3+vn0S9HDBpSV4cbwvbWy10NLDP8lDI3SdZfZJsAJGRSBLi+DYW82ZaH5X5IuiJEDTfKTSgSjso0gUPMLriKuRSRGM2lwfWI2VerO+skh38rAB9DvMC8DYbfbzOTa6fUc4uHjcutlBH39FfJDUippKAMd8KBq96xpz89F54jeUy0RxBBfvcrnLVlZK6d3+NJinrCogLOITIByZUEgcrmFJiKvnmiAbd21IblAK 2C/7QTJ5 u5f2T21k6b7FNfE1UkrO2eZU/dA0Hk349NOwRCAftqcgSn72abOZHEZH2V1JoqBS9Id2YEzP2L84n593DFHoWRWzdmfZfAPVF4RWTn06Rdg0tgCPbNCWlsJ+kr9EMGCOVpkztssNiTdvfyUg= 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 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.