Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2755285rdb; Tue, 12 Sep 2023 11:02:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7had8sJDGH+tr6UFqTrkmS+OVkpiR4Hx4BRUYbmdbaVzW5DDUpgG27FvTwzfg8752wrpb X-Received: by 2002:a05:6a20:734d:b0:12e:4d86:c017 with SMTP id v13-20020a056a20734d00b0012e4d86c017mr193088pzc.10.1694541730896; Tue, 12 Sep 2023 11:02:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694541730; cv=none; d=google.com; s=arc-20160816; b=lKIu9RK/rtjD1f8dIWftI18jCTEfitvXKley5eWKcC50ETWjyhipZmevov94fiTa0x HVLyFe2XdglQVexs380AdWPiT5JSQBHUGan2xeJkawgdofA0Zg/9J8xUl93jgDw4FMo+ xZg3Zs9gf6aa2z2ex26Qu1kBOKLT2/lq6xN7YGFjMlq5/SvorhkBxdg+HJFEh+Eh40gK aVw/TNIATFts7cl7f544Y4JPli1fkp1gp5/QSoB2RkTV9w2oafLz1MZ+2Lv7rCdm/PJr MPwOBse2sh90BxScPtrtNMP+l7O/0no0Aq856MPy8CHgPmGserSuM2tgbwMSp75/CspY zIqA== 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 :message-id:date:subject:cc:to:from; bh=l+n9FJ6lOfF30jIQ75PT+DFsBoxSFVNR8rLKeRoXW5k=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=uoypuZZsZ2K1bdeb3BN7Xx9Oe6b6vgTvn0XBr/gGCye4aY0wUjlMUyXEyVKfdFLnRn k69ZBLKwb79jLNBXP7YCi7V9xoKVWOKw76O0c0Y2+Aqj4Nq76MashM6/nZBC731TchI0 7OOrCDz9DGGZzx9I6RIXG7WrjlJzXHkzMARN8FGTfJemkgXnawH0neufCcwbPJYySCuo Yzco0/y0CjjZJc+xggx5QoO0H+pS6DsxtJy+2HJhcNrgxD3GUSFwQovrKZ9A+WcbT/o4 SOCU3co6uZISswszX07pgp9/X90Qd3si8mzvqltzI0nmSS5tWuJcVbv5mAcTNlLXzp6s 11sw== 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:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id g6-20020aa78746000000b0068e47f319d9si5464891pfo.280.2023.09.12.11.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 11:02:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 10BEE8167DB9; Tue, 12 Sep 2023 10:54:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237453AbjILRxq (ORCPT + 99 others); Tue, 12 Sep 2023 13:53:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236933AbjILRxX (ORCPT ); Tue, 12 Sep 2023 13:53:23 -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 C6EF01FF0 for ; Tue, 12 Sep 2023 10:52:54 -0700 (PDT) Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id D9E9DBCD1627; Tue, 12 Sep 2023 10:52:38 -0700 (PDT) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, akpm@linux-foundation.org, david@redhat.com, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1 0/4] Smart scanning mode for KSM Date: Tue, 12 Sep 2023 10:52:24 -0700 Message-Id: <20230912175228.952039-1-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 (lipwig.vger.email [0.0.0.0]); Tue, 12 Sep 2023 10:54:05 -0700 (PDT) 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 lipwig.vger.email This patch series adds "smart scanning" for KSM. What is smart scanning? =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D KSM evaluates all the candidate pages for each scan. It does not use hist= oric information from previous scans. This has the effect that candidate pages= that couldn't be used for KSM de-duplication continue to be evaluated for each= scan. The idea of "smart scanning" is to keep historic information. With the hi= storic information we can temporarily skip the candidate page for one or several= scans. Details: =3D=3D=3D=3D=3D=3D=3D=3D "Smart scanning" is to keep two small counters to store if the page has b= een used for KSM. One counter stores how often we already tried to use the pa= ge for KSM and the other counter stores when a page will be used as a candidate = page again. How often we skip the candidate page depends how often a page failed KSM de-duplication. The code skips a maximum of 8 times. During testing this = has shown to be a good compromise for different workloads. New sysfs knob: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Smart scanning is not enabled by default. With /sys/kernel/mm/ksm/smart_s= can smart scanning can be enabled. Monitoring: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D To monitor how effective smart scanning is a new sysfs knob has been intr= oduced. /sys/kernel/mm/pages_skipped report how many pages have been skipped by s= mart scanning. Results: =3D=3D=3D=3D=3D=3D=3D=3D - Various workloads have shown a 20% - 25% reduction in page scans For the instagram workload for instance, the number of pages scanned ha= s been reduced from over 20M pages per scan to less than 15M pages. - Less pages scans also resulted in an overall higher de-duplication rate= as some shorter lived pages could be de-duplicated additionally - Less pages scanned allows to reduce the pages_to_scan parameter and this resulted in a 25% reduction in terms of CPU. - The improvements have been observed for workloads that enable KSM with madvise as well as prctl Stefan Roesch (4): mm/ksm: add "smart" page scanning mode mm/ksm: add pages_skipped metric mm/ksm: document smart scan mode mm/ksm: document pages_skipped sysfs knob Documentation/admin-guide/mm/ksm.rst | 11 ++++ mm/ksm.c | 87 ++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) base-commit: 15bcc9730fcd7526a3b92eff105d6701767a53bb --=20 2.39.3