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 1440BC3271E for ; Thu, 11 Jul 2024 05:19:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7AA3A6B0089; Thu, 11 Jul 2024 01:19:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 759EA6B0093; Thu, 11 Jul 2024 01:19:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F9FB6B0095; Thu, 11 Jul 2024 01:19:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3D3F96B0089 for ; Thu, 11 Jul 2024 01:19:51 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D9BF91A03D9 for ; Thu, 11 Jul 2024 05:19:50 +0000 (UTC) X-FDA: 82326319740.28.B821BE5 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf20.hostedemail.com (Postfix) with ESMTP id CBBEB1C000F for ; Thu, 11 Jul 2024 05:19:47 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=BZlrQIN+; spf=pass (imf20.hostedemail.com: domain of sfoon.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=sfoon.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720675156; 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=FaXfwVv7F7bstL5whS5p0F9Y3saXeyxNh9uAI5iTpxI=; b=Jf3Pb9vsQZO73C4OopltGe+yy6/ZtXHSRBWvps9jJ3CXQvjzFT5lrP1lOXPluvWw4HHbMC v6bK9yDxZiV10t+VwTFNGIpWF9UzUh6/5Vh98PfUxaUhvdhBRmUp6FkmUnWcDeqqXXUAvq IIL2fz2Vtde7vgYmAyrf1soEqsp/UE0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720675156; a=rsa-sha256; cv=none; b=gj1tlzVikAOkaq4fK2XYjCG/wr/+iTYJ8Oo4DR8RiQBZO3NglE113FqIw8fUYOjMPq6MlU /IKphxR0L10dSvsMSffEhCBV94GXAE5hsmLAujSpiRKUU9bRm7rDlKqpMsZU5g9vLnNimn hjU/tVlEf7AsAtG+mpE8zxk6qP0YlX4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=BZlrQIN+; spf=pass (imf20.hostedemail.com: domain of sfoon.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=sfoon.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20240711051944epoutp02364bb2b10ba4d7d37fd68f25a8eb287b~hEPbA1sGO2369623696epoutp025 for ; Thu, 11 Jul 2024 05:19:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20240711051944epoutp02364bb2b10ba4d7d37fd68f25a8eb287b~hEPbA1sGO2369623696epoutp025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1720675184; bh=FaXfwVv7F7bstL5whS5p0F9Y3saXeyxNh9uAI5iTpxI=; h=From:To:Cc:In-Reply-To:Subject:Date:References:From; b=BZlrQIN+KGtaHaQ7I8rOJh6cQIlR5lu0dMPEpyaVzjmZYwkY28jrPgjPc1PBDJwAP B/uZ73eYOnK9itG64+p4aapIbhCKFJweEYUTsC4oJkYZ3DYBmLFxeLzq0PsjQgZ+ie 4J5TkHiP4wc/rpc4LfkYf1WyZ9XcOKwQzfPpY2aw= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20240711051944epcas1p4401afdc67e3cb7b1decbbfd934b53356~hEPaqW1cN3104931049epcas1p4D; Thu, 11 Jul 2024 05:19:44 +0000 (GMT) Received: from epsmges1p3.samsung.com (unknown [182.195.36.132]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4WKNMM1XXPz4x9QC; Thu, 11 Jul 2024 05:19:43 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p3.samsung.com (Symantec Messaging Gateway) with SMTP id 89.C9.09622.E6B6F866; Thu, 11 Jul 2024 14:19:43 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20240711051942epcas1p4d8db4336ff88378f42d15de09d938786~hEPZRBBfB0125401254epcas1p4j; Thu, 11 Jul 2024 05:19:42 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240711051942epsmtrp154598df129129cc6689c791e960aa6f9~hEPZQXqd71474114741epsmtrp19; Thu, 11 Jul 2024 05:19:42 +0000 (GMT) X-AuditID: b6c32a37-e17ff70000002596-83-668f6b6e2639 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id DA.1E.19057.E6B6F866; Thu, 11 Jul 2024 14:19:42 +0900 (KST) Received: from sfoonkim02 (unknown [10.113.222.42]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240711051942epsmtip20b38b9ccfdcbc77b5028134ea39fd4ae~hEPY7x47q2123921239epsmtip2B; Thu, 11 Jul 2024 05:19:42 +0000 (GMT) From: "Sung-hun Kim" To: "'David Hildenbrand'" , , Cc: , , , "'Chengming Zhou'" , In-Reply-To: <254bf3e0-0056-4593-94ee-8431a1bfc430@redhat.com> Subject: RE: [PATCH v2] mm: ksm: Consider the number of ksm_mm_slot in the general_profit calculation Date: Thu, 11 Jul 2024 14:19:42 +0900 Message-ID: <0fe501dad351$ef692cb0$ce3b8610$@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQGcuK2mUct4l8vOyf6OuFEls7CcWwIwXU5MAZluS6iyTt558A== Content-Language: ko X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGJsWRmVeSWpSXmKPExsWy7bCmgW5+dn+awYNWJos569ewWWw884nV 4uv6X8wWl3fNYbO4t+Y/q0XzhZeMFjvmHWS0mDH5JZsDh8fOWXfZPTZ9msTucWLGbxaPhQ1T mT3e77vK5tG3ZRWjx+dNcgHsUdk2GamJKalFCql5yfkpmXnptkrewfHO8aZmBoa6hpYW5koK eYm5qbZKLj4Bum6ZOUBXKSmUJeaUAoUCEouLlfTtbIryS0tSFTLyi0tslVILUnIKTAv0ihNz i0vz0vXyUkusDA0MjEyBChOyMx4cfspScE27Yt+lG0wNjPOUuxg5OCQETCRuzkzrYuTiEBLY wSgx891SZgjnE6PE2qOnoZxvjBLTj55k72LkBOton9HCCJHYyyhxas5CqKoXjBKLmy4xg1Sx CehILPuxCswWEUiRWNh0ih2kiFlgBqPE3GndrCAJTgE7iSnPDoHZwgLpEgu3bwNbwSKgKnH5 +m0wm1fAUuLYgYlMELagxMmZT1hAbGYBeYntb+cwQ5ykIPHz6TJWkIdEBJwkpt+2gigRkZjd 2QZ2nITAWg6J7hOHWSHqXSRetV1jgrCFJV4d3wL1mpTEy/42dkjAVEtMfc4N0dvCKPHv5X6o XmOJ/Us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fPpMrCR IgJOEtNvW0GUiEjM7mxjnsAoPAvJpFlIJs1CMmkWkpYFjCyrGCVTC4pz03OLDQuM8lLL9YoT c4tL89L1kvNzNzGCI01LawfjnlUf9A4xMnEwHmKU4GBWEuGdf6M7TYg3JbGyKrUoP76oNCe1 +BCjNAeLkjjvt9e9KUIC6YklqdmpqQWpRTBZJg5OqQYma/vUo3p3Tm3ap+bWmZa5kX3uxpvn Gecxeu535/vzXbNYSe/0j7nrzrrKOLZPWOOlHcW3feviP/eb7fW+NjHpTKndo7DgzDuFRxOu fOFb19lcpaE0i83U4VPAi9x171f1fLvTwqPGIdgldGpzLcPRI9kTXs0z+WfoxTHpPOefuOqu u16bfpfM5G29yPv/5m8lXSnZhffTJvDcMXLbYjFJ7vyj2CcaHMsv6n5e1uD3+GzN3EfSz0X3 xrHXBnLVKiz+zCJ9tL4lu4n9eK//+p+X1WvlVh83i1vd+lt/No/e6vkyXaf+ubF5F+xUbP20 8Z2/6M9tUtYG0/c8XqR83Duz6MPfB9/c2KO0BdefYdw+W4mlOCPRUIu5qDgRAJYtdTgjAwAA X-CMS-MailID: 20240711051942epcas1p4d8db4336ff88378f42d15de09d938786 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240620043920epcas1p1b57dce789304aa96fd83e5b2b194d244 References: <20240620043914.249768-1-sfoon.kim@samsung.com> <254bf3e0-0056-4593-94ee-8431a1bfc430@redhat.com> X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CBBEB1C000F X-Stat-Signature: nffyb6hqsyemx95q6oqtp8u1dni6trmu X-HE-Tag: 1720675187-755038 X-HE-Meta: U2FsdGVkX18v1q87J8iBbLrKXqhrYhH4qV81jojjU+LM7nTsx8IDADdJGyOkdYBNFtSD9QiEK5XrGIm8OYiaCvUy6qFg8ogFu366MLIGYVMbG6PFaVvaHjbiw+k7CPiGYoY8BWPCi0Vp8CHkv/VZB4Xfy67FGLQY1rnS1XDDViDPRBg3kEJFPWNKTmQWa/P+1+0lIBXMmrxavtoL+N5I5hxJ7PrGo1t5nQqcETccQjsWjW+JvludUxGOhG86NTRbv8T2Iv0HMTKmshGazPUsxq0ruwaGN+GF2nxhyxG/ZYO+b6pq6y2NeanAvLKYJ6Tv20znGTcR/fyIRKPf50pSp9whTkz0ktRw1PqxDAhLFrykjO3XhJ6NFLI8VTlDoHsoXvIXhMq2iaCwabohqm9G6sKC9kqLSMk83w1pNETT1BIJSJ/Mu0Gjo/UsC0j378SvV+SR1lLAPhkK17oyT1ygyveJ2UIXOhagMHsZka9+jiR/Y/T8EHG+kAxjGknqQBS4V5Ya+8JBezLyYcA89zpQRfKT1kJH+Dk+QuGsopffa3dGAey07VMaMEZIGW2CzEHE/BQs+r7Q5Iy8KXtHpianmxoWa08awvrk21fz3CDoCuKdHbQXFegP5722R0pU9yWbT7wegXrloV06bfMgs+GakCTi96b4k6epT3JWu55IayBbwsWvwjzURqvIuturCROqa4oRXwJ9gfYpo1KeGmIDSRMOJ0xGj8jx76Yb/WU22lNRwoevy1ZdMxDOrjzUFZOOtJZleJ6VS2c5upHNmBRmtpMShjrL71uH1TB+tOEU5dU7ykGWe+ZIbLtxv5An+2v86y2kchk1gTFq4eufV93XGx82rATLvFO2Mxp5jRJsKzbbQXBBgHzrEy2/RWX1Hju4nWzCuk4f4yW0KmyGwerswJobUyE6fC6GkOxLxvn/+Lr4/JBPvLmPcupHkMebv3NI0w9JKhdBKsdrOFRkvtO LAGJmjXT TwfDkg5EKH6XrpBmrLmoSOUOVtddTdspceCWza7lisqknr6nv/27AtVILO2K0hvvDqmAwNtAxM9nS91SVXpg6LW1j19uuuarygG7fuoPfXn87pc8R24eqq+P2y6G59lk33iGJKjRtwITH+9g= 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: List-Subscribe: List-Unsubscribe: Hello, I'm sorry for late reply, because there was an issue in the mail system of my company. In my humble opinion, this problem can be considered due to the objective of the value that can be gotten through general_profit. I think that there is no problem in getting the more accurate value through general_profit because it involves only negligible overhead due to the accounting of allocated metadata. Even the difference is small, it could affect the decision in the use of KSM on the memory-restricted device. Since KSM only wastes the CPU time to find identical pages if the gain is small, so more accurate information is needed to decide whether KSM is used or not. Even though ksm_mm_slot and ksm_stable_node occupy few pages (or tens of pages), if KSM found small amount of pages_sharing, it can affect the gained profit. Because of that, I think that including other metadata in general_profit calculation is not a big problem if tracking such metadata causes negligible overhead. It's my mistake in omitting the consideration of ksm_stable_node. The patch should include the calculation of the amount of ksm_stable_node. Best regards, Sung-hun Kim > -----Original Message----- > From: David Hildenbrand > Sent: Friday, June 21, 2024 4:38 AM > To: Sung-hun Kim ; akpm@linux-foundation.org; linux-mm@kvack.org; linux- > kernel@vger.kernel.org > Cc: sungguk.na@samsung.com; sw0312.kim@samsung.com; sebuns@gmail.com > Subject: Re: [PATCH v2] mm: ksm: Consider the number of ksm_mm_slot in the general_profit calculation > > On 20.06.24 06:39, Sung-hun Kim wrote: > > The current version of KSM does not take into account the number of > > used ksm_mm_slot. Therefore, when users want to obtain profits of KSM, > > KSM omits the memory used for allocating ksm_mm_slots. > > > > This patch introduces a new variable to keep track of the number of > > allocated ksm_mm_slots. By doing so, KSM will be able to provide a > > more accurate number of the gains made. > > If you take a look at the calculation explained in Documentation/admin-guide/mm/ksm.rst, we only care > about rmap_items, which can grow rather substantially in size. > > We also don't consider other metadata, such as the size of the stable nodes etc. So why should the > ksm_mm_slots matter that much that we should track them and account them? > > Any real life examples where this is relevant / a problem. > > > > > Signed-off-by: Sung-hun Kim > > --- > > Changelog in V2: > > - Add an MMF_VM_MERGEABLE flag check in ksm_process_profit for > > untracked processes > > --- > > mm/ksm.c | 13 +++++++++++-- > > 1 file changed, 11 insertions(+), 2 deletions(-) > > > > diff --git a/mm/ksm.c b/mm/ksm.c > > index 34c4820e0d3d..c8ced991ccda 100644 > > --- a/mm/ksm.c > > +++ b/mm/ksm.c > > @@ -267,6 +267,9 @@ static unsigned long ksm_pages_unshared; > > /* The number of rmap_items in use: to calculate pages_volatile */ > > static unsigned long ksm_rmap_items; > > > > +/* The number of ksm_mm_slot in use */ static atomic_long_t > > +ksm_mm_slots = ATOMIC_LONG_INIT(0); > > + > > /* The number of stable_node chains */ > > static unsigned long ksm_stable_node_chains; > > > > @@ -1245,6 +1248,7 @@ static int unmerge_and_remove_all_rmap_items(void) > > spin_unlock(&ksm_mmlist_lock); > > > > mm_slot_free(mm_slot_cache, mm_slot); > > + atomic_long_dec(&ksm_mm_slots); > > clear_bit(MMF_VM_MERGEABLE, &mm->flags); > > clear_bit(MMF_VM_MERGE_ANY, &mm->flags); > > mmdrop(mm); > > @@ -2717,6 +2721,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) > > spin_unlock(&ksm_mmlist_lock); > > > > mm_slot_free(mm_slot_cache, mm_slot); > > + atomic_long_dec(&ksm_mm_slots); > > clear_bit(MMF_VM_MERGEABLE, &mm->flags); > > clear_bit(MMF_VM_MERGE_ANY, &mm->flags); > > mmap_read_unlock(mm); > > @@ -3000,6 +3005,7 @@ int __ksm_enter(struct mm_struct *mm) > > list_add_tail(&slot->mm_node, &ksm_scan.mm_slot->slot.mm_node); > > spin_unlock(&ksm_mmlist_lock); > > > > + atomic_long_inc(&ksm_mm_slots); > > set_bit(MMF_VM_MERGEABLE, &mm->flags); > > mmgrab(mm); > > > > @@ -3042,6 +3048,7 @@ void __ksm_exit(struct mm_struct *mm) > > > > if (easy_to_free) { > > mm_slot_free(mm_slot_cache, mm_slot); > > + atomic_long_dec(&ksm_mm_slots); > > clear_bit(MMF_VM_MERGE_ANY, &mm->flags); > > clear_bit(MMF_VM_MERGEABLE, &mm->flags); > > mmdrop(mm); > > @@ -3374,7 +3381,8 @@ static void wait_while_offlining(void) > > long ksm_process_profit(struct mm_struct *mm) > > { > > return (long)(mm->ksm_merging_pages + mm_ksm_zero_pages(mm)) * PAGE_SIZE - > > - mm->ksm_rmap_items * sizeof(struct ksm_rmap_item); > > + mm->ksm_rmap_items * sizeof(struct ksm_rmap_item) - > > + (test_bit(MMF_VM_MERGEABLE, &mm->flags) ? sizeof(struct > > +ksm_mm_slot) : 0); > > } > > #endif /* CONFIG_PROC_FS */ > > > > @@ -3672,7 +3680,8 @@ static ssize_t general_profit_show(struct kobject *kobj, > > long general_profit; > > > > general_profit = (ksm_pages_sharing + atomic_long_read(&ksm_zero_pages)) * PAGE_SIZE - > > - ksm_rmap_items * sizeof(struct ksm_rmap_item); > > + ksm_rmap_items * sizeof(struct ksm_rmap_item) - > > + atomic_long_read(&ksm_mm_slots) * sizeof(struct ksm_mm_slot); > > > > return sysfs_emit(buf, "%ld\n", general_profit); > > } > > -- > Cheers, > > David / dhildenb