From mboxrd@z Thu Jan 1 00:00:00 1970 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 927C6CE7A91 for ; Tue, 26 Sep 2023 03:53:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 034FF6B0176; Mon, 25 Sep 2023 23:53:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F25856B0177; Mon, 25 Sep 2023 23:53:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DECEB6B017A; Mon, 25 Sep 2023 23:53:00 -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 CCB986B0176 for ; Mon, 25 Sep 2023 23:53:00 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 884E71A0EA2 for ; Tue, 26 Sep 2023 03:53:00 +0000 (UTC) X-FDA: 81277377720.21.9CD5BE7 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by imf28.hostedemail.com (Postfix) with ESMTP id 2CD6CC0008 for ; Tue, 26 Sep 2023 03:52:56 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=devkernel.io header.s=fm3 header.b=xpr6rCnO; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=Doal7zx+; spf=pass (imf28.hostedemail.com: domain of shr@devkernel.io designates 64.147.123.19 as permitted sender) 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=1695700377; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n5F6m7owvTyikPwb8qUq8E6SUtaRPWY4heCu/VudUyI=; b=4zvu7WiosBLDCk2jUQ8jONRHnhIaiKbCIoJtnTSfd5sY5mUfTYPCmhRrBMTCwWsQUsgddF L7WHMlakCEkCcUCC9EudtulDB7Mk6udgghd2rBR4qV3wy+RuoN87Y7HA/rZzlfArTRB/9D B8C+azk4Epz2yK2wWONgirG5TWk0gOY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695700377; a=rsa-sha256; cv=none; b=Ym5JwXjNmmAfATjvcSYGIJNTzDasFGiZxPPlv+obumoyrEtuf5aCPXw8FBzRWpsh24S1N9 QQT6qbV5ECMziU25IdSAbD6SFzeXF8QNeJ/UEhatQdWZhH0el3m1amGSRr3Rt2UZAZVXx7 BLMVLX8ept3jAE/m367EaTpbTZ2ecj4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=devkernel.io header.s=fm3 header.b=xpr6rCnO; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=Doal7zx+; spf=pass (imf28.hostedemail.com: domain of shr@devkernel.io designates 64.147.123.19 as permitted sender) smtp.mailfrom=shr@devkernel.io; dmarc=none Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 9D87D3200A62; Mon, 25 Sep 2023 23:52:54 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 25 Sep 2023 23:52: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=1695700374; x=1695786774; bh=n5 F6m7owvTyikPwb8qUq8E6SUtaRPWY4heCu/VudUyI=; b=xpr6rCnOy+rlnHBCVH iC3XmoPJ7a0Qe+xqvyxOhQz4pcCWQGE0apFZ4BnRu2KhgeuOrltfJN1AozXjsukT G7bU9HxYRehf1g/L5VdazF8WmkUphloNcHlXhXxNn4ck2Ec0hypXkFGYOAZgnvjJ rp130MFz6t+7v3GxhAi+k71QSHV+1hlJv4aIFmpVT1JL/Y8+kOx67phU8xyLLAzN WbRf8j5OY6cXWsIyQjpYoDmimJF3xd3RYpqhDuCuAwrHEYyK2Cm6y5hP3SXqSn53 YqYkRon8hwtHIt7Q3QXjnqN+NXR1j77wnM5I9Gkkwi08y19qhzlnGDZaMQOyLN4R UJWQ== 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=1695700374; x=1695786774; bh=n5F6m7owvTyik Pwb8qUq8E6SUtaRPWY4heCu/VudUyI=; b=Doal7zx+qrN7JLg3BU7kNHBbpslwr Uu/xPJcuBMTzoMUkDBVUcAPs9TQAR0vCsO0UZJd8wlkf+99pTbjiWpvq2yT+sU93 mAJyHpTbzGF8sKofb/A0IWQf5giUgnWe28z9RBUOIjqMzEx2jlbCrjP/eFiDe+TO p3pidDwbJ86wDMZovKsGphg0wTlD0brL2Ex+o3HbeI6HufgLWnTX4vQMpNgWGd3O 2EJyHItMYcasvqhumLeGWgAL1Ow0eiEq0bJdKQQnlh7mKfGdJn1CnMDNmB/JYmHU 6mZXnNPqfQOTcbDixV9kkLF6Z3QTw5foPEZbYI+/nDQxWUxDOuwnhhk+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudelhedgjeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfhgfhffvvefuffgjkfggtgesthdtredttdertdenucfhrhhomhepufhtvghf rghnucftohgvshgthhcuoehshhhrseguvghvkhgvrhhnvghlrdhioheqnecuggftrfgrth htvghrnhepveelgffghfehudeitdehjeevhedthfetvdfhledutedvgeeikeeggefgudeg uedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsh hhrhesuggvvhhkvghrnhgvlhdrihho X-ME-Proxy: Feedback-ID: i84614614:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 25 Sep 2023 23:52:52 -0400 (EDT) References: <20230918185816.1518366-1-shr@devkernel.io> <20230918185816.1518366-2-shr@devkernel.io> User-agent: mu4e 1.10.1; emacs 28.2.50 From: Stefan Roesch To: David Hildenbrand Cc: kernel-team@fb.com, akpm@linux-foundation.org, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 1/4] mm/ksm: add "smart" page scanning mode Date: Mon, 25 Sep 2023 20:52:09 -0700 In-reply-to: Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 2CD6CC0008 X-Rspam-User: X-Stat-Signature: 9f59yknguxqimqexiokromcsb41ehszc X-Rspamd-Server: rspam03 X-HE-Tag: 1695700376-689028 X-HE-Meta: U2FsdGVkX18jKoDIgB+F2HjqIaVnNwnojgbYBMaX9rQ9LuwJ66gfaNxJt9zn3U+v5Aoia5YDoUfr8zNKNEjy8Tz9jzQMi2zZBed/4lCX/Ngpcx3hmbHajiIQ2iOjJsH4HgvtebvaBkm1U7K28eU/yH00g4uSAoSwmSkVM+9dvHBKGVMR0dwGy0cpS9uXDllA4i1Y79OZbBcmjN6lHbSZwLLJIdcCDWzVEPj3x14a1OyNdvcoKP61DuWahxV9zIuIb7+rfspd85GzFPku9FCWXpehMA9VaKzx+ymxg4/te0pBBPIpAZbUDqfnAQBATgJOnqj3Um0ygWzCedroajq+cyIlZfTN75idqO0kYTisrBidEMY06ERpdLTpZzIUC2jbGlgTcX/0fQnJVyKXIntY++Wfl/xJ5Xi06c2OYqHqHhRu2m209xeOnnB/Nm/3l8/ImPogDOf34YpFOEvdPskMF5EKgXC2HBlpyWZJpTSBLfwj0C9wB9kIhl0QTyCjb6LAiwZjv155tsLNT4sbaIgvezCV2iQ4EAaCJA404hOtD4s9dYAt82fM2TaPlNNW4V/3rKVx5nyE8reIxnXJ2hTNykhL2aUiAfTuLdncHJtb7H7I9Q2+FQ8zpUBSSeU5anzGF3ugani+lN3nICiz2ooQ1W/iXH3SaXL3PYrKF9t8cFTHY/C9dobgn7B8orKCLZXIBxy7ed/XeU3Lc2desGAvTtIw9G+XcUHJYlCNo06q/ha98Nd2O5Khrm7h6On4PIl4SGI2j1tTGd4fAIqj+y8XA+KKjmJri5Mf5G4Of4p4l1DczPrdJWfqdWbhxaoC2ljoUrlz5MmMJFMSLq1VokFjF5l6OkPzc32tfpALbTCcG7yebk4nU0BOZX+0aiAaqd9KHBYgxiEfDWBTNcq0HpHWrkZ9jFG7viHcCjDtwAi4eYuqtR2oK04KG5jVLqpRBiOzuKagZv/FASm+dIH50Pj m6DGb8H+ JFt+Wd0BjCyT2rHDr43WlEVWLc7nhoatOw5c4dJXd2C6CtSQ+WzMHNxJ9L4vOZsWuKoJ6qtNuhyZdviQjtIzHHzHAo3rSukb//GIjqa40qJ5HnkTYWTui1oDNaNn41M0GMGxW318ZfIhxbeSCodu7QtaoXA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: David Hildenbrand writes: >> +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; > > I *think* of you move that after "oldchecksum", the size of the struct might not > necessarily increase. > > [...] > >> +/* >> + * 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. >> + */ > > Sorry, had to set some time aside to think this through. Wouldn't it be cleaner > to just not rely on this overflow? > > Instead, we could track the page age (which we would freeze at U8_MAX) and > simply track how much more often we are allowed to skip. > > Something like the following (which, I am sure, is completely broken, but should > express what I have in mind) > > > > 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; > > > > Would that miss anything important? Was the overflow handling (and scanning more > often one we overflow again IIUC) important? > That sounds reasonable. I'll incorporate the two suggestions in the next version.