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 09C22C76188 for ; Wed, 5 Apr 2023 17:04:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 658566B0083; Wed, 5 Apr 2023 13:04:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B82E6B0087; Wed, 5 Apr 2023 13:04:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 431A66B0089; Wed, 5 Apr 2023 13:04:44 -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 2C7556B0083 for ; Wed, 5 Apr 2023 13:04:44 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 07E6CC0108 for ; Wed, 5 Apr 2023 17:04:44 +0000 (UTC) X-FDA: 80647961688.01.7AF9CF2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 49EF140020 for ; Wed, 5 Apr 2023 17:04:40 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J7ZM0iS9; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680714280; a=rsa-sha256; cv=none; b=aZncPmcubEEG7npUvAftJidr+SmcU4YR/lJnZjICTgMzRnyO2E484fqa3K/cxzQWvcpdJV XkUGV+RSID/5/COcHExPvSI/+xZi7G7RScjFKVmgFuXXEgPVDMrcM8Vq0473RgM/MwD50Q H3WzlG/7zHN1uH/SPQehVd1kPGwOzEg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J7ZM0iS9; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680714280; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cJP3QkjqCwycJfPPFlfynLksaPqkFMupu9ad2mCFYko=; b=v+cCXw3ado7Gnpf6HTbBh1VTnHtcMIjAH2d2vB5vDwjM452mmoxbTlYVogigN9P7deAwt/ JGT//2i6f9ppofGOx7RZl/PerjZqYC1s0UDah+Dqo8hZ6QQ/1Mw7w1h5WzpwdZYkhmmhlu tNijWMVuplyKLDM49oXmREqJLIwdMes= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680714279; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cJP3QkjqCwycJfPPFlfynLksaPqkFMupu9ad2mCFYko=; b=J7ZM0iS9sU+mgj1UKpcTde7pq7rh9KMT5cXFEeoZbTyr+o0XnK4vaMtn/prVjo5SId/QV4 mqw3hTL5wv81g2qt3FOScnKpjOTGqSKJRbbNGOCR2sGRzEB4BotQE0RlqtSeqqSH74M0VG OS5ISfdee5+iXp6Hzzlf5U57XnipBsU= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-38-sCRteaTIOESXhyQlFCCd6w-1; Wed, 05 Apr 2023 13:04:28 -0400 X-MC-Unique: sCRteaTIOESXhyQlFCCd6w-1 Received: by mail-wm1-f71.google.com with SMTP id p10-20020a05600c358a00b003edf7d484d4so17806161wmq.0 for ; Wed, 05 Apr 2023 10:04:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680714255; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cJP3QkjqCwycJfPPFlfynLksaPqkFMupu9ad2mCFYko=; b=YkOHppqg+7I5eFPrnaF/+B3V9nN4LcTO2xgE+ADk3+w/NYvzFUfAK3EmEwp7Y0Hqk9 H37g+ykDR0iYpkzM7UKwPA3hs59T6O4BfeDuMgySYooh5Km8waDbCLyR+b8zd4V+mMzC wfKu8unOh1gm3NdXlsy9C5/brIBQO/osseuV8sZgL+Y0SJ5UG+lFxYfaRmZf0OA7QQd7 qRJkgwPXTmQSMv+AZWfdJQQsYyPrnHkNNlm4oBZ71/9+B+o96h93cEYxnGdrH5hvHoBi sVKZ489LTsN/eF2b4pyMMoOzc7u2mYH7Fyq3lorq8s9lEpBI/a0oJqp+dpHnCBSnx//9 NaIg== X-Gm-Message-State: AAQBX9dB/7Mgi1is7F8Zh0KZgHlZUc+OwdoaFYmYtADDJAAtxNqWk/Jl 0DQfy3F9j6nXFceMMDzAc7jGR0PurxiZUtL+U2aSlMoJ2pI6jTDUR+6Xqcf1VdrTVvMiWgoDjfX vb3nFMA2Dw88= X-Received: by 2002:a05:600c:ad2:b0:3ef:624a:d042 with SMTP id c18-20020a05600c0ad200b003ef624ad042mr4920524wmr.17.1680714255267; Wed, 05 Apr 2023 10:04:15 -0700 (PDT) X-Google-Smtp-Source: AKy350amhqFteNi09T2ntknFXQ4YviCJPSlDHhxXZw76znlymOYkAKOaTd5dRq5YRgcFSyRLORQKDA== X-Received: by 2002:a05:600c:ad2:b0:3ef:624a:d042 with SMTP id c18-20020a05600c0ad200b003ef624ad042mr4920503wmr.17.1680714254958; Wed, 05 Apr 2023 10:04:14 -0700 (PDT) Received: from ?IPV6:2003:cb:c703:d00:ca74:d9ea:11e0:dfb? (p200300cbc7030d00ca74d9ea11e00dfb.dip0.t-ipconnect.de. [2003:cb:c703:d00:ca74:d9ea:11e0:dfb]) by smtp.gmail.com with ESMTPSA id m19-20020a7bce13000000b003ee1acdb036sm2750457wmc.17.2023.04.05.10.04.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Apr 2023 10:04:14 -0700 (PDT) Message-ID: Date: Wed, 5 Apr 2023 19:04:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 To: Stefan Roesch , kernel-team@fb.com Cc: 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 References: <20230310182851.2579138-1-shr@devkernel.io> <20230310182851.2579138-3-shr@devkernel.io> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v4 2/3] mm: add new KSM process and sysfs knobs In-Reply-To: <20230310182851.2579138-3-shr@devkernel.io> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: 49EF140020 X-Rspamd-Server: rspam01 X-Stat-Signature: jio8yxopyuca9mfp1sfg3mc9xxhxzjpx X-HE-Tag: 1680714280-121028 X-HE-Meta: U2FsdGVkX18+4+2eQBc5ZjO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ynmdpuKJbZcFLNa8ziC0yz+/SY5w7tMoOQPRht4o+ERpWRfaH/O2WHypqJBm1+I4/EZiboVBnee3JjQ8MCBdH/inOji9aX5SW3+eHvuF5Rw7AU+qYq3jxyPvqU+gBPTpsAcoGvTv+rrDPze5r0XXgnfO6rHyEylrJQq66fjftY+3+8SQad8WbJ4miUvvMX64wzJhUNn9UpQH4iLDxRYnORMeg7K0kqEL7VXw2QO5V2pCT3BGmCYxEKPi2WNOO5clnxvX9JmVAAHIbC9/FM1HanGqXL5V2O7kk/qZeF3NYZ7BQbjE/vw/wRTSqmDmoFjbvIyOlfbQI9613JYyYzOUG7N/ZRr1GGdlnkUV4S0ms1DYu7lVwOULgQZ7YfXAafhmhCrk/KMohNwNbhik1JmladYHjtm/julnB3ZuSo2LIibItauSySXC/0WcdXEVE6e0cX2FKuxNZ2+v68S5DV+MogUDei43RnoAV+wWZy1UOKq/g32sheK8Egqf17G6LWZ1EvC+LasnLhGLEO7K0Eg1WT/Wst4rdCia7HukBArTYY3ZzsemOsUFvn3gbBonguHS45gAqz2udiQeIGNExzgtVJBl9VDLaBH/vXfcN0TOTbFJA= 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: 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. > 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. 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; Or is the < 0 case relevant here? > + 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/ -- Thanks, David / dhildenb