From patchwork Mon Sep 18 18:58:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13390256 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 B2651C46CA1 for ; Mon, 18 Sep 2023 18:58:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 235786B0439; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E4656B0443; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05E186B0444; Mon, 18 Sep 2023 14:58:37 -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 DCE026B0439 for ; Mon, 18 Sep 2023 14:58:37 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B9C061A066A for ; Mon, 18 Sep 2023 18:58:37 +0000 (UTC) X-FDA: 81250629474.10.222B20D Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf12.hostedemail.com (Postfix) with ESMTP id 0E3E14000C for ; Mon, 18 Sep 2023 18:58:35 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf12.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=1695063516; 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=PnD0j3CFAaIwzzQ1YfkRhProDe9jd/PYbopPSi7hmHA=; b=O2XMwoYA2BZs7O46qiHVVcvA3sO1iVHQZa45aW8sVyX2NvnicudLpGxbEBym1hzf8b7ihF apNKqRX8cAgeHV5jsvcyYPstS2CJ6U5Rjp8xZBZ0yPJi1KxbwiJXgu2wOMQKbcP9KqWsci s1Rq+XY1FZ903Hsi5Cc/y+HK/1AH/EM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf12.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=1695063516; a=rsa-sha256; cv=none; b=X86h2ePtf/GxxGoYMTr89bAzJ9/Zqq7iDL8wvf6SKAAjvwT71nQ+A+5eC6rTRDwjea/Uwa gve4EhN54S9SelVt/Kr9JHzO80mNQWHYiko5Dz1bM85OnjoMupfg+vXoN8IXkpQEwch4Vi koJpuFsSycobLxScPJLWz4WVydcz5+0= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 1CCD2C25F826; Mon, 18 Sep 2023 11:58:22 -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 v2 1/4] mm/ksm: add "smart" page scanning mode Date: Mon, 18 Sep 2023 11:58:13 -0700 Message-Id: <20230918185816.1518366-2-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230918185816.1518366-1-shr@devkernel.io> References: <20230918185816.1518366-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: dxsq6ytp4emaebqcw44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Ozl++nzzKGd7NlEBqENgikxgIEFBPx 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_age 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 | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index 981af9c72e7a..7a1aa3872cf4 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,78 @@ 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; + + /* + * Smaller ages are not skipped, they need to get a chance to go + * through the different phases of the KSM merging. + */ + age = rmap_item->age; + rmap_item->age = (rmap_item->age + 1) & 0xFF; + + if (age < 3) + return false; + + /* + * Page has been skipped and reached its target age to re-enable + * scanning the page. + */ + if (rmap_item->skip_age == age) { + rmap_item->skip_age = 0; + return false; + } + + /* + * Skip the page and calculate skip_age on when to re-enable scanning + * for this page. + */ + if (rmap_item->skip_age == 0) { + rmap_item->skip_age = (age + skip_age(age)) & 0xFF; + 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 +2490,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 +3534,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 +3576,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 Mon Sep 18 18:58:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13390258 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 05906CD37B0 for ; Mon, 18 Sep 2023 18:58:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED7B66B0446; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C471C6B044B; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D4856B0447; Mon, 18 Sep 2023 14:58: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 700246B0443 for ; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 51010A046C for ; Mon, 18 Sep 2023 18:58:38 +0000 (UTC) X-FDA: 81250629516.09.C739007 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf05.hostedemail.com (Postfix) with ESMTP id B7685100013 for ; Mon, 18 Sep 2023 18:58:36 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=neutral (imf05.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=1695063516; 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=awJU8GMl6Va3wNMo4dFdW3id0t0DydghBy65nawHNHc=; b=x/ttwDElrzOGydXyWuUiJLj0vywF0u96caOLGvJuqbKlmRwkM4HsW7s13tFl8DbTqVqNuR erbvoOFzS49UyEua0NhGzwDY6s3IXF63UosaG/WowfD76IZbCgSBIxBBkDpq4WvQ4ldb9h FodAUOxyYHBRhOdmKYrbGArRGmoRII4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695063516; a=rsa-sha256; cv=none; b=ZtLQnw7q8yVs3cOrZ5umS5b/8JzLnFu0I1YZLt+d37KMugf3UaEB+GRLxSAOpKqNw3l95b ZDEV4eKkKsEuwuiMSzyixZRcr0dbpO1DEXtTsCT9tK3vANO+L2OY5CAvFOJDAn0qL/GU+P /txjNoBQpz9dLYqByVU19AAW6Y2FDQY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=neutral (imf05.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 2B029C25F828; Mon, 18 Sep 2023 11:58:22 -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 v2 2/4] mm/ksm: add pages_skipped metric Date: Mon, 18 Sep 2023 11:58:14 -0700 Message-Id: <20230918185816.1518366-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230918185816.1518366-1-shr@devkernel.io> References: <20230918185816.1518366-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: B7685100013 X-Rspam-User: X-Stat-Signature: fo7ei75fshr3s8dzheb868aibgoueejt X-Rspamd-Server: rspam03 X-HE-Tag: 1695063516-345054 X-HE-Meta: U2FsdGVkX1+mXw/2gmOUyF3iMZZcV+lZ7Ag5G4zv3VMO/9HUpUeHB5TvhLVW1AOVsSS4X+13Q5R/DMrk/CbKAftRI244Gb4dQItbUtRVNu2d1xyM/tIbWHDcrpYgY4v0A5XhOhT/fvoekyW15ILfyINmyM69suqxOvGHuoiZPxYgEgCVl+QUtApV6wYdTQgz3XT4Xn1pq3BprKb9D3DjxvL1HS84CrxBttBS9cq3QdnWkyaaAxH+pF/QKIZKpRRczQ6VxlqP14JrniSMYTOkb6sraKSUYes0pHzskiGFlVcaoGRoQMEZidpJVe1KlI5sF3UxWSIhBbOstLL2Xu5dxtIUlEfOHtR/ft7s1cf60vfUXo2DEsvI4kWwVi5My+MdGG7k9FsIdIbeVD1NNdcfDSmAI7498XVn9mcVSlGkuo10tgU+UkvLoe8uRmEQanZ6LF33QNULrg+BX5Yhz+wxqxuv/nQCdpcF3Hyi7ccJyYON+SdsRfFHqensJoxlIyVose7clBHwDe3m0rvGMeDSkwU73P62nN8UDgZ2adDlAy5Zv4D8cnwmKRy6Ao3withGc2kwYg5HAqcA/cIaxEWAD7B+cZrvW6D2IlGMY2Emc1jDg7Au9aDpUuOr3kND6UUUwcubaNpHhry0JopoGNxe0vg0PmGKOEOaJrI4DOJljTDCA9AHEK3uHizGzvtO7UvYW9KNIrApoK9nGILGgH/3xUvqacS992ptyuITQ36lC8obPHiFyed6YlcihpIxCuSGgIBjsMedTlXP9ghWqEqbr7RJRBPTVEe98WdAjZyzoSgkq/DxpLXAMJUcYFN7IvTaekBAiWICPXnAgEtmqXLHvNfQFRU9eYvillp5rQpO4kODGeiTnqJhAGrzCv/9KbplBZ1TNboNPW4aDJBcD4d/LGBg3fuFwVCT6RwbuqlrgJifCx1dQ87pJ5WG3AnhlAixxfWKNQspHDc7AjJWicb NP9KmYc8 vWeyYGApLGR6pQwV9nhzON0hTMzpcV67Nh9KO22KyQhiKegtAhAf1y7ec4W7oYhxydCGYfp06LUYaD7qA6ZCuvH5P7w== 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 7a1aa3872cf4..7fbf22814c8d 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; @@ -2378,6 +2381,7 @@ static bool should_skip_rmap_item(struct page *page, * Skip the page and calculate skip_age on when to re-enable scanning * for this page. */ + ++ksm_pages_skipped; if (rmap_item->skip_age == 0) { rmap_item->skip_age = (age + skip_age(age)) & 0xFF; remove_rmap_item_from_tree(rmap_item); @@ -3468,6 +3472,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) { @@ -3565,6 +3576,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 Mon Sep 18 18:58:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13390257 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 596DFCD13D2 for ; Mon, 18 Sep 2023 18:58:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B37006B0443; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE4826B0446; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 937626B0449; Mon, 18 Sep 2023 14:58:38 -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 7DC1D6B0446 for ; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 59F31120B46 for ; Mon, 18 Sep 2023 18:58:38 +0000 (UTC) X-FDA: 81250629516.03.D61F55F Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf06.hostedemail.com (Postfix) with ESMTP id B886D18000F for ; Mon, 18 Sep 2023 18:58:36 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=neutral (imf06.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=1695063516; 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=p5nvpdKflSHlKNAzmLapJGZEtyZ3jDhwuiof3cVO6/msYxim2p7H1JiY3ELRAUH6JluUg3 rRdiWFsHo++63irXzemRog4FX3oAQsy4s4GAn36bWRQNu5y9FiAPa3yQy+lqJ4vLeo2wVC AWVVwLPA2xKpDJX8jZJ5BmEBVOoRMV4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=neutral (imf06.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695063516; a=rsa-sha256; cv=none; b=bcaBy94HZsicop+fvZoXwXY57iSPZRQeitvLSgt/We8YxLq6yEfmtauFCyNOAVhMCXAJVv RNGVpopwW7Ohpzauvw+nZrBIw4gWtTke6C7ki5Izf86mOYhwBJact+zD1qjd0IGmzBv2I9 Tm69LtlguY3pqzCW7l6bBNzQJTy7hIw= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 35309C25F82C; Mon, 18 Sep 2023 11:58:22 -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 v2 3/4] mm/ksm: document smart scan mode Date: Mon, 18 Sep 2023 11:58:15 -0700 Message-Id: <20230918185816.1518366-4-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230918185816.1518366-1-shr@devkernel.io> References: <20230918185816.1518366-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: B886D18000F X-Rspam-User: X-Stat-Signature: oe61hrt3wpnoezu5kk4dftnmj36ezu86 X-Rspamd-Server: rspam01 X-HE-Tag: 1695063516-209059 X-HE-Meta: U2FsdGVkX18xlY2/zvbBS172t7HoP5Movbp1FBt857nkSeXW7A/cBbPZMf8sk4vphuYalHcxe/46S6KyypIxvH8G0AY8wPMidDnJMuTX+r7ir/beUHoYINO0770deTlnVUz7A3SocKQu16b2ZQCr3khNsSVf1mRwyz5BndjIE/HuO1XbpSZFb7XsfSb/KgsdaD7j0NP8XzePYUmtWpuoX1Tnxv55cWqcPUTfPg6SrFHgTvMCX0VRuo0eN6vG09Fbwq0gARe1iDJ34ngjv92RygG0lEcS1ScY1uD6a45Op/e5G7nqxLzmf8VXsBDT5CuutmK+PxUIrj9hFfIUvWTwgtZJpivIvZwhLcMLcLEz+AfpJkieHMhUHblvYuur7Yz37qpBpNZ/BTE0VBeGeQRia02iW7h8YBs1kD+O9PN8xV4UEJcAw3gO1X+9ht0tf8Ud1Nj0atHQBS8oyoM5fgecmEUNfIBOL0i19A1CgdEAaFde/9pePQTqkRvL/ACFSlToZqHOoAxQdTcr7Gfjnz4ideYtjUdkCUth00RdooVB/S6ZAs75c09vwCUDjtYdMtREKuqoOw6rQrijReTGldlygnI4KKVOuqgwqEPpHiBMkrasTe4tro3zBuWypVef+BQFabS3SrjwZG6UhxyFdEL+FUSFXW+pwBNpQzNoAS3u6CTvFpLjTFInPbdF31DqJZjCm0aHTOLjhavFK6Jn9JlsVaEK8CvS3psnBr09QtqR1Am+ClrKC3E/sYpaUbpDwMUXBgAqU6l3ZZp9E5hFQEP4+fovIXQ4k94rxsO+7DkEMc0al9c2ZrGaSxqBKdlWe1aBl2AlyIYj5/AeXG/du6zyMcybTGCKm9nLMnYgY8/8WxtDtq5JvYGFRZXvcM7aSJ5hFq02aZ6FeKEY375N8mTfNiXucgwg1zzXHtxORMzo8HMRzS2bQaXZXJoQpacHacEbhK3+NZ9fUHukbl+SgFK Jb1KvyfI ptOG33XeZnuWiUrcXVihqHJIV+Brt60G7NngQc8VB+uLy/iWCxZbAnKI8MA== 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 Mon Sep 18 18:58:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13390259 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 45D11CD13D8 for ; Mon, 18 Sep 2023 18:58:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FE086B044B; Mon, 18 Sep 2023 14:58:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95DD66B044C; Mon, 18 Sep 2023 14:58:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78DE16B044D; Mon, 18 Sep 2023 14:58:39 -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 65D406B044B for ; Mon, 18 Sep 2023 14:58:39 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3A578B3DFA for ; Mon, 18 Sep 2023 18:58:39 +0000 (UTC) X-FDA: 81250629558.25.057682B 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 9709518000E for ; Mon, 18 Sep 2023 18:58:37 +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=1695063517; 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=U1Nom+AtRgrtZfgQRIw1WTlBXiD4PaIArWqAKxu3PzMqHDyV7ScFKHgpxKAD0W94Fs3Vsa 65XycAWV8L8ZreGBAMrIa8trzstRz4zqOQ+Sxf9pcecGJNiO/0DiqEKl3JV0e6RT0a4uQd uZPplqeHO4ZQMNtp5vvMANzugPycvCg= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695063517; a=rsa-sha256; cv=none; b=YGgRdjTOZn7xY0/Tl6J2nxz+WhH6g9NaiavJAUck3/6+RsZXGLZX/ND5agybjodiK2+ODc Wm+6xm6MJpGlyBEAZrk7c2L+XexW+mur12BhYQVEUxf+iuXFIbo6Hx3pvsUpYGmYXiNExv kDx3UqviXE1A4rBehcW0TJO8UilLpS4= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 3D51DC25F82E; Mon, 18 Sep 2023 11:58:22 -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 v2 4/4] mm/ksm: document pages_skipped sysfs knob Date: Mon, 18 Sep 2023 11:58:16 -0700 Message-Id: <20230918185816.1518366-5-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230918185816.1518366-1-shr@devkernel.io> References: <20230918185816.1518366-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9709518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Y6L F6lSY/ju nL8Wg3mvoVKCoSOcmP6iU5IX1Hi2cHDDZlD6i7yCB5t73BAutrdpygilOx/SBBDiTVndxlaJGQFeh2Z2qK6lHrQs92g== 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