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 0598FC32796 for ; Wed, 24 Aug 2022 13:02:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88AAC940009; Wed, 24 Aug 2022 09:02:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81358940007; Wed, 24 Aug 2022 09:02:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68CF1940009; Wed, 24 Aug 2022 09:02:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 556DA940007 for ; Wed, 24 Aug 2022 09:02:48 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2EC3DA0BFE for ; Wed, 24 Aug 2022 13:02:48 +0000 (UTC) X-FDA: 79834500816.12.AE71B08 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf21.hostedemail.com (Postfix) with ESMTP id C8AD51C005C for ; Wed, 24 Aug 2022 13:02:46 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id p18so15603366plr.8 for ; Wed, 24 Aug 2022 06:02:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=XAUfWXnBLgZU1RF+IGZaqoW6ICyj5iA/u5hjNGQLXxI=; b=ml6sUCaOrs4Y85o8JF0FnzbqASxpqnG1xaur25bhRlu+8c14xl+WPd/ubvyTD3AbaN 17lWfMoDrAaU8X9gjekNKYTMaq2Daz1G/0MjNxFYEVVHuzLxxfnm10/p0BmkC4h3D7hJ b+a42hRk7lo2lHHKkKKFnzU+26pTld7JervGIhLTiVgcC+kQLpa8RN+QbT7v2fWbfuHa JYdnHu70C2E7/ZToINbIG1KyI5eZ1ZwZPCFbtL4yFMnZ5E18fAaDWmO6pZ5ze08qyGY3 IpbCtM+XPP5G8EkhYMMjmElKVwL0prPlMbV7GIRM4KTmQLdqlnh/xFIBPv52+37FQbjr ag7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=XAUfWXnBLgZU1RF+IGZaqoW6ICyj5iA/u5hjNGQLXxI=; b=BlOudIV/S5heKE/vtuPrFpTq06YUjK3L+M+LvhkL73eYmbn2kcVgC6F3CblS0jHr9t 6DgUSh7dP36U1JiumaxC4+PGvBrN6TW8Q6aI6nmk/LxgRBt/d/syI/KbW8jzL50Dubs8 OFmt72Fwp/uZbt+BYNiboLtxFTR8BKmeLtN3s9dx9njBvnuQNI1MPG96rNk/dO9CwXA/ v29deSdS6RdDvYfPYLNCOHcg5SOzMLudNKYMr6Rr3vWsumQKRG8A9dDruBpaBovTaM0z v650YzgGwSgRvfID3hAtRWSVFD+rywNcjfMCE/YPT/SfX2kZDs2pkorDn0FmJ6JaMzyJ BWWQ== X-Gm-Message-State: ACgBeo2BUPn4To+amFledepEw11bwsMOCP0omLsBS/AFNyUs7N6ksTY7 1XbOJVpCX41lR1YuwCoD000smeY1dCODWQ== X-Google-Smtp-Source: AA6agR7iSr6MO5nHFFkVW+VyeKCo9O5k5c+zoHN0cgAt3sWclsbmuR9+RmWuMfqngSjjYWHw0xFOPQ== X-Received: by 2002:a17:90a:c78f:b0:1fa:e505:18e6 with SMTP id gn15-20020a17090ac78f00b001fae50518e6mr8465701pjb.23.1661346165672; Wed, 24 Aug 2022 06:02:45 -0700 (PDT) Received: from [192.168.43.80] (subs32-116-206-28-16.three.co.id. [116.206.28.16]) by smtp.gmail.com with ESMTPSA id c127-20020a621c85000000b0052ddaffbcc1sm12834062pfc.30.2022.08.24.06.02.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Aug 2022 06:02:45 -0700 (PDT) Message-ID: Date: Wed, 24 Aug 2022 20:02:40 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH v4 2/2] ksm: add profit monitoring documentation Content-Language: en-US To: xu xin , akpm@linux-foundation.org, corbet@lwn.net Cc: adobriyan@gmail.com, willy@infradead.org, hughd@google.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, xu xin , Xiaokai Ran , Yang Yang References: <20220824124512.223103-1-xu.xin16@zte.com.cn> <20220824124846.223217-1-xu.xin16@zte.com.cn> From: Bagas Sanjaya In-Reply-To: <20220824124846.223217-1-xu.xin16@zte.com.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661346166; a=rsa-sha256; cv=none; b=RecamyEUDvRbKxLE8UuzRlI/KaYKUdDgTyQW33h7davpgD9EpKU2R85+gWwcNqAHRGhqs+ qiNfJGYPsEJjk7GhLmCrexAvqxIcoZnWOdm+9H7udTSpepXMP4SMHjl+/XD3gIUPk9bejg 8u4Uyt0cgdo2D2FJiAPSlLGw3+yBepA= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ml6sUCaO; spf=pass (imf21.hostedemail.com: domain of bagasdotme@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=bagasdotme@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661346166; 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=XAUfWXnBLgZU1RF+IGZaqoW6ICyj5iA/u5hjNGQLXxI=; b=1cuyajp6H+WMfvSGvUbmoh6nqmAi4AmcRH4eEkFivMAyobVSWB+Ful6EBGebGlPneR2uA6 osTOStDhnzoSXbLCDjl2ij/QAtisnAfZMFDKsi61I+EJT31pgOLbmdvG6jWTT6oLJ4MH7x DgVo4Prb/eNyESGG/+63s4Z8l86D7aU= X-Rspam-User: X-Stat-Signature: 88gktg9d9kkjyuesqkcxuz13owe6t8hy X-Rspamd-Queue-Id: C8AD51C005C X-Rspamd-Server: rspam12 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ml6sUCaO; spf=pass (imf21.hostedemail.com: domain of bagasdotme@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=bagasdotme@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1661346166-171510 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 8/24/22 19:48, xu xin wrote: > +Monitoring KSM profit > +===================== > + > +KSM can save memory by merging identical pages, but also can consume > +additional memory, because it needs to generate a number of rmap_items to > +save each scanned page's brief rmap information. Some of these pages may > +be merged, but some may not be abled to be merged after being checked > +several times, which are unprofitable memory consumed. > + > +1) How to determine whether KSM save memory or consume memory in system-wide > + range? Here is a simple approximate calculation for reference:: > + > + general_profit =~ pages_sharing * sizeof(page) - (all_rmap_items) * > + sizeof(rmap_item); > + > + where all_rmap_items can be easily obtained by summing ``pages_sharing``, > + ``pages_shared``, ``pages_unshared`` and ``pages_volatile``. > + > +2) The KSM profit inner a single process can be similarly obtained by the > + following approximate calculation:: > + > + process_profit =~ ksm_merging_pages * sizeof(page) - > + ksm_rmp_items * sizeof(rmap_item). > + > + where both ksm_merging_pages and ksm_rmp_items are shown under the > + directory ``/proc//``. > + > +From the perspective of application, a high ratio of ``ksm_rmp_items`` to > +``ksm_merging_pages`` means a bad madvise-applied policy, so developers or > +administrators have to rethink how to change madvise policy. Giving an example > +for reference, a page's size is usually 4K, and the rmap_item's size is > +separately 32B on 32-bit CPU architecture and 64B on 64-bit CPU architecture. > +so if the ``ksm_rmp_items/ksm_merging_pages`` ratio exceeds 64 on 64-bit CPU > +or exceeds 128 on 32-bit CPU, then the app's madvise policy should be dropped, > +because the ksm profit is approximately zero or negative. > + > Monitoring KSM events > ===================== > LGTM. Reviewed-by: Bagas Sanjaya -- An old man doll... just what I always wanted! - Clara