Received: by 2002:a05:7208:31d3:b0:81:e143:7c29 with SMTP id v19csp2634519rbd; Tue, 9 Apr 2024 12:28:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUtgjU4tgwPjbAsexdSfL340ql0y2B0foz9TSCREP8IGtDOcQQorBHPdj6fDAW5Q0EvTMqa4MGRs8mgv8WFRDYAemvChY3ryaSL4eqXzA== X-Google-Smtp-Source: AGHT+IFhGWRoECggvZBSJatChEDIST0v94E3DLODNmlRQdVNw1RwQ3iFm7iQdYbIHKWk8RMBdQGB X-Received: by 2002:a05:622a:180f:b0:434:6658:b281 with SMTP id t15-20020a05622a180f00b004346658b281mr5769143qtc.2.1712690896435; Tue, 09 Apr 2024 12:28:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712690896; cv=pass; d=google.com; s=arc-20160816; b=sN/mIA49rYPqJ19JNId7H9S7Q9ey8SWpEIjZQ6DWrYRF0O6AHwI8MxKyDaE863wOpw +8qtkROALMJkUeMKfLfRMuzfYSmoqURbgkWJLkvT5cioh1V+zWjyjj2J6wL4bpG0P6+F Dj6AsNpRniO1qP6gFZP0jgWX1e9KRqUB2Xbxg9FcubhV8Y3/d7RvBhF+hwX/kyc4A9CD 3tq4nonJPiuv+6d24aEHcupThhaTN9RHzZxZBp0t6M0IanJNmbvFDitsfIJ1yG9+o2cq QO8JUII1SLnldeMdEdqXKdH4ggEcyIfWMAlC+MSXJnDk96oB76p8N8jke42Q+oEJwR9C AjCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=IN3zVkAYwXXWogoRwDYvxGTLC4K4Gwg+xwqZ7vjK29g=; fh=6UXOkRl8PLWnLRlJFkZ1FKxRpZrfO06mwvecZ/lFyqY=; b=H2QOirkFKSU8IbTaHYYHLp+ueJx7rjzn7qUO0JrvEk9urUMmvbqmSlMN6xzS36cJLx ZNPLnrtfS1VtkwlFhntZxucQF71t9onexhyHf81ZNVk5jZG+R5mYlvczEBfwKvkbfLJ0 dExlQp1NSSmXq8vUdIOEiQIajrtqP3DE1pvofMrU1JtHHbXlCcrF4azNOXsyQOuyyIvQ 93pLYel2a+EJRWWMxi7F/JulO2d99plptNi5Abg3FKgjm+fG+3JFRdUhLCWGskXiacK+ QGggyTnc+Y7+wJi4F6wc68ETjmISp7zX1RghwnnB2I/KqT9YWMlXUOWZHr0JHQHqKTab PxuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WcaIEv9i; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-137529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137529-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id o7-20020a05622a044700b0043155865b0asi11313885qtx.313.2024.04.09.12.28.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 12:28:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WcaIEv9i; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-137529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137529-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 52F3E1C21EDB for ; Tue, 9 Apr 2024 19:28:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AD03158A26; Tue, 9 Apr 2024 19:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WcaIEv9i" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5F9F157E6E for ; Tue, 9 Apr 2024 19:25:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712690752; cv=none; b=p4jQ8YuU1jxYNM7ve4kwTvGQwNxshW/oi4dBNL1cJzXiGZlZVRwynKapHuP8YTLdIGK5Q135ynTPKvV8pjIqTG2z6DHtGYTikrOcr6PrjLK2IYimfBD+ikSx5/WanYGqKEBKX4Pw8EyecQis6WEnGAZmJbnnLAHGjOQM4+fdhmg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712690752; c=relaxed/simple; bh=Rq0Sd4YiurfGdBcBbt0nVkWNo0X3AhfDegChcctLqBs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=apb5lY0rJ4O8n/pcweyfmWN9z25xFtEbnjTayzYCjdtqoM37bE32QtqthqcabuIFc5xSBQzWjT2nOASpY9R0fG4sdYNpQZlOa1YJOMNXYTzERxQIXKEXbNigJuIHmoZs9AlgghhI8D5a1F3SKWxHLwZqL1X7RT9OtTSWJEiQ+Vg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WcaIEv9i; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690749; 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=IN3zVkAYwXXWogoRwDYvxGTLC4K4Gwg+xwqZ7vjK29g=; b=WcaIEv9ipwlKJm15CPSP8WEdnTVRIHpHrwu82ZuepXM4FSHmcxU4snDrsj+L+B70Y2p1oE FhH9jaLK2L071H8U0iZVoTP8kb9EoSg9+k6KmSwZ7Ac6UYR5Rmiex3xYrJ+v9lQtEgQqdp 9e6kSPwFjFwZntmAt/0tgSPaPj5APLg= 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-512-p7aYNzngOOiEyTZuHcjUMg-1; Tue, 09 Apr 2024 15:25:44 -0400 X-MC-Unique: p7aYNzngOOiEyTZuHcjUMg-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 A0997830E7B; Tue, 9 Apr 2024 19:25:43 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD0CF419FA38; Tue, 9 Apr 2024 19:25:33 +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 11/18] mm/migrate: use folio_likely_mapped_shared() in add_page_for_migration() Date: Tue, 9 Apr 2024 21:22:54 +0200 Message-ID: <20240409192301.907377-12-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 We want to limit the use of page_mapcount() to the places where it is absolutely necessary. In add_page_for_migration(), we actually want to check if the folio is mapped shared, to reject such folios. So let's use folio_likely_mapped_shared() instead. For small folios, fully mapped THP, and hugetlb folios, there is no change. For partially mapped, shared THP, we should now do a better job at rejecting such folios. Signed-off-by: David Hildenbrand --- mm/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index 285072bca29c..d87ce32645d4 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2140,7 +2140,7 @@ static int add_page_for_migration(struct mm_struct *mm, const void __user *p, goto out_putfolio; err = -EACCES; - if (page_mapcount(page) > 1 && !migrate_all) + if (folio_likely_mapped_shared(folio) && !migrate_all) goto out_putfolio; err = -EBUSY; -- 2.44.0