Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1636348rdh; Mon, 25 Sep 2023 21:12:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9hQKClwYhBeA77A2Y2wk0oerGkCNwb/t/eTvaWr/vwCDgebLdMRV2hjdb8Pf9PERHeLW/ X-Received: by 2002:a05:6a20:8f18:b0:15d:7e2a:cc77 with SMTP id b24-20020a056a208f1800b0015d7e2acc77mr7594040pzk.48.1695701570624; Mon, 25 Sep 2023 21:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695701570; cv=none; d=google.com; s=arc-20160816; b=TXoC51LXq8/gbWCcW8dpdqHFKMDlXOXsFJapYaMyQfKqfwkJByS0V96SOG17jDAdS+ dnILKfxlVsF0vteaaPISTRYIaBpQwceZYbv+IV1TrvE4gH9l5mGB408ULPEmJwvLK67o /QZHTXGrW4xQD1yvJIQ+46w1gzSCPwmLPd5vFG3nWx3lJU5Qn4netUa0iM/G2Z23Sws2 xc7lvWej+kBcfkGtgko7M0u3xTGLRTHVI2pZQQItMgo54GX5a2mQCFpZo2XeSAHW2MAQ 9tXQ3kGhQ+s80lbGMvmjAATqPmRKi4WSD5wxgDkPENPuN9tevZYQrVlkXaOgOucEQTfn w0og== 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=quiZPEwVsomz+3qDn4CYAnjmi+qE0NI9Q5KbHcwpxC8=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=XGfPldkxwoKEmB36/Sfs4Y2Arf4vIBeZLzp+pqOb+cmiMKNWcepbzK9Jjkp3lsc/jg rBPoGb6Zeubcl7fMuTzh+91WrYow4VRTWW159WswOP6EibB6mQ/aXq21XoBbvolad+cR MkI4K/vYO+BEzA3KtymXY0YcURdpMaikc4SS20DX0gGTTywv3iNPnON2XXElvdcKYGKx A49kVmQG5ncQrVHtxgzkP4vnV12YSCOsc/0GrTRhgzG8hgoBD7zetO0biW2S8m5f4MZO fdeaUAnlAIB4vH1ximJsE0/5lLU/2Jg1oABMW6ZHZAM8djN5fK1g4RDmPWkdpoI3gvGT NnUg== 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 Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a5-20020a170902710500b001c4514c872fsi10790373pll.485.2023.09.25.21.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 21:12:50 -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 67A8D80ECF84; Mon, 25 Sep 2023 21:10:03 -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 S233371AbjIZEKG (ORCPT + 99 others); Tue, 26 Sep 2023 00:10:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbjIZEKE (ORCPT ); Tue, 26 Sep 2023 00:10:04 -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 F0450BF for ; Mon, 25 Sep 2023 21:09:57 -0700 (PDT) Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 5E7A2C8F2415; Mon, 25 Sep 2023 21:09:42 -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 0/4] Smart scanning mode for KSM Date: Mon, 25 Sep 2023 21:09:35 -0700 Message-Id: <20230926040939.516161-1-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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, 25 Sep 2023 21:10:03 -0700 (PDT) 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 how often we skip a page. 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 Changes: - V3: - Renamed field skip_age to remaining_skips - Moved fields after old_checksum - Changed should_skip_rmap_item to use remaining_skips field - V2: - Renamed function inc_skip_age() to skip_age() - Added comment to skip_age() function - Renamed function skip_rmap_item() to should_skip_rmap_item() - Added more comments to should_skip_rmap_item function - Added explicit modification of age with overflow check 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 | 115 +++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) base-commit: 15bcc9730fcd7526a3b92eff105d6701767a53bb --=20 2.39.3