From patchwork Tue Apr 9 19:22:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623131 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 CA731CD128A for ; Tue, 9 Apr 2024 19:26:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DE176B00AE; Tue, 9 Apr 2024 15:26:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 58E356B00AF; Tue, 9 Apr 2024 15:26:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42ED86B00B0; Tue, 9 Apr 2024 15:26:24 -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 256306B00AE for ; Tue, 9 Apr 2024 15:26:24 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C3F6E40553 for ; Tue, 9 Apr 2024 19:26:23 +0000 (UTC) X-FDA: 81990974646.06.A8D8C08 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 219651C000C for ; Tue, 9 Apr 2024 19:26:21 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PifanRhK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690782; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=P0NYc9fiw7RbFbzUOP+c9IZVrablCrwSqa05Gf/mEjM=; b=sm+OCUOUxvAfghg1DitF0DaDt4lzNlMHpInBSTEJPUsw7k0XtFSYg9/+Fy3ppJ6MnDJIKV 8nZgDj2bfRn2e33C8as3a8DHyuWY04H1ztAsv1KxQHcOirJK3M857rcAbAsRh6n0dXf4T/ WdcF46910vkMvfk2qp+xUL+rTHuvg9E= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PifanRhK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690782; a=rsa-sha256; cv=none; b=pzeDHedZTyJRN2pmy2EHJj2evWArx8yAgeI8uUpJ6m0Uw/LLmw0blDCmPxE2FAsBVqjtCm wFnEbE1P41sfNOQETKVPIZ5CGAB7sDbcjeIXkdNQEuAIi2fLSaUzlHhq+d5UmulxiE7jNd zmXwUERFwnaoRbf1RD7Y0XrmAyEGIRY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P0NYc9fiw7RbFbzUOP+c9IZVrablCrwSqa05Gf/mEjM=; b=PifanRhKtHC+q6DszmwWXFttV97v5KhkTV3r2fI5cE1bRgpmNae5jnjfW/wHKQpPVSY8R5 TwYAbl6uffl9hQjoXa88gEt8mp7ip92TJ5em/WWi4RIpx7sRy14eV8T3Wg8+dQSablh+QT ZZCZrADcXiY+GotAcoIuPBCo7EAg888= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-227-LSK2VHheNtull5pEDNikGw-1; Tue, 09 Apr 2024 15:26:18 -0400 X-MC-Unique: LSK2VHheNtull5pEDNikGw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EBA28890521; Tue, 9 Apr 2024 19:26:16 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9815E40B4979; Tue, 9 Apr 2024 19:26:08 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 14/18] mm/migrate_device: use folio_mapcount() in migrate_vma_check_page() Date: Tue, 9 Apr 2024 21:22:57 +0200 Message-ID: <20240409192301.907377-15-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspam-User: X-Stat-Signature: q4cr34udj6quenwj4awgytfhignf7y31 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 219651C000C X-HE-Tag: 1712690781-856174 X-HE-Meta: U2FsdGVkX1+RSEAPiDFdAdFclYRkhZpdNZ579iYVkKx4+YemPgfB14xQlZ0zmqeztFkUiUJFXcd1eCBBCozp6nVmSXbRBwhuHHZvcfq3eIbWYRKvNWPQmERHeIFrRu/b1FyWvBtxPPAbIiwpNIhPTzeGp7tcAjxOlVCBTkkg0W6Zys1AMzi5BdLAEUAE7xjUAvQowS3JCXycKS5Rf8zSXeEIoS+01tUsf2qwcbQqC4PcjyGCKNHD8djVIrTxupnvbY2D7buac/R7FTVo2XY3HQfovF8UfRdrlzuTOhU1PG50v56BKVzOCFaCW5BdEZJklRgKnqHSbuRLLRePBNszfbZl1/pIWfZuVl+Xvs0VIqDTGyKrt6p2ReVQnVsnd4OBcMgbgFmrFlejcCKuTboIpDzAYuGqAv05QEC0lfPPnkyUbVmWgcfSR+yEgEqSQHAL3p4Rgm7/IbhMXEgzepjVwaQhLyzEQijEGBeJPKo7FQafjkckTkbv5M118z6BEQDXE3544qn0aDJ1OUtJaVBDggKKexcYasiY2zBXNcASIWlijf23E6s5jts1mj7jOaBfHKmOT4sa4Swot5rZdtsbKB2sUeOylKAi3idfaDebtI8HFvn4NFImiRO473pYGBJnWwLGwwHkCap1oA+v1Y8+NVM/d/jub2k2+CcnmuHFP9dSCRg3QSKF6TKiAz+I6/OfT67BpGhu1X2062SV2GJSp/6pnOZKlsRbTHjtiwQTuaVcsuiKvUCngstKgWUa71ydLgzWTzWmlVlSVHW/HDrgIln5S12moYZakdXo5tWwiSnm49hk8EjZGbbW0AurDGztcH5UJH7C0wQWvn6XHL7KnykSzbUQssvBgBuN5JM0gsV11xxPE4YR93b16SZcKrCRBenkYIIlT/nip4Li8voULDpms8j7CLphns0kUhn5hCUVn4Z/Nga4WlGqIgUfmAixP+V3Aap1znJSU5eO3/d R5iAWQA+ M15WuI3HUZ8nYUk582fcfqghsGiHpu8yJjfOqS27If4tt9ky2YCHEkYqVTA1K67swXpHQVaCc0fE/IPicfvPlHk/+RXhGXJjbXcRgIro4NhpWOeJFLdrjHh5MHE9HoK5fMDyYpEX8PKRB9UAEzikyrF1wkDMULU5xoQxZ2cuMy2KG9SLpUFRbCOntFvIdIhB9L6eExsxyHkd5LZVhzI/ORKcItFlHtZsbWhGe 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: List-Subscribe: List-Unsubscribe: We want to limit the use of page_mapcount() to the places where it is absolutely necessary. Let's convert migrate_vma_check_page() to work on a folio internally so we can remove the page_mapcount() usage. Note that we reject any large folios. There is a lot more folio conversion to be had, but that has to wait for another day. No functional change intended. Signed-off-by: David Hildenbrand --- mm/migrate_device.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index d40b46ae9d65..b929b450b77c 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -324,6 +324,8 @@ static void migrate_vma_collect(struct migrate_vma *migrate) */ static bool migrate_vma_check_page(struct page *page, struct page *fault_page) { + struct folio *folio = page_folio(page); + /* * One extra ref because caller holds an extra reference, either from * isolate_lru_page() for a regular page, or migrate_vma_collect() for @@ -336,18 +338,18 @@ static bool migrate_vma_check_page(struct page *page, struct page *fault_page) * check them than regular pages, because they can be mapped with a pmd * or with a pte (split pte mapping). */ - if (PageCompound(page)) + if (folio_test_large(folio)) return false; /* Page from ZONE_DEVICE have one extra reference */ - if (is_zone_device_page(page)) + if (folio_is_zone_device(folio)) extra++; /* For file back page */ - if (page_mapping(page)) - extra += 1 + page_has_private(page); + if (folio_mapping(folio)) + extra += 1 + folio_has_private(folio); - if ((page_count(page) - extra) > page_mapcount(page)) + if ((folio_ref_count(folio) - extra) > folio_mapcount(folio)) return false; return true;