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/MtpXn7iTwJZyiW7ESzWdaNOxxCIP+jDV9J2KsbJfd6sWJDl07ygh7RluQULsIdBfJlb/DMOP/vzdO5cDmOSa99BkwJJ+u4BY0hYSzBcqO6SR/U1rcWOflE1ZHmU+5EMmUhE1o5vu8OkYavYMhn3tKDu9toAG0Ke+BDdyagkk82l6NR97ftaJQnVxJK5QqDKWGSVWuMevCVQeRbUb/OsgiGGcfYfB7ZDhnW/JmtRM0G6p+yUQIlR7moUgcMULY7FUrJfHldcUsNDthvmii4t8jMLTecLzjOluMI7lDWs1jo2nEAXlO4+V2cibjrKXjpXVZnj1WM1LoCbtzYCcSAh1GkvqC43Yj0SYetXMC5p4kLajRh7/2dRdCs0OIgysNdlZCT5ciALyKmnNefMpgScNgRrfyLI1oQ5K2MYUWNuJGwX3T1uDuEUqJFkifaY1eDQyj7+ydo1RxYOZw/VsYchdcK6gtUdwE+l0IunQkgQ7KdriUftk1EUiig0BYkAYfPqG4XAeKWZV+lHGt2bh7HGQum10Emr7DhKdAA8AuQmnzE0qkE6caMNzKcUOGm1lSmfznr/9ROZdSF9bbgHe7h4aIuof2M/Y8Sm5kjL42D1FVr9XQS3Zq97X2hdKAVlESIcEBcp739wbXNohmHhu6XOxW/UnNeQwO0wErOQAEKUo4FYYyjlEt6W7pj0F2cKVncvEa5LgopQWyfwiPCGE2oj3Ev8K0FoMc3z9qqUeBZJKQzKtQFk58l4jOcMnYiSKSHQhTBHyIPkJtuPLfuFQwwtcvuvrZXgE5hW0MtCkIH9bouMTW+9kCP3ohKtyNZCs7wQQBf+z1BdE4S3Xb46E74WD /cZfRWqH xlVrnHFI5cazvem8gbRg5qJRJp/U6sSOdbNPBo8lDItegEM4GXeFAf8J7t3hcuxxQ/KEm1tFWP8Wds0h2N+J2fyzJ7KQ+bXcB9Irb7hDr7Z5kdFOMlxcLXwiy47XojMfKhXdw6H1/TqTT6CFPdnzP5A+N7qCkTTKoocc8LVQXBN3MIRUGVpSWBWKUcQqm2HdMm7SUDTor/xinMOj7FVU6iqVAm51EarGFafIDE+kJ/defp8E= 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(); } }