From patchwork Tue Sep 26 04:09:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13398635 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 B1A31E81817 for ; Tue, 26 Sep 2023 04:10:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 263826B018A; Tue, 26 Sep 2023 00:10:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 213676B018B; Tue, 26 Sep 2023 00:10:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 102596B018C; Tue, 26 Sep 2023 00:10:00 -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 017A96B018A for ; Tue, 26 Sep 2023 00:09:59 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C79D1A0E79 for ; Tue, 26 Sep 2023 04:09:59 +0000 (UTC) X-FDA: 81277420518.07.695E5CA Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf09.hostedemail.com (Postfix) with ESMTP id 350C4140003 for ; Tue, 26 Sep 2023 04:09:57 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=neutral (imf09.hostedemail.com: 66.220.144.179 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695701398; 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:references; bh=quiZPEwVsomz+3qDn4CYAnjmi+qE0NI9Q5KbHcwpxC8=; b=txCdqV6P6pd9otdYUJwJDenmNyNHZG9Q1/I92o3fmj3BKMJKNMBn0njQ9MNd0EiitKy0P3 gfa6GjvMOa6MGhMrchZheoL+QHrIKySiK532R+L1EwLDQ1mMZDu/FKndcLYk59raqhO/1y 0gwX/rnmihR25+5MqswsxZqmz+5+mqE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695701398; a=rsa-sha256; cv=none; b=mBj8MF8Nfj1lHYbOpFFPvoUjsQqj1CaHjNdAFRA/eX5pMdgQXrzmjfsOqrzKq66j56sDsZ eh7yLig9qksxQ3iQlN21jvXsDYerdLaMv7Q8wOX+0Zjf9TTSIK3uxW7V6iCrX8kF+RD3NM l6QDj7322wced6lpkiFwjMS+qdarNRs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=neutral (imf09.hostedemail.com: 66.220.144.179 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 5E7A2C8F2415; Mon, 25 Sep 2023 21:09:42 -0700 (PDT) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, akpm@linux-foundation.org, david@redhat.com, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 0/4] Smart scanning mode for KSM Date: Mon, 25 Sep 2023 21:09:35 -0700 Message-Id: <20230926040939.516161-1-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Stat-Signature: w6iuakcqejinidnxd31zwz4jab8p5f4a X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 350C4140003 X-Rspam-User: X-HE-Tag: 1695701397-331316 X-HE-Meta: U2FsdGVkX1/Jh0pFbjchx/gbroiGhpvSpol7pjgez/lPvCb2plcCWeo3dt99rkYhqmxfjdMCed7zJUiZI/fSpr6K6H1U0/aiYSre+w9wJJ9PrcRoU4Ma/KIfYIYZN82A5U7B3dAG8ETvEcGuhoZIHsRpPsH9XrxEE3qRfKrVKiQW70jfUp2Rgib8krOixF/Ujiu2njacpkl8uEn0rlW03CLHkI03mPu+BpeHHjipiImz0EC2+jNNbmQB+auf3E9UAZhC0ZXrscEwkCLbNeSrjZBX9UDqxL10m7CR0UGrjAPCHQWzb+/F5o1KqdveunMVHGydXykz9eUp8SWXiTACMdq2ggRZjHKICAV0lEViQPOU5j5R27d2vl7Y6bsJBSLzj8/Sr2+LhJv4laK4O7uvePpumklo5rWp79pI8zfAHp6koV3IhJGsKBZUn+K4PEoDmCcS9iuIK5pUFhVDsWV8VRsBuhYr506C7Sc3kWrR4URFWLvlhcl8MaeZlSM7OS1XaenG1L60TfDJub25pDstsPC486VpMaMLe1lNn0oiSIHoEyvC+SpiaBjNZRgsCchq4z/foP08yWqdOLeJlZi/5xWErlQVOelNnXTSOd901jxbMBkDyXhn0i2KcouhgG4M5aBBcvzzQ7HvbSvDwUA9Y3i1Z/a/RP6L/M7foy7SxxL4GyV0y6vbhiYBCvGnvLx/PjO6Bf5jjgtclRC2x1fudstMSmhkv0/W68F4wx5+XXN1HCa0Zl32rA3+b/Mv6vUg6M+b9NrbDcqn8n+pXg6c/Rm3BN95U6iA4s30WdVUPac1rvWRK/H92LP0suTac5z0eKVd0SMsS9ekB4Y+0YuKl24FU2922iqZmy+4OquBjmu+AwL+/MwdXNZ/QmeTspE6pCSfUqXg9LdsW+U5r1L336OxnXKyQ2JnmPWiMFz/qtpWMQ0m8U0+eT9yzkSgc3RcTU7Rf1XRF8sxpshP++/ Onk/o0xD kYzK0s0ud9n/0ymI= 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: This patch series adds "smart scanning" for KSM. What is smart scanning? ======================= KSM evaluates all the candidate pages for each scan. It does not use historic information from previous scans. This has the effect that candidate pages that couldn't be used for KSM de-duplication continue to be evaluated for each scan. The idea of "smart scanning" is to keep historic information. With the historic information we can temporarily skip the candidate page for one or several scans. Details: ======== "Smart scanning" is to keep two small counters to store if the page has been used for KSM. One counter stores how often we already tried to use the page for KSM and the other counter stores how often we skip a page. How often we skip the candidate page depends how often a page failed KSM de-duplication. The code skips a maximum of 8 times. During testing this has shown to be a good compromise for different workloads. New sysfs knob: =============== Smart scanning is not enabled by default. With /sys/kernel/mm/ksm/smart_scan smart scanning can be enabled. Monitoring: =========== To monitor how effective smart scanning is a new sysfs knob has been introduced. /sys/kernel/mm/pages_skipped report how many pages have been skipped by smart scanning. Results: ======== - Various workloads have shown a 20% - 25% reduction in page scans For the instagram workload for instance, the number of pages scanned has been reduced from over 20M pages per scan to less than 15M pages. - Less pages scans also resulted in an overall higher de-duplication rate as some shorter lived pages could be de-duplicated additionally - Less pages scanned allows to reduce the pages_to_scan parameter and this resulted in a 25% reduction in terms of CPU. - The improvements have been observed for workloads that enable KSM with madvise as well as prctl Changes: - V3: - Renamed field skip_age to remaining_skips - Moved fields after old_checksum - Changed should_skip_rmap_item to use remaining_skips field - V2: - Renamed function inc_skip_age() to skip_age() - Added comment to skip_age() function - Renamed function skip_rmap_item() to should_skip_rmap_item() - Added more comments to should_skip_rmap_item function - Added explicit modification of age with overflow check Stefan Roesch (4): mm/ksm: add "smart" page scanning mode mm/ksm: add pages_skipped metric mm/ksm: document smart scan mode mm/ksm: document pages_skipped sysfs knob Documentation/admin-guide/mm/ksm.rst | 11 +++ mm/ksm.c | 115 +++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) base-commit: 15bcc9730fcd7526a3b92eff105d6701767a53bb