From patchwork Tue Jun 4 04:24:43 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: 13684606 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 104DAC25B74 for ; Tue, 4 Jun 2024 04:21:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B15F6B0088; Tue, 4 Jun 2024 00:21:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 86E6B6B008C; Tue, 4 Jun 2024 00:21:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FF306B0089; Tue, 4 Jun 2024 00:21:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4A8076B0085 for ; Tue, 4 Jun 2024 00:21:38 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E88E51C1D5C for ; Tue, 4 Jun 2024 04:21:37 +0000 (UTC) X-FDA: 82191907434.09.A69409F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 4E095120003 for ; Tue, 4 Jun 2024 04:21:36 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AguJvBU0; spf=pass (imf29.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=1717474896; 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=0qkwW+WKN97TLxrl291rlnxJGM6JOScD4lNewveoewM=; b=vfHl7vondGLEdebWe+gbOBJ/1XiN1JKcFthQ7iN6AuvOSeerW/MBI/t3MTQ4qepTZ+qgIC /TAwa/y079kWqmcmOg4WLGFZ6/QU3+pBfJ7ikmNKlBwmXEOkLxK/P2QmTuoB/r6Z52pgvn bRWHW58Kx3GzFhXg30siQRJ7T6yN9w4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AguJvBU0; spf=pass (imf29.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=1717474896; a=rsa-sha256; cv=none; b=Ku4c1SZi8fXJXK/cZhzbCYW0Ek9JHQZRzFOMQUaajL5Puixlt2VhJRYfHd/NxtdQ3oN+o2 2VmB1vM3MuCk5CXcOS/oElNBxWms261pNYs1/dlUn5IqyM8w/6g6jI9uEcoWJg61mJiwxZ s1NerJikgGyn5EUiuDe7R+PXVcdWcXs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 56B5C611F5; Tue, 4 Jun 2024 04:21:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B71FAC3277B; Tue, 4 Jun 2024 04:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474895; bh=occLtpiGpNG6/OrTWQS6BvyTS0mi9to3RbiYlw3PrkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AguJvBU0+LLRweQOatueW/u5AH06TbIns2J0lyV0b25QR80ATqmiQBTyEWut9FC7m L8V1+t+hIkHS1njzCmejNwswpulFnR5Li3oPulT/Ye88s41xidUgi5DWxEknMybnYs SrQrv4Pmisbv32VKHqIeHL9Ellc0qaqvI+uP3XI6QVmtr/L+ifE9aXqzuarObMzY8O xED9gD2pIUppXTXXqcVvaC4r497TaeSpG9V8R7EKpBSq8/F+KSdxZfOVDe5cK94jq5 KfEM5HmCAV0abs8mRLCcl6FBU8N4o2oFmv4dCKLRSJ11rNxKDFAzZ9ZEx2mDsZMfYO hnt1ztORdDlgw== 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 01/10] mm/ksm: reduce the flush action for ksm merging page Date: Tue, 4 Jun 2024 12:24:43 +0800 Message-ID: <20240604042454.2012091-2-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: 4E095120003 X-Stat-Signature: 1i3xprrky3wsw8htg5t9u8ywfjbn4i5k X-Rspam-User: X-HE-Tag: 1717474896-382488 X-HE-Meta: U2FsdGVkX1+3oxD0hJ7Xtz31XB3+L+u3j1rXQbEwVdphp8DhQHqGl8BDr0VXjumUHMskFnoxFGQn1xh835bYvUd7EkMR7DLk6A9pZfpPoLnGEGS1jRTFI6QhlT9TO+VfGIZCj53M8EZ9XCfQ71q3R0XX/ew2ZlriueCoVqNs4G1kom/X1/pDqULmQn7qd0AVCXrnaqBqZTEKr9LUtalvQuoTvEn0+AFPfkt8BK1Ro8i1AJgQ6Hcobeqpt/0kJAWJ/1D+xkiYiTxq3hZ43fPEpNRVissLqzrj9RIt/ie2YGCpQj79pF/jY7zCl19knfce7pBiAMBR9tubYaVY0ksCZej/MjumHSg+u7v5zbnQadSaXBomJUeP2bmjYmGsa1t61ibTJFF8cK8mHaEzEbmaUTBHAD+dX6DWBVZlIrLhEgxGjxkBAGYfZIMRUv6h847UqHmF6s36z+A0txKlfcD+27cQqqyW1ZpW9RYqOQIzidLQv7IzY38FJlFE6qjb6a28tfMCjqMk3OBWAs3dz6R/RA5iGgy+DTRgHdFkZHxlc4RjuGWkI8GmBVisJ/rHb6/YkBa5URDr7+naNVJoP+hmZxy5dI0ufB90aBHenWShEOFQQxrBxIGF8Zgvv0Y5wpgsoAswMLooj92CMFgtXvGtGmB3ExChm/9NjSDGP+IuvKEnQ3L8JgCZxrS2EQ5rCblpvGhFl3WHGyBj+15UXTDVSCyC/WCLftKB8x6xdpbpRqJKm18Hj7mb16w8W2GxPFFckvNPAFu3K58cvup4SEz84lTXre5rRGF4aM8yMKmrg5aozzKYyyL6hivfbTDpzON0VJ0XfcaGW6SCH5QPkqPDGTo5AcZTenRbEzMNsv9Xj6wqUmSR5hEEFmiX2lEpVxdhAY8k6C17MF3ok6VvndLNqZYUavPNLbWojX7rslYPvI4At5rrPBGywWOFKURBBOyJGrEASDsLxnTxPiLtyB7 xiT/Uado DwAglkyYSc5oa/tBBu8XeMF8B6ZEWz67g5WhtKUwIF9jiIRlnkkASg5EhKhlKR/Hi5Hkfc2dFXMVMRTwDesmhyNo8gd4WgVqA9EJhaBdFfXyBrBKpWzrPW6DDZpuq5AsxaMsSWMqt0PqZXLw2NCtnkA7cDqRz3yjDr4NRTLDcobKKJfhJoHbDybNg6N80cMkhK8UB/4yZ3vUbsS8lDr+Pr+hPzcAV4XYeeSxQv511AeB2hRw= 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)" We can put off the flush action util a merging is realy coming. That could reduce some unmerge page flushing. BTW, flushing only do at arm, mips and few other archs. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index f5138f43f0d2..97e5b41f8c4b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -783,10 +783,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: @@ -1473,8 +1470,8 @@ static int replace_page(struct vm_area_struct *vma, struct page *page, * * This function returns 0 if the pages were merged, -EFAULT otherwise. */ -static int try_to_merge_one_page(struct vm_area_struct *vma, - struct page *page, struct page *kpage) +static int try_to_merge_one_page(struct vm_area_struct *vma, struct page *page, + struct ksm_rmap_item *rmap_item, struct page *kpage) { pte_t orig_pte = __pte(0); int err = -EFAULT; @@ -1500,6 +1497,9 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, goto out_unlock; } + flush_anon_page(vma, page, rmap_item->address); + flush_dcache_page(page); + /* * If this anonymous page is mapped only here, its pte may need * to be write-protected. If it's mapped elsewhere, all of its @@ -1550,7 +1550,7 @@ static int try_to_merge_with_ksm_page(struct ksm_rmap_item *rmap_item, if (!vma) goto out; - err = try_to_merge_one_page(vma, page, kpage); + err = try_to_merge_one_page(vma, page, rmap_item, kpage); if (err) goto out; @@ -2385,7 +2385,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, + err = try_to_merge_one_page(vma, page, rmap_item, ZERO_PAGE(rmap_item->address)); trace_ksm_merge_one_page( page_to_pfn(ZERO_PAGE(rmap_item->address)), @@ -2663,8 +2663,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) { From patchwork Tue Jun 4 04:24:44 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: 13684607 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 D0413C25B7E for ; Tue, 4 Jun 2024 04:21:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F2686B0095; Tue, 4 Jun 2024 00:21:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A2FD6B0098; Tue, 4 Jun 2024 00:21:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41C6B6B0096; Tue, 4 Jun 2024 00:21:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 17B6A6B0092 for ; Tue, 4 Jun 2024 00:21:44 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BD64D8101B for ; Tue, 4 Jun 2024 04:21:43 +0000 (UTC) X-FDA: 82191907686.12.47B8FA1 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf25.hostedemail.com (Postfix) with ESMTP id BBD0DA0003 for ; Tue, 4 Jun 2024 04:21:41 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Cs1MCtQ5; spf=pass (imf25.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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=1717474902; 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=3rCxAKB6b5eDBe4LpW42dCn0nSMzkZsZ5uZy6AYoYi8=; b=VbWNSKtJOL+KnwqXUGDPCXfzZliTY5a/ZQb3Sz99HtofSveyl7hPh8dDK4jPXWsqMGs1eV 3fLcgyaWPo2jCy/WCpnVAfPzMYL/YsGLy7UJj1AR6j7X82CynQJIdnXhTFyJ5otBX42SYe EiVxa3d2cxb82PbObIsfd3Zw6UYwxk0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717474902; a=rsa-sha256; cv=none; b=ToZ2Fe76De9e1Vmx/BNUrkiVnbZ8L5uG/yft374temb8H2dMBPfb77BPccEu/vlmOn3qkN ogU2CyYfo0VsUNXzfdfsckEhHfhwMzVglg0YtMM1Sl+TTz75AyiHXi0KuGRLXaB0Cc2bEn T1mAV0KfrZ+g1p679YJc5zhvkoxoRMk= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Cs1MCtQ5; spf=pass (imf25.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id C23BFCE0FF3; Tue, 4 Jun 2024 04:21:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4F92C4AF0A; Tue, 4 Jun 2024 04:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474898; bh=P0itGeZCXEfvARIWHRoE92wg+ZB0+ncoLLqA7cA6dRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cs1MCtQ5uXJAEfguDsl9n6PCoX3lPNYo1TZbsFptY7tRN/JeBiGX7aLwjXVkjEjP6 gzJtAWsoo23HZ4+Xwld8DivVjPrM/axC3AWBXBgFbVhFye8646fQl0FEVCgnus7ErB +xhs2Tfn2Qkp41rTdPVsTbIPRBi9scA3yz80vVEF60NFVyYUYLBqx+ldEpKMUtAznx QkC9gXYgaUuhdCohrrJoGYJs4e1pF7R0beiZ+UQ+PqqbfZ8KpYJG13ms3sw4fzDZqf x+9aM6ykvs/PQUHdUrVeSR+BU7KapA9qAI2obkv+dWjpqjmNZ7trkgxufE2OkJYsC+ SdXnLZW54tSSw== 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 02/10] mm/ksm: skip subpages of compound pages Date: Tue, 4 Jun 2024 12:24:44 +0800 Message-ID: <20240604042454.2012091-3-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: rspam03 X-Rspamd-Queue-Id: BBD0DA0003 X-Rspam-User: X-Stat-Signature: de14xhjhwqe7wormhapewgozbmxqqspg X-HE-Tag: 1717474901-489176 X-HE-Meta: U2FsdGVkX19Y0ZehQVGneadjykqCDIF4c8RuBtamrvxXW/3zJluq+EwizD0+HNTtDG/uvs6t7ARpm9UiRvvrk5k+pnaglcBWSjXqGGtkL8b+lGoe7B8gKEvJCU8lXj/MtpXn7iTwJZyiW7ESzWdaNOxxCI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8E= 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)" When a folio isn't fit for KSM, the subpages are unlikely to be good, So let's skip the rest page checking to save some actions. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 97e5b41f8c4b..e2fdb9dd98e2 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2644,6 +2644,8 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) goto no_vmas; for_each_vma(vmi, vma) { + int nr = 1; + if (!(vma->vm_flags & VM_MERGEABLE)) continue; if (ksm_scan.address < vma->vm_start) @@ -2660,6 +2662,9 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) cond_resched(); continue; } + + VM_WARN_ON(PageTail(*page)); + nr = compound_nr(*page); if (is_zone_device_page(*page)) goto next_page; if (PageAnon(*page)) { @@ -2672,7 +2677,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) if (should_skip_rmap_item(*page, rmap_item)) goto next_page; - ksm_scan.address += PAGE_SIZE; + ksm_scan.address += nr * PAGE_SIZE; } else put_page(*page); mmap_read_unlock(mm); @@ -2680,7 +2685,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) } next_page: put_page(*page); - ksm_scan.address += PAGE_SIZE; + ksm_scan.address += nr * PAGE_SIZE; cond_resched(); } } From patchwork Tue Jun 4 04:24:45 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: 13684608 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 79BCAC25B74 for ; Tue, 4 Jun 2024 04:21:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C2496B0092; Tue, 4 Jun 2024 00:21:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 972086B0096; Tue, 4 Jun 2024 00:21:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EFFB6B0093; Tue, 4 Jun 2024 00:21:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 36C966B0093 for ; Tue, 4 Jun 2024 00:21:44 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D0263160CEA for ; Tue, 4 Jun 2024 04:21:43 +0000 (UTC) X-FDA: 82191907686.09.7EF9400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 365611C0003 for ; Tue, 4 Jun 2024 04:21:42 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LVNkYZ54; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 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=1717474902; 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=jaTa4hdmBnimMLa8wYkNVT/2zgdLaWkSGqmxeE4jtSI=; b=vZ6vBWOYbPuq3gtre79kZJ71f18G0xt5V5XLuq4wxWg8tr/FwmIGlL1ELa9Qh9IQ7XsDmo LLwMCUdJlA82lXq0+EL2hl9VEYQcuxH0er3TA6kPmVitsZH45wlZ2JHKsKMky5zcv6UdSs prYhdge0K/c2KRBW3M5QmyvlSBwcN/c= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LVNkYZ54; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717474902; a=rsa-sha256; cv=none; b=ncUp0Dt8/ZLruse1IsPJcBCFbcqBhtqWzoxRzXMXTndBvhnkWPPib0uxGqmi5vFKp8M87K 9ZpXxpK0/dTMsOSHs195R18gPHTLRSh3LnK3V0nvudbH4wdJZZXMUGL7gM7yu8qIUqzj0u o/3348nEAg66YVLQYv2jdB26+p8ukWM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 58523611F1; Tue, 4 Jun 2024 04:21:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95F25C32786; Tue, 4 Jun 2024 04:21:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474900; bh=CfvlQ2M9KWnaqxKPXvUUKqZr9diZgDumxJiDtxK8xLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LVNkYZ54FWWO0xDgawCPCmAKsUuesOzTQxtIVVhIDWRFB+BRrf0loqYP6nhYl+ZxY 4/FZDa5Z71YUuEhj74spNoj9ub6BKUBfz6kLqA4rTWFIZUJHInhVTnX/Q73H75AiZE 85lX1fl8SDh3Q25c6Noz3NN0Wl8T/1GRCbq6062CnvkbylpQ2xwZz64V3O1XnQv1GD rbF+PTkdvZSFnKI6OjAVUsldEzoxEUdBOuyOnpHHZA6UHSgFrSTxZfnCboZeZh5zMn hdaK9PWG/w+vABWb3fmiH/Jgh1v2eloKrI0GKrme2D4X1hpN3ameLMF8M7ylbqpR3O 9mJ/sbzJPl4rA== 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 03/10] mm/ksm: use folio in try_to_merge_one_page Date: Tue, 4 Jun 2024 12:24:45 +0800 Message-ID: <20240604042454.2012091-4-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-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 365611C0003 X-Stat-Signature: fgppgjuu89um3oxbs8jdchpgfbme5mig X-HE-Tag: 1717474902-737140 X-HE-Meta: U2FsdGVkX1+v64CEAKpvY4j+pj/7MT+Rh3NwzOQodMGYO3UZGeQXt0O4JO4sc+0MpYRKlCWRvn2w4dj2CzliNfcNt7XD3KFpY6dTssiJealaclKWOHjRAxe5X4cDByQZzlUaHxYRa70qzwgSoOkvkqb0465sg9hj78no1+vmsHlBT7efgzIPFeI0vLVlv8yWhEd+UJ9Z0GVvjOBfOhRo8xwsFLCRl7pPvy9IKK8zjwgxo5RaEffiBoEkhO50NynYUptFspJR5dYrKeBAcB7OH9B9A5xcsHDNmwhxw7+e1Nu6hlmZ09259zgbi/pf4eeAiXpvl+/3UQMNgsFUahJLX8KmsV/A+SemCBre1p9e8M14iXNNxbEjVLT9oje6pMWGOPJ2IRbJrvhJT6djx4FyNYhavurOJWyM1KMssevmDAoINUYRZ04n8gpObjCvxgNZLuq9MgMiKDDHhzx8kEmoSOjtkgTQTrffCkDG+LX9lkYcmCldZ8tjWXelu9KkA2++K+W7AbbC2hmrb4ELfLuciREeybhdOeEJlDrWGdeS/QMc+j5uALuZLkWLhadd+ibCvs6HFasCC1PfWTfA+Dr31XIde2lLZg39Tcqqk07kiOhQETq/L2o0RbR1iGhm14m2C1elZIPiQRcwGViVdFAlNpnPiPFy1aGgrz6pPbotsjkSeVPIBQwYaspL+TlRnQ8bPpzOV7mermT8bUQ4u5UwrfjQ3MnitHunELU0hYLk32bdshDlL52bNUAia2QKcLYg+T+hkOdu9lvQaDz389yBrSx6WxPHqBtYGoEZNxOHX5ZKRFFphaIpRCMCL+wyMC8lfvFULGaDzq+i4nfpXdWIzOnYS6eRUG8SNRf7ZwCtfLzCHh18kHrNNSsUSxXX+MaGq0wxrrX+A6D3ahv9PZoU+niu9GDNU6pIzyB8ahMVMhIVshO/EJP6rVkVKx26wxwzvtHPKlnLr2/HB40/Nnd 3A0+wRlR wjYR0jL6Bdwr8JTQgN+mDA/3uaJsaWJOT8QW95PimcsfQii5JdkASj7xAW3dOuqWPPRnWnJ5LOKEEvw2LGCK1vtRv5qcfkb1jYciC4P7aGDY57Qnyhe6aJKXc8PUi3CsjvIFNTX3rKCZculia40a/FuXaJ4dIKzYMgvgDRp7Vhdwj9oGXZ/phVr6vTs9A6tGB3+tGxDjvBklpDCRhOkml6MKs0xoYXJN7vosRxf1DQDZkUGyy+x8DIeZqIPshqItjIaj0ZvC876gWWnx7L7nSpb2WRV7q8Nu0V2Vr 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)" scan_get_next_rmap_item() return folio actually now. So in the calling path to try_to_merge_one_page() parameter pages are actually folios. So let's use folio instead of of page in the function to save few compound checking in callee functions. The 'page' left here since flush functions still not support folios yet. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 61 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index e2fdb9dd98e2..21bfa9bfb210 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1462,24 +1462,29 @@ static int replace_page(struct vm_area_struct *vma, struct page *page, } /* - * try_to_merge_one_page - take two pages and merge them into one - * @vma: the vma that holds the pte pointing to page - * @page: the PageAnon page that we want to replace with kpage - * @kpage: the PageKsm page that we want to map instead of page, - * or NULL the first time when we want to use page as kpage. + * try_to_merge_one_page - take two folios and merge them into one + * @vma: the vma that holds the pte pointing to folio + * @folio: the PageAnon page that we want to replace with kfolio + * @kfolio: the PageKsm page that we want to map instead of folio, + * or NULL the first time when we want to use folio as kfolio. * - * This function returns 0 if the pages were merged, -EFAULT otherwise. + * This function returns 0 if the folios were merged, -EFAULT otherwise. */ -static int try_to_merge_one_page(struct vm_area_struct *vma, struct page *page, - struct ksm_rmap_item *rmap_item, struct page *kpage) +static int try_to_merge_one_page(struct vm_area_struct *vma, struct folio *folio, + struct ksm_rmap_item *rmap_item, struct folio *kfolio) { pte_t orig_pte = __pte(0); int err = -EFAULT; + struct page *page = folio_page(folio, 0); + struct page *kpage; - if (page == kpage) /* ksm page forked */ + if (kfolio) + kpage = folio_page(kfolio, 0); + + if (folio == kfolio) /* ksm page forked */ return 0; - if (!PageAnon(page)) + if (!folio_test_anon(folio)) goto out; /* @@ -1489,11 +1494,11 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, struct page *page, * prefer to continue scanning and merging different pages, * then come back to this page when it is unlocked. */ - if (!trylock_page(page)) + if (!folio_trylock(folio)) goto out; - if (PageTransCompound(page)) { - if (split_huge_page(page)) + if (folio_test_large(folio)) { + if (split_folio(folio)) goto out_unlock; } @@ -1506,35 +1511,36 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, struct page *page, * 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_folio(page), &orig_pte) == 0) { - if (!kpage) { + if (write_protect_page(vma, folio, &orig_pte) == 0) { + if (!kfolio) { /* * While we hold page lock, upgrade page from * PageAnon+anon_vma to PageKsm+NULL stable_node: * stable_tree_insert() will update stable_node. */ - folio_set_stable_node(page_folio(page), NULL); - mark_page_accessed(page); + folio_set_stable_node(folio, NULL); + folio_mark_accessed(folio); /* * Page reclaim just frees a clean page with no dirty * ptes: make sure that the ksm page would be swapped. */ - if (!PageDirty(page)) - SetPageDirty(page); + if (!folio_test_dirty(folio)) + folio_set_dirty(folio); err = 0; } else if (pages_identical(page, kpage)) err = replace_page(vma, page, kpage, orig_pte); } out_unlock: - unlock_page(page); + folio_unlock(folio); out: return err; } /* * try_to_merge_with_ksm_page - like try_to_merge_two_pages, - * but no new kernel page is allocated: kpage must already be a ksm page. + * but no new kernel page is allocated, kpage is a ksm page or NULL + * if we use page as first ksm page. * * This function returns 0 if the pages were merged, -EFAULT otherwise. */ @@ -1544,13 +1550,17 @@ static int try_to_merge_with_ksm_page(struct ksm_rmap_item *rmap_item, struct mm_struct *mm = rmap_item->mm; struct vm_area_struct *vma; int err = -EFAULT; + struct folio *kfolio; mmap_read_lock(mm); vma = find_mergeable_vma(mm, rmap_item->address); if (!vma) goto out; - err = try_to_merge_one_page(vma, page, rmap_item, kpage); + if (kpage) + kfolio = page_folio(kpage); + + err = try_to_merge_one_page(vma, page_folio(page), rmap_item, kfolio); if (err) goto out; @@ -2385,8 +2395,8 @@ 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, rmap_item, - ZERO_PAGE(rmap_item->address)); + err = try_to_merge_one_page(vma, page_folio(page), rmap_item, + page_folio(ZERO_PAGE(rmap_item->address))); trace_ksm_merge_one_page( page_to_pfn(ZERO_PAGE(rmap_item->address)), rmap_item, mm, err); @@ -2671,8 +2681,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) rmap_item = get_next_rmap_item(mm_slot, ksm_scan.rmap_list, ksm_scan.address); if (rmap_item) { - ksm_scan.rmap_list = - &rmap_item->rmap_list; + ksm_scan.rmap_list = &rmap_item->rmap_list; if (should_skip_rmap_item(*page, rmap_item)) goto next_page; 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+1mlBbuDY8FZ7o8VFQ1bjDWNuf8ZiDKwiVQv0x3An3w0PRuxrboPMpf0CuNtpHhQ4N6fyMdeZa5yk1vZOPGeo2srg9MwDjFMvCKwwWccScOfg9VdmolALGE4Vi2FbkcNamxh80NaydQcz7TcWAHh5hSYDUQ5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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); } From patchwork Tue Jun 4 04:24:47 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: 13684611 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 613E9C25B74 for ; Tue, 4 Jun 2024 04:21:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46D056B009B; Tue, 4 Jun 2024 00:21:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 41A646B009C; Tue, 4 Jun 2024 00:21:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294756B009D; Tue, 4 Jun 2024 00:21:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EE60E6B009C for ; Tue, 4 Jun 2024 00:21:52 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A7615C0CF2 for ; Tue, 4 Jun 2024 04:21:52 +0000 (UTC) X-FDA: 82191908064.07.4EA906B Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf08.hostedemail.com (Postfix) with ESMTP id 7070416000E for ; Tue, 4 Jun 2024 04:21:50 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MDSl5xy6; spf=pass (imf08.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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=1717474911; a=rsa-sha256; cv=none; b=KW0VBe/ArXZ9CB8lVFfLWlRrJxqfqvNZyaxj8luzk25WQOCagVMgxi0IQyT073T74awh2L 8lZ5zsYHzRIrlkYSWE7ybO6CKsBYPDJdrQIeg8Rm1YpcZ9jSk/bs7AI6pm6Yl2QiUf75dT ApG2uHRcKch7j9RU4SCUEnJOWlcYMr4= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MDSl5xy6; spf=pass (imf08.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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=1717474911; 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=k/DC64RVeyqPliY9iy4ZmvrEyGxjD2DKSlqV1GS9qDQ=; b=Sbf/Q3o2TrhF8W/WRvxjZ8HZCwxaR5PXMVpS+z5gELUeuX2tvHcr6/JoNClYQeIbPZw8w0 NU6jXLYr48UWMSe5cWYRUfy8yCawLmTqaejWBBLwQRmxxv1yw+XRrIgVaRQ/lL1De7qI6x c8viUqFFrP+9LbYY1Qj7Tm0sJi2Puv4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 93F8FCE100F; Tue, 4 Jun 2024 04:21:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F76EC2BBFC; Tue, 4 Jun 2024 04:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474906; bh=coNrFyNql7rzA+Wu1zS+Imisztx1VEYHkdkeqtcLPJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MDSl5xy6AfvB2jwDYUYciKw0WAPH6HVMDLpvUtKv4MiMW2nJPsr8687kDmSuMgS2i 8ir4mEf4IzJsZxyqCpwMRG7zPuqEQoO2FcqBJt1Toe9V6ugm2H3oSFrRFxB0nJRYvO 6ZjV1r2iscSWsLM8U1FBXXxPO9kLwGNyw46O7MPHow2J0CcrcBysxPOMtS9OSJHTXn kLsG0fd7lCw5iMa882oNvtx9mV5k5rsta8bJgKJcmH9Tjy3MLvJBxnK5D0J6VcqtKB /pWRYqxUdW7oaEdmPbUUkTDWV9VnNFT8B2tYE9n58p6TzwY1lajVhpANa7W9F7pRhx S/9+Par00zx4g== 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 05/10] mm/ksm: use folio in stable_tree_search Date: Tue, 4 Jun 2024 12:24:47 +0800 Message-ID: <20240604042454.2012091-6-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-Queue-Id: 7070416000E X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: fxu9mkg47e5pygued8ipugqzyuxeajqe X-HE-Tag: 1717474910-737125 X-HE-Meta: U2FsdGVkX1+WNw5ja1qo6yvxxLxVT7W/JKayJGJ6YhsaV8L7ScmULZI0lEo7VohSu/S+/zL4qSjcexSe+4v4hw6FpjV74ycJaUTByv62TJ1I0z2Xlou9sIX5I3hQg7Ji0qEl1uF1tmgL1BEX8BTmpAd89sbgXQG1TiK5v1JOBmXwmF9nR9p3fwQGzv/VuBBQiPPolj6+A4ZXKI2Z1PS8XYgZrH8XwhB4K03etXJfEno9aD+WwpkWTjfyy7SUVhf3/vkKqu5z8+Z5+ptCeu3JuH4/5454UlV17PDdPTfkzTHmFnEG8rZpQMTAaBX03hYNaB0Nm3GlxCf/uvW9HpXU19y/NQsnuguamU+iskcbLgAseguLJwx7EtR7RzTNkyqV3cEt56UDyVvTm23STPFnGdV2NWIMv3OvoXBKeZaR2HksTARU+l41S2oTNbu/PKG1r8oo5Xur14+9Kb1ygRqxIrthdsuaadvwB9GT2e7u12T55TRFnDE4CtVr2i19tDdegKmkGjf85cvybAvDPv6nw2pONXkjV9Vyas4B0h564LF+zwHLAPCGBA6MKmCMI6BSbzcxlRY6gZCTKbJZYAe4N2xnopWFTtf1oKcnlkvoJuboOslp2U4+npAUEiOwrzCni5jIDFGrjRT3iKD3ZeGxIDFJJfF/BWKXxNyHLlpofSBk/7XOvoCQRzoJtySgAx5ZG0AdFxztJrAbWabFnYxc1fI6bmRDK6XDt4IyScF7P6AjNnyS9u4wybJSkBx5AKczx90zCCMxJzfyNheulTq0MvMz9aFs6iigb3Xn9woLCu75BROc5ylHdikDpbF8aVNXkJUAjSbajmRg/e+l0OiqEY2g/V0vKHq84E0eD1ni/cDIo74JUR6oAOuMjgnxSknqibHWPz3338w8UXmBaP0qMBgQ/c+hF25NhhxCSQH1D9Ew59pzYwCqANoJN21vAjGPpyGr2U4nlCr7l500mum dNmb6mDr gRnK81qPZxAmhVzKh475CD0t6b4gvMJn42VU5AIwz1TU+b0exlMD4JoB33tuRpjKt+nwJJuiIo7N3/cSvpCMNcyKT6PziU2vbAJQll01iU5ewEA22QWnhBwJdLIbI63IkRXwuoHqzmerbHu98kRWbfb3b2fgBMnGmAyxuPuW1XhNnb9xVqOlgp4y2f+O2LYhGCIHm4zYun8FNLpi7V6UZE4ICcKWY7ouMlBf7mzQzFNIunPMu+Ma2CKBrzwmiub3MkUewbFa6LC7uJa4TJXCmU6LTP73dtKSJ2s+N0d9BRKd8uH7933FntPu6FL6uUTkTtBZi+gV15CJ7Uuc= 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)" The stable_tree_search() function is actually using folio internal, just pass the folio parameter from cmp_and_merge_page(). And in cmp_and_merge_page(), the parameter 'page' is actually a folio too, so use folio to save a few compound check in necessnary context. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 2e4790842515..f68779651841 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1825,7 +1825,7 @@ static __always_inline struct folio *chain(struct ksm_stable_node **s_n_d, * This function returns the stable tree node of identical content if found, * NULL otherwise. */ -static struct page *stable_tree_search(struct page *page) +static struct folio *stable_tree_search(struct folio *folio) { int nid; struct rb_root *root; @@ -1833,14 +1833,12 @@ static struct page *stable_tree_search(struct page *page) struct rb_node *parent; struct ksm_stable_node *stable_node, *stable_node_dup, *stable_node_any; struct ksm_stable_node *page_node; - struct folio *folio; - folio = page_folio(page); page_node = folio_stable_node(folio); if (page_node && page_node->head != &migrate_nodes) { /* ksm page forked */ folio_get(folio); - return &folio->page; + return folio; } nid = get_kpfn_nid(folio_pfn(folio)); @@ -1907,7 +1905,7 @@ static struct page *stable_tree_search(struct page *page) goto again; } - ret = memcmp_pages(page, &tree_folio->page); + ret = memcmp_pages(folio_page(folio, 0), &tree_folio->page); folio_put(tree_folio); parent = *new; @@ -1973,7 +1971,7 @@ static struct page *stable_tree_search(struct page *page) folio_put(tree_folio); goto replace; } - return &tree_folio->page; + return tree_folio; } } @@ -1987,7 +1985,7 @@ static struct page *stable_tree_search(struct page *page) out: if (is_page_sharing_candidate(page_node)) { folio_get(folio); - return &folio->page; + return folio; } else return NULL; @@ -2037,7 +2035,7 @@ static struct page *stable_tree_search(struct page *page) } stable_node_dup->head = &migrate_nodes; list_add(&stable_node_dup->list, stable_node_dup->head); - return &folio->page; + return folio; chain_append: /* stable_node_dup could be null if it reached the limit */ @@ -2324,6 +2322,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite unsigned int checksum; int err; bool max_page_sharing_bypass = false; + struct folio *folio, *kfolio; stable_node = page_stable_node(page); if (stable_node) { @@ -2346,30 +2345,31 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite } /* We first start with searching the page inside the stable tree */ - kpage = stable_tree_search(page); - if (kpage == page && rmap_item->head == stable_node) { - put_page(kpage); + folio = page_folio(page); + kfolio = stable_tree_search(folio); + if (kfolio == folio && rmap_item->head == stable_node) { + folio_put(kfolio); return; } remove_rmap_item_from_tree(rmap_item); - if (kpage) { - if (PTR_ERR(kpage) == -EBUSY) + if (kfolio) { + if (kfolio == ERR_PTR(-EBUSY)) return; - err = try_to_merge_with_ksm_page(rmap_item, page, kpage); + err = try_to_merge_with_ksm_page(rmap_item, page, folio_page(kfolio, 0)); if (!err) { /* * The page was successfully merged: * add its rmap_item to the stable tree. */ - lock_page(kpage); - stable_tree_append(rmap_item, page_stable_node(kpage), + folio_lock(kfolio); + stable_tree_append(rmap_item, folio_stable_node(kfolio), max_page_sharing_bypass); - unlock_page(kpage); + folio_unlock(kfolio); } - put_page(kpage); + folio_put(kfolio); return; } From patchwork Tue Jun 4 04:24:48 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: 13684610 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 6E2ABC25B7E for ; Tue, 4 Jun 2024 04:21:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E55996B009A; Tue, 4 Jun 2024 00:21:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E05EB6B009B; Tue, 4 Jun 2024 00:21:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7E8E6B009C; Tue, 4 Jun 2024 00:21:52 -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 A7D096B009A for ; Tue, 4 Jun 2024 00:21:52 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3FA79A0B90 for ; Tue, 4 Jun 2024 04:21:52 +0000 (UTC) X-FDA: 82191908064.29.5112557 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 997FD1C0005 for ; Tue, 4 Jun 2024 04:21:50 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=f0kDChGN; spf=pass (imf21.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=1717474910; 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=5D2cnaClGiUXa1btfWrU2w9JyrvIrp3p/yNIHBcKdpY=; b=CnadBQxTo3rvfNBBC0thYc7bYisGyL2jqOXPt93mYuYKlm+W2Yr1RirFWp7ytc+SkO+De6 gZie7fW61iWRYas2lTEz2kyd4GCJVGzhOON4sYgb1gNwe+WAElExHvq+XNzpq2dWATOs7T H+hoCV89zl+PVZcPaXwrXNCLrVJ3gHI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=f0kDChGN; spf=pass (imf21.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=1717474910; a=rsa-sha256; cv=none; b=hzs1SDD+MbNpo3GSMvDcFK950JxRPcQFYrwFIta+0vdToAoPe7WjhFFHE6OozRlAq2BrS5 P95ATH6m09zF/pKaWY88KQfLtSSjwE4fvDDyMpy9YD828gQuTJCEzJYzrzurBWq2FFZoQs DDRPKitHF/hMbrb0EaDBQCD+wG56nUc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E1B7F61207; Tue, 4 Jun 2024 04:21:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C2A0C32786; Tue, 4 Jun 2024 04:21:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474909; bh=r3mq/HoGLqusQ4dyUdx5DxYmG67Uuzo2XB6s67qh+EE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f0kDChGNADArwjFTu0Ecxn/z6ERtbQhoafRczm2xl1DKivY/FBSpOu3M+FIXHE6fF 9Q0KEuEWhS6uMtUMtCAR4SdvOqzexhe1KgXmnM9iLbGsMsGOhrlExEnyIhzDOgWHGL cDtkyQewEf1KcrjO6fI9ttmJUheFSRDfKyw5Y508mgtq2AIqf6Dcd037olbbAV+Nct Oojtpd89prXDc+dzsNEoIqTpc7ewALNrTL2+F1hmpea4SqHVs2ba3fufnIKMh5xfPB lykxIhWDHzdJ/3dNwpJ+heYxTFMd68/BX7l3eRuP3lfSY4mAibw2pQq/it3pAyAEGs GYPBMNqRZPP3Q== 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 06/10] mm/ksm: remove page_stable_node Date: Tue, 4 Jun 2024 12:24:48 +0800 Message-ID: <20240604042454.2012091-7-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.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w0p7OUky82ggmtfsASd/0E 2YgtND3R NZ11TbeGRlThmsuy1SPJSIOgC7XWSLtxNZD0RMWaWeOzQDeRX4b3Yk37XkbjEqpRntV8ga0awAnl87E8VlS8YCjUaOkseBk9529xoJ8QC39pSCWCdEwWtQNt1lT56d9AHtvKL6T7SRnELECfcBmSp6gXHzx3AG9Dsg+73k+gtEfJAT0gc6/2C6vVXCJOVgf3Cxx1A3Jc8CMssmzaiZ64FrctfrWBWDecRaW+kAWS+CwqIt5eOJm1wX/4hd12VwMdSm6B+bCClLXsu8h0miXZc+U7xpn4uXIYYZNLcsdovuAud2Xw012FNzxT7zjhtwVjePtZMwUMsZcDOP3I= 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)" Since folio_stable_node could replace page_stable_node now, the latter function could be removed and save a bit context. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index f68779651841..24de562b64e1 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1086,11 +1086,6 @@ static inline struct ksm_stable_node *folio_stable_node(struct folio *folio) return folio_test_ksm(folio) ? folio_raw_mapping(folio) : NULL; } -static inline struct ksm_stable_node *page_stable_node(struct page *page) -{ - return folio_stable_node(page_folio(page)); -} - static inline void folio_set_stable_node(struct folio *folio, struct ksm_stable_node *stable_node) { @@ -2324,7 +2319,8 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite bool max_page_sharing_bypass = false; struct folio *folio, *kfolio; - stable_node = page_stable_node(page); + folio = page_folio(page); + stable_node = folio_stable_node(folio); if (stable_node) { if (stable_node->head != &migrate_nodes && get_kpfn_nid(READ_ONCE(stable_node->kpfn)) != @@ -2345,7 +2341,6 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite } /* We first start with searching the page inside the stable tree */ - folio = page_folio(page); kfolio = stable_tree_search(folio); if (kfolio == folio && rmap_item->head == stable_node) { folio_put(kfolio); From patchwork Tue Jun 4 04:24:49 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: 13684612 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 E79A7C25B7E for ; Tue, 4 Jun 2024 04:21:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A04B6B00A1; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74E506B00A2; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57A136B00A1; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3592E6B009D for ; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F204DC0CCD for ; Tue, 4 Jun 2024 04:21:57 +0000 (UTC) X-FDA: 82191908274.20.AE658F8 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf01.hostedemail.com (Postfix) with ESMTP id 09BE540008 for ; Tue, 4 Jun 2024 04:21:55 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RHO3PveI; spf=pass (imf01.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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=1717474916; 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=0qXDX5IodeViaksXd9hYvuDk0UPvXZwbSx+HRfowjMw=; b=KvTGy+V572Bb4CxPQuzMdis/YAnOJWYQyI9rH3WoHo/WAXvxCI1rwjSaQN1RdOdpwmYlPR SmmAE11hmJbzt5bIfKkL9+O7EX4DKP/u1uz/QDadY13gTBH7nKLD8QbG5d0Wr1hWf/95n6 Fad9VbYDM4rE2dxTnaajJfjRIK28oR8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RHO3PveI; spf=pass (imf01.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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=1717474916; a=rsa-sha256; cv=none; b=JA6+SaZR6lN9ru8PTaDZA+NEq3PKecRmEU8CsEEQ0oeH/EsaOspvkDnrBZT3hxWLpjGhtp lNMqus+FDmjD9L/N+DSggNfNUJmDSIZ5pUCaTl9K2BO67cbZRfvAswlZ0yVodlZRzG93yT aRL/1eO49Jf/eXvli+vOCL7bUBXA4D4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 6C3A4CE1018; Tue, 4 Jun 2024 04:21:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58B25C32786; Tue, 4 Jun 2024 04:21:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474912; bh=LoJfO2Ls93RlnzKSfQa0n7wjB2DL3+BBi16/0XKQwOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RHO3PveI2oavxMNpkEuXKJde+ksLgcEi44dvri14Czc1WMsBGUjH7nsZo+HgzTwk5 kfBBUNQ1X2VjlkCaCQICHYJLyHlCcfs2H8EyjLEvhrkJwzbgl4rmrIrXh8KKw4GWgO +B7V62sDNVW43wX7GKXMJgGFTVJ+75KTJIAEthNzgAiuA5wbii6dkqQrRn+CrErtt/ njhraJfTdI1oXQjkB2w2DQlBnqUjSaHG3MCsGDWZMPTiVe+phXMDyARlN6r68pExT/ RKud+RLAPmKjpo5VaCpohWROwJiE50q3C3lYnqt7siuesgAwYO0z3cbI4Ctydrks5a OfEPkCx5Z9wyQ== 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 07/10] mm/ksm: use folio in unstable_tree_search_insert Date: Tue, 4 Jun 2024 12:24:49 +0800 Message-ID: <20240604042454.2012091-8-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: 09BE540008 X-Stat-Signature: 4xpcu1md6n3mjs7fsy58ypxwb59way7s X-Rspam-User: X-HE-Tag: 1717474915-489523 X-HE-Meta: U2FsdGVkX18Ivd3z4q9TKtHEoDDdEVsFGkgfUYCbpJW5jFT6i4XQpcHrZBWFRSamCRBGX0S6YmVhT+gmOZDejzOqnrll49/4jGeHmjVftNWAx1mNgpy+CHnyy3DFOrwGGRb+BcWnYq1FcUtBLpzs2Ot/AxJu0gga10ZDreYv7W8HqWkL7AyxOob95jayjYuqxkvIjOYFa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WN//abljIS 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)" The calling path are using folio actually, so start to folio in unstable_tree_search_insert to save few compound checks. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 24de562b64e1..14a7ca53fc91 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2194,15 +2194,14 @@ static struct ksm_stable_node *stable_tree_insert(struct folio *kfolio) */ static struct ksm_rmap_item *unstable_tree_search_insert(struct ksm_rmap_item *rmap_item, - struct page *page, - struct page **tree_pagep) + struct folio *folio, struct folio **tree_foliop) { struct rb_node **new; struct rb_root *root; struct rb_node *parent = NULL; int nid; - nid = get_kpfn_nid(page_to_pfn(page)); + nid = get_kpfn_nid(folio_pfn(folio)); root = root_unstable_tree + nid; new = &root->rb_node; @@ -2220,12 +2219,12 @@ struct ksm_rmap_item *unstable_tree_search_insert(struct ksm_rmap_item *rmap_ite /* * Don't substitute a ksm page for a forked page. */ - if (page == tree_page) { + if (folio == page_folio(tree_page)) { put_page(tree_page); return NULL; } - ret = memcmp_pages(page, tree_page); + ret = memcmp_pages(folio_page(folio, 0), tree_page); parent = *new; if (ret < 0) { @@ -2244,7 +2243,7 @@ struct ksm_rmap_item *unstable_tree_search_insert(struct ksm_rmap_item *rmap_ite put_page(tree_page); return NULL; } else { - *tree_pagep = tree_page; + *tree_foliop = page_folio(tree_page); return tree_rmap_item; } } @@ -2312,6 +2311,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite struct mm_struct *mm = rmap_item->mm; struct ksm_rmap_item *tree_rmap_item; struct page *tree_page = NULL; + struct folio *tree_folio = NULL; struct ksm_stable_node *stable_node; struct page *kpage; unsigned int checksum; @@ -2411,7 +2411,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite return; } tree_rmap_item = - unstable_tree_search_insert(rmap_item, page, &tree_page); + unstable_tree_search_insert(rmap_item, folio, &tree_folio); if (tree_rmap_item) { bool split; From patchwork Tue Jun 4 04:24:50 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: 13684613 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 2657AC25B74 for ; Tue, 4 Jun 2024 04:22:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B49D56B009F; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF79D6B00A2; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79DBD6B009F; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 549806B00A0 for ; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 044FA80FBF for ; Tue, 4 Jun 2024 04:21:58 +0000 (UTC) X-FDA: 82191908316.19.62ACAB0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 6A29F80009 for ; Tue, 4 Jun 2024 04:21:56 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Snb8+csf; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 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=1717474916; 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=Ab8yOUA35E8hZghbTFRcZg/Dm26N2XAaXftBThSJ4wU=; b=S1SXNErwm/F8T2wKZoae0yLs+FhOWddLosR1XrIssIQ91qIeHdZGPVaHJJxl502aDWXrO7 CVrxj1kWy0vWUL/3O5nILFPBa/lt0r4YcEGQj224wA0XtX+xWE14IQd+5CVP4VsrV6OxxV vJpB6q8H9gULJN9glSNtDlbaJfNsdbM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Snb8+csf; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717474916; a=rsa-sha256; cv=none; b=c/5px9cR2+ET7sVmCX7n4FxP3Go3trXcpnTJHnXw2B40nE/K7nKgANs7zDPd0pcLvC1LlZ Wbf4T9yaTie/DNkXpNcYgg8Wamt6ETLGNqS0kvU0K8pJhLMGmDnUYey1AcSoKk7Oiij+oX ENFOcOoAh7As+ai0IJ1umvV7NQ5JF14= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B99746120B; Tue, 4 Jun 2024 04:21:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 455FCC4AF08; Tue, 4 Jun 2024 04:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474915; bh=+wxYOCQhGAvuabF7WUDH5FG6NDiLukYmLnN5Qc7mdHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Snb8+csfuq27jG6c8lfDxSgt/4j/QIAj9TQhYFFMh9FFT0v2DENV7qrcE36FqNJ2r 1bE47raxT2o35HbYAezf6ONYaO4XuHDqGEBVYscppHzq4Y7XMwccQyYP1ERXNIrTbT RFvF8+Z84L8XaaPM3RcfZ9HCjdVaCoECnBZDoBxEviTQ8tzrh/6ZTdVKmaJIYNmerq 7L2s0BkeVPHs7RoKsrQCcFw+ddIyu/Gs4l1Arj+k8Kg+S5tT25HXNzu6XTI3wu26hh 0Dih/9LM2Mv/2NLu2Kmwz63CkFfrgCJGwJL8B2MxkYUPExNcSMpPJLyWiT/6uCJ+ea aW7RreqKYOa0Q== 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 08/10] mm/ksm: use folio in try_to_merge_xx serie funcs Date: Tue, 4 Jun 2024 12:24:50 +0800 Message-ID: <20240604042454.2012091-9-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-Queue-Id: 6A29F80009 X-Stat-Signature: zqzt8xtr9pwp6sngpitheh81wpjbrgea X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1717474916-641269 X-HE-Meta: U2FsdGVkX18BJodYJ/GnAlrv/mjUoG/LmPNvMIOab0YOsl+lXlSsUYP66nT7Y+2ror29SxO6EnLa0357L7sg8/wZ98AyKJXPgR2EBfcij1+fhgZsvmiThtil0C6opFuhgvmzVtd3lI1om/D2hctWVqzq8HnOjbJnT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pzCeDE8PMJttfwbFmxj7u8rHhTRNKU22 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)" The try_to_merge_ serie funcs are using folios, so change the parameter and variable 'page' to folio to save compound checks. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 54 ++++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 14a7ca53fc91..b9c04ce677b9 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1540,22 +1540,18 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, struct folio *folio * This function returns 0 if the pages were merged, -EFAULT otherwise. */ static int try_to_merge_with_ksm_page(struct ksm_rmap_item *rmap_item, - struct page *page, struct page *kpage) + struct folio *folio, struct folio *kfolio) { struct mm_struct *mm = rmap_item->mm; struct vm_area_struct *vma; int err = -EFAULT; - struct folio *kfolio; mmap_read_lock(mm); vma = find_mergeable_vma(mm, rmap_item->address); if (!vma) goto out; - if (kpage) - kfolio = page_folio(kpage); - - err = try_to_merge_one_page(vma, page_folio(page), rmap_item, kfolio); + err = try_to_merge_one_page(vma, folio, rmap_item, kfolio); if (err) goto out; @@ -1567,8 +1563,8 @@ static int try_to_merge_with_ksm_page(struct ksm_rmap_item *rmap_item, get_anon_vma(vma->anon_vma); out: mmap_read_unlock(mm); - trace_ksm_merge_with_ksm_page(kpage, page_to_pfn(kpage ? kpage : page), - rmap_item, mm, err); + trace_ksm_merge_with_ksm_page(kfolio, folio_pfn(kfolio ? kfolio : folio), + rmap_item, mm, err); return err; } @@ -1582,17 +1578,17 @@ static int try_to_merge_with_ksm_page(struct ksm_rmap_item *rmap_item, * Note that this function upgrades page to ksm page: if one of the pages * is already a ksm page, try_to_merge_with_ksm_page should be used. */ -static struct page *try_to_merge_two_pages(struct ksm_rmap_item *rmap_item, - struct page *page, +static struct folio *try_to_merge_two_pages(struct ksm_rmap_item *rmap_item, + struct folio *folio, struct ksm_rmap_item *tree_rmap_item, - struct page *tree_page) + struct folio *tree_folio) { int err; - err = try_to_merge_with_ksm_page(rmap_item, page, NULL); + err = try_to_merge_with_ksm_page(rmap_item, folio, NULL); if (!err) { err = try_to_merge_with_ksm_page(tree_rmap_item, - tree_page, page); + tree_folio, folio); /* * If that fails, we have a ksm page with only one pte * pointing to it: so break it. @@ -1600,7 +1596,7 @@ static struct page *try_to_merge_two_pages(struct ksm_rmap_item *rmap_item, if (err) break_cow(rmap_item); } - return err ? NULL : page; + return err ? NULL : folio; } static __always_inline @@ -2310,14 +2306,13 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite { struct mm_struct *mm = rmap_item->mm; struct ksm_rmap_item *tree_rmap_item; - struct page *tree_page = NULL; struct folio *tree_folio = NULL; struct ksm_stable_node *stable_node; - struct page *kpage; + struct folio *kfolio; unsigned int checksum; int err; bool max_page_sharing_bypass = false; - struct folio *folio, *kfolio; + struct folio *folio; folio = page_folio(page); stable_node = folio_stable_node(folio); @@ -2353,7 +2348,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite if (kfolio == ERR_PTR(-EBUSY)) return; - err = try_to_merge_with_ksm_page(rmap_item, page, folio_page(kfolio, 0)); + err = try_to_merge_with_ksm_page(rmap_item, folio, kfolio); if (!err) { /* * The page was successfully merged: @@ -2415,8 +2410,8 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite if (tree_rmap_item) { bool split; - kpage = try_to_merge_two_pages(rmap_item, page, - tree_rmap_item, tree_page); + kfolio = try_to_merge_two_pages(rmap_item, folio, + tree_rmap_item, tree_folio); /* * If both pages we tried to merge belong to the same compound * page, then we actually ended up increasing the reference @@ -2427,23 +2422,22 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite * afterwards, the reference count will be correct and * split_huge_page should succeed. */ - split = PageTransCompound(page) - && compound_head(page) == compound_head(tree_page); - put_page(tree_page); - if (kpage) { + split = folio_test_large(folio) && folio == kfolio; + folio_put(tree_folio); + if (kfolio) { /* * The pages were successfully merged: insert new * node in the stable tree and add both rmap_items. */ - lock_page(kpage); - stable_node = stable_tree_insert(page_folio(kpage)); + folio_lock(kfolio); + stable_node = stable_tree_insert(kfolio); if (stable_node) { stable_tree_append(tree_rmap_item, stable_node, false); stable_tree_append(rmap_item, stable_node, false); } - unlock_page(kpage); + folio_unlock(kfolio); /* * If we fail to insert the page into the stable tree, @@ -2465,10 +2459,10 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite * the page is locked, it is better to skip it and * perhaps try again later. */ - if (!trylock_page(page)) + if (!folio_trylock(folio)) return; - split_huge_page(page); - unlock_page(page); + split_folio(folio); + folio_unlock(folio); } } } 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; From patchwork Tue Jun 4 04:24:52 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: 13684615 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 8DC8BC27C52 for ; Tue, 4 Jun 2024 04:22:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72A2B6B00A3; Tue, 4 Jun 2024 00:22:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DA876B00A4; Tue, 4 Jun 2024 00:22:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 579D46B00A5; Tue, 4 Jun 2024 00:22:04 -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 3612B6B00A3 for ; Tue, 4 Jun 2024 00:22:04 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E9895A0B90 for ; Tue, 4 Jun 2024 04:22:03 +0000 (UTC) X-FDA: 82191908526.22.BFAAB7B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 51611180004 for ; Tue, 4 Jun 2024 04:22:02 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=n1n6Rqkd; spf=pass (imf16.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=1717474922; 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=D25PVgx888IOPs+nLo4v1cjbsQQlK7jqAMxF2FdVb28=; b=bkhmwb3OJ8JTr3IZ7z9HEeukwSUYb0Lx8+uv73ueoyBBFOrb2rOvYCsG46AvMV5rJcv9og 3QK7vcXmU674ceDvIbnFGvXYuDkvCf5keW5/TCRLm+GDgTtpk4+JxUMZcdCqqvMbN0UIZ9 PyCBwQmAomGgPJgqVqH2h8f6L7O0WTg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=n1n6Rqkd; spf=pass (imf16.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=1717474922; a=rsa-sha256; cv=none; b=1KkYVQAXeEPizaQTTWTe6r2SrquMG7dR0Rbb1nYKs+WTgeUfdOuL6HPXakl0+t/AS9jzHw f6FcKzg0QeeDpu9DwjvsmLNJKpB8xUY8KCL0ZNaBpqlQIJ1Tv7N3k5l5N1RO8ErYI7caLT 09wHzXK8trppQ67EiGE0g5SgmTqExrg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9BA5C61203; Tue, 4 Jun 2024 04:22:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F02A6C2BBFC; Tue, 4 Jun 2024 04:21:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474921; bh=zYmT3lwFo6rWfb+tk0qEdUJ1sHLo1w0Ku5xx7RwN91E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n1n6RqkdZBqCVuUxiRYbqCsvhoBbYlLF6Tvbv/GcWyfrKGI0NaYyHr/QY8N+fCXeo ZyqzSABKskTK19EVEKFZ0dPpOIG49//2tmiIEI5wj1RjvoGrfxWZMwUvYk3U1fMLZq M0sQEx6nVa6TrVMytPlCJK79PonvX/LOvVR9KZwKxF8cWxEHsRVrel6+djm0sUbqfy l+sZVswL5p6CcvKVP6t8yEMZlFgtcRTcEBMqW8CS1+bnZjfS9f6CSOaJL/axF4ejz7 RRoM2ihQmnQSyii+KyuXtFT5x+qw/CElR9Gf/KgRbdPbJIcCsvuGxA0QwKM0IhZkAE bgeMB1Y+dWEFw== 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 10/10] m/ksm: use folio in ksm scan path Date: Tue, 4 Jun 2024 12:24:52 +0800 Message-ID: <20240604042454.2012091-11-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-Rspam-User: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p+LGSkbkkZnpVKWbSy 4Hg84OuC Odynhrirr7/kZO0JXvOvcscNnpOo+r3jrxWqvU23LzylncBxXymuL+PjKDjr87BC6uhNXSS6oJ7T8BBZudc9ty7JCtcInSXghzYA8KpDzblANf2E/1eAsK5MEzj8GK3ZGoL8MdHV9xGScSeYFotSM9/7Wh8c9aoh2f2kLp64Tl6tkeUfOHg/ZEwo+XF5wt9Su+3BN/G7uCaRX/tnoH5/dqZVa9JI5+CWEuxspddOiv2VsTSI= 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)" Now we could safely use folio in ksm_do_scan path to save a few compound checks. The 'page' still used since follow_page function still no folio version. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index dc2b5e6a9659..57904b3b18dc 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2304,7 +2304,7 @@ static void stable_tree_append(struct ksm_rmap_item *rmap_item, * @page: the page that we are searching identical page to. * @rmap_item: the reverse mapping into the virtual address of this page */ -static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_item) +static void cmp_and_merge_page(struct folio *folio, struct ksm_rmap_item *rmap_item) { struct mm_struct *mm = rmap_item->mm; struct ksm_rmap_item *tree_rmap_item; @@ -2314,9 +2314,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite unsigned int checksum; int err; bool max_page_sharing_bypass = false; - struct folio *folio; - folio = page_folio(page); stable_node = folio_stable_node(folio); if (stable_node) { if (stable_node->head != &migrate_nodes && @@ -2518,12 +2516,12 @@ static unsigned int skip_age(rmap_age_t age) } /* - * Determines if a page should be skipped for the current scan. + * Determines if a folio should be skipped for the current scan. * - * @page: page to check - * @rmap_item: associated rmap_item of page + * @folio: folio to check + * @rmap_item: associated rmap_item of folio */ -static bool should_skip_rmap_item(struct page *page, +static bool should_skip_rmap_item(struct folio *folio, struct ksm_rmap_item *rmap_item) { rmap_age_t age; @@ -2536,7 +2534,7 @@ static bool should_skip_rmap_item(struct page *page, * will essentially ignore them, but we still have to process them * properly. */ - if (PageKsm(page)) + if (folio_test_ksm(folio)) return false; age = rmap_item->age; @@ -2566,7 +2564,7 @@ static bool should_skip_rmap_item(struct page *page, return true; } -static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) +static struct ksm_rmap_item *scan_get_next_rmap_item(struct folio **folio) { struct mm_struct *mm; struct ksm_mm_slot *mm_slot; @@ -2655,36 +2653,41 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) ksm_scan.address = vma->vm_end; while (ksm_scan.address < vma->vm_end) { + struct page *page; + if (ksm_test_exit(mm)) break; - *page = follow_page(vma, ksm_scan.address, FOLL_GET); - if (IS_ERR_OR_NULL(*page)) { + page = follow_page(vma, ksm_scan.address, FOLL_GET); + if (IS_ERR_OR_NULL(page)) { ksm_scan.address += PAGE_SIZE; cond_resched(); continue; } - VM_WARN_ON(PageTail(*page)); - nr = compound_nr(*page); - if (is_zone_device_page(*page)) + *folio = page_folio(page); + VM_WARN_ON(PageTail(page)); + nr = folio_nr_pages(*folio); + + if (folio_is_zone_device(*folio)) goto next_page; - if (PageAnon(*page)) { + + if (folio_test_anon(*folio)) { rmap_item = get_next_rmap_item(mm_slot, ksm_scan.rmap_list, ksm_scan.address); if (rmap_item) { ksm_scan.rmap_list = &rmap_item->rmap_list; - if (should_skip_rmap_item(*page, rmap_item)) + if (should_skip_rmap_item(*folio, rmap_item)) goto next_page; ksm_scan.address += nr * PAGE_SIZE; } else - put_page(*page); + folio_put(*folio); mmap_read_unlock(mm); return rmap_item; } next_page: - put_page(*page); + folio_put(*folio); ksm_scan.address += nr * PAGE_SIZE; cond_resched(); } @@ -2755,16 +2758,16 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) static void ksm_do_scan(unsigned int scan_npages) { struct ksm_rmap_item *rmap_item; - struct page *page; + struct folio *folio; unsigned int npages = scan_npages; while (npages-- && likely(!freezing(current))) { cond_resched(); - rmap_item = scan_get_next_rmap_item(&page); + rmap_item = scan_get_next_rmap_item(&folio); if (!rmap_item) return; - cmp_and_merge_page(page, rmap_item); - put_page(page); + cmp_and_merge_page(folio, rmap_item); + folio_put(folio); } ksm_pages_scanned += scan_npages - npages;