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) {