From patchwork Tue Sep 26 04:09:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13398636 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 E7C46E81818 for ; Tue, 26 Sep 2023 04:10:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BB306B018B; Tue, 26 Sep 2023 00:10:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76B3F6B018C; Tue, 26 Sep 2023 00:10:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6326C6B018E; Tue, 26 Sep 2023 00:10:01 -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 4E0E36B018B for ; Tue, 26 Sep 2023 00:10:01 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0FC3EC07A7 for ; Tue, 26 Sep 2023 04:10:01 +0000 (UTC) X-FDA: 81277420602.07.E13E8D0 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf16.hostedemail.com (Postfix) with ESMTP id 6CA6C180006 for ; Tue, 26 Sep 2023 04:09:59 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=neutral (imf16.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=1695701399; 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=wM4Sh7wNLr/HEbxi4LofFi4JD4PV8ZH53mZErVMmhPo=; b=7LguuAuWecUYkrr3nYF2SIpjisu6ls1LI+HduoAz5I/49QCm9z/RGbcaqpMgJKPb/2YMBr s8lg0qqDfkzYbQS9KJasKCb5yoIkRu8wLUP0FPjZIVbq1NtZSHFl8gpSwFRJyew7h3Eupe ivxa8Dv0vWcM0ZBuKzpft+Wcg4BLSG4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695701399; a=rsa-sha256; cv=none; b=uij9flJVd92jddS/djcYvebJYL1CrCisBQmWsGC/mgv77rECa5m0pT/IWmIstpIl8qkmj8 SzKY7XfEc8R1Tenf4OuPfZNdQ0tDRcWguX8Do7hw7QlENtYalR9YzbdpGVJQsKToM27Mgc X7NsAYWe7EFFX0GGppHGnjT+JGr5+8s= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=neutral (imf16.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 246DBC8F2417; Mon, 25 Sep 2023 21:09:43 -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 1/4] mm/ksm: add "smart" page scanning mode Date: Mon, 25 Sep 2023 21:09:36 -0700 Message-Id: <20230926040939.516161-2-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230926040939.516161-1-shr@devkernel.io> References: <20230926040939.516161-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6CA6C180006 X-Rspam-User: X-Stat-Signature: sjk48m81j1tpc4pc6cce7dds6u3x99cx X-Rspamd-Server: rspam03 X-HE-Tag: 1695701399-301774 X-HE-Meta: U2FsdGVkX1+1v0A2xI6saVg9CpRUdxvXPwaJ0OWQvh1lhY9teeLi9UotNQehFYsShDmZt08C5yZRAHpmbEiXgSblgQyWS8/fA9049MZl+YYorm048tTay19BL3mc1+YsvgASsbhSDDxX9CpxBKSe9V5R29OkUgiTug2C89OOLcVmi3P7jML4Vuz0NnbAORRtRyDfqH9T1W0sfrTxwBD7u0XMnhj5las9EinOjeS0/1Wx28ZWyD5+3zKbLQ4Z8xgZiHgyLqg1DWA19iuPKlMU+5iCzjzszVte06+334PveMhhVgJp39VwJtHosAA8EkFvC/JyTdQlSpIMycOF4Q3G/As9moITmZzXpCWlaYUaWNLNrL4/oKhm/Nmm7XuE1orzkiEohL+ADnPND7dXHrjRSsWNS1lTfPbApkLQazAZ3n/5C+UCDNNaRIhKJpex6zE1xqWq2CwVLNdSlc0Uq9zHwNiWF+2gYpX9OFrZoW/pbP7Hb9LMq80BQ8cE7ycjsRaNUSYGfSC8RwAmeHchlZJqyrSqfKZ4j8TVCxuZzltyNQ9OOxX8MQWyZtBbF6biLM/eNhms+mqFgtZLHbv0EIKGB20nug1qwH4yBAGtSQJBp3F4ipLPHL27McjxIuY/fQ2Gg+kDw4kCqju5HTYyswru0+cmETVBhaz1YC4RlrTHbZhcjPlMD6qXezSFDEC3MVWDvEyBWVSr5z/+tXiGThisSCg0DrFW6y1LFuWuxNb2r1/myJm53ox64tvs7jR6ynIIlGa6VygKOfFfMQiMClcww5aYpvKru0dawoh7VUMZjYIWFlbHgskDFoy/cHfJ/fhKb5kH1wUeqKcUZP3nthQWFrvDlO8WgO3GWWQ/DRBh3jdx3idgqpyyup+l4UFq4rPvXz3ajelRhvYCWw1jRqKdI3h/s1Zz1RwBvbLZt8r+e7c4K0tBM0SHdN1dNIFOtAqYPWStxqZhVSUNZ7xbglI TDj99T93 WuFpzYXWQe5Ci7AAHPRpckINdOQ== 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 remaining_skips. age, is the KSM age and remaining_skips determines how often scanning of this page is skipped. The age field is incremented each time the page is scanned and the page cannot be de- duplicated. age updated is capped at U8_MAX. 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 Reviewed-by: David Hildenbrand --- mm/ksm.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index 981af9c72e7a..d65eb48f9a13 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 + * @remaining_skips: how many scans to skip */ struct ksm_rmap_item { struct ksm_rmap_item *rmap_list; @@ -205,6 +209,8 @@ struct ksm_rmap_item { struct mm_struct *mm; unsigned long address; /* + low bits used for flags below */ unsigned int oldchecksum; /* when unstable */ + rmap_age_t age; + rmap_age_t remaining_skips; union { struct rb_node node; /* when node of unstable tree */ struct { /* when listed from stable tree */ @@ -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,73 @@ static struct ksm_rmap_item *get_next_rmap_item(struct ksm_mm_slot *mm_slot, return rmap_item; } +/* + * Calculate skip age for the ksm page age. The age determines how often + * de-duplicating has already been tried unsuccessfully. If the age is + * smaller, the scanning of this page is skipped for less scans. + * + * @age: rmap_item age of page + */ +static unsigned int skip_age(rmap_age_t age) +{ + if (age <= 3) + return 1; + if (age <= 5) + return 2; + if (age <= 8) + return 4; + + return 8; +} + +/* + * Determines if a page should be skipped for the current scan. + * + * @page: page to check + * @rmap_item: associated rmap_item of page + */ +static bool should_skip_rmap_item(struct page *page, + struct ksm_rmap_item *rmap_item) +{ + rmap_age_t age; + + if (!ksm_smart_scan) + return false; + + /* + * Never skip pages that are already KSM; pages cmp_and_merge_page() + * will essentially ignore them, but we still have to process them + * properly. + */ + if (PageKsm(page)) + return false; + + age = rmap_item->age; + if (age != U8_MAX) + rmap_item->age++; + + /* + * Smaller ages are not skipped, they need to get a chance to go + * through the different phases of the KSM merging. + */ + if (age < 3) + return false; + + /* + * Are we still allowed to skip? If not, then don't skip it + * and determine how much more often we are allowed to skip next. + */ + if (!rmap_item->remaining_skips) { + rmap_item->remaining_skips = skip_age(age); + return false; + } + + /* Skip this page */ + rmap_item->remaining_skips--; + 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 +2485,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 (should_skip_rmap_item(*page, rmap_item)) + goto next_page; + ksm_scan.address += PAGE_SIZE; } else put_page(*page); @@ -3449,6 +3529,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 +3571,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 26 04:09:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13398637 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 A5A46CE7A8E for ; Tue, 26 Sep 2023 04:10:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E14A6B018C; Tue, 26 Sep 2023 00:10:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BAE16B018E; Tue, 26 Sep 2023 00:10:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 659E96B018F; Tue, 26 Sep 2023 00:10:02 -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 554226B018C for ; Tue, 26 Sep 2023 00:10:02 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2C28580E45 for ; Tue, 26 Sep 2023 04:10:02 +0000 (UTC) X-FDA: 81277420644.28.F45F02F Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf30.hostedemail.com (Postfix) with ESMTP id 9115680011 for ; Tue, 26 Sep 2023 04:10:00 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=neutral (imf30.hostedemail.com: 66.220.144.178 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=1695701400; 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=rEeKjj+nCu8+n8S1jluBJxwJZhUI2GEoXKLMBjiuJJY=; b=hDh4LMn3F+nylDPGMI9qnTiMr93ZIXbqrZ+AQrY1sHaW8cifaRbsxnmdIRw0Yx8ww9ONUk zdlUZFQ9W58+IBNdlNxPzLIIsFM8+rlg4g+xWjB9fHlDH2m94aLoDKyWPdJMCybuEl3P5n XgxxNXMYwY6IkTdOMk99yyvsrKp6FMg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695701400; a=rsa-sha256; cv=none; b=WR9BmQRSY0r27motgY/yDubeONscIZSpebNL97+aqdUG824NWvLOb8eWmi6C2Ypudwr13d tK6Oecdhmdi8khescMtIfw333CvGTdjVfUXe8EhgL1JoJcA1sjluipUL5XMDzY1w/5rzIu DoMSYxeIpy5jZ1/7Xpdld7i7DeMJsIU= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=neutral (imf30.hostedemail.com: 66.220.144.178 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 82FD9C8F2446; Mon, 25 Sep 2023 21:09:44 -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 2/4] mm/ksm: add pages_skipped metric Date: Mon, 25 Sep 2023 21:09:37 -0700 Message-Id: <20230926040939.516161-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230926040939.516161-1-shr@devkernel.io> References: <20230926040939.516161-1-shr@devkernel.io> MIME-Version: 1.0 X-Stat-Signature: twkmf8qxjqet6gbfenrb3oinxgyoun4w X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9115680011 X-Rspam-User: X-HE-Tag: 1695701400-208777 X-HE-Meta: U2FsdGVkX18nHfBNQYvaCsoIB718ooBdI2NzvXCitpRhT3I0Gkz8M32AMCc/3RWRXR9YkCxYFaZt6kV5EJDsvldbmsIxOVE7vYiukt+vGdj2fhI0p+eQ36d+8HhqaQMxaiTaJ//qvcAn9uoWMqgPJjoHKiMisMdczijB76Gbf0hcOaGbqT8Tehk8WQMG2y5U0EQTa81Gys7O9PlrBsktBDXksqSKgM33Xl2xiqPx+vbf7IhJ+oNgdABXJSGMQWVID9bv9t1pJJtxpPHIjOb1i6T+xm3nOvtEjXnbV+/J6u9Y5rhfBp3SfDf9dw3ntJAQ9pb/agWo7wBiBHFxf1mM3tMcMQ2+JYjnV7YuXsTmKg9BX1K4paXUISXoodvNNzZuCgvUhWr8Nc7b/Hk4kTR/ZFb95U40QpThLjXm0dB7UXztl216PtfC2sV3FgwzS32Ft7KTAe75noyaWjvUrdCpPOTc8ecD/MOCPHxprMLGG416hMEUaZipELPor9KPKur2RPPb9D5pyvLwDbgVcEY1JPOXM9F6ec1voXmClrKfl+82Q2QbKA2/HaewRcb0NpIpkS6jeLb3sPbYbujf7JBy7QVREn+mVSEQhYrirEuvs1G/qonwFvsGET7hZF7kKIc/CzCStJIPTqMKQXNfyc8bv7vOOXpw7sFifurfQoy4y00IjvmDme2kuGzmtI1i+Z6HorpwqaQUywtYyJVLJsi5vHxm5pALalzWdwmrLeLRln0vTKQtNBMoH5ISyji2N2Z69j/fi5qX/4adgrwr2LRiLmETNe1tBlDpry0JayBfRzaTSOhIm0BXx79rS4TZ8goWMc6AevE4PmJDdEUGYUG3Ol3F4PvoY0/GDIP1sJuBQjfJDVd4jbutQ2M9VO1ng9+a341w6G3b3ZQA7Kl7KoWTgSQ6we/TTy8IcTUdTLlOYQ1g5kBtf3Xg2t+FuqG7PYmZNASGbwj4B+tioK/CJoY 1C05IDHq gOCrlE9ECnLqREkEjr/wJfOQ3XL/df/tTYNZvi+qdE3x+jUkjqR5YYjy3fX/geQooyrI71VFvDZLOgpGo6bSYgbdGnAO/kVhqdsWJczXJJDEqNDg= 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 d65eb48f9a13..3de130d170b7 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; @@ -2376,6 +2379,7 @@ static bool should_skip_rmap_item(struct page *page, } /* Skip this page */ + ksm_pages_skipped++; rmap_item->remaining_skips--; remove_rmap_item_from_tree(rmap_item); return true; @@ -3463,6 +3467,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) { @@ -3560,6 +3571,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 26 04:09:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13398638 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 72F4FCE7A8E for ; Tue, 26 Sep 2023 04:10:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFC8B6B018E; Tue, 26 Sep 2023 00:10:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DAC706B018F; Tue, 26 Sep 2023 00:10:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9B816B0190; Tue, 26 Sep 2023 00:10:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BAABB6B018E for ; Tue, 26 Sep 2023 00:10:31 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8FD3E1CAB29 for ; Tue, 26 Sep 2023 04:10:31 +0000 (UTC) X-FDA: 81277421862.28.76913BF Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf25.hostedemail.com (Postfix) with ESMTP id 08955A000E for ; Tue, 26 Sep 2023 04:10:29 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=neutral (imf25.hostedemail.com: 66.220.144.178 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=1695701430; 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=nRm5bKQCajx84URLpQRvcjK4/PXHSs3c43bjhVyrNbg=; b=X3dzosJgS7egcXWItdvWCbqiSGoQmhxUgdYkJgA09v0DBGgCxIu6FXn4u8YM9Olvv1tR6M mszWzADKL3aKHlZeYTGO2wjVWn/hs1zc2lVaJOV49phZ9cLqT8T44P/SxtVfbb7lXOx8B7 mE3Nt9lm6NeRggldGChlE6x85/WVK9A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695701430; a=rsa-sha256; cv=none; b=kHaF0aBFjWr9s9vWesks4c9mbt+Ljtap6HtcCE0G0AL1fweVj37GWLENv6VnZ62DMO5URg 6kyDt13xw1FW1+dkp1m4O3k8zvKC8/ZagHhJnv1OTFhr+Eo3aH4Cw5RAIMA23VDOgp/K7Y MYAHAPNiJFHDFztltiYLtN0qrABibas= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=neutral (imf25.hostedemail.com: 66.220.144.178 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 C9CEAC8F245B; Mon, 25 Sep 2023 21:09:46 -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 3/4] mm/ksm: document smart scan mode Date: Mon, 25 Sep 2023 21:09:38 -0700 Message-Id: <20230926040939.516161-4-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230926040939.516161-1-shr@devkernel.io> References: <20230926040939.516161-1-shr@devkernel.io> MIME-Version: 1.0 X-Stat-Signature: iamdrjkhkfyuwy6oud66w5ipz44nhxn1 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 08955A000E X-Rspam-User: X-HE-Tag: 1695701429-216764 X-HE-Meta: U2FsdGVkX1/60MLD20zBgQQUaDAvP3YP38sS6WtzPt3n7Sd8q6x65v85ffMktiSCdIEZ3QGt5a5feLhjpWzvBmXZpxGzhi2b9d789TFuOCNcaBoIDHiaBSRe74egl4yAXKDsOyFZ5dmJWlm1OEkKm0jQYxRQ1w7kLayiVs1IqxeO7BFgr0Y3ZY0lv+/PU3SCHHMV1ndW9dvKDv4+Z3R9OmNZfCABZKzNu84VH0WEYMBQsTIjZurN9sGMQx7tCGb2OdPGLVDpoJKCRr1LtIQWxfI4UY2VDkNO5fiuR/1nGev421Au2y9fLSFbypnxo+/eW8WAGE7BXhJWsnxPVCLT5frgej9Ln9XUdJJTzdOg0dR42lwoAH64pFPYVDLki/02ZqpXCTriOIvS+Le/F4fLUVnN0lAZO3R7+OtRrVP78Ibk9lIZHn0gEymA28UgLOBNeFN7GTedAjb7ZbaoBIjOICYWd5yuHXRQ8bcdBFX5mMJISHvmoY4loTg4o0pD1iFCa0tvys+Bj9xRdF5Q/aoY3RrJObi+rs6hs2+aJP6UPD+BMdmic8bJQ4SMPJJn2u8WYHohPuZvEyTpDcEZc5EvbhS7jcvHWvk8XFsyhDKhZ6+PT0kabkgb3PD70yvuRk7VXhZUOy9C+/a4wJD2U8P3leOmrVZExlcmh+emcSU9Mlaf2VoajmLHCeAb3025RMagf+uiCqsx8Yv/dAK/dwNdhVgNmyU1UzE2ottzfcP0vLbKtHwaKPQ1ydUQp1sY1pF0dcBADu4Bk9CW1tLxbbm6tSO/NECQ+4LvrquVpKWp8GfX/opMgF0JSjHBjNHTdI9FzopKpdcW716inLhmXpSAnbwblFCKaGxJVYkPRYxsIdaQrFNqUMm+fc5wUKC7CgFjrAK+ojDPWbvEtzmXpSapokILHyUTMoAS7+SZtDDi/wu3FTXAmXHZm6VETfGR54RdJ7ClVFq/fGuoq4g+oji zv+eC+dW Dep1VNXE7ZRlgCQrpjAH0S1rWTCUYAUVubDOFmpiPnqaLAR4rZuuWZ9lL2Q== 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 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 26 04:09:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13398639 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 60FD5E81817 for ; Tue, 26 Sep 2023 04:10:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0E156B018F; Tue, 26 Sep 2023 00:10:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBEF96B0190; Tue, 26 Sep 2023 00:10:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAD6D6B0191; Tue, 26 Sep 2023 00:10:40 -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 CCEC16B018F for ; Tue, 26 Sep 2023 00:10:40 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AE12C1A0ECD for ; Tue, 26 Sep 2023 04:10:40 +0000 (UTC) X-FDA: 81277422240.11.6095316 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf08.hostedemail.com (Postfix) with ESMTP id 17251160008 for ; Tue, 26 Sep 2023 04:10:38 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf08.hostedemail.com: 66.220.144.179 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=1695701439; 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=k8NgTpKmmuGsb/3inQnuQsluCd3KJ2GgD7vI0QdXM9I=; b=AIyZOLYJn1psOrtd2KgaSsIg6GcsTN6j3GEMDzmACAra2Nv9tYPiVSzhSfMqizHY9K3sPO lFdCznpeahvhZrs6stsXQRX8CGd+V2uznvh4hFmWXyv6OLTypNw1tSv8NFv2MTODYVQiDW P0TkU5mxm0uF/RHmqMWkVOh3Mz6iB3c= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf08.hostedemail.com: 66.220.144.179 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=1695701439; a=rsa-sha256; cv=none; b=76rU8cxhULTjPHmUFITwyY8mnGba1x7JhVQ7uzao2ctJ4w+KWTJhcednk7QQZG9i/QNyaD byCMm8GM72aJYeEijXOxxf+TUpPj4+ouPt0mCBr0zeckNHLYAz2oLCaTbVGt3BM4n+ECC7 0mtqkRQaJVxg5vcOMnW9bEHjB387ysg= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id D82EAC8F2513; Mon, 25 Sep 2023 21:09:48 -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 4/4] mm/ksm: document pages_skipped sysfs knob Date: Mon, 25 Sep 2023 21:09:39 -0700 Message-Id: <20230926040939.516161-5-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230926040939.516161-1-shr@devkernel.io> References: <20230926040939.516161-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 17251160008 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: enujfm4a7ym13gah7tua8oteb56wso8f X-HE-Tag: 1695701438-690396 X-HE-Meta: U2FsdGVkX18WKVS2/vfd4amg0oCLZZ5JjLW/H2ZVrCrKArTzPU+l9eiBAnoBRk1sDCVFtk4lpDxVKJajVJ/0jb2kbEpBh/IgiZWcqk+Wl4kmBTWZan/b5h3UaeDI+LE14oHwymvpUgFIBr01zSFvxtm7P5ed3WgtqklcIl70yk6PCkDss689bJtHCoytL8I2TrrWVmpEnptM5KwBbY9chyA9OSLJKFKe7GOUd3SfJZummZYiB7woHlsfBM13Rs6sqObZb58uz7+zIs/w02Dz9sLGEgmte7R2hK4fmlV+S9yxTON9OUaLO8P/qNP/8MauJ1TBklW1Raku15sxeA2Xbe8GJ6eOzMk0Nv6gNUtSYUYjFmoTgWgK1KYyI6TPHGxM4w1eJ8d9xVqlKpcWXsH8OBBwFs6N687U7IXmjrPb5G7O1XWMnlMy4ia92KPfAE+HdRuYO9oyQ26abNk8685n96Ow///agq9wupuiJ+n9i3oDg5mO48ghjGti6Mevq2wnvmymLh8jJ6raqPeDj0DAo88/+aCPwDIjDDpiXyExOjAtnRrk1es9US/MqZiArA7eIx5MgIudchCpQTz5kOaHHGCtwrC2i9WRWvgPa+bAatlq+4+x067HEicr+ZO3BSInRgHoBvrz00JDybFPMfCWoYFuZkvHF36nqkTC7vEmqQdC/keMJFZU/V1nbl+Dde6CxGe6qtVy1ZUqT6QTeMG/JlNGHPfyv+iNxClHVPX1VvX/0DIGsymSG2wZ2T/8feLkG+kUlk1Jpjj+ZzrcG2ehQEEuBl8YlN6J78FW//1LEtCvSarqkc0lo2rn3AakzowYzehztacNRr6ZpEOoiVFk8aQh5BZ7hyLVF1LWSQLTffiYG665NKdJsWdmaOBjSpQyAZTL3S1Y9DHR53uoY+23z6RoqVuK7KOcE1AAZOZc1aqMTp3H91GPZHLxVwW0oQpwGTdFPgt8N2Lv5Tb1BOr 1RhLdgI6 GMjfiVPW/FsSIz9LaYlVc8MP6ENmfPHe3xc4QuJATicH5EuDRMVJeHE22RgT1QFk2wxb+mki+BOwvyRg4Y5OSvM+cLQ== 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