From nobody Fri May 17 02:41:19 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 38C1912EBE2 for ; Wed, 17 Apr 2024 09:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713345809; cv=none; b=jJsLKw6x7a+bHsxm+gzS7NnEk/Kr14LSeHJp6CVfhS8LmYnHPfkXzlPLFOzFnehdvESVRd4o6NHS5/bDXXUuuuEzENHbxWih/4UawJso6Kjxuzebs0V2gHbPuBMv7af5vG9a3/94UDzx5DZDZMdfoQWchNYUm6Xk9D1cyrRMVsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713345809; c=relaxed/simple; bh=kR7NgpoqseIcWNXCbEV890XSu1aVULd4AJRo63fLdGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lmFT6ZI6ZmmSMQQZ0ix1hxBjQCOrE0oJyvpm5zBxr8E+eMqzHoEAVZhanijS6PnRduhOckez7nyEVuxMH8zZn90bRmT6TwkEtl7ExpzpcxJgths4VA5Bi3zdmHem4Q4Tl15wukgc+V6qe+a+yg69Vt4N2QDjSlDZLVRRBEl1iNU= 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=WfiYuU+c; arc=none smtp.client-ip=170.10.129.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WfiYuU+c" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713345807; 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=4XkSYCF8J11KhT1kD3yECHdoktxsLGeadBVxc6aZ2IU=; b=WfiYuU+cNDI+tUaotrawNtkbzhKH+u72O7HOZqL1iRGTT5UtYvgAuvjGONM7paQ0qJz8bC xt6Dtm6+MtTi3IAi49Xt8ifby5/hs5erBLjOIU2sn+LfuIrVVPUbOmYRFgCkwSzxncRq4a 7+CH7CD8B1yAslg5bSuD3gsOAPi9264= 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-433-pdv014c2NOGreuXLt_k0MQ-1; Wed, 17 Apr 2024 05:23:22 -0400 X-MC-Unique: pdv014c2NOGreuXLt_k0MQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 91F0A830E7D; Wed, 17 Apr 2024 09:23:22 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.252]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F22C2166B36; Wed, 17 Apr 2024 09:23:20 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Muchun Song Subject: [PATCH v1 1/2] fs/proc/task_mmu: convert pagemap_hugetlb_range() to work on folios Date: Wed, 17 Apr 2024 11:23:12 +0200 Message-ID: <20240417092313.753919-2-david@redhat.com> In-Reply-To: <20240417092313.753919-1-david@redhat.com> References: <20240417092313.753919-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Content-Type: text/plain; charset="utf-8" Let's get rid of another page_mapcount() check and simply use folio_likely_mapped_shared(), which is precise for hugetlb folios. While at it, also check for PMD table sharing, like we do in smaps_hugetlb_range(). No functional change intended, except that we would now detect hugetlb folios shared via PMD table sharing correctly. Signed-off-by: David Hildenbrand Reviewed-by: Oscar Salvador --- fs/proc/task_mmu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 8ff79bd427ec6..cd6e45e0cde8e 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1578,12 +1578,13 @@ static int pagemap_hugetlb_range(pte_t *ptep, unsig= ned long hmask, =20 pte =3D huge_ptep_get(ptep); if (pte_present(pte)) { - struct page *page =3D pte_page(pte); + struct folio *folio =3D page_folio(pte_page(pte)); =20 - if (!PageAnon(page)) + if (!folio_test_anon(folio)) flags |=3D PM_FILE; =20 - if (page_mapcount(page) =3D=3D 1) + if (!folio_likely_mapped_shared(folio) && + !hugetlb_pmd_shared(ptep)) flags |=3D PM_MMAP_EXCLUSIVE; =20 if (huge_pte_uffd_wp(pte)) --=20 2.44.0 From nobody Fri May 17 02:41:19 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 CEDC312FB3E for ; Wed, 17 Apr 2024 09:23:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713345815; cv=none; b=GoTK1fSejrrttSJxd4LIFWr/ExqcmEJ1a8RWqt0tUvQQg8HSx50mPr9rIWVukLXliWuhEXKlQ+2hhfcahN25zxi09aC+bqJDrzYrnG8WoUl3EG79HheQ1gIrDZvmg+8wXtTkI3UdjaXPr2pIVJVxrpFuBt4cZclZUuF+7mMrbq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713345815; c=relaxed/simple; bh=6/aOw9dUqBfjPQSRan8VN1NA3JWXNdX0DKCTq/jBgsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H9nhrUwRLDBOv+8vbi8FKUDwLJIPxvlGScnj8N/45P7kZEbhz9IXOPu3fcxismTstyK/5knyFVVLiDEGBYj22NRmiCZLUFHJhLkUj+O7vOB+29utJ3auGIin+3AyzXdWLI7ZZYFqDcJuMdLemifdwexgxx5ySknmjTbUfK1UBqA= 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=Tvhj8g+e; arc=none smtp.client-ip=170.10.129.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Tvhj8g+e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713345812; 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=0KJlX59pWoV+9ju0XmT0Dv5XXIefdKD1ijqlf4oKq4Q=; b=Tvhj8g+esjqrVKLf0yRPmhJIDFqhBx4xS+SVcpnPmgAkoWLZsbjLJMnO9/iYL+lg5fN4In J3+VjCs+wwUaeI6zUPPYYenO+n1XQrcvF3IRDX7GFnRMcKfaopsQD2ePOqmyOPohPxFZk/ HY+R9JUPAtSGcb7GAIWFGF6ZdAucEds= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-439-Tteg5mGVN_yPaHS7lxTX6w-1; Wed, 17 Apr 2024 05:23:25 -0400 X-MC-Unique: Tteg5mGVN_yPaHS7lxTX6w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 D1D1938116ED; Wed, 17 Apr 2024 09:23:24 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.252]) by smtp.corp.redhat.com (Postfix) with ESMTP id F31922166B32; Wed, 17 Apr 2024 09:23:22 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Muchun Song Subject: [PATCH v1 2/2] fs/proc/task_mmu: convert smaps_hugetlb_range() to work on folios Date: Wed, 17 Apr 2024 11:23:13 +0200 Message-ID: <20240417092313.753919-3-david@redhat.com> In-Reply-To: <20240417092313.753919-1-david@redhat.com> References: <20240417092313.753919-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Content-Type: text/plain; charset="utf-8" Let's get rid of another page_mapcount() check and simply use folio_likely_mapped_shared(), which is precise for hugetlb folios. While at it, use huge_ptep_get() + pte_page() instead of ptep_get() + vm_normal_page(), just like we do in pagemap_hugetlb_range(). No functional change intended. Signed-off-by: David Hildenbrand Reviewed-by: Oscar Salvador --- fs/proc/task_mmu.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index cd6e45e0cde8e..f4259b7edfded 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -730,19 +730,20 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned l= ong hmask, { struct mem_size_stats *mss =3D walk->private; struct vm_area_struct *vma =3D walk->vma; - struct page *page =3D NULL; - pte_t ptent =3D ptep_get(pte); + pte_t ptent =3D huge_ptep_get(pte); + struct folio *folio =3D NULL; =20 if (pte_present(ptent)) { - page =3D vm_normal_page(vma, addr, ptent); + folio =3D page_folio(pte_page(ptent)); } else if (is_swap_pte(ptent)) { swp_entry_t swpent =3D pte_to_swp_entry(ptent); =20 if (is_pfn_swap_entry(swpent)) - page =3D pfn_swap_entry_to_page(swpent); + folio =3D pfn_swap_entry_folio(swpent); } - if (page) { - if (page_mapcount(page) >=3D 2 || hugetlb_pmd_shared(pte)) + if (folio) { + if (folio_likely_mapped_shared(folio) || + hugetlb_pmd_shared(pte)) mss->shared_hugetlb +=3D huge_page_size(hstate_vma(vma)); else mss->private_hugetlb +=3D huge_page_size(hstate_vma(vma)); --=20 2.44.0