Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp374343rdb; Mon, 18 Sep 2023 19:25:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSmAj29jJSwoTtSRGfVLlKSKFU1hxwbnBsKKRHUyKJo7X0NxMPdJd6BojhgpQoLpxpiIGb X-Received: by 2002:a05:6808:912:b0:3a7:2570:dcfc with SMTP id w18-20020a056808091200b003a72570dcfcmr11562982oih.43.1695090316030; Mon, 18 Sep 2023 19:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695090315; cv=none; d=google.com; s=arc-20160816; b=R/oaprnPcXM2DYwvUMDHrwyLd2ssYpskJ7XHI2kS68qM3D9BMJXlKwmrlJs81tmbJJ d4lfgmxeWzsvUSOcqTZHzcF3K0pglINLdspqN6RjhQxhyTcxcFuebhugZBs9cqsyN9NX WxGyvdO+xEPqBzjG39TyVkSVauMKY28nFnFeBHPXE1rxK5ssY93sr+3hszt2b8a5YY4+ Cfsdy9lMKqAW4l13kdaGdg5QpNRvx7eBK8jZpNNLQrBDgJCVcSAGjXu6fpawOFo3CjdY JX7eSQoS5jlOPbomKp7uTkdoZG6CXxojykYpJD4PUj6OkmH1qHtfm8z2f2zRJn4R1c0A wD7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:feedback-id:dkim-signature :dkim-signature; bh=GCXTb1jWNrkSvBUMw1jlbEFNJJNh08VrOT3LyJE/IuE=; fh=4yab9sgk6bnYvZDbVqikwkrODM5Y2lzG3PnlNfT3s6A=; b=K1JSyhqzftIgcB27J6rrc0zCEBAZKpjn1DgHt+Bnxmpn9r+MpfUgmkvY+sK8FitymS fuBQkmmJWxNzFqm4n176UDldzDmJHJif4A3cMbz12JzK9+b7js+DAQcQ8vW0fpLECwHW /uPvHBpna3mcdwrrgP+1dYRB+F4Gfvv8pEAEwc7D0YBQqu9RtKDF/cx4923eGoBE0x8P ilHSkjbiavnLGcU5ZOu6464StqTAN+2qwueJSd7wQK3W4iYGqPgNsk9ebUMJ+ZzYnLdk VS56jKCK/o35+b4gSd9meqQ2rmNmfJKZF0rgwaXXVSo5sA9m65KgmLODzBTiWjHASBHO iRyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@devkernel.io header.s=fm3 header.b=dI2VU9B4; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=V3XJ5sC+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id v9-20020a17090ad58900b00262ff3a4545si10803884pju.169.2023.09.18.19.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 19:25:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@devkernel.io header.s=fm3 header.b=dI2VU9B4; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=V3XJ5sC+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 2C395802B10E; Mon, 18 Sep 2023 11:50:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbjIRSuF (ORCPT + 99 others); Mon, 18 Sep 2023 14:50:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjIRSuE (ORCPT ); Mon, 18 Sep 2023 14:50:04 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72BACF7 for ; Mon, 18 Sep 2023 11:49:58 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 54C0B5C01E9; Mon, 18 Sep 2023 14:49:55 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 18 Sep 2023 14:49:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devkernel.io; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1695062995; x=1695149395; bh=GC XTb1jWNrkSvBUMw1jlbEFNJJNh08VrOT3LyJE/IuE=; b=dI2VU9B4pM2Ef8PrUX 4Y62eVvCS43pIHAkoKiRteuIsTmEjUOsbLzsfpLt2KtAeR1RRmiEKJfyCSlBmslK 4y+5z3NAtELpOYWw/FWbHclhgtEx7YciyKaUaXRFEzoeJoL2Oscwua1pxJP+q7gI J93jjccN3xyO1+QjBZucOrBXMVY+fXU/DL/zDtcjpkxC8YhtXka+ns7aKZoVy0ho aJIKIKE9kI7P399oukmlSs0Y9ZLeWidfQsGr/GTz/9XNkHbUASVpNDLqW58wCtTa T5U/R0JFOT4GVFZMrtR9wurs+6JZgiNzjPlK5PVYjkjdnYWHCdNM50WZinL2C8wc Tk7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1695062995; x=1695149395; bh=GCXTb1jWNrkSv BUMw1jlbEFNJJNh08VrOT3LyJE/IuE=; b=V3XJ5sC+hGOCRXQazHAQjgzHZEC4H 03I82mzu+StO45MHTrz0gY5Yetqc0D8oCkSKUK4LwKHBwjkfBLMgjmtKbOusveFe 8oowhWEosmOyGeRRyAIn4g3U2T+PLriIQv9hNvFSx4knNVm/7ukFvEmKjSOB+zXa xj3lQ7vz3JcNj00QBXXMoaCWu8H2Lis4bZV616ThU+pg8nJxZ5k7bdU2dFLx0Wjt IsmnTVBmI+73ubm66DCCh5pVbOl7yzpW4cHix/1Naw0oEhNdPXlREjcHpuU19Oay LsVwNKlW+hu4bDm3qI9FSDlHqbQZp0aHcJY+q/QCvePJQ4bkKu57wSZOg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudejkedgudeftdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfhgfhffvvefuffgjkfggtgesth dtredttdertdenucfhrhhomhepufhtvghfrghnucftohgvshgthhcuoehshhhrseguvghv khgvrhhnvghlrdhioheqnecuggftrfgrthhtvghrnhepveelgffghfehudeitdehjeevhe dthfetvdfhledutedvgeeikeeggefgudeguedtnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomhepshhhrhesuggvvhhkvghrnhgvlhdrihho X-ME-Proxy: Feedback-ID: i84614614:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 18 Sep 2023 14:49:54 -0400 (EDT) References: <20230912175228.952039-1-shr@devkernel.io> <20230912175228.952039-2-shr@devkernel.io> <20230913140750.616d3d87fe986a74d870b71f@linux-foundation.org> User-agent: mu4e 1.10.1; emacs 28.2.50 From: Stefan Roesch To: Andrew Morton Cc: kernel-team@fb.com, david@redhat.com, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v1 1/4] mm/ksm: add "smart" page scanning mode Date: Mon, 18 Sep 2023 11:47:57 -0700 In-reply-to: <20230913140750.616d3d87fe986a74d870b71f@linux-foundation.org> Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 11:50:11 -0700 (PDT) Andrew Morton writes: > On Tue, 12 Sep 2023 10:52:25 -0700 Stefan Roesch wrote: > >> 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_page is the age for how > > s/skip_page/skip_age/ > Fixed in the next version. >> 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. >> > > All seems nice. I'll sit out v1, see what people have to say. > > Some nits: > >> --- a/mm/ksm.c >> +++ b/mm/ksm.c >> >> ... >> >> @@ -2305,6 +2314,45 @@ static struct ksm_rmap_item *get_next_rmap_item(struct ksm_mm_slot *mm_slot, >> return rmap_item; >> } >> >> +static unsigned int inc_skip_age(rmap_age_t age) >> +{ >> + if (age <= 3) >> + return 1; >> + if (age <= 5) >> + return 2; >> + if (age <= 8) >> + return 4; >> + >> + return 8; >> +} > > "inc_skip_age" sounds like it increments something. Can we give it a > better name? > > And a nice comment explaining its role in life. > Renamed it to skip_age in the next version and added a comment. >> +static bool skip_rmap_item(struct page *page, struct ksm_rmap_item *rmap_item) >> +{ >> + rmap_age_t age; >> + >> + if (!ksm_smart_scan) >> + return false; >> + >> + if (PageKsm(page)) >> + return false; >> + >> + age = rmap_item->age++; >> + if (age < 3) >> + return false; >> + >> + if (rmap_item->skip_age == age) { >> + rmap_item->skip_age = 0; >> + return false; >> + } >> + >> + if (rmap_item->skip_age == 0) { >> + rmap_item->skip_age = age + inc_skip_age(age); >> + remove_rmap_item_from_tree(rmap_item); >> + } >> + >> + return true; >> +} > > Would a better name be should_skip_rmap_item()? > Renamed it to should_skip_rmap_item(). > But even that name implies that the function is idempotent (has no > side-effects). Again, an explanatory comment would be good. And > simple comments over each non-obvious `if' statement. > Added more comments to the function to explain the different cases. >> >> ... >>