From patchwork Wed Jun 5 09:53:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexs@kernel.org X-Patchwork-Id: 13686524 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 D7A33C27C52 for ; Wed, 5 Jun 2024 09:48:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C7CF6B009A; Wed, 5 Jun 2024 05:48:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54F026B009B; Wed, 5 Jun 2024 05:48:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EFBD6B009C; Wed, 5 Jun 2024 05:48:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1DB9E6B009A for ; Wed, 5 Jun 2024 05:48:30 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B1DF4120427 for ; Wed, 5 Jun 2024 09:48:29 +0000 (UTC) X-FDA: 82196359938.14.DC46DB2 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf22.hostedemail.com (Postfix) with ESMTP id 41A86C0010 for ; Wed, 5 Jun 2024 09:48:26 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BERZumqA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717580908; 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=2OTsB9t/Dou0CMwaiAHJETWFDgAHSWlPwCHL5wg4K3Y=; b=O89LA7qKLVDhZrBfY+PCVRKzMDzMeRMaajrLX3rgoUtwkPZoBI8Fgf1cbJtWpOIwl7vKvO 2n5tot4PrrGa7VIVqjX+csOdRQZjeYJFjv13vcA023rXZgIPoU+agmIjezCACew+UnfVNB BcrLXtJPHPQrKFDDkwDkAJPbzpZ+pJc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BERZumqA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717580908; a=rsa-sha256; cv=none; b=7Uyv7ikhdAwfn75D3axcAcPcnPDthyfGqle52Rgj/vo7ST/zGVR4S8k62gZCri6XGMG4Yq HtHe44q27GJO2gu7JRfq61dnr7LWehyVqmU6nqDyly6KbcETTdQAR857whvdrsaXP43ND2 I9jyN2TsCnNlFvEZJE9WH3saDEXpOMI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 62966CE165D; Wed, 5 Jun 2024 09:48:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA735C32781; Wed, 5 Jun 2024 09:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717580904; bh=l4kI/Eqa/s3yp9ntZCNg8OdmGCzV7tDDQHa1fg1fi84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BERZumqA2vlBVurZbqf3ltU4dd++VsLve3ArCLFM5cVVJE9xR7Wf/usLMZOgMaoPH MkjMktd7aVDlimP8qcGYJzOZo4QPKr58biZZF3aZF3i4PBQ7smQ+uy7baIJZE5EIio +BpT2b5kvjzZFcE5C2U6WAUeYLVoOeXuVeOoguYB3YAOOU6HTdtq5Vi2HJ1LHUAsUD 6gJv+IbIiHtdqJhOhmck8hkjIi8BWxHkgB2MOHtLL/07/Ked6czniRUmR4EyI64gfr /NlMkMKCgEedzMMvz6IrPV+FTqewyJ1lwDcgcrXvUUqf/5pUuXFZ4nMnPs+WvRaPYb zLg/T9ccxC/AA== From: alexs@kernel.org To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, izik.eidus@ravellosystems.com, willy@infradead.org, aarcange@redhat.com, chrisw@sous-sol.org, hughd@google.com, david@redhat.com Cc: "Alex Shi (tencent)" Subject: [RFC 3/3] mm/ksm: move flush_anon_page before checksum calculation Date: Wed, 5 Jun 2024 17:53:03 +0800 Message-ID: <20240605095304.66389-3-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605095304.66389-1-alexs@kernel.org> References: <20240605095304.66389-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 41A86C0010 X-Stat-Signature: t65h5oqonobdz6zy17jdfqgz9zsdun4x X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1717580906-780518 X-HE-Meta: U2FsdGVkX1/vGLNH2m4TAgx+MR4AtiL4GYpo211ylo14XS2+zz5bwQ/sudGlww/jCzdbcVSolp8AbHhT6vD3h5MXqHeZY/2N5US7DQypKSHiaz+ERcXaOGvCsRiobI4aFeITrkLQTjNIbl7zHTGssaDmeZzBO5vRAyg1fNmMhHaC7fCouWOIVLkSV2VHknDIf/ckM5TyH83Lg+KvCMG+fNzI/NF7+3Fp1Q+Cp/ZtNhQ9JeE9Ra+PSh/R9aODpe/XSCwYNbvjoo1K387f8S2jNBPD9XPfHOV5BkBRtA2CcKUoPpemO4l4uGr9YorFpyUKty9kdiKg5CSKYC9zgleYJOjjgKRfm5h2SdS+GhQDH1QMtiSbDZhUJaZN6B36OnSL/GfJngQpCINc5GpyXclxiL0+bRD7fuz0akuUMOVEOvK6SOxfkxFSizsLQLEevdN/dyS/HOxKH9Mzwo0viB2DSAqmQzbzwy9SZKPZkKW4vC0YtDPZsAoG07cvvOhljU+W3Z2EfgMJf3+4JNhYH7UkqZdIPsdJiPgdN0CWB8IdNjzt65m4xxkFKI+w9enetAWttSg4HIFf/SCvMglXt0TI5k0fYzNCYJ8ZJi1DxxZSLgC1p0/gs5PA02LChQsHQZFUEZsia431FS1b5/Y6R/ZFqWPShcFBKQ08yL4Q8pM5aiT+6DJOSOKZ1aHeMMpzdXW208QPxV1tERK/Bp57oMlPwcOsaRaIkP95VVySRhLQs/XGcOmTYXMToPYSb9iOJqO3hesKhzOTpN3GGNdJumWsdqWsq3XhlcYheSjjRXiNMA8SbSIbsXJJYtwt7V9l+BWTN6fuPOOiMLjFcmiUunrha4Ncw0c5vTUvz2iHaTi0bVB6WspxRtAyFjaZEvgFlwCzyUI2paen/SGGTszz3M0DLpHsiGqSN3clivAFTudTXIBEAFg/NiHSW+VRB5PLvKQJr8Mrh5U7OOVjHTKFHp9 q9qCrLxF Ih4PudsX+qEyo4/Jk3trUtj0U4mh1Hdj3pZJ2GbrPNMfcG+V0OKw9aPOolgpSQi82APtqsqNcIaar2GIWVYldBl9ja4JNyH9OPamplcA79MwBEZfvv0uz/nNATRrtLKjxT/YdqthWiUTxMwZjeOX2bqRhddPXgw7JBfd9lCKm1T+uRd8Q2jCZcWMRs3yHEOz0+Ew2iZ+xnEn3M0H8LfgjrVivkTNJ2VnIH7Cv7jnzMYWE+4LpYnlSus9TfhI1KF65/0EATZM+4A5SXDB65HmzO3KCEvl0jkAMgOis 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: From: "Alex Shi (tencent)" commit 6020dff09252 ("[ARM] Resolve fuse and direct-IO failures due to missing cache flushes") explain that the aim of flush_anon_page() is to keep the cache and memory content synced. Also as David Hildenbrand pointed, flush page without the page contents reading here is meaningless, so let's move the flush action just before page contents reading, like calc_checksum(), not just find a page, flush it, w/o clear purpose. This should save some flush actions why keep page content safely synced. BTW, write_protect_page() do another type flush actions before pages_identical(). Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index ef335ee508d3..77e8c1ded9bb 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -784,10 +784,7 @@ static struct page *get_mergeable_page(struct ksm_rmap_item *rmap_item) goto out; if (is_zone_device_page(page)) goto out_putpage; - if (PageAnon(page)) { - flush_anon_page(vma, page, addr); - flush_dcache_page(page); - } else { + if (!PageAnon(page)) { out_putpage: put_page(page); out: @@ -2378,7 +2375,12 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite mmap_read_unlock(mm); return; } + + /* flush page contents before calculate checksum */ + flush_anon_page(vma, page, rmap_item->address); + flush_dcache_page(page); checksum = calc_checksum(page); + if (rmap_item->oldchecksum != checksum) { rmap_item->oldchecksum = checksum; mmap_read_unlock(mm); @@ -2662,8 +2664,6 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) if (is_zone_device_page(*page)) goto next_page; if (PageAnon(*page)) { - flush_anon_page(vma, *page, ksm_scan.address); - flush_dcache_page(*page); rmap_item = get_next_rmap_item(mm_slot, ksm_scan.rmap_list, ksm_scan.address); if (rmap_item) {