From patchwork Tue Jun 4 04:24:51 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: 13684614 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 BC2B7C27C53 for ; Tue, 4 Jun 2024 04:22:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57DD76B00A0; Tue, 4 Jun 2024 00:22:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B6696B00A2; Tue, 4 Jun 2024 00:22:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 331846B00A3; Tue, 4 Jun 2024 00:22:01 -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 1170B6B00A0 for ; Tue, 4 Jun 2024 00:22:01 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BC78A1A11A3 for ; Tue, 4 Jun 2024 04:22:00 +0000 (UTC) X-FDA: 82191908400.17.FC79959 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 32E8840018 for ; Tue, 4 Jun 2024 04:21:59 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vFtitKi7; spf=pass (imf27.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717474919; 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=9oAWrZ8y33BqVe5nxUrKoBAUKkyrxV5HJdlP1s6nA2c=; b=prHpZFaevbQjifc/mvq4HKYFR9Z9ifgkRXAkP8w1nq7QKxDGiHNuYTpUuQb4ERAo1+e/j3 y9SMl/5AQGgbQFDzs0k5P+YVS8T2LjlF0ZIXclYc55XyRCZ1Xn5WcdmzSK/4LVfOvfjT9u h2sG3Qfs8wVwESwW0/9jxdk2SUOpyIQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vFtitKi7; spf=pass (imf27.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717474919; a=rsa-sha256; cv=none; b=zxGNoKyqwxQV9epLUN5hI9aptKXI/29JTz7CTLex/dv4Jm+zF1g+lb+rpE/9kViCBDRnRP aM6SklykkDXqq6HOxpVHMvl0i6BseSJKM54ida3k9VHErbUSjEsP2SC0xlspWk2G60uXHF KIxI5I0yx0F3KHoJ5FSLx7d1CPFqC/E= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 83F056116F; Tue, 4 Jun 2024 04:21:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31BB0C3277B; Tue, 4 Jun 2024 04:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474918; bh=oMozYVrFFGB9vcI3OPMo0SADR+/06RLvlkdM1E9kWqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vFtitKi75VkslnGm5HM61imI+AbUmGKz0XcZjPDTUXd4NBl0VY8yLM7DCkeyfOfHa xce4eXMDrC42qjTbB9rUkdRq2a8Mzr/gRE6n7jyJ5wrIijxuvx0EVz+2JWscYQ1eni PXd30EC2VbtuS7mAYSInQcYOKXDWQzdtJKehTOrmpw7gchDRcLFb4IPiBkG7oRjrw/ QLBif67iTIrzHu50sls1bMYAS8pxVccQzenPPP2FPWCPsP2Yx06/yzy3ySpSkZbALD tLysh0FKSJCUIYf7cfuUoZEVxngYOJc+k1Gn93FmkAzrAKJC1ycbvaV12i1sfA743L dAD75MsvLbzcg== 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: [PATCH 09/10] mm/ksm: calc_checksum for folio Date: Tue, 4 Jun 2024 12:24:51 +0800 Message-ID: <20240604042454.2012091-10-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240604042454.2012091-1-alexs@kernel.org> References: <20240604042454.2012091-1-alexs@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 3imj78gw8xewy9nyit9zbcjgjc63fmo8 X-Rspamd-Queue-Id: 32E8840018 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1717474919-961664 X-HE-Meta: U2FsdGVkX1+E1PvERYtSTwYG3EG2spEsOA+5sn5FwfeDzcEajYEfKc2XBjX+eaM5EbAH4IVwtM99n1he4ySt6typu/xme2jDLK15OetMH/4pRre6V6Tl5g79GeX4X3MpM4V2RtPqTPPtHQs4hu6fHZ10cm/JTPEySdvoh/h8BceVxmp1K2VWEq3AFxoqZow+HS/IiEHtBDT251f1tQRMzkS2x1JVmfYtitbAU5MMKPHcWge9N0bRhQ7Fiugkj44FTx5ng18Rgru8wppZCRi0CcQumNM+OuhyKQC6Q8BmdflyOoK6UK8yhJLOEKRYXTQoICfO0gSFfpUNEvE1r4ckjKKSDPJ4NVOuSTiNuI/Bn2vAbMFTQ4TBQyqFiXao9lvQ/4WWL6jObEM6WILc+xjVa4vl1Hsw5Rz8C/JN52AfIt06k422xBgD3MtGeroVWE5R+Zpj37UgoKwPZriMlb4wGnm1QCpVhXLlGuI6xUBlXvwrq/2I/YEo17sjdjjoRHLAnuh6z7i3tR7uupiYCtQThrQYOsQufjfikpJGYw3UHe/U1+8kMoRYyXXqPNpg8yGRo2P5vmJ2MzTth3wexVCrFZqlicyobWsnd8kzJv2ek0xJvudCr35JDuEWf9CQ4jmN6tmJJPTpk1lzxRnaZ2KaDRvYptCJzvbW9K4SDuxcykMNW1GDmz8Fjm2KdoykqWe6wxrlU4aH+IXve6pvkH6bvU/mQKIltTvOb7rLSxNCLDWokjhHZsYrI236bh0F2w5Fa9HuO/dNaQybmmLF5lzka9AXSD+yfneLphIHSY0dycwfMv0ubP8JGH4955Iq319BoiDdS665gSb39Ty2vytpthYcjXylMniatFv5vqW1BnxUTxI0+LhthjTQa7s05r1nolsyJFpTPVFw6UwvpWX0hK90Wlg+YPmGhI9q3H4zFfjRftOpBD1WcZBhcC7iyY0G5f1rzQODY4A/2yPVjeE H6lKTCrL 3yiTq5yAnwPVQoM8rn59luwkvQ0k0XF5J0HxuyHQDA6vl+3g/PGqdGKJdEXx88tr6dw25wkIiIMrGSnwivIhpjFBIXT2oAwHAiy+CnLnJPENBURVaE6rt0a6yHsrVop8ebZrLSd+GzPM/JGHrE3Yio2EmfogyPSrib+lsVj8zIhxDsn1OsdP33/LcS5s4hM2ntcaFQPFbxy/+cosDFP5YjTOTuUNylcOfF3JPq2TPYy8NcUdo0Lv8RLpe12dr4ZKRBZjb/4ZxH+asTEIj1xaT/nys9Oxgs9U7rjxo 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)" Let's check the whole folio for contents change, don't count it if the folio changed. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index b9c04ce677b9..dc2b5e6a9659 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1258,11 +1258,13 @@ static int unmerge_and_remove_all_rmap_items(void) } #endif /* CONFIG_SYSFS */ -static u32 calc_checksum(struct page *page) +static u32 calc_checksum(struct folio *folio) { u32 checksum; - void *addr = kmap_local_page(page); - checksum = xxhash(addr, PAGE_SIZE, 0); + int nr = folio_nr_pages(folio); + void *addr = kmap_local_page(folio_page(folio, 0)); + + checksum = xxhash(addr, nr * PAGE_SIZE, 0); kunmap_local(addr); return checksum; } @@ -2369,7 +2371,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite * don't want to insert it in the unstable tree, and we don't want * to waste our time searching for something identical to it there. */ - checksum = calc_checksum(page); + checksum = calc_checksum(folio); if (rmap_item->oldchecksum != checksum) { rmap_item->oldchecksum = checksum; return; @@ -2385,7 +2387,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite mmap_read_lock(mm); vma = find_mergeable_vma(mm, rmap_item->address); if (vma) { - err = try_to_merge_one_page(vma, page_folio(page), rmap_item, + err = try_to_merge_one_page(vma, folio, rmap_item, page_folio(ZERO_PAGE(rmap_item->address))); trace_ksm_merge_one_page( page_to_pfn(ZERO_PAGE(rmap_item->address)), @@ -3916,7 +3918,7 @@ static int __init ksm_init(void) int err; /* The correct value depends on page size and endianness */ - zero_checksum = calc_checksum(ZERO_PAGE(0)); + zero_checksum = calc_checksum(page_folio(ZERO_PAGE(0))); /* Default to false for backwards compatibility */ ksm_use_zero_pages = false;