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: 141525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2892697vqi; Mon, 18 Sep 2023 12:13:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIdKCLlZANOvDTT9jgDUwmM34HNoNilJDm15tjQSzxH5iIRb1yEvHm4DOXMqAAlTfUziOA X-Received: by 2002:a05:6a20:8f02:b0:13f:13cb:bc50 with SMTP id b2-20020a056a208f0200b0013f13cbbc50mr697927pzk.25.1695064398727; Mon, 18 Sep 2023 12:13:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695064398; cv=none; d=google.com; s=arc-20160816; b=DNJ66cLs7Vu+rm27Yg7YrDHCS71iHCg/ywkvdxJ+Lm2zX1P6MAz6S7Ha3ASMVXDdez pKTkevtu60pmgEhK6C6AJCkaV2H8Z5NN1Z1pKesXHsg955s33Cw9SGBUQ0hEfIStBR0R aeZTkAv7W47ZU5yu3sqP+4ugthZwsZKAfnVN4o2ksb4sFk+HEqodvS3IXlzB1NZwDxcc l5+zhVc6DFZPTGMBHerW8DhmnpRDwF8AgWLXr14P7e6YbbG++6y8tA9gzeGgE5hXAJUQ Tbt9YnqSqu9CWtIBfIbRjNsxwQf1UgPmedSx2XMmkDSppmc8t4ITWFrcHjyr8qUikuVi GgWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PnD0j3CFAaIwzzQ1YfkRhProDe9jd/PYbopPSi7hmHA=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=QwlaMF8wewQ9fQOgEczYTXQaemaO7sFjd3MUQ62/G0V/8cn6i7tz2VgiqKr9y0Adgj dRDJGOGCZJb3sPvjHTxl2FLbuO4YbUztQFEtQ7zYiVBsVpGVzq1Gu8SNh/lceK1FX3Ur cITDC2o5iieZzkUDzLF8PcDrR6G6T4PkxIXZPZqMQpVOgpP0FHHad1G7JUgfVaJx8ziH GqIDeQx95GPbCy6H/GjsIhC8BBfy84um9WeOCG5Skx+R5b84rwxoXB6GOh8dKofjQ4fA kSHfgYZPGLiyLr1bUGECfw3gzQveprig26hq4QqPzYgmVwp02s5W5PDmomD/Bh7LwK1r MtDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id q10-20020a056a00150a00b0068fb1a85ec8si8560535pfu.370.2023.09.18.12.13.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 12:13:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 17F0280293F7; Mon, 18 Sep 2023 11:58:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229906AbjIRS6r (ORCPT + 25 others); Mon, 18 Sep 2023 14:58:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbjIRS6n (ORCPT ); Mon, 18 Sep 2023 14:58:43 -0400 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 130F111C for ; Mon, 18 Sep 2023 11:58:36 -0700 (PDT) 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-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RDNS_DYNAMIC,SPF_HELO_PASS,SPF_NEUTRAL, TVD_RCVD_IP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 11:58:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777403846621683515 X-GMAIL-MSGID: 1777403846621683515 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: 141523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2891329vqi; Mon, 18 Sep 2023 12:11:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVGwlDHx4yCuW2xi66MWDZUkKaYiFYR9gYUKlIwhNPw+eBo/RhXMWNfzDpvgK88ffQhFXW X-Received: by 2002:a17:903:24f:b0:1c3:52ed:18f9 with SMTP id j15-20020a170903024f00b001c352ed18f9mr9482721plh.62.1695064265337; Mon, 18 Sep 2023 12:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695064265; cv=none; d=google.com; s=arc-20160816; b=t6MLotgfDauwLbcZGW+/tQgs3sTSxRWB9j5J0GeZCjFU5AcdUVkWJUUp1yRhmRpJJ0 DkEu/NCMwAmQP0VzrpFVTcSn7tiftx4Uf4XsSMMrSBQtEsua9NsvVYBgYgGLBAok0y1Y wHXIddv3zBqumV9dX6HMFjAsLlzVfZkhla2JZKEfH8Yifc9v8YNjON19XVvPHocQcOrT 8j+aK2RiOiaBJWS/Y3t4yD38l5tRcbS6lGKxOcIHmKlvKTUP8C/36Xr47sosXKdT0XSL fXgLaQdOQeRXY97W4JqZZKNIKB27yHGFa+0qYrY+PdKZ0agiXl6PyeV7/rVE8Myuqhnm xyKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=awJU8GMl6Va3wNMo4dFdW3id0t0DydghBy65nawHNHc=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=DoPeXRm2qlpeAg2HmXSrM/ejRb3ELpF4G0Qk3xPowrMHuDJ16WF4c4OOT1f7bftC24 yc0XwDtFiWONlW11Cv4sguL5j1zHIzkgQ5iz1DBdxSjoahmjC6rVV1uIZlsOU4wyU4YP NbqAaU4xorQg0mha5GXKCbrqpZpW61k7P/vPFkvBAcwVAAOViv1M7ZGSFC65mCbTTp+N 8youETBYUvn6w5rWTs7XW6oWJz+1y4xFaDikv1pKSsWeDALpV1Ab04a5S1fKBozRnrsK ev/VnJ51H1i1+ZoozSPyi7oKgcqJ3q/LZv87JmHRLgHrba4489z3BJh/oAbhhKc7zMLN U2YA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id b13-20020a170902d50d00b001b9d0ad0d40si8270426plg.128.2023.09.18.12.11.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 12:11:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 2963F80BF19D; Mon, 18 Sep 2023 11:59:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229947AbjIRS6x (ORCPT + 25 others); Mon, 18 Sep 2023 14:58:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbjIRS6n (ORCPT ); Mon, 18 Sep 2023 14:58:43 -0400 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE087121 for ; Mon, 18 Sep 2023 11:58:37 -0700 (PDT) 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-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 18 Sep 2023 11:59:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777403707279233939 X-GMAIL-MSGID: 1777403707279233939 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: 141526 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2892760vqi; Mon, 18 Sep 2023 12:13:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJOeTZX6jk/VZnsP7NRpRdPcRE/ZDOeMwxx5OF3ZZtUOENspGDRiuk4O87/QjN1ALi4iYm X-Received: by 2002:a17:90b:23d7:b0:25b:c454:a366 with SMTP id md23-20020a17090b23d700b0025bc454a366mr9421548pjb.5.1695064405262; Mon, 18 Sep 2023 12:13:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695064405; cv=none; d=google.com; s=arc-20160816; b=QZuLW4wzBSr5JKSNCSGN+DesZqnrxDnrZrX5FSjbW/3MMCMaVZSARTEkDM2d5OjAK8 hhH2w0mQIAmtUTjLHFDHvntnVWUu4h/4ZjyNAn6EdPq1RhEzA27l1hfGo2AZMeU/9mSv maA3l/SMXZ1P492f7GtVZC4Vv9StFPZE2nDWAAtSS6UY16RdC89a6whHgLTvPgLokoDk /1F1xp4UIPPHtY/5RMTM03/C0Domljd0WBj0UhnPuDnveWLfB8JOtkk/9rRPq/YMxpa2 QEP3chX+fk4idUUtr752NQzlaCX3RAnLSZknTGgLKe6YPwK5YtGcc05Uo/hGbRP71K+l 6P+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=nRm5bKQCajx84URLpQRvcjK4/PXHSs3c43bjhVyrNbg=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=TcPdR6IHGzEOm24WtMvu8B1GuAdZuqYUDNa1WTEAsKN6LBmb1HYhfI0l9MdoqMuoaF iFpjc8ujWukJhod3ZoAWrZoYQsUAorq1aSYSLEGBzShVVWBZdUx7TnnzX2WU5wjzEMWG a7jNe9iJdQY3KrP8rmdZ9k2Qt17UgztOZo0vvfYyh35Z82n+3/lVXEk0Bqb6SaTtM9BM PxXiNBZ4WxrN0mpc3P+tkIZOapyUJtOwMfHAsRHpNkzY1fa2V0zefJ7sHJp+uAiyenVX GGPnVpxbTMmDaZFzS/O7pwC/3flDyAnGEMD3rPdRIMhBJ57zn6CKfamPgFxWaVN3leLn /BnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id gi23-20020a17090b111700b0026818f6a0c0si8422716pjb.86.2023.09.18.12.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 12:13:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 579FF8027DD4; Mon, 18 Sep 2023 11:59:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229918AbjIRS6u (ORCPT + 25 others); Mon, 18 Sep 2023 14:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229883AbjIRS6n (ORCPT ); Mon, 18 Sep 2023 14:58:43 -0400 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E33D11F for ; Mon, 18 Sep 2023 11:58:37 -0700 (PDT) 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-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RDNS_DYNAMIC,SPF_HELO_PASS,SPF_NEUTRAL, TVD_RCVD_IP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 11:59:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777403853585971114 X-GMAIL-MSGID: 1777403853585971114 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: 141524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2891415vqi; Mon, 18 Sep 2023 12:11:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9jvJ/lFVqP8HaftaPokQfYIKBsY/X0ATKa4HjIRNbBL2EduiLNbqSiVJ7udFowAOXCAOC X-Received: by 2002:a05:6a20:9381:b0:15b:c800:48af with SMTP id x1-20020a056a20938100b0015bc80048afmr2769698pzh.23.1695064271846; Mon, 18 Sep 2023 12:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695064271; cv=none; d=google.com; s=arc-20160816; b=sUWvGPvQURu45A+7OAiYIAV0S68nol2duIbkiaj0ag4wTAcRQhgpthMAdBAO3+jVnF BGE0E1qRJaUVZyLiHkMVFiBB/o+ujR7xBOt6RDlD5t7VpKrZ4LmHYjREfrWa/ZxFOSbK jaVLYUl1qTZ474I5EPEZFiIfwpcefp7W2C6PoYVwCPFwpzl5DfjkIUioWVkbKAMqvO+c 45Jsky6Nwsv2mAAtvleSWkL5XMmkkhY7K2GCOMRrazcNCQhg4M05Ygm9zVN9QwR0ccNV GdrGVE/kj1vGDxs71OI+5vAQ6fTHPs/GYXCS/V+uCSrAvDriRpaFl47wkPvMgIN0zkZz eVLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=k8NgTpKmmuGsb/3inQnuQsluCd3KJ2GgD7vI0QdXM9I=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=X3UtvJolzrFjmqEk95nEtf2Jm9Wgd6Ap1GfB8IcJ9/NI0N60Y6B6oMyGssiQ22Crls tOGXlv7x9xLgmM9hLoryNuGiwKazkJyJYzLbyOfbtlWKpWk1KiHlgp6utCSPFygUum6k x1tAJAuMgCK/do1tsK3rSv9C8FJqjHrpfxKpqBZ+8uH7s4PFtaewDy+fS/WgRofks8dd NPRfEf+X3IAYsyltuQhIH9xT85AOTUL9ksGaYKdd/aWtbxal9pITgxytAUwXzRX/0idb 6heCQ80668MMUG3JQImb4hefLoAIC2nAJDw2iL+q9/MEtSp0cr56krwt1ywZSxc2Gps1 oDgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id k23-20020aa79737000000b0068fdc320483si255570pfg.225.2023.09.18.12.11.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 12:11:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id F3F0C8021ED8; Mon, 18 Sep 2023 11:59:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbjIRS6z (ORCPT + 25 others); Mon, 18 Sep 2023 14:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbjIRS6o (ORCPT ); Mon, 18 Sep 2023 14:58:44 -0400 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42050109 for ; Mon, 18 Sep 2023 11:58:38 -0700 (PDT) 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-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 18 Sep 2023 11:59:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777403713467781106 X-GMAIL-MSGID: 1777403713467781106 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