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 08532C77B6C for ; Wed, 5 Apr 2023 21:31:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 432846B0075; Wed, 5 Apr 2023 17:31:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E3BE6B0078; Wed, 5 Apr 2023 17:31:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 283856B007B; Wed, 5 Apr 2023 17:31:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 186216B0075 for ; Wed, 5 Apr 2023 17:31:25 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C17D81A0BBB for ; Wed, 5 Apr 2023 21:31:24 +0000 (UTC) X-FDA: 80648633688.02.CCED11C Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by imf29.hostedemail.com (Postfix) with ESMTP id 2C3BE120013 for ; Wed, 5 Apr 2023 21:31:20 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=devkernel.io header.s=fm3 header.b=XrSaSnmR; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=J3pbKhKZ; spf=pass (imf29.hostedemail.com: domain of shr@devkernel.io designates 66.111.4.25 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=1680730281; 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=FBIggV7bE2CLxugCSVAleO54ungHAYPbbVABvtF3t4Y=; b=VJJODn5svEURTibnnPTLMIWqPfu99gUkOiCx63RQwSL1vMESg0atjmdWhGQCTXWV5lZtKI KFNHwIvOXjShqXoXbxgxmdDIZoW82gTh0bbRJFPMJNrsm1UDkJX11UV+YeBitKVC2OlWcX r9R55N5moyVf3z4nprCVl87+rfNrxD8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=devkernel.io header.s=fm3 header.b=XrSaSnmR; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=J3pbKhKZ; spf=pass (imf29.hostedemail.com: domain of shr@devkernel.io designates 66.111.4.25 as permitted sender) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680730281; a=rsa-sha256; cv=none; b=IVJ+S4ra+4j/ZND3kAx7s1YczS80Q6zJhkdmiQgVOQG/b79BdHDg9/Pv22L8gbRsYeKvPI UTp3zf5HhiEprNTIRts4SCls65cLXA87vYREyyhB7rSWeHuhiaORj0+21RLKOSIxLqrm6w qolS3NH/xog+KEzI3+JqxaT8fkkEuzA= Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5EC4A5C004D; Wed, 5 Apr 2023 17:31:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 05 Apr 2023 17:31:20 -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=1680730280; x=1680816680; bh=FB IggV7bE2CLxugCSVAleO54ungHAYPbbVABvtF3t4Y=; b=XrSaSnmROk71DrVAgi QmaTrjH4ETY1+XoaYuRJISZ/pI/FZ5ogcvfPc3kfssPQTCq9eHdtQqvFzOAws4LQ AVCrr5fdjpyebktlfht9lRIwiVqMzbVsJx5dNTOuNOI+NSAYENu7u/kOiuDPFvU+ bs90sgOkIgjJrRcFJj0bRlsMV5BGiGsgktHdRHZsHcSZ6y7/nIGvBhQR49uDywRz S3jUXfXyKxvKgpGdZsGrSorBQSyCEjDt1IUlynLMjmEeSJB2T94mnP5XHsw9xqmG FJTtgg1S59Y8dQfRqVh6A/RFZVCTGwR5ZyD+EAyoOEoJO/h97btZW9xT7ivphuRQ aCmg== 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=1680730280; x=1680816680; bh=FBIggV7bE2CLx ugCSVAleO54ungHAYPbbVABvtF3t4Y=; b=J3pbKhKZpku2ttX/Un7hljU+h05pI mSUGgJ3yq2bCMjFCMmq/T8DGVhEqHXciNetD7Kz6wCJsvgNcKKQKF3Ex8bPqA66f G5h2NTpTyTP7bGpUp12Uw52KlNAlGb2RSXNozjVP8tabnT3OF7GbwYaww5IJGNvV cDxiAjln5DmEsyQsgYHB7XVvC889XA4UGSSxiMAffkX6DrcIF4bmq6vsBWOXbhPK OBXd57da3RHUIFT7wBHfKX+5MCzDameHrggblkwkMrhwEy5dOXI8dVrj2fJ5cZYr 6i28cejyVq5Vbv+npic9anZOThz14bMlodLShhLTju6YSog54YAdWMNnw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdejuddgudeigecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpehffgfhvfevufffjgfkgggtsehttdertddtredtnecuhfhrohhmpefuthgv fhgrnhcutfhovghstghhuceoshhhrhesuggvvhhkvghrnhgvlhdrihhoqeenucggtffrrg htthgvrhhnpefhgfejveduudehvdduvefguddvffefgffhieeuudefudfhhfeijeefjeff heelvdenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepshhhrhesuggvvhhkvghrnhgvlhdrihho X-ME-Proxy: Feedback-ID: i84614614:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Apr 2023 17:31:18 -0400 (EDT) References: <20230310182851.2579138-1-shr@devkernel.io> <20230310182851.2579138-3-shr@devkernel.io> User-agent: mu4e 1.6.11; emacs 28.2.50 From: Stefan Roesch To: David Hildenbrand Cc: kernel-team@fb.com, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org, hannes@cmpxchg.org, Bagas Sanjaya Subject: Re: [PATCH v4 2/3] mm: add new KSM process and sysfs knobs Date: Wed, 05 Apr 2023 14:20:27 -0700 In-reply-to: Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2C3BE120013 X-Rspam-User: X-Stat-Signature: q1xfrs9zftd3pmxsszda1s4bihw1upin X-HE-Tag: 1680730280-855701 X-HE-Meta: U2FsdGVkX194X5aJe/ofM3nPkoiZOWmMQ633XqhQVUfejJGhLwZFXUPNnr3X4lXbki1HFcUOcyfeM8Dc7b7mC4lidqAhRDD5y0UPl//Sh5zQCaiav2see/iwxrLTbf/pnwaCe3u/TZ0mnpIWeC7FcrpJvA+lhCYdKEZg2EOUaOKqgrRnDj89OyHMVcNKDUeMM4YmkQqp45BtKRvKrXaQ+PgtAQhAZ34BJAw76LJLkPbjydefMyZg0RuGoEGDjjkTlltaxCUWrXeNgav6k5F8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oVCknk0Im+dj6RkOLH9BBYgQMyOWbRrWOW5b4hmHnYruT5DTT7rkiji1wBHHeNyEe7lGgkp6BqYvsBCJqBuhQ5UlHNsarMjgtR8DPQalIgLM8aU4Ts03yoce6w= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: David Hildenbrand writes: > On 10.03.23 19:28, Stefan Roesch wrote: >> This adds the general_profit KSM sysfs knob and the process profit metric >> and process merge type knobs to ksm_stat. >> 1) split off pages_volatile function >> This splits off the pages_volatile function. The next patch will >> use this function. >> 2) expose general_profit metric >> The documentation mentions a general profit metric, however this >> metric is not calculated. In addition the formula depends on the size >> of internal structures, which makes it more difficult for an >> administrator to make the calculation. Adding the metric for a better >> user experience. >> 3) document general_profit sysfs knob >> 4) calculate ksm process profit metric >> The ksm documentation mentions the process profit metric and how to >> calculate it. This adds the calculation of the metric. >> 5) add ksm_merge_type() function >> This adds the ksm_merge_type function. The function returns the >> merge type for the process. For madvise it returns "madvise", for >> prctl it returns "process" and otherwise it returns "none". >> 6) mm: expose ksm process profit metric and merge type in ksm_stat >> This exposes the ksm process profit metric in /proc//ksm_stat. >> The name of the value is ksm_merge_type. The documentation mentions >> the formula for the ksm process profit metric, however it does not >> calculate it. In addition the formula depends on the size of internal >> structures. So it makes sense to expose it. >> 7) document new procfs ksm knobs >> > > Often, when you have to start making a list of things that a patch does, it > might make sense to split some of the items into separate patches such that you > can avoid lists and just explain in list-free text how the pieces in the patch > fit together. > > I'd suggest splitting this patch into logical pieces. For example, separating > the general profit calculation/exposure from the per-mm profit and the per-mm > ksm type indication. > Originally these were individual patches. If I recall correctly Johannes Weiner wanted them as one patch. I can certainly split them again. >> Link: https://lkml.kernel.org/r/20230224044000.3084046-3-shr@devkernel.io >> Signed-off-by: Stefan Roesch >> Reviewed-by: Bagas Sanjaya >> Cc: David Hildenbrand >> Cc: Johannes Weiner >> Cc: Michal Hocko >> Cc: Rik van Riel >> Signed-off-by: Andrew Morton >> --- > > > [...] > >> KSM_ATTR_RO(pages_volatile); >> @@ -3280,6 +3305,21 @@ static ssize_t zero_pages_sharing_show(struct kobject >> *kobj, >> } >> KSM_ATTR_RO(zero_pages_sharing); >> +static ssize_t general_profit_show(struct kobject *kobj, >> + struct kobj_attribute *attr, char *buf) >> +{ >> + long general_profit; >> + long all_rmap_items; >> + >> + all_rmap_items = ksm_max_page_sharing + ksm_pages_shared + >> + ksm_pages_unshared + pages_volatile(); > > Are you sure you want to count a config knob (ksm_max_page_sharing) into that > formula? I yet have to digest what this calculation implies, but it does feel > odd. > This was a mistake. I wanted ksm_pages_sharing instead of ksm_max_page_sharing. > > Further, maybe just avoid pages_volatile(). Expanding the formula (excluding > ksm_max_page_sharing for now): > > > all_rmap = ksm_pages_shared + ksm_pages_unshared + pages_volatile(); > > -> expand pages_volatile() (ignoring the < 0 case) > > all_rmap = ksm_pages_shared + ksm_pages_unshared + ksm_rmap_items - > ksm_pages_shared - ksm_pages_sharing - ksm_pages_unshared; > > -> simplify > > all_rmap = ksm_rmap_items + ksm_pages_sharing; > I'll simplify it. > Or is the < 0 case relevant here? > A negative profit is ok. >> + general_profit = ksm_pages_sharing * PAGE_SIZE - >> + all_rmap_items * sizeof(struct ksm_rmap_item); >> + >> + return sysfs_emit(buf, "%ld\n", general_profit); >> +} >> +KSM_ATTR_RO(general_profit); >> + >> static ssize_t stable_node_dups_show(struct kobject *kobj, >> struct kobj_attribute *attr, char *buf) >> { >> @@ -3345,6 +3385,7 @@ static struct attribute *ksm_attrs[] = { >> &stable_node_dups_attr.attr, >> &stable_node_chains_prune_millisecs_attr.attr, >> &use_zero_pages_attr.attr, >> + &general_profit_attr.attr, >> NULL, >> }; >> > > The calculations (profit) don't include when KSM places the shared zeropage I > guess. Accounting that per MM (and eventually globally) is in the works. [1] > > > [1] > https://lore.kernel.org/lkml/20230328153852.26c2577e4bd921c371c47a7e@linux-foundation.org/t/