Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp979485lqp; Fri, 22 Mar 2024 01:37:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXs3rxOPd1Or+EsiB4yb1JO/K0bOyIBJNlukYqrRkYnblPuPBKIlXLg/TeAcIWYourVdZUnNrmRkN2ukelhAGTnDUvnmrExW1sobz2TwA== X-Google-Smtp-Source: AGHT+IEmo5cFkFYlF73cgY/lz6tB8qj+nVtFKXbmZcVG3Pka55Uy79LiL2fWboy/GI2ykDXEiFJz X-Received: by 2002:a05:6a00:2184:b0:6e8:1b04:29f2 with SMTP id h4-20020a056a00218400b006e81b0429f2mr1832871pfi.28.1711096647397; Fri, 22 Mar 2024 01:37:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711096647; cv=pass; d=google.com; s=arc-20160816; b=X8TmExyibP8VsQo5rfYFLdDMEazvaF4h8SYpBarNsOhygzzPTMqAr9ujbIZLsetAof 7f1jtC7BulNtcRU1mjHdBrU7Ud83EJWvT9YF/es7Lcq6vbwU6PbiPsDrC2hmYq6vpAfZ 8zInh5w6frJEFuzeZ5+E+UuhrIAbpKXQU+Xg6atYh+Q2YUlhKVnKr0QCbuTjk/7uw0Y/ X17w5h7HdR3nrEHuIOEKklZ4AI5qZZpQT2caJ3RhJLf6GtxwrTk9AOW/knucp0t383pZ eMJaMhlirEm2K5CTpyx/FNdvV5y4U+P1s4NBJFp6fhyyB6IKz4FVCA7kVUZZpS3ajtpP LbEA== 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=zepfTSSuU1H47LHDp7z16x8iMxIzac+uuTIZHWvltoI=; fh=CTFdFrbtP7Z7TCdMbqsgkrQi425Yz+qx6YS+cHHF8Sc=; b=I3QF8IiEUqabc2AtCVLJ7udVwyqtpZ6ljJVqnjzwVmxwgnPLyb2rJRvFCilmyJ2M6k /ExED+x7n5ZaoViuSxXN05mhCp22CRCnsKaln5AhE/FZOO5O07laMGmR/d8Pk7wNbQJj zZv5qLbqcb8NtJA6KPjo8HBec5gqiRMvvrqf/etmpzdyxvLMEXV8MgDNxHHYIcWw/Le4 bs1suJ8KNHAk1TCHCpSJGPWUIv2o6HXRTDB8dsLQkAerr27rDKCWfg/5StUeM2b9QlOA iD4StUIoQ63tkPvCZI0/TN8pf2LbmX+3Y4Ujj9GXLBgNoRDyIzSxQYzduV1ponFbgFo9 d9dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GPndUjay; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-111136-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111136-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ka2-20020a056a00938200b006e628ededf8si1573496pfb.74.2024.03.22.01.37.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 01:37:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111136-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GPndUjay; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-111136-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111136-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7A8F5B21C5D for ; Fri, 22 Mar 2024 08:36:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9859F1863B; Fri, 22 Mar 2024 08:34:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GPndUjay" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C1D9A168A8 for ; Fri, 22 Mar 2024 08:34:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711096491; cv=none; b=thB+W3dP1JV1ETyM0tdJpAC4L7leHEJ+TW7EHyKckIYb0RLLawjIZ9+V5WMW2WHU8fEpNu/trPjKjKz/Iqc9jEdYJLWGLvPQZrm0Ya1CgBnUK5Em1ZQlYzBGAtml/Fm881X5SYtZlmHOfv/vMPKuPJkVIpJzmOss5pzEXJeLqJQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711096491; c=relaxed/simple; bh=CRD+qsq6X8eUY6+mfkkDNsd4MjPhDaxu0Mmm/KE7kcA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YZBlhBS0uj6alESBnWiFBCOWARiwke1q3FhPKlnt9eD3sV9I6SQcA1+gUiEJHnqeH5xcFPMbL/yKlGLkANTCbbICC4asrVGZxFH9fO5VugC9RhpZXj4KUjudm/lpEdje5AaEphzeRFEw90yDU6Qs+bddXCQVF8ZSKSUIKplLFDg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GPndUjay; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42C56C433F1; Fri, 22 Mar 2024 08:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711096491; bh=CRD+qsq6X8eUY6+mfkkDNsd4MjPhDaxu0Mmm/KE7kcA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GPndUjayFYuvxAfrdHVpgbn3recU3ex9yh6yyygkZajGGC43bK7JvpNx2k8KyYj2J SJ3AcquFw5gxtAwAzsgJcAX10ry74rQoDSQg6coQUWfwSoNnkQ4hPcT6KoDm4Qj8/U 6y5ZJFVIIb9ByKLPS6cnCjQgKXY/+0LepUrK+9bYUtm0y6hw/KBKkQM+3wp0RX2pLG neO9o9EmWT94cbmzT1QVbawxNScHRds6LaBQoT+obrK3rMc57EGxTIrZysRoIg/vO1 UJJsrjQG4U4+0lxFljPG9881vtHf5Bm7IZpbJ8h5yXFaMcVQg9g2Fa4AhjlRGpICqL z8SLLhp6LhmDw== From: alexs@kernel.org To: Matthew Wilcox , Andrea Arcangeli , Izik Eidus , david@redhat.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: "Alex Shi (tencent)" , Hugh Dickins , Chris Wright Subject: [PATCH v2 07/14] mm/ksm: use folio in write_protect_page Date: Fri, 22 Mar 2024 16:36:54 +0800 Message-ID: <20240322083703.232364-8-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240322083703.232364-1-alexs@kernel.org> References: <20240322083703.232364-1-alexs@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Alex Shi (tencent)" Compound page is checked and skipped before write_protect_page() called, use folio to save a few compound_head checking. Signed-off-by: Alex Shi (tencent) Cc: Izik Eidus Cc: Matthew Wilcox Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Chris Wright --- mm/ksm.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index cd607b942c26..f41491cf13c6 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1289,22 +1289,22 @@ static u32 calc_checksum(struct page *page) return checksum; } -static int write_protect_page(struct vm_area_struct *vma, struct page *page, +static int write_protect_page(struct vm_area_struct *vma, struct folio *folio, pte_t *orig_pte) { struct mm_struct *mm = vma->vm_mm; - DEFINE_PAGE_VMA_WALK(pvmw, page, vma, 0, 0); + DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, 0, 0); int swapped; int err = -EFAULT; struct mmu_notifier_range range; bool anon_exclusive; pte_t entry; - pvmw.address = page_address_in_vma(page, vma); + pvmw.address = page_address_in_vma(&folio->page, vma); if (pvmw.address == -EFAULT) goto out; - BUG_ON(PageTransCompound(page)); + VM_BUG_ON(folio_test_large(folio)); mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, pvmw.address, pvmw.address + PAGE_SIZE); @@ -1315,12 +1315,12 @@ static int write_protect_page(struct vm_area_struct *vma, struct page *page, if (WARN_ONCE(!pvmw.pte, "Unexpected PMD mapping?")) goto out_unlock; - anon_exclusive = PageAnonExclusive(page); + anon_exclusive = PageAnonExclusive(&folio->page); entry = ptep_get(pvmw.pte); if (pte_write(entry) || pte_dirty(entry) || anon_exclusive || mm_tlb_flush_pending(mm)) { - swapped = PageSwapCache(page); - flush_cache_page(vma, pvmw.address, page_to_pfn(page)); + swapped = folio_test_swapcache(folio); + flush_cache_page(vma, pvmw.address, folio_pfn(folio)); /* * Ok this is tricky, when get_user_pages_fast() run it doesn't * take any lock, therefore the check that we are going to make @@ -1340,20 +1340,20 @@ static int write_protect_page(struct vm_area_struct *vma, struct page *page, * Check that no O_DIRECT or similar I/O is in progress on the * page */ - if (page_mapcount(page) + 1 + swapped != page_count(page)) { + if (folio_mapcount(folio) + 1 + swapped != folio_ref_count(folio)) { set_pte_at(mm, pvmw.address, pvmw.pte, entry); goto out_unlock; } /* See folio_try_share_anon_rmap_pte(): clear PTE first. */ if (anon_exclusive && - folio_try_share_anon_rmap_pte(page_folio(page), page)) { + folio_try_share_anon_rmap_pte(folio, &folio->page)) { set_pte_at(mm, pvmw.address, pvmw.pte, entry); goto out_unlock; } if (pte_dirty(entry)) - set_page_dirty(page); + folio_mark_dirty(folio); entry = pte_mkclean(entry); if (pte_write(entry)) @@ -1519,7 +1519,7 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, * ptes are necessarily already write-protected. But in either * case, we need to lock and check page_count is not raised. */ - if (write_protect_page(vma, page, &orig_pte) == 0) { + if (write_protect_page(vma, page_folio(page), &orig_pte) == 0) { if (!kpage) { /* * While we hold page lock, upgrade page from -- 2.43.0