From patchwork Thu Jun 20 04:39:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sung-hun Kim X-Patchwork-Id: 13704847 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 2B593C27C79 for ; Thu, 20 Jun 2024 04:39:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85D7C8D009C; Thu, 20 Jun 2024 00:39:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80D3D8D0066; Thu, 20 Jun 2024 00:39:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5754C8D009C; Thu, 20 Jun 2024 00:39:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3A9BA8D0066 for ; Thu, 20 Jun 2024 00:39:30 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B44251C2CD9 for ; Thu, 20 Jun 2024 04:39:29 +0000 (UTC) X-FDA: 82250013258.29.D39D4D3 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by imf17.hostedemail.com (Postfix) with ESMTP id AFE0B40011 for ; Thu, 20 Jun 2024 04:39:25 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=iu7x2imo; spf=pass (imf17.hostedemail.com: domain of sfoon.kim@samsung.com designates 203.254.224.33 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=1718858363; 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: references:references:dkim-signature; bh=CSUudlip9Vu0/VD7Ao8r5qsubjjl3lKW3KeE+ma8usg=; b=dJN7heRZdnPIsECUVGKuZkeZWNCUAvwZHexdjvwIeBvJ+vKeDt2ZRrXtuhlzR/LFAHTz5+ aMGSmzoH0QEeH7hOiNd/Z34ixjeP7B/Qta6+CV1+MD/YrIO7qA7Xf825dtK6FDgMbj+h6G mBKOK0PuK4pRRnAAl4cvEmeTOzq/87w= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=iu7x2imo; spf=pass (imf17.hostedemail.com: domain of sfoon.kim@samsung.com designates 203.254.224.33 as permitted sender) smtp.mailfrom=sfoon.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718858363; a=rsa-sha256; cv=none; b=Bul11x6ijCssKDD+qVFCEhUiW6+yhV+A4zpu5QenBWdyvO37mV0KMiXkPUWRozqlhZNLeX +VOklFUixWlcyiqyfy3dJAbVBLSM61JqT5paJmF/iKrPbkHfoA2W1tPJIaj4vDaYMCeAnw N/wpO1iIMoQvlygWiCZc2yRFEIdERZc= Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20240620043922epoutp03202549421f1032e89a86142e560355b0~anJLkcwCs2967029670epoutp03Z for ; Thu, 20 Jun 2024 04:39:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20240620043922epoutp03202549421f1032e89a86142e560355b0~anJLkcwCs2967029670epoutp03Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1718858362; bh=CSUudlip9Vu0/VD7Ao8r5qsubjjl3lKW3KeE+ma8usg=; h=From:To:Cc:Subject:Date:References:From; b=iu7x2imo8oWipQ052gUk9RR6wanPOcn8VjMklguUOOroQpa8DIhBWdSCYl8FF95c4 QREvXKZURZ7ahCvfaR+5EmPeZU+wRnfVrV9iZsBhkLB5CUWcneAanFCS4UyMYU7kOT Wc4aSH9hb+FjiLLIVbBuiRaFE01wdNfo/1I4jAh4= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20240620043921epcas1p42f94b1137c0046596b7341cf784cc334~anJK2lcYv0713107131epcas1p4f; Thu, 20 Jun 2024 04:39:21 +0000 (GMT) Received: from epsmgec1p1.samsung.com (unknown [182.195.38.233]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4W4SSS5Td7z4x9Q5; Thu, 20 Jun 2024 04:39:20 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmgec1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 62.E2.09847.872B3766; Thu, 20 Jun 2024 13:39:20 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240620043920epcas1p1b57dce789304aa96fd83e5b2b194d244~anJJRvjcV2075520755epcas1p1P; Thu, 20 Jun 2024 04:39:20 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240620043920epsmtrp25c2610d0f9fa9b649d81f8065ccc1ad6~anJJRFfMg1486114861epsmtrp22; Thu, 20 Jun 2024 04:39:20 +0000 (GMT) X-AuditID: b6c32a36-60dff70000002677-70-6673b27887ab Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id A1.CA.19057.772B3766; Thu, 20 Jun 2024 13:39:19 +0900 (KST) Received: from localhost.localdomain (unknown [10.113.111.45]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240620043919epsmtip13d55b576ec751cf51711cd170ca8be48~anJJA9xwC3203132031epsmtip1q; Thu, 20 Jun 2024 04:39:19 +0000 (GMT) From: Sung-hun Kim To: 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, Sung-hun Kim Subject: [PATCH v2] mm: ksm: Consider the number of ksm_mm_slot in the general_profit calculation Date: Thu, 20 Jun 2024 13:39:14 +0900 Message-Id: <20240620043914.249768-1-sfoon.kim@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMKsWRmVeSWpSXmKPExsWy7bCmnm7FpuI0g02tEhZz1q9hs7i8aw6b xb01/1ktmi+8ZLRonLac3WLHvIOMFjMmv2RzYPfYOesuu8emT5PYPU7M+M3i0bdlFaPH501y AaxR2TYZqYkpqUUKqXnJ+SmZeem2St7B8c7xpmYGhrqGlhbmSgp5ibmptkouPgG6bpk5QGco KZQl5pQChQISi4uV9O1sivJLS1IVMvKLS2yVUgtScgpMC/SKE3OLS/PS9fJSS6wMDQyMTIEK E7Iztl8IL9gpUXG9aRZTA+NWkS5GTg4JAROJB6vPsnQxcnEICexglPjRdYYRwvnEKPF0+ldm COcbo0TL22+MMC3/nz5jh0jsZZRo3HKHCcL5zChxomM2C0gVm4CWxLb9l8A6RAQCJS4u/MoK YjML5Ehs+T4RzBYWSJbo7GsBq2ERUJVYeLuRGcTmFbCWuLhnEdQ2eYmZl76zQ8QFJU7OfMIC MUdeonnrbLDzJAROsUs8vr+YCaLBReLrlAVsELawxKvjW9ghbCmJz+/2AsU5gOxqianPuSF6 Wxgl/r3czwpRYyyxf+lkJpAaZgFNifW79CF28Um8+9rDCtHKK9HRJgRRrSzx+GAzC4QtKfF1 33WoCzwkmn5vB7OFBGIlvq/5wDiBUW4Wkg9mIflgFsKyBYzMq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5NLUgtgskycXBKNTBN6egpln8ryy78RvWtwbzU5iqlKUoiWn4fWHhsC5eeEK2fcp21 OjzRmVvi57HKBc8jTWpX2Xiaxxn6s5tcczNVC3txoLLt26Pn34ycbA7HfS38kc909fbthXc3 LF1/MJKjOXD1c973s1+yuS+WKLTdfvk4x55oVfYH1lHeOX5OFzl/fJ54OqrlXuXy5Kzi8s8V 9e7Np1lnGe708vVQko2cmXhMtEVkktT3+If+AUapa7+WnHJds2ylUlzzCus1nOv1mJdGVbDu VnAOYjQufHaG3+cp+/wrx850r1aVunlA+NBGH19NPh7Nnaa2tV6Li6zyQtKlxWq6St6FxRiE tDmnLf+YMaWzPbX6R8NqJZbijERDLeai4kQAPhYIfMACAAA= X-CMS-MailID: 20240620043920epcas1p1b57dce789304aa96fd83e5b2b194d244 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240620043920epcas1p1b57dce789304aa96fd83e5b2b194d244 References: X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: AFE0B40011 X-Stat-Signature: cu9tcg195gg6uy5o45m8d4i3ghu3fs77 X-HE-Tag: 1718858365-888474 X-HE-Meta: U2FsdGVkX18T7bmiS1hbQxsCJNotXFXzATTLXqYJvOfCoe5tJvd2H6RQOIA7QudQ2MTZl66WXY5H14GNnZkkcsBbN68nMTWRWkvCIvfEyI4v+n3u1ug1gaqmjh4Ri+SxTCKhMOyeN4g82dlkRPyoAUhlPYf/xPDmSfSvrYGeMbO4+F2/QoEQEdinP80HOeq74sikAAWSWNHg2ila2cWC7zX03CKDrqwHox7I9cUfMzr7Se31+0a7IKzVtsk4DB5hQTPK0uOv7EIeD73vXW+JUIfeAu0OMCujUqqfR4d36g9re6X7G3gRYdnZMDuu20Z33Cp4FVgcfwNYb2rezqMOJy8ayIDs0mHGxtcDrAb7lJ05PfrTrx4kssRWihkNtL1glMQEdUMdXkUKjXg+j5MmYNFLlk07TJ8CKkmhVifndCkOVuTHhndKLV+j3kH2/XPAqGKHjavXv+sYBUNa/1ZlTnK7PonWZdaiyxmssb5BP/iiXoAynPigkBh/67d+OTOHR3NMbFGlvrNU8e6hBq0FmKcvyWM8JBhsotBVfTc8HAiPa5kkVfHWtJYOFB7Ol1W18oVITsSACunehHs/u4qluJ1UUSfDcdguYL3uQLXROznFlu9UFNKJGpBiUnahulj44wqZJCy8mMV8x4I7p40vP6MlPNaf+Wbz7kFbaL83idN+E68+6uRTgeNl3eeknBaAPFxFDSdrCy80BjoMKTimhy3NhsJOvjp0rOt/+InvSXmMeebZ4KRGCIr61sAnaTxsRNEdjL/eqyL7P5i1oOT1q66aYGWyUPsC431vK73Y9kHlE4h2kK97KNzyfgeyECdDnS13U0RZCWt16Z+UD1p4d+TX+I9S9QhPz8ObaTRCzZAfX1JZbylNIycAnIwl/M54ZaFfg2Vr3aFrxwRWafpwbQK9YHHffnXsdIB5+MIXJygq3Yon7tGOw0apiOR4tv3XEt7/hWiQwZ7p1M3LsHl p5nB0mL0 SGZ8F7LBSDODirXeWm+JzKu6JwVMDZq/DCKXdC7Nb1kihYaOcN5wBN1DNe58tgKyGl3XMnVLvH4JYhoJwQK5mhTAz6bPr4cBpmy3V47RkjkHLCTWP5RmvsSt10vel3bvGf+5LVs12/9aNcsI= 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: 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. 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); }