Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1363237lqj; Mon, 3 Jun 2024 21:22:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWp/7xe+AADkOYofdDa+nSC0+4ZNkfj0u6hN0Za9n4eaVKunaeXrYUhMGB0RtCyz1ZgaaXcIXrWf+v11uPAHBV0OSa1ahk4AeZ2Ynyl0g== X-Google-Smtp-Source: AGHT+IEcbi22XzuhSoRVuzzrxtjA065QJSE5Sf5I0LfhH4+J18qWzYPl2mkgSrMehskj7XlPnMSD X-Received: by 2002:a05:622a:34f:b0:43f:ed49:a3e8 with SMTP id d75a77b69052e-43ff527c3a3mr124864401cf.16.1717474950910; Mon, 03 Jun 2024 21:22:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717474950; cv=pass; d=google.com; s=arc-20160816; b=cDV7X5yFhHhbFSkBWAe+DEbzRcWx5tYvyHoZ7DUlutjNCr/kn3u4J5CAMI/FGBKefS uW94RvHC/5ofI8ZXyRKnrijqDLac8OxaNWTBes6R0Rol/XjNY232mjzSj68GODkA0ICA YVE+zvKOBuE05mvXTeKnpQj9IPL4ftV72oQ5c6g9qPIt1x0JPIJDePf98r48+X5UE73O bljWndT2qwIONox1pK/PSZPbQjqG5A3m2KkQgclkSE8K5AtKyG8PU03Ts8/1R/iW1u16 Q5B0RHnhpUZFJz6gyXNLMZaGHZ/LNUiB/5b/NQ0/9GaOChlnIHwv3Q1zrIFVG2NW5Jrr sdEQ== 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=STMymf/q39pdV8bpsO7JUnR6GSizUsXFHnAFDrBR7Ks=; fh=8klvRVDD56yFrB+N2y9E7zuvf70XnrIgM6sxOhtJUBc=; b=gIEZMX5JEzpFVoZasPxN90H6bO2iDZOJqdEeDQI3iJB4zhQQPAZkCqBifVRnjTNvre C2+yW9X4mKGz17zGjGnxkNSA4LvTK5s/rZVLdUQF8iEM6vy0tlwO7QQMYQjKx+h8oNuY Rf0vq7ayUmoJZO7iFkP2amQEJlyDq70Sc5SvzS+JQrABV7STR8XnMkd/WblvnGSCy1Rx cFludSpBBZY/3e0Ixj5J1Rirt2D+ePWlQ1px5X35nuoa8M2h0JT7gTeMxDTz+A2yYOF+ 7t8Dt+VqF/NbZo1Ku6vHWlpA2KHXIVF1njzhHDcUNrXIw7+W4WjpRScgGUx1x9hne7OJ eb1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BrDK39h9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-200008-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200008-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff23ac704si102550471cf.129.2024.06.03.21.22.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 21:22:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200008-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BrDK39h9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-200008-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200008-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 51A3D1C243A2 for ; Tue, 4 Jun 2024 04:22:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF1BD13F45E; Tue, 4 Jun 2024 04:21:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BrDK39h9" 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 0FC6313F442 for ; Tue, 4 Jun 2024 04:21:44 +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=1717474904; cv=none; b=Itsvackrgdmd5GbNF2T5uUBwTZBtVYmAERK8N/yZHMQEnpeGHMJeHfdEak0Hb2CplCbDcum4Aar5kuN+nTm2MMf1hN3TZjCu/lYQUpqn8o90jUVpRPjbLh3UP3G69YWRM4Hv3HZRXxd8ILO+szuqM10CA50uuogsQB/QSi1m/Ys= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717474904; c=relaxed/simple; bh=8rn+89eKdjpnGRg9SATPm/FCPUFDqEev/EjdjwcPsX4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d/veBnqDBCVrx39cayeXaNwOQRdom211T1cG3QXr9cdMQ7B7uAKxqtYmRLoFSVJLsrT2v9xAiw3lNtET6VSihDcnhJEzYDrLkASW7vxSxTG/8vmY14Vl4srnqzugsDOimxffl68FMayswuC24XHRpWl0DI67FfCn4RPy9Z+pv5A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BrDK39h9; arc=none smtp.client-ip=10.30.226.201 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> 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)" 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); } -- 2.43.0