From patchwork Tue Jun 4 04:24:46 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: 13684609 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 E2C8AC25B7E for ; Tue, 4 Jun 2024 04:21:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0EAB96B0093; Tue, 4 Jun 2024 00:21:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF1066B0096; Tue, 4 Jun 2024 00:21:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCE0B6B0098; Tue, 4 Jun 2024 00:21:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AA0166B0093 for ; Tue, 4 Jun 2024 00:21:46 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5A6A680FE1 for ; Tue, 4 Jun 2024 04:21:46 +0000 (UTC) X-FDA: 82191907812.26.882860E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf24.hostedemail.com (Postfix) with ESMTP id C2EB7180004 for ; Tue, 4 Jun 2024 04:21:44 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BrDK39h9; spf=pass (imf24.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=1717474904; 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=STMymf/q39pdV8bpsO7JUnR6GSizUsXFHnAFDrBR7Ks=; b=lA3AsT1zrsHZs62rCnG5Wf1l0csOo1C6yimI4LD9iMHAqUy5KtdQ0D8SNIl/+e/srzyxSC w6WVs/m4UPXq6vgLpZgcCHbPFwH6EJ8UpFWB+k8mdyTvXNQCjSdaI6imexFCFxHkJR6t9q MLOkdstSil9/T04tjtUeWr1mh8JnOyY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BrDK39h9; spf=pass (imf24.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=1717474904; a=rsa-sha256; cv=none; b=Ht+owWCFU1bRp3RVE3vpL3b5o+cPKm08oqeBam99cxoi2ImyLz4WrSEaHX5iNDFsMsgfjP vgcb2188ys7NO4HOXkLEqDb5qcWOSrmgIUortMC6YBfdhEA8ARmymaowi3huo7PemymRxB u7hBy//qInALDfDhGkJK2WoD0EF6VXA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0C2B8611B9; Tue, 4 Jun 2024 04:21:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83CC0C32786; Tue, 4 Jun 2024 04:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474903; bh=8rn+89eKdjpnGRg9SATPm/FCPUFDqEev/EjdjwcPsX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BrDK39h9fOI8f7AxXV5VEsT+hcMTOXnlEQKMg/6aZTTxZNso2DZQD1OtJONwRjRkG GTotLiw6R+JnHOjQ+F4Z2QdlRSZJW/+/D2lxocg2C9GOt0+eA01KBD7PK6qZKDn93v oJmb0/AUR5k1JJjqlHrm2uenG78NcxWZ2ZRyhPdoGDBTxMnKmqVIcSzL2j5jAAFEig HQbh7x3JlQMRQX9xktOcMM1uYVXNp75jz/PFQLKdr4hYqEj/e+x0sMkhIMH8YDhZfw 1Lu1MRZv5GG3zPR5gLx+97v8YSf9U4PF/EC2hDxnpJ5FSUVfzwXiBharDCB7Osnutq bkpUX1xY27wMg== 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 04/10] mm/ksm: add identical_folio func Date: Tue, 4 Jun 2024 12:24:46 +0800 Message-ID: <20240604042454.2012091-5-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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C2EB7180004 X-Stat-Signature: 8ih5apokkwfg93xk8apb4q5zidbo6yiu X-Rspam-User: X-HE-Tag: 1717474904-975810 X-HE-Meta: U2FsdGVkX1/tAH/Ngq9Er3jgfqvyKrD9Qd1RWN+1mlBbuDY8FZ7o8VFQ1bjDWNuf8ZiDKwiVQv0x3An3w0PRuxrboPMpf0CuNtpHhQ4N6fyMdeZa5yk1vZOPGeo2srg9MwDjFMvCKwwWccScOfg9VdmolALGE4Vi2FbkcNamxh80NaydQcz7TcWAHh5hSYDUQ5oGtuFud1GFFsL0IuBXpyh6za+J2ECLssme52kR9AR4eHSzrWwOcZlPFBpXLcYuUKzlnbRPDctNzhIvGLrXMSxSwyo8eqsGol8lZVTIgIbeOiQdVTIIOMZN8SyoxeUCxsWGm4IOJyfPQf9RkRAV+KO9qtceN6XNANb72ayBGWoCoBYzd/vtSFW2vvyEG7K/IUhVmTV91rSoEJmlulw5MdLz9c6MCDzr89rxciJCRQfX7kXxyco70rDRGzH+WQXlr7vFEPOQugjwedS8UEMdvYYNpN7u46ocsjiWjQFDwfxVGkX1qsny9WjKTndeUrO0XzbX/wdVL2U2KxybdPIEWIV7BWG3V94yEJ74GxyHHYzIodhosXsGJX0lSKEReEQDmmMpUOeFh9JcOQm52+bkZOHidiUqJherNH1N7uL9UzsJogxiaC84NfZsNmM616+w7BpXzJup3H+T8tkOR8FiNathMCSON03xVHdF7NgMqndkTxFOc6l0Ritdzzq3eHYHf/tkwJcJBzUGC9/rpy17ofJldp8/ykcRbr4bVHp/NzilCTaCyPofO60hrR2y+eUFmjE7noZV6eI7g/xpGSTSW2iDyJBgMqqPfC5KI1mSAVQoxg2hYxCskypWuCNIRtZP/rSbcsV06Ow8GpREt9litrDWxhI5Z6Bi+b8enCM1j0+oLiyU5DOY0LFdPMMnrzgHBi8Viluq5qjpzyTxotuAO8IPLUQV3LNKcTR2bLehdZYnnAIppIQu5YPwo9Ywbedlm7Qv3o9AxJH12MHFxbL E85koEU/ skkgREUYVJ5jK3asO5Wlg0RWds6vNF+/k0z+uv/n4IPbBNXknHW2Wj+jcVuozX2nGq2rVewQG5b7JYv7g9Wdhx6cB364tRsScpIp5oif9SW3BtyR/k93DfZDo3OtdQSd4XznOA5qvdW+d+5aYvspqHUswmAVpjOyOV97uzVGhWAZLyICEKDgQwYj6N/HaQuLkU64divHsrKpOkZhcojn72XhadU9gpcVMnU9HwN7m/bdsuYhIFAxaCb1IiGd+HOr3dgR0rPiFSFWlGQaspPPp+EDvosnPCFM10X5n 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)" To replace pages_identical() func and further reduce the 'page' using in try_to_merge_one_page function. Signed-off-by: Alex Shi (tencent) --- include/linux/mm.h | 17 +++++++++++++++++ mm/ksm.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9849dfda44d4..2d1f16ffc6ac 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4164,6 +4164,23 @@ static inline void setup_nr_node_ids(void) {} extern int memcmp_pages(struct page *page1, struct page *page2); +static inline int identical_folio(struct folio *folio1, struct folio *folio2) +{ + int i, nr1, nr2, ret = 0; + + nr1 = folio_nr_pages(folio1); + nr2 = folio_nr_pages(folio2); + if (nr1 != nr2) + return 0; + + for (i = 0; i < nr1; i++) { + ret = memcmp_pages(folio_page(folio1, i), folio_page(folio2, i)); + if (ret) + break; + } + + return !ret; +} static inline int pages_identical(struct page *page1, struct page *page2) { return !memcmp_pages(page1, page2); diff --git a/mm/ksm.c b/mm/ksm.c index 21bfa9bfb210..2e4790842515 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1527,7 +1527,7 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, struct folio *folio if (!folio_test_dirty(folio)) folio_set_dirty(folio); err = 0; - } else if (pages_identical(page, kpage)) + } else if (identical_folio(folio, kfolio)) err = replace_page(vma, page, kpage, orig_pte); }