From patchwork Fri Aug 2 15:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13751722 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 966C5C52D6F for ; Fri, 2 Aug 2024 15:56:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 267346B0096; Fri, 2 Aug 2024 11:56:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 217666B0098; Fri, 2 Aug 2024 11:56:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B8786B0099; Fri, 2 Aug 2024 11:56:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E151B6B0096 for ; Fri, 2 Aug 2024 11:56:15 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9B6DC16127F for ; Fri, 2 Aug 2024 15:56:15 +0000 (UTC) X-FDA: 82407757110.12.2F5BB1C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id EBC3480024 for ; Fri, 2 Aug 2024 15:56:13 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eVkHIZBd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722614130; a=rsa-sha256; cv=none; b=D5JMLvn82qObwrWPA2LKh6PjRzMm0JhaMdB6bxs7cTqpiO9nKYAA7AWxCCrgidJDS5+ceT Ch2F+qfh5zZi4yzZDHx8qrM5Lf5cFmA6h+E17EUtP6xs8PiZhrr8kHt8cJXyADR7m3eOnv d7mrmItaXrED8LSvEV/0EaS2rU4BL9Q= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eVkHIZBd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1722614130; 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=Dsokb2QZ1A8J7FAYTpU1vDg99kVkubfGaPDc1WAA3q4=; b=Z69RhLDVz2on91Qs5tCi6hpNTVFuGTrzCsdomErCL5zk+TfXJUJhL1ToMYOkOLdsTKAi1T 54eOzstmt+C7AHDBeqKA0lvuDPfPLmMrVFNzNnHpgrLtZXQhb4hVbxTDyZtDti4J2SHv6a hLd0yJb0qW4hkSUUifv1nB5N1STiShM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722614173; 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=Dsokb2QZ1A8J7FAYTpU1vDg99kVkubfGaPDc1WAA3q4=; b=eVkHIZBd93wrpJN/ve1Ux5Wk0m1cGTYPOwToXz75Uq7IR/kBL/6nD+MasBLuK4B2U48hUB 1r7s3ohtVpfvgz+NUZjMyOJIV0pt3y2pqkeGeN6yQUum29PM0mqsEG8RRFvy6nTYZ+tD/1 O4M6Xkz/L4T05OMYn6oHXIJCZglv4Jk= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-318-NNjgzyEROca_nRik9KEcaw-1; Fri, 02 Aug 2024 11:56:08 -0400 X-MC-Unique: NNjgzyEROca_nRik9KEcaw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4CD5B19560B1; Fri, 2 Aug 2024 15:56:06 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 241AD300018D; Fri, 2 Aug 2024 15:55:59 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Jonathan Corbet , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Gerald Schaefer Subject: [PATCH v1 05/11] mm/ksm: convert get_mergeable_page() from follow_page() to folio_walk Date: Fri, 2 Aug 2024 17:55:18 +0200 Message-ID: <20240802155524.517137-6-david@redhat.com> In-Reply-To: <20240802155524.517137-1-david@redhat.com> References: <20240802155524.517137-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspamd-Queue-Id: EBC3480024 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ktqa3xkwbxp1yjtss7kxsoqy1ntkzy3c X-HE-Tag: 1722614173-904500 X-HE-Meta: U2FsdGVkX1/3q6YdYftsFB/5eMlXStOwdppdIHCSsCU1LhyvjSWsXa6lQESLrHX9ZMljolQ5ErVyxUqUycMZP2Hk0bciSwpAjqV4IrTZJUQnPxDPWkUhxltzWvW11lggsftSpM2tfzf3cDJX6fGmi1qX+EZPuLPhhr1VJQOVin6AJXTt/Lg8PF7JhbJI2F4HmMKlTPAIcHePtvT7MV7bORaTASOIgOobIUmLjVtLMMmbU6hVbwXEECRtSLCE4zym5MnSX0kLyJSPB3E0EHPVz/atla2sqK5wxpHwOshXUBtxBX7Sy8gdtHdOgoKz1ilRob9Cdl/qLyyrGiTUR0RLrdMF6AhO58G1oDhTz9NvJ4xBkDXULrMgU+sHgsJQrRgJ+4td/l9/Q3P0mLDxx9yCPQeL1/QoOXLSlJxAHLVVmNKVi8QPJSvof1ayHApIEyv1nOooroJ1SAMeV1auJzOAR9dg1Ou8/a9m9VWa++m8mKnUgiKx/off3ylPNZZYU2Rcq0VRNXfLhg93nDcrSc0p5tFvk63/X7jdsxItoPEBOmv58kCPDJipbf23ln0WKqtHoTgaO/pOTp1v1ZCfq/hZIg6WSryRBxj4qjNz2JguMbf6rdOAMN9DqiCIbkAJHjRShdCS6bjKPA2d2k5ZwK4nYR8y4DCz2Ry1bjDo/wlz5K515yHsg4Qo2A/LRujpqk+uEIqNiZLlItDfaMitf7aOnaWCFTh437j7mc7235PMGcUZ3Qbp5zJ8MpDH9bJOYZqTMQR6emixNnZNh6fYbn1AwYnb4/BDm+VBSTwGqklRurh4qRnnXukr+fvENF/mP6g3aLo2CEqOVtR/+jOh3gn45lEAH4Ank9PgKNb/H5VPLWLY7SDVymjoRH8bGCsSGmvXeaK/c5e5CiU4LBuSExshKSXIi81vNAwnBz14xeRNU5Z2PIjHypL9EvP06w7LpbqGveBk7sS7PUarOZkz7wc sNXgcrZ8 NhjhBHqabv/Dk/EmbacDbRiX9epMJRNxegB3/OQh5uysWt+VgFX38AHnK/aXQcxCq99kJYJEQ4QXrDyX+3nPMJV1wUQ8OJyXKTox2W8eMX13tGABOTlu2tqZtyf5gJRL8N3k3D0xs156YbLGExJa1TTznnq814+wsJMySyG/ELDkt7whs3r2OAEH3GNH8mktuc4bscy+tkt6MGmiWEhp8ztyU9g5LqkOhQGMgrNzr+7l/sv9vVfJbVTqtSaEddWW/56Y0HeMrQu0oMF8iM5qXiHbRmpGB3uBP85WyAu2RUcCAf84G+GNLEfENG+cjO3fYE0XHOB6WtYE1Q3KarPRnLv4uuw== 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: Let's use folio_walk instead, for example avoiding taking temporary folio references if the folio does not even apply and getting rid of one more follow_page() user. Note that zeropages obviously don't apply: old code could just have specified FOLL_DUMP. Anon folios are never secretmem, so we don't care about losing the check in follow_page(). Signed-off-by: David Hildenbrand --- mm/ksm.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 14d9e53b1ec2..742b005f3f77 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -767,26 +767,28 @@ static struct page *get_mergeable_page(struct ksm_rmap_item *rmap_item) struct mm_struct *mm = rmap_item->mm; unsigned long addr = rmap_item->address; struct vm_area_struct *vma; - struct page *page; + struct page *page = NULL; + struct folio_walk fw; + struct folio *folio; mmap_read_lock(mm); vma = find_mergeable_vma(mm, addr); if (!vma) goto out; - page = follow_page(vma, addr, FOLL_GET); - if (IS_ERR_OR_NULL(page)) - goto out; - if (is_zone_device_page(page)) - goto out_putpage; - if (PageAnon(page)) { + folio = folio_walk_start(&fw, vma, addr, 0); + if (folio) { + if (!folio_is_zone_device(folio) && + folio_test_anon(folio)) { + folio_get(folio); + page = fw.page; + } + folio_walk_end(&fw, vma); + } +out: + if (page) { flush_anon_page(vma, page, addr); flush_dcache_page(page); - } else { -out_putpage: - put_page(page); -out: - page = NULL; } mmap_read_unlock(mm); return page;