From patchwork Tue Sep 12 17:52:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13381990 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 BC603EE3F09 for ; Tue, 12 Sep 2023 17:52:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 98E586B0133; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 90B1C6B013E; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50EA76B0140; Tue, 12 Sep 2023 13:52:56 -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 33B936B0133 for ; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F2883C02A8 for ; Tue, 12 Sep 2023 17:52:55 +0000 (UTC) X-FDA: 81228691110.20.78E51EC Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf02.hostedemail.com (Postfix) with ESMTP id 54A508001C for ; Tue, 12 Sep 2023 17:52:54 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf02.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694541174; 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; bh=4cyzr/0K5Dw6Q79NtyCfj6eo018Xmxirx96tjFXharo=; b=297q3Qaz4t/OuUyuz8+eCFJhZlzEYj2d/YKr6L3sLxsmdofGZsenEX2q0YUtHC/kgb6iSc mlfaEDJAf373hO8piqQTiEnEa+dNdkvg0P+iZkZ4R8xiXnySRbdLdYGb0RWyO/tXwAO8oa UdfEPs2oA8ILPHxGZvqW6ywSASpFL8w= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf02.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694541174; a=rsa-sha256; cv=none; b=OB0wYVmWQS8/PWPH/BOZOSh7bXSM5POjln0BUMa3FaW9yz1KjcTQeMrEoPgsOYpgv4kP3U U7gh+1cKRW2g5lNcR9ExAkH+DX8BVOxa05AP0sCXdOFsrTqMSA5qYNLU7eQ3o2EMNsRngj kn73sr3xeTM4g7fbMz/SXsjb9L74b4U= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id DF124BCD1629; Tue, 12 Sep 2023 10:52:38 -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 v1 1/4] mm/ksm: add "smart" page scanning mode Date: Tue, 12 Sep 2023 10:52:25 -0700 Message-Id: <20230912175228.952039-2-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230912175228.952039-1-shr@devkernel.io> References: <20230912175228.952039-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 54A508001C X-Stat-Signature: ysyn4cgn4d7wchgrtahit3qbdcqyxbbc X-HE-Tag: 1694541174-261528 X-HE-Meta: U2FsdGVkX1+vNEZP8HuGrGjBaIfNBNxAPfwsQjgbhIKPFYrjpGgLIMBriFS7ZRzU0K4Dzg1I5IaX40b94w99x5CT/yyNQHBh8vo6f8WOwAWuGE5hK4uGEmiopKoDrawmI5d6jHhOPyvQwdgCZH0oYHfHvnAVolCA04MqodsIYN8R4lPmXv5ciUvpH4Xt4v5emFHVU66ibKKEy3qAf/tw4ZeoEQprQUYJN0eoeH9OosfXjAwVo9/XpdoF157WJM4Nvkm5BONZemulIqs3ZXcAhrimXw5wFgxkWTiLT9w9VqHptRgWN/jhqphPeSQEbH4npjw2XOda9I8vNT4pcyUkk2HRfUVyiZ1SUbXOHOLC/1UqSCgZJFlgrJ8iIWAb14Aw608tY4hJxzRoHiJ9yIvAU+BDp4VZ08CuATZVptiqrURTneM7OYF9Gr5Lgel7Ay1QCJn986oBX9C3ITcdP2+4Y/xXA3X2wSODjEhKOyHRNkczqL8v7ydOfgVRlH/v11YKNeiv7Ti6lYIzHCa1yrChE3nZEWDlrDKKZQhYDNAa2MqFCWTYBwNODNtlRIch0zH/3WcW7oIpjc4c73mjFevHEjtsEpvneuPAP4LlAPSjBGNLPauNNh60TRUxMNG4AxSesFG/m4x7nPCfNI5UHAlnTGCbciHApYq0Hdh4chhxASX6Pfp3Fu7qqyo0fCAR9ck8jtS1nhIBEx+E+HrNudO/j/8zgp7VoAq0Jcg+QRiBZjqe8dAonL5rKEuhsM8IzpnYzD3e8QND/0u2U54bZ3Rc60zw4EdE/NQMfg3K1Gavz7qkGrU4VOPNv+0veRfVr/6b7XSfWHP8diN1A9pR4KZ1VaofUM8vPEbDaLn0sTkmVOKmwpzfE8YFohRwAW93zAmI61p4DsMKqwd5RbHfENZm6tsXtmpy1z7igNQePggTuRpMApX0FPzpuQI5AaIopYtp6k6WrhK4FMI7WRK917/ a71RStxw DMB8kA+bnsEjmw+7/tV188CTVV+1SBN9f/tGt 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 change adds a "smart" page scanning mode for KSM. So far all the candidate pages are continuously scanned to find candidates for de-duplication. There are a considerably number of pages that cannot be de-duplicated. This is costly in terms of CPU. By using smart scanning considerable CPU savings can be achieved. This change takes the history of scanning pages into account and skips the page scanning of certain pages for a while if de-deduplication for this page has not been successful in the past. To do this it introduces two new fields in the ksm_rmap_item structure: age and skip_age. age, is the KSM age and skip_page is the age for how long page scanning of this page is skipped. The age field is incremented each time the page is scanned and the page cannot be de-duplicated. How often a page is skipped is dependent how often de-duplication has been tried so far and the number of skips is currently limited to 8. This value has shown to be effective with different workloads. The feature is currently disable by default and can be enabled with the new smart_scan knob. The feature has shown to be very effective: upt to 25% of the page scans can be eliminated; the pages_to_scan rate can be reduced by 40 - 50% and a similar de-duplication rate can be maintained. Signed-off-by: Stefan Roesch --- mm/ksm.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index 981af9c72e7a..bfd5087c7d5a 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -56,6 +56,8 @@ #define DO_NUMA(x) do { } while (0) #endif +typedef u8 rmap_age_t; + /** * DOC: Overview * @@ -193,6 +195,8 @@ struct ksm_stable_node { * @node: rb node of this rmap_item in the unstable tree * @head: pointer to stable_node heading this list in the stable tree * @hlist: link into hlist of rmap_items hanging off that stable_node + * @age: number of scan iterations since creation + * @skip_age: skip rmap item until age reaches skip_age */ struct ksm_rmap_item { struct ksm_rmap_item *rmap_list; @@ -212,6 +216,8 @@ struct ksm_rmap_item { struct hlist_node hlist; }; }; + rmap_age_t age; + rmap_age_t skip_age; }; #define SEQNR_MASK 0x0ff /* low bits of unstable tree seqnr */ @@ -281,6 +287,9 @@ static unsigned int zero_checksum __read_mostly; /* Whether to merge empty (zeroed) pages with actual zero pages */ static bool ksm_use_zero_pages __read_mostly; +/* Skip pages that couldn't be de-duplicated previously */ +static bool ksm_smart_scan; + /* The number of zero pages which is placed by KSM */ unsigned long ksm_zero_pages; @@ -2305,6 +2314,45 @@ static struct ksm_rmap_item *get_next_rmap_item(struct ksm_mm_slot *mm_slot, return rmap_item; } +static unsigned int inc_skip_age(rmap_age_t age) +{ + if (age <= 3) + return 1; + if (age <= 5) + return 2; + if (age <= 8) + return 4; + + return 8; +} + +static bool skip_rmap_item(struct page *page, struct ksm_rmap_item *rmap_item) +{ + rmap_age_t age; + + if (!ksm_smart_scan) + return false; + + if (PageKsm(page)) + return false; + + age = rmap_item->age++; + if (age < 3) + return false; + + if (rmap_item->skip_age == age) { + rmap_item->skip_age = 0; + return false; + } + + if (rmap_item->skip_age == 0) { + rmap_item->skip_age = age + inc_skip_age(age); + remove_rmap_item_from_tree(rmap_item); + } + + return true; +} + static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) { struct mm_struct *mm; @@ -2409,6 +2457,10 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) if (rmap_item) { ksm_scan.rmap_list = &rmap_item->rmap_list; + + if (skip_rmap_item(*page, rmap_item)) + goto next_page; + ksm_scan.address += PAGE_SIZE; } else put_page(*page); @@ -3449,6 +3501,28 @@ static ssize_t full_scans_show(struct kobject *kobj, } KSM_ATTR_RO(full_scans); +static ssize_t smart_scan_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%u\n", ksm_smart_scan); +} + +static ssize_t smart_scan_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err; + bool value; + + err = kstrtobool(buf, &value); + if (err) + return -EINVAL; + + ksm_smart_scan = value; + return count; +} +KSM_ATTR(smart_scan); + static struct attribute *ksm_attrs[] = { &sleep_millisecs_attr.attr, &pages_to_scan_attr.attr, @@ -3469,6 +3543,7 @@ static struct attribute *ksm_attrs[] = { &stable_node_chains_prune_millisecs_attr.attr, &use_zero_pages_attr.attr, &general_profit_attr.attr, + &smart_scan_attr.attr, NULL, }; From patchwork Tue Sep 12 17:52:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13381988 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 D984CEE3F0B for ; Tue, 12 Sep 2023 17:52:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E43A6B0134; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 337C86B0132; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 163DE6B0134; Tue, 12 Sep 2023 13:52:56 -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 008B36B0132 for ; Tue, 12 Sep 2023 13:52:55 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B4CC31C9ADB for ; Tue, 12 Sep 2023 17:52:55 +0000 (UTC) X-FDA: 81228691110.23.D83D3E6 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf14.hostedemail.com (Postfix) with ESMTP id 298C5100018 for ; Tue, 12 Sep 2023 17:52:53 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf14.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694541174; 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; bh=CN2i2K1yeQi3CVF3AoCmDBQsHD9chBIcu/eGaGP4nGc=; b=OdNazek95dbtZHXaKLuwhYW93w2jnJZYbKunPwVZCN7ZfpCrJzVmvKn0AJ9s+pyWdC8GSC /VTsNwbvvVASDgXPgq98URfwJmEY0y42NBhjdpcRhaovhB46gD7YilFhVKhz2hVbmvKONH eW6WZgLJjA8hNb1ryQ18+wfFKezUGoA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf14.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694541174; a=rsa-sha256; cv=none; b=mOFl39TOpM+4gZE1Zuq6lf3Ga/wj0ogyKTx9TDASyO3BoF4fMfxZh8oZfy45ph404jAylH 8xhDzTjiRZ0HwA05mNkg0Jbjh/hco+HVCHmDl2TYkILK/yY8842jDRrbWTp5oAR6SlTD9p 0s+zxDAk+z9FqHK4QjDqq1/x2YCoPzo= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 28DACBCD162C; Tue, 12 Sep 2023 10:52:38 -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 v1 2/4] mm/ksm: add pages_skipped metric Date: Tue, 12 Sep 2023 10:52:26 -0700 Message-Id: <20230912175228.952039-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230912175228.952039-1-shr@devkernel.io> References: <20230912175228.952039-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: jao597uja9w3rmw5ns7oa6umuk391saz X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 298C5100018 X-HE-Tag: 1694541173-700683 X-HE-Meta: U2FsdGVkX19kVVM9LUTRBHB+P2sSqR2X3GeHbNAKEGRvOHBY4pEstc7gkpMO1HxLXij6yJE7pZloMPHzsCdibUvmznMXpcZ1oPWcn2ADoGfGjR4wvqa9t+s3T8VgWt0NuZU4CpvyehsbrzFkvEgVA6wqW18POEnJNZfPyASTGSGSz9AaXI9uvKMq50ckKXbM0kOUfWzENnNk0CdgEHcIz+G+jpDMEZcH5iMTDB1dfiIPW64mZ92k0CEwU18nk7rD+IoAfnyAnum606DDpahuJLXLXtdTs+4AVm25YYEeiiHwYk+NAJJ6AkqHu18DFP0Oq4nlDPn3zMWAIF76pPiQrbQRQ8WGKE5GwBXgzZLTxNtfpyrVzlKieNKSFw8YmkAshmyslw8B6TQFieS2p8+EXOqEKHzEbXeDf+MH6F8DiSQ3frOUV56V66ymLy5/GQZcemtI5fhwpJIxosfS/T/Pf/2YOaMvPUU3N5sR47xjA2rOxPXwLpBZsdGQljXCwh61KxG6X9SEvOFjioWchkGZTIrL8BFSb8OnlWNYtr3Y3T5+J60zWAgcWJdSDg6eSExJvsH7FEY5hLcDneTQGXG9tofkx1H8B5J46+QLpkvZBhuPnOqGbiW4JNCciiIdGXN685QZ8XsbATOS3cEuvYW0CgK5bYGR1Kg2qoHQb2RLF3kuHICQO66haXrq6r08dmnLv65m6wrSurFp+xIPjhlQkA0H4nNSjaSr8AFJYOJkwy7nDTtIFRulziF4fcUQ259e/P0cY+z3zLEHpquLhSR94rsgdknwgC1dJ0PuhB5gbgGUBD6f5N6MdwCMmS1TfNQzuvxrFiOKhqr5K3Mu2fRQfY4oznnEWYmrQ7tsxfStJJYbHcw+XdtODlJ4iN1/qTU/0i9utuNcPyux7erUXBWngxLg+T7fwGUiCJMJNDI1TU744p4ErXUnGS1CwJGNI52rpbGVsB3exXTZTfBCKj1 tiH3VU0h sp9QAREd5vQSFQp9o6Uf3HbKccXpg5iUUYU4BLrnyXXFbNNv8LJ2f4a7B5eXVTLYDi5QUYuYwOgkmZxonhag/TbLqg1L8+ZlWNAVmkrBTLk4j7hxYnt6vTK0/y8TCdxkedKuZ 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 change adds the "pages skipped" metric. To be able to evaluate how successful smart page scanning is, the pages skipped metric can be compared to the pages scanned metric. The pages skipped metric is a cumulative counter. The counter is stored under /sys/kernel/mm/ksm/pages_skipped. Signed-off-by: Stefan Roesch Reviewed-by: David Hildenbrand --- mm/ksm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index bfd5087c7d5a..728574a3033e 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -293,6 +293,9 @@ static bool ksm_smart_scan; /* The number of zero pages which is placed by KSM */ unsigned long ksm_zero_pages; +/* The number of pages that have been skipped due to "smart scanning" */ +static unsigned long ksm_pages_skipped; + #ifdef CONFIG_NUMA /* Zeroed when merging across nodes is not allowed */ static unsigned int ksm_merge_across_nodes = 1; @@ -2345,6 +2348,7 @@ static bool skip_rmap_item(struct page *page, struct ksm_rmap_item *rmap_item) return false; } + ksm_pages_skipped++; if (rmap_item->skip_age == 0) { rmap_item->skip_age = age + inc_skip_age(age); remove_rmap_item_from_tree(rmap_item); @@ -3435,6 +3439,13 @@ static ssize_t pages_volatile_show(struct kobject *kobj, } KSM_ATTR_RO(pages_volatile); +static ssize_t pages_skipped_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%lu\n", ksm_pages_skipped); +} +KSM_ATTR_RO(pages_skipped); + static ssize_t ksm_zero_pages_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -3532,6 +3543,7 @@ static struct attribute *ksm_attrs[] = { &pages_sharing_attr.attr, &pages_unshared_attr.attr, &pages_volatile_attr.attr, + &pages_skipped_attr.attr, &ksm_zero_pages_attr.attr, &full_scans_attr.attr, #ifdef CONFIG_NUMA From patchwork Tue Sep 12 17:52:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13381991 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 C54B2EE3F0B for ; Tue, 12 Sep 2023 17:53:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 906886B0140; Tue, 12 Sep 2023 13:52:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 867DA6B013F; Tue, 12 Sep 2023 13:52:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 730C36B0140; Tue, 12 Sep 2023 13:52:57 -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 5AC336B013E for ; Tue, 12 Sep 2023 13:52:57 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 27DA5C0310 for ; Tue, 12 Sep 2023 17:52:57 +0000 (UTC) X-FDA: 81228691194.09.8494375 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf15.hostedemail.com (Postfix) with ESMTP id 6E83FA0022 for ; Tue, 12 Sep 2023 17:52:54 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=neutral (imf15.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=1694541174; 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; bh=7hiLlIvC4E6ZG09k10WszVkbuStDhbkQ3XWN2o6TQ4s=; b=Spgd7S/rtPswNSjjDXdqLp+4uz+HEnTrRHSTJxH6TTuu8dAUS5CGXDk8wkBlvegEipWsUr yfFrRmQX44M1qekYwPUk75eb25pRABj1AQh3czt/5STtbaSZVKBNrHXf2FtGxJbl940wsr h8bK7nzBeA5NcsIM2Xl8G32TAjDlac4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=neutral (imf15.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694541174; a=rsa-sha256; cv=none; b=yjA0Yjz51wTQ0OqYXpqvQzXUrXHQ8zmoacA3PS7W2ufv8hJLp0hxNbzICUwQOT2kvBJt4Y UgqLGc7WPh6ZHGrDNNwappEDl3lbpE9zBV2XTZ8POtOo/Um4b6JpxDeFQGDl5I/ka7LuTO 2lOuXQBpTt9zxj/trJvw9rR9POTNhpY= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 467C8BCD162E; Tue, 12 Sep 2023 10:52:39 -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 v1 3/4] mm/ksm: document smart scan mode Date: Tue, 12 Sep 2023 10:52:27 -0700 Message-Id: <20230912175228.952039-4-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230912175228.952039-1-shr@devkernel.io> References: <20230912175228.952039-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6E83FA0022 X-Rspam-User: X-Stat-Signature: tb367ka96scs6yg84jx7mm8ouepzib4j X-Rspamd-Server: rspam01 X-HE-Tag: 1694541174-247768 X-HE-Meta: U2FsdGVkX1/+JoSaf6V2583HiSys+Nf4g6drvEuAAUjbOjdxKXOlF243drn5+8Ebt66Mw9jQnb//YmZx9QWDJXukv5+0xp8lpGXEnUxDEgFyRWFBAbIYoJe5JT8YgPjNlk/faudQwQpsgLRPZGdcHduEDep0qn4Ul0818Ii1aTbsApQdaDXojfRs8tLcTKoUS3FAKD505gsiMcG/38lBPiMvjrbGjr/6HsR2clj8Onsab7sjPWNwBtvcGFKGoCPdd7e8nnVqWBIpwzzsJvSqj1kHYCebytp1IMmVnBvm/rfkGcnUkr4TsviSOJQrjVz/ALGOItFHkOlpoI5SsKM+NsYxNJG/1iMctAfH6XB2869ttd4inKgP5WiMzg0vsHf6xsLF81F7mgo9oDjv1SAdl1kE033MfQy8QU9ximomoBtGCqQOAcmGBrGavntIdm6kn96b3nqe3bNwwPuLI57m0CaskJ8P+j1ehvM4KOBzceIcc8vjN9OduD1fpw4k3pAQvG9+LZh3nz8KO1MJs/dcvHsVGJDWNRdRW4NeksFHk09uxF73RSYtKvDo8WBTYMrRQo3L/bjKQUquVG/Izj4K682Rw0M6ErdW2s8DDCDTwGD1EGvmsKWp5hHZiR5zmop1VtsxUMpuLamRR7MjReB+C3iAJ6VM2RFaixzaNl1pvlXqv5IkS4oyY2O0lz5CD4y36fAVNLjQGVEgr8sFlcVZynazRYmkLOMuGO1qgiqYubORB9TmoBwUssVbhJKXMvPruK8b1ldHvMlhLotToeuSymw/3nEkGqEbNdiGFPo3zRRT68lpUy/s4vTBPTOH0cdoN5mZZNtTQhlOcgJ5PNrIiMAx/gh9/GG7etcPRlXjBU63zeOkHlSRp3BA+5gBoUr2Cwx9zVmtqWs9mhF7WcxzhqfNbYOnqI7FP0YFCfFgE0e2EianhEIXN9q0LYbO33xrg4mvl266+w24fpVgMhS Z9lk7SHf cX6fB02trddoXBVE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This adds documentation for the smart scan mode of KSM. Signed-off-by: Stefan Roesch Reviewed-by: David Hildenbrand --- Documentation/admin-guide/mm/ksm.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst index 776f244bdae4..1762219baf51 100644 --- a/Documentation/admin-guide/mm/ksm.rst +++ b/Documentation/admin-guide/mm/ksm.rst @@ -155,6 +155,15 @@ stable_node_chains_prune_millisecs scan. It's a noop if not a single KSM page hit the ``max_page_sharing`` yet. +smart_scan + By default KSM checks every candidate page for each scan. It does + not take into account historic information. When smart scan is + enabled, pages that have previously not been de-duplicated get + skipped. How often these pages are skipped depends on how often + de-duplication has already been tried and failed. By default this + optimization is disabled. The ``pages_skipped`` metric shows how + effetive the setting is. + The effectiveness of KSM and MADV_MERGEABLE is shown in ``/sys/kernel/mm/ksm/``: general_profit From patchwork Tue Sep 12 17:52:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13381989 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 12629EE3F00 for ; Tue, 12 Sep 2023 17:52:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FB6F6B0132; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D0B66B0133; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29B8C6B013E; Tue, 12 Sep 2023 13:52:56 -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 17A876B0132 for ; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EB3BF1207ED for ; Tue, 12 Sep 2023 17:52:55 +0000 (UTC) X-FDA: 81228691110.20.80C042A Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf03.hostedemail.com (Postfix) with ESMTP id 5DA352002E for ; Tue, 12 Sep 2023 17:52:54 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf03.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694541174; 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; bh=9xcbn4tr09Qqc62Dv3C/v1C43Yd0eirFtwweDMiZotE=; b=XGSISFXW1ZKrQD7dSgRc/WppL0M1Nuz+kirmIxWjVE3Ip5ou5YnYbh3ExQDwzmiNEoRcug BHclBAX5icuGQJnYnzXISo4niwxLsGxyEwlVbgAkkjtIt66cbYraw9VMdP6wrREuAri6fp AazNuxoz06FJnA6nfRjzn6O1g4V357g= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf03.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694541174; a=rsa-sha256; cv=none; b=wImzNkLOh/JbiWDs0WXKUP4bt/aIwoS/Rq85PLQssqjxSApIzV+VtZDLoCBpc/+Awt8xQm +xX+SFTJmwozkrokC1ccZF7mQFnTX3Phjeae8VCjGmhcyhJPChqXUhYYaChoWx2iMJMBZ3 lWXfh33zkgeZut5LHdpRLru+CMcVZjg= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 9C4ADBCD1635; Tue, 12 Sep 2023 10:52:39 -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 v1 4/4] mm/ksm: document pages_skipped sysfs knob Date: Tue, 12 Sep 2023 10:52:28 -0700 Message-Id: <20230912175228.952039-5-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230912175228.952039-1-shr@devkernel.io> References: <20230912175228.952039-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5DA352002E X-Stat-Signature: jdqpunoh5tgo17d7bokqhapm3y53hhnd X-HE-Tag: 1694541174-791298 X-HE-Meta: U2FsdGVkX1+LREL+zl94kj1XMi2LKbsO1SAxjXya8aRx7d1/C7msiwfMdrCKnK9Ywwk7llet1pehYCCm+3+ogtr8eeRyixBbvFEfIdGLa1CA5zLGS9hvKFvGa2Nh17L/WXhY1llVXTxKTn4GkY/DEnIQ01A5KZu54ewLa2nhfKYSxYruigDYhV1HpsPVoUCDLREthfN4YMkBKxWKRNWNRVZiNWMVHbmHYDquMjyqaZv7rX0EXFJl4f77Wu+pqisnulv63/Y1ms2ZarMnwfGUUBcOYtNZyL2ANc1IiefB7Ff9CjmD7Fa0EaSy3iFOsV5fGmmmIV84fu1bpkMoqxdrOL5dRcUQTn8cdhCCxcgJ3d9KTNccL/9G2HWMpghJSreQMHtzOdDCPUsE0IMGg5Iy2gAFNEqd71Dqnt8D8SDStWcCPfww++nnD1HsytZ6Kb13BgTtWlqNTXOFUoEkSJ2NNKXs9Dblj4ub1935ndEbg5eY5l/ULUhH5QcG0GuPj0cKEQ85sR5Rg602RRNkNRSmX2r0FYobQrgjZmABlLLDijf7AVfLgTxxlkugH7Mqnfnftp2Dk46xTmW9WBFkIgwI3iYhu9S2Fd7AbFZWCnXY1vD1du3Sa9LLBgq79Av39zeF91Ybr8CfKT1iSlwAxZHmnqYrl4h6iN9x0NFSDv+qkT176tnoGDfZcmORYqeWkvFvRFPeDe4lg6oIO44NFYaOQJT6MyglvFFq23QNjmWfbfFzwC85aY787DKdjKETdTx2XmuLx91jra/us9NAl3guFvbPEv6B/5ooYuZdggi3/TgnJOI4SaLeH/gNaX6o1MqySDfT/UhOnoSqSS3EmXkryqNvjK48I/2ydbWPfVcMuXUaBGoDYk3VI7FiSWyfB3PeoBAO750hEEnTl/cbY+2PB1WnWZxJfg1cIvXGUoHlaKGiMVUS4KlyrNNk1ytFVOwJSZO9W/MVOgf5tKdL/At 82yNkZaR 99dNqlAo7LRRxctccxOP1SJEYVMP//5sC19qFquWUyGAfWxj1HjALzGir7tZjv1Dn1/ht 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 adds documentation for the new metric pages_skipped. Signed-off-by: Stefan Roesch Reviewed-by: David Hildenbrand --- Documentation/admin-guide/mm/ksm.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst index 1762219baf51..27d949250b67 100644 --- a/Documentation/admin-guide/mm/ksm.rst +++ b/Documentation/admin-guide/mm/ksm.rst @@ -178,6 +178,8 @@ pages_unshared how many pages unique but repeatedly checked for merging pages_volatile how many pages changing too fast to be placed in a tree +pages_skipped + how many pages did the "smart" page scanning algorithm skip full_scans how many times all mergeable areas have been scanned stable_node_chains