From patchwork Wed Sep 27 16:22:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13401341 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 E89C2E82CB2 for ; Wed, 27 Sep 2023 16:22:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E2F58D009B; Wed, 27 Sep 2023 12:22:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F6468D0098; Wed, 27 Sep 2023 12:22:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8F128D009C; Wed, 27 Sep 2023 12:22:48 -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 B3A368D0098 for ; Wed, 27 Sep 2023 12:22:48 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 852BB160255 for ; Wed, 27 Sep 2023 16:22:48 +0000 (UTC) X-FDA: 81282896016.18.5EB431A Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf10.hostedemail.com (Postfix) with ESMTP id E09C6C0016 for ; Wed, 27 Sep 2023 16:22:46 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=neutral (imf10.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=1695831767; 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=ekjszAzCmJfqkUJ4plMMs/7OpHGzCtoSFSggNtD/+So=; b=PENnmRC3KOJxUPbaQmfUCiy0hgKN4obgpBBEiIFJ9vlFPt4V5uRJ6z6opORJOhEc0eQl9u C386yHOzP49KycVTkJbLZKeZs+GHpfRtJ+v85XX1hm/3JErSRGaQwM3iNyUKw/ExhaZ5/p x5cFlkj05ecRoxdB19bQNgNnmikIWL4= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=neutral (imf10.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=1695831767; a=rsa-sha256; cv=none; b=EM7mD1oAUpyW/3R2cwfvI/VvnY4U4lB7WVrr4QJRchbbeli4LfuNvkwdhzIrmKflJFQwfr LwXFOIEr6LCh/B8GuWuKmCeo0s46kjlEKL0qlTvkbDOXVdj1WUkdLQm2jZF5gYakLiimr8 TT2vZob+useYzyP6rOW0cr65dbxKDGY= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 3B9BDCA4DC0F; Wed, 27 Sep 2023 09:22:32 -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 v4 1/4] mm/ksm: add "smart" page scanning mode Date: Wed, 27 Sep 2023 09:22:19 -0700 Message-Id: <20230927162222.3827551-2-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230927162222.3827551-1-shr@devkernel.io> References: <20230927162222.3827551-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: E09C6C0016 X-Rspam-User: X-Stat-Signature: jk8afe74j56nmnbpbo9sw4mity1qfcup X-Rspamd-Server: rspam01 X-HE-Tag: 1695831766-120261 X-HE-Meta: U2FsdGVkX1+8py5Y97uCjia9ZI8a5qAOaDr0COdU7dXe6LMg2nWYlCBc7XvkYJQT7ocVGHj067tOPW06XzAHCskb8A0M/h7qE+n7AV9WM7odGZKp/bNJglDEtzAYLyBrl4Q6U6xmvpbspP+jYRGaplsb25dasW4fC+1qdZ359SYSTQigIitjyKZp0CvNjMjZJRDJ6PXjSbtTD5yCkXNd5g1wrdtGO/Lu1ApCQP3G6cHW3Fv+t76xH1Fq+sgQDzbiX/+ylBnaViaMThIcFF6KNJMfVDQaClQFG4TJqSRNzQpzOW3YXMl0gXyqXo4UITrqs3dZpECsOynbJL4MGjQYP5Ab+fSgoEJzLiDLK7zUcpVzoAGSdKVwJmmQbMVMjtrAzsned2gNjxMc+zXF4Dkgog4eO2uKxIkXwwkorJA2awChuXUl+vBEz0eYMQheFarFqeVpqQ9PB30en4p2QJo2uBc0TSZSnuBAnzHsSLrSLfQQ+4DBQ22T72M1W6+0+PTZX2eqqYu3aYtMEiUR1LFSD7AqbKeo66bNeoQdMu7DIwYQ5243HR6KtLgtiTIUrFbclnZznR8XR4wR0yM7dkl3iAQuKBZ+EgHZbVNK5lPnkFm8YK97nktwM/FE3FDM7LCXL5xbhDUJxasro+xrBh+Hc0AlcushwE+SQbEyueM2Zo9MJfg+UqMnHcJQZi+jwIHZWMOjMV+/as70uMD3Anl24sM6v0+fk31hfPUDZYca+NWkdgcVYlCWJsrySanD8J8K2gZ4MNhdWv5gDDtlceYpEutbtmOTsoNFnOgINPWMYmjYbYN/KvjGZ4l7KgM60QUYvAUcYmH2ZPgmyci/HI4GxboaKQ4xQKm4b9n7FtfAwa8a5IkxykinaM+AdaFQTaBF4GbuhFUwzznRGgUPw/O9opsb1QmbDCs5vefmcJeGYBu0gTVe2aRJqD6Muh/M4ZXAssv68RjnTQp93YQeAN6 QH16pJrs jaEP2HIMsnf2DS4ovdqPuRosFMsEw1A32yKwgkj0T0Az16fE= 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 enabled by default and can be disabled 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..c0a2e7759365 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 = 1; + /* 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 Wed Sep 27 16:22:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13401342 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 506C8E82CB0 for ; Wed, 27 Sep 2023 16:22:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58BF18D009C; Wed, 27 Sep 2023 12:22:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53C1A8D0098; Wed, 27 Sep 2023 12:22:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DCE38D009C; Wed, 27 Sep 2023 12:22:52 -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 295218D0098 for ; Wed, 27 Sep 2023 12:22:52 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E7638A0AB2 for ; Wed, 27 Sep 2023 16:22:51 +0000 (UTC) X-FDA: 81282896142.14.A821D24 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf09.hostedemail.com (Postfix) with ESMTP id 5B871140029 for ; Wed, 27 Sep 2023 16:22:50 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=neutral (imf09.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=1695831770; 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=1LdjbrSTW7GDbAqE3wkNtvp3gXo6eKi0BIzKiZfMuRg=; b=8EtTCZwzAtcIgto5EMyz3ORGUJ54r/xQ9zbcT0QjDNELvmi2PdCNtAkUEa8Juk5P11ay7V dF2gQ7AuuW2kvrTZsoivVP17pcmtA03jczDXLQnhRIrb02wErM1sGefQfvVSnXAMNJGEeW 45736q9SqoGCkjs4wwCWcod5MQScmAo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695831770; a=rsa-sha256; cv=none; b=ECr9lwgxu30qufIQfuKkNG7CQNRhlYzaikx0lfMmoFoU07f6m4NbNoz8DC8eHM/EGClgSH NHnLeWkAVdfbxJr6jdgZS7nABq0ATl96KWqj3L56X4bD5VwJbI7eXrYwBrXI9+kuftsz+S NZor9FkqJ4gZdV2VdR6f7FXaba8l6oQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=neutral (imf09.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 47CAECA4DC12; Wed, 27 Sep 2023 09:22:32 -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 v4 2/4] mm/ksm: add pages_skipped metric Date: Wed, 27 Sep 2023 09:22:20 -0700 Message-Id: <20230927162222.3827551-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230927162222.3827551-1-shr@devkernel.io> References: <20230927162222.3827551-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5B871140029 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 7fkc6pgmwj3dc368xd85ubn3e5o3nhed X-HE-Tag: 1695831770-793569 X-HE-Meta: U2FsdGVkX1+7p5t2Y44uOJZIEWo9bRhZMdBPiCHVsbJhAQ9zZ+POjrC7JW6SWXB4OBtgokhw5iN2yQ1mlMfOKN6uTxjpGsJAdAy3A/1iOTkmDNKnyyDcRRt87Ac+baacW61m4n7ja/Y3RhBIAJCYf0oTs9l4DmA+eKZJazU9s/mMaxAo7a54RjAqW1zaSBNb7OnlzRNh+HzfriaKH9bi6CWylKHxKNMk/mRK4Mj+diTi5ZuhpSpfqhSSGz7ZEyFMBdCQk3SxeFk/C4UN7TbZ41YTfmb37AG2A6Ri2YAiSo7YSTOE9f/xY/1smIYJfJaBEUJh1eUcyL1Fk1KXEbAJ4eX6Ckoua9m4EBREBzDvNHCfoMwfPg3X6qN4SWlNE9auZZOSa+QvZRSmP+fdDvqypVIWqRFbEHs9zMC4tNBmFTHlfeS8Yf+/6wUjVsiihhx6v3T+PHzMuoIZjwy8RFyPVC0Aj8vkmZnk2HdfA0GuWu8aetHvWJ64vwVKK4WDbAd40PIkCUEvKKukhrSPb1tbRHKS5O69NEfrcIheO8vulaxqHiPHZq95P1YN17kpdGPDKE1Q7onCpWu7FSLzlNqRXJVygS6BEh/xMbxkuuJQzOP9F5lu47KKVGcSyIxobb+jyOYq8cwkmJUBpM3xbvfH0I4GMWA5wDljWjvcZumv1clvFfrW6SAZohIfjYE+rs3lfLo8cQkebrPv6ioNjIK1aghjFgs8bRbm7WzA2ZpmkNj4HHWJCmacJeHVygDwLI0c8peHc6OCL9F2eaDws1VIs0uW29xa6EhYyDp5hX3RgAPbgyQoVo+/F2w6L6HYqniewdN0do0YRk39Yv4IAaCFByvcAgjUVTcBACfC5PdFpVglVg7GQB9XHEZ8MDHwbyzMAJ9jqFxj0TIZ45dh2IC7vye4Bs4VJB2sYeSTjQLUnyIVx7fA/NL+B05HS8d7j0KIf3cSYyxovrVVsrzVv5J NfIbMajU YV4NHo9WPI0vecbzcQlxI6W1s8p57M4rJ8Rcqt1zdda0g1XhV+GaboVSPbM8XR09wCyXixPpkPJYJyQO2clpXwQ8gtt0dc6zIsbXt 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 c0a2e7759365..1df25a66f162 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -293,6 +293,9 @@ static bool ksm_smart_scan = 1; /* 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 Wed Sep 27 16:22:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13401340 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 EC5F6E82CAF for ; Wed, 27 Sep 2023 16:22:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C447F8D0099; Wed, 27 Sep 2023 12:22:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD0B98D009B; Wed, 27 Sep 2023 12:22:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A43B98D0099; Wed, 27 Sep 2023 12:22:48 -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 8FF8D8D0098 for ; Wed, 27 Sep 2023 12:22:48 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 67FE1A0204 for ; Wed, 27 Sep 2023 16:22:48 +0000 (UTC) X-FDA: 81282896016.22.6E641E9 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf21.hostedemail.com (Postfix) with ESMTP id C37A41C001B for ; Wed, 27 Sep 2023 16:22:45 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=neutral (imf21.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=1695831765; 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=dj4Uw0ya+yBYIJV/MmafOuUQqTKYXOAk3384f1ynkjU=; b=i5bGMl4U4J4UWbgtcNKVrvLBxWYMqr/sMLBzEuVAgc8G4yq8JtjdN4eT+FJsWdSa5rwVzk +z3RAkPTtgbNdICz+ev4M40qeWVSg0HLguleUproSD4/CVQJm7l7PQbhskDjTpRvNtBbjY O3AjPwYvh4FqK/93pNHUI81kPBlQWJI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695831765; a=rsa-sha256; cv=none; b=EZ/5FNxf7H8TgZ4b0CVCrPc9TD/08Rwwr+Ax3oyJNNP4l4oeOK1fbmkRCSyqii0tX+qtXu cG/xqy+LoFfhGar3hqyDGr+Zw1+ih4oJuO6kUeCH7rMe+GiYh4PjEIOhrSguyYSaO8o5QX 9CZvPBl9MaNUMsOyCcVUjqw/nWn+x0Q= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=neutral (imf21.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 5401DCA4DC14; Wed, 27 Sep 2023 09:22:32 -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 v4 3/4] mm/ksm: document smart scan mode Date: Wed, 27 Sep 2023 09:22:21 -0700 Message-Id: <20230927162222.3827551-4-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230927162222.3827551-1-shr@devkernel.io> References: <20230927162222.3827551-1-shr@devkernel.io> MIME-Version: 1.0 X-Stat-Signature: txmof5youu4mapybti8aptsoymbiymw9 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C37A41C001B X-Rspam-User: X-HE-Tag: 1695831765-597245 X-HE-Meta: U2FsdGVkX1+ktno/Xep9H43w4kpzryJBs+FIXwWT4agclHbSnEDQIVoVNtHicGiOa0ctKQhPmjw9TehKcBIEmSi0PPz0hVmXdW2dpNKKdZyCzRGl5CnB/zxSa58sdkdJ4v/+UvlNOP9wj1fSmEy57jo8uDqYO3KUTuK0Wd2zKTBjgypJfyJNN3Bq8BLSFYotABOdypTiWyVibFehcBPSr3QFNGDWKFZemsGyWkzTI3WYsT0xnyW6qV3FFQHUmC6Fe3NApi4vLGtjC08JUgGwFdkaktyE90OBouaXk+w2NXpFivDqB9hLXu8NQI0ojIBmgZgM8f+gn1Az+mMkRhBxN4gW083hjNKmA3RyVXyOozE0XESrfwjZbQZ0P6/wyyCgBnlcyqT+9zwAmENM8DVX5FgCgtP3v0tMTntKQ9aHz28z/Q/v/zHtGCt+70j15EIrJ+yfEkN6Io2jHL9x4xcLIZx8cjyHQ433Btq3XjoL/SCtM5DPerZqaCjE2E2A5Wry78sUw6xvQP6UyrYqfr66xO5gK+ZGsjbi9r2V2gmQRVPW5PoaOeia/2ps8WjRhfzpa4J2Gr3P6yNDSStRrIOJyhVIYFIpzwzAnDzuqKENMLq4UfN2U2Ra2usV0QN9A/kn0iDS3Fn08dmYwQLmdoo+fbVtWTKjLqLsJVtfd39C7xWV3v8SYfneYii4aZ69f4LKekndI8ZL2o8SBaMQGJSXaFvPOEj6dQprVr9Dli6gMlzv/XRwmqgEFbKB+2epwR0REexPur+d9t89n0LVGz36kv+0un+KB57uIVvDan24MUkSytkwIlW9QD4aTeeWcE+qVZIOxOuC00q5CVAeL35cXc5vxj/dbQelUot97839GjrQZaTmT90XTrwd9ZJbD+O/qdlP7FdgI8nly+uSjaWXKaXHLeCQPPO5uX4gq6q4Gk/UJq3VaGkHh7RhgIpMgjNeo5BK8Kj6HpbsdZcx3s2 oJkMRJz8 uI64A6Vp8Xc64UDDamYDsdjWP9SZR5KhJA5m54DoLtj+6164= 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..2b38a8bb08af 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 + Historically KSM checked every candidate page for each scan. It did + 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 enabled. The ``pages_skipped`` metric shows how + effective the setting is. + The effectiveness of KSM and MADV_MERGEABLE is shown in ``/sys/kernel/mm/ksm/``: general_profit From patchwork Wed Sep 27 16:22:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13401338 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 4E063E82CAF for ; Wed, 27 Sep 2023 16:22:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCD978D009A; Wed, 27 Sep 2023 12:22:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADE388D0093; Wed, 27 Sep 2023 12:22:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BD468D0098; Wed, 27 Sep 2023 12:22:47 -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 7C50C8D0093 for ; Wed, 27 Sep 2023 12:22:47 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 53511160D1F for ; Wed, 27 Sep 2023 16:22:47 +0000 (UTC) X-FDA: 81282895974.30.C8290B6 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf20.hostedemail.com (Postfix) with ESMTP id BDE011C0038 for ; Wed, 27 Sep 2023 16:22:45 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=neutral (imf20.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=1695831765; 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=71+GN8RZXaq4jWr0yJG4sss0ixOgqD2wHt5QC1Bg9nE=; b=uRYkkjZiTzJqZ9yUWBy81Fl2e0597fy+2EKHD2rgfukPrRDuZoJci3+bAAhB2rafMo6/NJ NOy+tJwGvL/qn/mfiwo1KEuoEZiEfMfk/4EPj0RiIV3aU98YDtfcl0gnVawbsTL9cY2IEg 1ogEpaVtkI7L1qZXuVuZr9dTrSWidCs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695831765; a=rsa-sha256; cv=none; b=MgTC9vBzUPJhVkjRjjkA2elNVdBt+oLdeSOmVN+nH+YOuAYYq9dpyQcgHBhy4WCBLr1GMI euFUd8wmOT8H6EqZG9KSdF9TfYS8I8UHgzPDu3jiXwNx2aqoia6qKJ7Iu2GkOy/yxeg+YY B22XwiAnFJV8cFA6j/lFAEx2iCfDZPw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=neutral (imf20.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 62387CA4DC16; Wed, 27 Sep 2023 09:22:32 -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 v4 4/4] mm/ksm: document pages_skipped sysfs knob Date: Wed, 27 Sep 2023 09:22:22 -0700 Message-Id: <20230927162222.3827551-5-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230927162222.3827551-1-shr@devkernel.io> References: <20230927162222.3827551-1-shr@devkernel.io> MIME-Version: 1.0 X-Stat-Signature: 59apakx3hw4h1b7e7w7z5weucr8ed3z6 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BDE011C0038 X-Rspam-User: X-HE-Tag: 1695831765-105979 X-HE-Meta: U2FsdGVkX18a32qylUA4l/FkAX5Ka8TZ/cjvIy7rycsfPA3u+95894KIo+51R1jFP+tII5z+20AtHx6FjlnWc/m9SMxNDM3DGpb8Ol6mUNEZV+lJHOEXVzl4X++NGhNs5u6f/WGZDHjAu6WNNNWBGEXu7TMpbiL0pMHfVynxuVsB1hSLzMIFTTAuAc+pYmmBviffqWqq/XsxqnwGryKbXnjIRITzF5WvWKCRATvl+bcHxgTqqQC3jA5vfJFrTIOJjFz/o3usKXwhMDSVgXpFrJEtmaV1rc7+MwNkGX3ykI41ulyPS0m9h3doR8Te2FdoOPO28ZRQznb8YXoL8A/fhwiLRzq46GJ0WkrYoFX644GXxLsassSgSzw1hYyouSV0CRUzD2wD9mCaJPl7gCukaIlkBP6eY7NBnb9KItJWA9VS2bz+S999WrPjXQe11l/P3QfJKk8FPaOV7pJWiVwgrIbE7kowJV2wXUp5meum2MdmG0I+n6mc2PgveloSJ5DqgW1XxuFh7bXYRBZ97XJ3t3H5ojP4UAd2ezOxZer2BJfQXvWSnHeij8aCKCcmp02g20eedHmPwMkazKZn7bTfTUaqKKixHV/6TQy8bcJazBfGv7HpucU3vheBXL9cgagLyJnRZ4sPejDFdH4/418v5mZ9+r6wOup5dHaZv6kHE7CdB8UAy+4jZUmnlFENR4KEsIPYrVObsLjCPhOV3eRjBPkbA3SYpY7KXaQfeT2bvQw2PmUtpUSjqIHLu4ZbAZsN4RvEAMFKEe726RTO2G7FhxoNxkIS9mdAef6mKAfllXdOJ/x0QSa75YzU2ikCoqQjBql6R9sSylqC8PA304yn3442IzoqH3c+9At9rd80vQg7L4y0vY512Vrf8Y0iC/ozbjjtTkWQD5hoQtuCASjUbNuLymseEGOrniUcTRhvVGSqwmz2+N9EYeOftEfBkq9/NHnSqLYdqFB2npf4Xqj 9Mg9yw6O YObKlyFs4Mh6GH+2gqKFRDjGAmWOpU4OVGaZjkOhUE+NEadr8jdiRU23T6Oe9PyGZaTNiDsdN/4RYZsKq87ZI2w2TXQ== 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 2b38a8bb08af..0cadde17ae0c 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