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 C9BC2C28D13 for ; Mon, 22 Aug 2022 21:10:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D32E8D0002; Mon, 22 Aug 2022 17:10:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 182558D0001; Mon, 22 Aug 2022 17:10:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04C2C8D0002; Mon, 22 Aug 2022 17:10:11 -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 EB5478D0001 for ; Mon, 22 Aug 2022 17:10:10 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BDA7DAB357 for ; Mon, 22 Aug 2022 21:10:10 +0000 (UTC) X-FDA: 79828471380.31.F5413A5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 3F03E40083 for ; Mon, 22 Aug 2022 21:08:46 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 84C646130B; Mon, 22 Aug 2022 21:08:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2D3EC433C1; Mon, 22 Aug 2022 21:08:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1661202525; bh=nKbiyNWYpVKB+Hwt2mf/xNvxcNjbAbIus/sQjP8jnW0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LBb/wjffwju7RJR12v2axipRiMOItkI7iMW6Uh4KYfDKSVtlaTO5RzkJxt24N0eDZ 15xjNUw5vEr1u+oswKkWyMfGX6T+VoA7QsdV4KNVpN36Trr3LNf89PEOuCsP0OpmL5 lPvd03vcEP0kHIiIVj0eTqjUIVsdxspxaOM80dEE= Date: Mon, 22 Aug 2022 14:08:44 -0700 From: Andrew Morton To: xu xin Cc: adobriyan@gmail.com, willy@infradead.org, hughd@google.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, xu xin , Xiaokai Ran , Yang Yang Subject: Re: [PATCH] ksm: count allocated ksm rmap_items for each process Message-Id: <20220822140844.26cfb85dead5e0e5c4de4737@linux-foundation.org> In-Reply-To: <20220822053653.204150-1-xu.xin16@zte.com.cn> References: <20220822053653.204150-1-xu.xin16@zte.com.cn> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="LBb/wjff"; dmarc=none; spf=pass (imf01.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661202526; a=rsa-sha256; cv=none; b=nnE22ruiCH4fC6xeejRBT1h1lgv3h3ru6TDu64axAMqSpr2Yjwrh7uy3RS/anZ/BjvjcIF quTSz9Si3jOBxUadHk1jvuHvzWyTFueQA2qQEvHpcplcX0lkf07nlO9F0/d1TybDbrc+Nv OEK8UlsPukLNErIs+6ekVUXf/kpUHkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661202526; 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=0nmbSrVgEw9WDqiC/Qbkt5DAYvSXKfUcIIBVN18qeWw=; b=sRVvS0j/lhnkmNAkUuuOfM2I7W41fog1kjp17uRZQKFMUnM/crfL9Qp2cdZOKhm+Vx3mgm cnsMwnIZ2a+6rnaHnFyo44MiQKHVlSfltbXkszEHBNPb1GAPCOSz0EPnr+PkEe8/3L7vXt rx4hYpMJVVU+RnRQVTpdDF9EnZfFEDU= X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="LBb/wjff"; dmarc=none; spf=pass (imf01.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: 747wjj5j8wjjzqrkdsfxxzgfk44naxmg X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3F03E40083 X-HE-Tag: 1661202526-992692 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 Mon, 22 Aug 2022 05:36:53 +0000 xu xin wrote: > KSM can save memory by merging identical pages, but also can consume > additional memory, because it needs to generate 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. > > The information about whether KSM save memory or consume memory in > system-wide range can be determined by the comprehensive calculation > of pages_sharing, pages_shared, pages_unshared and pages_volatile. > A simple approximate calculation: > > profit ≈ pages_sharing * sizeof(page) - (all_rmap_items) * > sizeof(rmap_item); > > where all_rmap_items equals to the sum of pages_sharing, pages_shared, > pages_unshared and pages_volatile. > > But we cannot calculate this kind of ksm profit inner single-process wide > because the information of ksm rmap_item's number of a process is lacked. > For user applications, if this kind of information could be obtained, > it helps upper users know how beneficial the ksm-policy (like madvise) > they are using brings, and then optimize their app code. For example, > one application madvise 1000 pages as MERGEABLE, while only a few pages > are really merged, then it's not cost-efficient. > > So we add a new interface /proc//ksm_alloced_items for each > process to indicate the total allocated ksm rmap_items of this process. Please add documentation for this profcs item in the appropriate place under Documentation/. And please ensure that the documentation provides readers with a decent amount of information about how to use this information to improve their system's operation.