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 0AD17C77B7F for ; Fri, 12 May 2023 15:53:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DF9C6B0074; Fri, 12 May 2023 11:53:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 590166B0078; Fri, 12 May 2023 11:53:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47E4D6B007B; Fri, 12 May 2023 11:53:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 389D36B0074 for ; Fri, 12 May 2023 11:53:13 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F2447AEC17 for ; Fri, 12 May 2023 15:53:12 +0000 (UTC) X-FDA: 80782047024.25.913B035 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf21.hostedemail.com (Postfix) with ESMTP id 897C81C0007 for ; Fri, 12 May 2023 15:53:09 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="l5AHP/BX"; spf=none (imf21.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=1683906791; a=rsa-sha256; cv=none; b=sEebOISl6HgkESAlb2yLu3GjRHKmeUy2phb9HwVuToSo9bTPJDYr3Qb3+PDa2veXMfG5as 47ZhF81/lEtKTLwoLBWy0qHSiAZ/YjE98bB7xniM2Tz12VN2HBeXuBE/apLAtYYxX4ra3z hnHSxLmTU/TYm0fsEk3dpNASRzp9+m4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="l5AHP/BX"; spf=none (imf21.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=1683906791; 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=9PtRxZ5aZFbDSn+K6JjNYaJc4xVjLjlpJ8ds1gSxwQc=; b=oPg5YTuN+YH0yHgvSGP3vPW/sql05qiHpNWVhSVRStbLTnP0YxC3XvsPoqkj6mlhqlpoex WxK/ZZpSLdRJrJvdmoMuZ+13WNoTn6xZK73U8DfjDRDe6Rh3KbFNvO8esapV0x4a52RMET LjeowkitvPS1EALMQk9NM4O41eyILgo= 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=9PtRxZ5aZFbDSn+K6JjNYaJc4xVjLjlpJ8ds1gSxwQc=; b=l5AHP/BXmHK3iaUJnWAkTMjbSZ oZ0XRVbKepuGju6sGxIsUZXQOBdC7+Cyqz9/qbrX7v7dB2GAYxO7LuoZeXa1qnfpn6xPB/6DJdD3U qnf8YrB84PiKTLBmGiSxLPIhjdLAGduMoJRe8vH7FHOnk1aSlJwDCCK7u+GMbkLQQpr62rZhwMC6q IfPizzLXzicavrPhqrqyWJEq3dTLW0EdL7hu8if5UqE8Oza5rlABFHMSLoMxuvDfmpMvi1XjM47Hz C85CFJEhXNod9iu4sTWt/0Uksz/wZOUTiUK3G8E8V/rnrVj/T3OhXhOmjaLL1Hvl1JIXLVlUoIYXI 8qa0qz0w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pxV4o-000oxB-53; Fri, 12 May 2023 15:53:02 +0000 Date: Fri, 12 May 2023 16:53:02 +0100 From: Matthew Wilcox To: Khalid Aziz Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Steve Sistare Subject: Re: [PATCH] mm, compaction: Skip all pinned pages during scan Message-ID: References: <20230511165516.77957-1-khalid.aziz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230511165516.77957-1-khalid.aziz@oracle.com> X-Rspam-User: X-Stat-Signature: k8aknh3qwmb7x69ffmgbdgdhg5669mrx X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 897C81C0007 X-HE-Tag: 1683906789-397135 X-HE-Meta: U2FsdGVkX186ul56PgtVhlrA04Ep8KI/o898xR6fylYcSzPbpdR5TnwZQ7IQCfWZljM/mBZ1nLJWRNHc+HYQNDscg/Vk7WL5nA0SHPvL7QDJkwsBGh2jFUYRZIDAh3IVzKlbeY6WeXP48Iq4bBwGRGOgytAcTeoZI+JF/vJpuigr750pyPyj9/hIYcini5IjcdFKubJyzFGOo5lSkMI8nrCY63AcPsSR9O40WSw4E/1ZcbPtKQny6vvIXJ7rZsJZvHL36xMetqKXvmizqHdR9Iu9e3rIkERis+KNgK/anGzjOX+H0ZJtFwTuIaM7M5QqbA1Z0gBGI2DT/C3CnoHEsAxK9btoIz3hdzUjMnWu0JOYyj8oWoKvf2IPLNziUIC6rkA/LrlkjMpwvclmSrPg5HucURxB7PJnYOOnPtZB0BpKBwikVQxxJ2RDiCH0o2boDz5j0y1Tq7JhjZ5GAmfGX8IWn2HGi4Y5CFEHDGylpv/l8xgv1njc3+V1Z+tTZCfs76K1T4uMUzRmvTCndmjDN15JuFgS8UiCmESPPr3AJUs+hZm51IRJrq0Svpn0A7b+cj1kTcfmsH5pPlVY0vP5oRpZau7cf1cJHR8+X0h13pb7xiOMM3wkviZuYcJ9o1GbSWWIADN/65ofC/cI1/5qQoaSBMt8f8UeQNbNuHKZ4lsfX16HO0FJhaoNIeHyhsBy3xLkB2OZhOVfB5A18TBPhJLBTMSch+IV94T0AH3a2VpB4s6GHI1sEgIJ8nmqUV1k1alUVg2IPUBi2XQMk1iwS8mLQ6Bcw29xgt2ru5SI2zWsvDtMcTSDyx/8mPIJQQczz+zlvviTGefgcOfla9VBWEa4ksl/SzXY3WdKoFjWlvz+6dmyYoOlrMlV1lFGo/Ir9I5apn8qy2miYWB++5VLSDVeIwFibu7TiM6HOP94gqIq80qv3eX1Clc+OP8huGVharagPdH7kfxRJ7x+WPo cU58ZAfR 2cd9lsi8rCii0j8M5CRmD7p0pC7zwE0FjUNyyYu0yTdFP7WpTb6QrCRONCA6snMVNTW1OWH7wi0UPOzbkLoXzB7kvbhcWmVpQ0GHXLnn9UT91FmSOS8F9yVhsUMtz7ktW/t5ztFqtF3ayPUo= 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 11, 2023 at 10:55:16AM -0600, Khalid Aziz wrote: > +/* > + * Check if this base page should be skipped from isolation because > + * it is pinned. This function is called for regular pages only, and not > + * for THP or hugetlbfs pages. This code is inspired by similar code > + * in migrate_vma_check_page(), can_split_folio() and > + * folio_migrate_mapping() > + */ > +static inline bool is_pinned_page(struct page *page) ... yet another reminder this file hasn't been converted to folios :-( This part is particularly hard because we don't have a refcount on the page yet, so it may be allocated or freed while we're looking at it which means we can't use folios _here_ because the Tail flag may get set which would cause the folio code to drop BUGs all over us. > +{ > + unsigned long extra_refs; > + > + /* anonymous page can have extra ref from page cache */ > + if (page_mapping(page)) We already did the work of calling page_mapping() in the caller. Probably best to pass it in here. > + extra_refs = 1 + page_has_private(page); page_has_private() is wrong. That's for determining if we need to call the release function. Filesystems don't increment the refcount when they set PG_private_2. This should just be PagePrivate(). > + else > + extra_refs = PageSwapCache(page) ? 1 : 0; > + > + /* > + * This is an admittedly racy check but good enough to determine > + * if a page should be isolated > + */ > + if ((page_count(page) - extra_refs) > page_mapcount(page)) page_count() includes a hidden call to compound_head(); you probably meant page_ref_count() here. > /* > - * 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 is pinned in memory, > + * so avoid taking lru_lock and isolating it unnecessarily > */ > mapping = page_mapping(page); > - if (!mapping && (page_count(page) - 1) > total_mapcount(page)) > + if (is_pinned_page(page)) "pinned" now has two meanings when applied to pages, alas. Better to say "If there are extra references to this page beyond those from the page/swap cache and page tables". So it's probably also unwise to call it is_pinned_page(). Maybe if (page_extra_refcounts(page)) ?