From patchwork Fri Feb 10 21:50:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136498 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 DE650C64ED9 for ; Fri, 10 Feb 2023 21:50:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E11F6280018; Fri, 10 Feb 2023 16:50:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DBD41280003; Fri, 10 Feb 2023 16:50:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1245280019; Fri, 10 Feb 2023 16:50:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9A1F7280003 for ; Fri, 10 Feb 2023 16:50:58 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 758D01201DE for ; Fri, 10 Feb 2023 21:50:58 +0000 (UTC) X-FDA: 80452727796.07.9344A69 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf07.hostedemail.com (Postfix) with ESMTP id DC7824000F for ; Fri, 10 Feb 2023 21:50:56 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf07.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676065857; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3lJe08hmVrQFw22kviPgqf1tesn8y5yO7ml9nb20jGU=; b=zeAiDHOzI8CjJyZorwt4ejw761BTRIjxymSrDFOoewwvdQ3yLZs8y6MzxyJba7kgqY7s9l fvDLQCHjOOHsAY6l4Qo08kjfwUWvKZ7iBNic7YPm6UweDwVGHx2JGRZLkrA4QIEYdiqp4I vxHP95AclUIrjvJ1kXm46ayuJlroVec= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf07.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676065857; a=rsa-sha256; cv=none; b=7ZSpt/yRproY70Gbc2ywLLAwgBcR1dRAIjpLF0ybTI3INjcn6MhPwAA4tJK1KI/kK7Zj2F g0HjKKI5FV4aZVdacG6VKG0K3akHqbUIok0wSpr/+41A2UTszVYZzfSHI1tA1J+sU68e0M c2qcMDw+J4XVA+G1DgSgoIRF4BIEe8w= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 656676BFC2C2; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 01/19] mm: add new flag to enable ksm per process Date: Fri, 10 Feb 2023 13:50:05 -0800 Message-Id: <20230210215023.2740545-2-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DC7824000F X-Rspam-User: X-Stat-Signature: te5zht5krofg3k5eo9145jakgupr9y1w X-HE-Tag: 1676065856-169932 X-HE-Meta: U2FsdGVkX18pDAFj8+Uyos1PeOP8msapnL9+lXtoFRsoukvW8eNbQ4+dIw9xaCFhwVr1DsGB9YrRVXLcYIcakb8rDM8vJSUrw26AIDZscUkiiEvS91j7BEXmKFB9ssR9Pehp3YVlWEjIbEce8ZydHiqthx7njWDh3NmtyFmSJE+CWWJiR2ROjBzkCb+m7gbna6GkhfTLxczZHpKiPFcWUjlmOcX2HkfOrQTnhC6/g539DP6bQIpKOTbgYL3B/zhS/46yKp803Gww74hLuMlBn6/Tef1hrTcjfpK+JA1mAiGsjRfLpY9JXE/y2vSkUnQOv2m7u6WctpvinkGHUhlICiwAXyUN7c4TZ4x+tMtxD0dS12a+78Z+v35G0rzCLFHTAxh6bDc3cDkgIHLW/KHs9VOzOcgTOZ0lyFyKXKOXUu6f9jIeU8pmntn7FMrp6URI72rdLwwXOz/fosRf6Gi3iwcDw0lSmyJoZzsyrvYaNvhb6i285mhtNLs2c8jDpsdwhFBdz5Rtg4WPQB/vin3papNV4Xnwd2n7CZ/YAiB6x398ikS6NGemMQEscPWxbkiolgQZcUmwGXE2iy/MgfX2snkNDda5JfzDvPELwNUo+UKYyrXqy4q9S+n0Qg21Oi80Jwf2/MeWeJzHNJUdQ9X/yUcs3THpnt3QnwAKQQ54YbrHXJaSVvZ0vbxaxQ977GT8t/9Y8fRjpQtmZDlqKcHSFO6n7YpZ8l5+StTNJjr1bPUjewIp6HxuCmyUZyrsHGPIpJMGbuxZGFktcdMxC8Gvn0TvyvMIvI4Oec08U1OP1tMfjvCGg7MVGUnUpOpmoAaQlxayWwgUH4m48eBLQ8f5WDsQmEqu5t3Zac1WIjKwYIA9EHSmzPnOHziaB+hraT/9mXR72TvdhMOZWjNEqigweetWFk2lr9Dq0RLAQMambSxGlGTBOhMPm42gCfLjoWsHKq5YyVRoacMIxmLKvA/ V1YkvHpy xdHPo95KCi7S7IvLU9/zLTuNvyGBNci+PgZqMSOImQuLsNxwslvTBetF1fw== 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: This introduces the new flag MMF_VM_MERGE_ANY flag. When this flag is set, kernel samepage merging (ksm) gets enabled for all vma's of a process. Signed-off-by: Stefan Roesch --- include/linux/sched/coredump.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h index 0e17ae7fbfd3..0ee96ea7a0e9 100644 --- a/include/linux/sched/coredump.h +++ b/include/linux/sched/coredump.h @@ -90,4 +90,5 @@ static inline int get_dumpable(struct mm_struct *mm) #define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\ MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK) +#define MMF_VM_MERGE_ANY 29 #endif /* _LINUX_SCHED_COREDUMP_H */ From patchwork Fri Feb 10 21:50:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136495 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 4BB5EC64ED8 for ; Fri, 10 Feb 2023 21:50:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71D60280015; Fri, 10 Feb 2023 16:50:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 670BA280003; Fri, 10 Feb 2023 16:50:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F9076B01F2; Fri, 10 Feb 2023 16:50:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 25C816B01F0 for ; Fri, 10 Feb 2023 16:50:52 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0163BA01CB for ; Fri, 10 Feb 2023 21:50:51 +0000 (UTC) X-FDA: 80452727544.23.7CB599F Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf27.hostedemail.com (Postfix) with ESMTP id 4DD1D40008 for ; Fri, 10 Feb 2023 21:50:50 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf27.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676065850; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WX9C0EVQ1MCmBYsInw+wO/0YO449MXgKGXrN8NBE9ds=; b=Qk8p1UlyRmUSVhYGFJpqCRrP4zI7XoC5rK2+XzYWaUnAtUQg9Wp9VrxlZMW4qDGHTErXMt XfNknEg07o5pxX3cXNrc0dY2tDl0YeXXawoUZudb+P2kGH9MyyYhagrFVCQpCsnCNFlTe/ gmvQHasOB29wLDdXqVYIKybpBEdJVTA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf27.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676065850; a=rsa-sha256; cv=none; b=Y8quJWG8CAIvjsNTW7T8lH43XMx13l+UC+KOsEuiB1KjJYkaHV972av30/qjWxN9d2dm1V 6u++wzE+U+wa6Rt9A7RpMKR9LVJLiTeoxKKCv1BuVFIUF3j8mft/qLRG3pqNi/qvVycRRB J/CrgGKMiPqg3YpehPpBiisPDq9zBxM= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 69CB96BFC2C7; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 02/19] mm: add flag to __ksm_enter Date: Fri, 10 Feb 2023 13:50:06 -0800 Message-Id: <20230210215023.2740545-3-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4DD1D40008 X-Stat-Signature: tqg8udefkcpzaso4eouxe7s3czysnzzu X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1676065850-846911 X-HE-Meta: U2FsdGVkX1/7gwYBD12NR34bCBBQIKb7JE41r2SEF5Mjwl7bL3M2a8hf/5rAlRec3843inwt6Iu+QHYVrx7VQiKQExa4IuDtfhSnBcClvn8x/OO8h4bZB8FpFxExrTiQGHQM9X0UGt3obwGO4s+/BIPmFiB++hD+/Z79n0mdl0Z+8S8jzlGPXeGIexIQiPDod6EE6j5ilQrM9HBL2lOkzk8FV0cs97qCEnGYsNaI4BTc6OZfMBM2g8h1x/VQ2XjdIa9+TppxTBZSrchBj1HYQnBQGSLSspb/yUSceMulKKPal2/80tYo/3IRTzigcZsDwBkCIGKWW60Br7PQ/jGY/L7qZjWXE2kDQ7XWdisU+nbhPXcGb12O3w6l9gRCLaFt2QRd5Lpp4Wy9mNx5DzkXrViAp5m7Oz9tUXiw0acEq0evt69kuMu+0G7Kp9QJIUPae24r6fqfX3cUlylQKmzEhaeOWuItE/JYunxPR02rQNCAFtpk5IRmcI1DrkZXro8/ix0AIhPAuyq3GEgqNF3CkbHSDanTevdFH3VyhFHYLsPdiMNBBSturFCHf1ig60WFInYeHy4Ay3UyJ0SFI28IveK6m//l7Ulqq4Cuj4rM3ioIH4W7vBpcDjtM5w1YWvGKKUhQENpZ6faBcjlJqtmXcXa2zdass2iz1apcAYadwsFnvFk3HoaENDHuGo5C26HpEZufHVlBSTfGo0Uj64rqSSWkKHU7+6n41Gy/xwQF33sbcHkB2RaJNNLocI2t6FBZG6gAcGmmNM8YS0QNNRXWkh/rqjL+wXhPsBef9wc1s02PJUrHoGHNZ06d9ZsmIq/hWrDRYIBBVvfK/lMdleTjoQG48CZ8wgh6vnRQiQPLOjIoMMcuGWxOY7hbfkBKr5qvjddhCgeGbDmz6fsClUdRaEw1rJ4ne9hi2kUMNbwkbcHK6CYc06qMCyw5m1MWtd8do/d3A4sHH/Qku/hwR15 vEZ5yveI guLFzM6xrgxTwLNpE/M6YNX7wnMTyB/kX5lfgrYbJluPRKgpfT0nhwheCFzxP8u1KvCaG11jQeuORF2oZWnCAmN248ETN0SlUrsXd 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: This change adds the flag parameter to __ksm_enter. This allows to distinguish if ksm was called by prctl or madvise. Signed-off-by: Stefan Roesch --- include/linux/ksm.h | 6 ++++-- mm/ksm.c | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index 7e232ba59b86..50e6b56092f3 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -18,13 +18,15 @@ #ifdef CONFIG_KSM int ksm_madvise(struct vm_area_struct *vma, unsigned long start, unsigned long end, int advice, unsigned long *vm_flags); -int __ksm_enter(struct mm_struct *mm); void __ksm_exit(struct mm_struct *mm); +int __ksm_enter(struct mm_struct *mm, int flag); static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) { + if (test_bit(MMF_VM_MERGE_ANY, &oldmm->flags)) + return __ksm_enter(mm, MMF_VM_MERGE_ANY); if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags)) - return __ksm_enter(mm); + return __ksm_enter(mm, MMF_VM_MERGEABLE); return 0; } diff --git a/mm/ksm.c b/mm/ksm.c index 56808e3bfd19..afc0980592af 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2595,8 +2595,9 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, return 0; #endif - if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) { - err = __ksm_enter(mm); + if (!test_bit(MMF_VM_MERGEABLE, &mm->flags) && + !test_bit(MMF_VM_MERGE_ANY, &mm->flags)) { + err = __ksm_enter(mm, MMF_VM_MERGEABLE); if (err) return err; } @@ -2622,7 +2623,7 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, } EXPORT_SYMBOL_GPL(ksm_madvise); -int __ksm_enter(struct mm_struct *mm) +int __ksm_enter(struct mm_struct *mm, int flag) { struct ksm_mm_slot *mm_slot; struct mm_slot *slot; @@ -2655,7 +2656,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); - set_bit(MMF_VM_MERGEABLE, &mm->flags); + set_bit(flag, &mm->flags); mmgrab(mm); if (needs_wakeup) From patchwork Fri Feb 10 21:50:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136496 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 D31FFC636D4 for ; Fri, 10 Feb 2023 21:50:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33961280016; Fri, 10 Feb 2023 16:50:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29B05280003; Fri, 10 Feb 2023 16:50:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1186E280016; Fri, 10 Feb 2023 16:50:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E34A5280003 for ; Fri, 10 Feb 2023 16:50:53 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B9BB1120455 for ; Fri, 10 Feb 2023 21:50:53 +0000 (UTC) X-FDA: 80452727586.07.62987BE Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf30.hostedemail.com (Postfix) with ESMTP id 298788000A for ; Fri, 10 Feb 2023 21:50:51 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf30.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676065852; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tH1aMisEakR+8J/dUNezqYTnMcIISoU8PJF94N16sdY=; b=2sG85/ONQnX4JwHDavOgA/aWV0xbtGH56OMCg6WEh1VHvMKDypvaOKIc53t+AmKDwSYY8b baNVV0h+D4ljfLKFPgknj8QrQ95YxC08osMLeU8yXMDjfvEbGlxqyCm87VRTnbOEIF7E+2 yCH5Bz5h+JVNIrRAhMBVhYhUNrmW13g= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf30.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676065852; a=rsa-sha256; cv=none; b=VelE/XPYNYzm3jNPxVa2qMOTHGfiIh1/VRFyqdWdohRAWqSPTzcnOw0BMqgNsmH8W59ZKy T5Oj152etcPVfKQXqdO3K3qqSP2vjmC+DTT9C1l0veGF3pGrCzvG840onkNMU+K2FBZe/x 2c+Lg2Iw9upKCmBCoXp8L30GJ2mJaBY= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 6E3806BFC2C9; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 03/19] mm: add flag to __ksm_exit call Date: Fri, 10 Feb 2023 13:50:07 -0800 Message-Id: <20230210215023.2740545-4-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 298788000A X-Rspam-User: X-Stat-Signature: spkej78tznhb8wk1xbgnzeoh5adjeci5 X-HE-Tag: 1676065851-705038 X-HE-Meta: U2FsdGVkX1+HUg/pdEYTnR72Rx7cF9k2x3VxNOeF2Tmc2tw74U65JhLrcIxz07mNvfscq77QchwxewC7Rt8gNh81ejDakWJqWOG69CB1pPuEqGbC0NRpjQJDHJw9pMhybYLXjtCW0PNt3Js33brKhHMtiLmGS7f0Dtw/qkXkE0L5jLz4JjHXdGEkkFcsJEvnI/IyMLvVGdmUAentgmMTfRpdT4Kh3Uh9MsVIgUybM9L1JiRJFMgh29Kh7EYv92p8WOiKJIFbRwfS7jyUmIL9IiuUE67KCu/mL9GrPhRUnDlVnjTohnrxf+DKA6byQbpSt2q0zMyAB1eSIniszvByIgbmAMvIVRpUQzr4D3YfEbg2XVfGMbgvzKCBh94LkfXlP3r3y0RxJShajMqVzKv6HBqpJIfWiXcjxAfRftfrnWrN11hpAz3QTJuRiINE4POyEa7o0O5ZHgBfjcj04BO86SLoTp+CmykwJv+UUXVTtM7asV9xPRPQ8GiX1wDubW/GBFL/ThkBcN3DZWIDYAgKaKoCnQE0qsNxUPOmb+gHNeD6PsbKwvRqwvnA1bi1uI76pZJ8mp/Rv+4WHWEUo1T9TAb1WXUEWTu85VtQKJMDL8QPaRinPxFzvsbmRUpcEBfPN8/i4+pUl1jUEWuOTuZ9TirFlLpXOa0/hvXFA7fAFHURxCpIgp/N/8B3yG2WZqX0MKmLW19BMyW3I8Jwfnw3KPvfQfcdkbh/j/Fy912yUIV1dPWkB40uk/tj0hwli7Tqv2ghPepLtkmnrJTboiA233JPZx1XCFNZ2q4zF4rm3TmEDN4RMJybm1VAzIKRi+RX17k60uZKlCSMnxOJwpj9/eRDi5YgiMSqKmPGCfiiunAuOKE0NiMye4rSTWWQTLlS1ESpKHrST1+Am9x/nrl4LClknntwrrfk7LVs0TBYvnJa0gqFlCNeY9s4Gy9JEWieebD4MWWyNLJidAyILFq guNWcStF 3shgULwSTrJB1mfjp/JRUSu/Pi06EZO9azOIooVcY7pIJ5zXu/1GtUHsR1C1DuQATJ7HIa5YcNJ11cQ6sU0I1N5/jkVN9e+Z/SQkX 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: This adds the flag parameter to the __ksm_exit() call. This allows to distinguish if this call is for an prctl or madvise invocation. Signed-off-by: Stefan Roesch --- include/linux/ksm.h | 8 +++++--- mm/ksm.c | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index 50e6b56092f3..d38a05a36298 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -18,8 +18,8 @@ #ifdef CONFIG_KSM int ksm_madvise(struct vm_area_struct *vma, unsigned long start, unsigned long end, int advice, unsigned long *vm_flags); -void __ksm_exit(struct mm_struct *mm); int __ksm_enter(struct mm_struct *mm, int flag); +void __ksm_exit(struct mm_struct *mm, int flag); static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) { @@ -32,8 +32,10 @@ static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) static inline void ksm_exit(struct mm_struct *mm) { - if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) - __ksm_exit(mm); + if (test_bit(MMF_VM_MERGE_ANY, &mm->flags)) + __ksm_exit(mm, MMF_VM_MERGE_ANY); + else if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) + __ksm_exit(mm, MMF_VM_MERGEABLE); } /* diff --git a/mm/ksm.c b/mm/ksm.c index afc0980592af..3597ae52fe7b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2665,12 +2665,16 @@ int __ksm_enter(struct mm_struct *mm, int flag) return 0; } -void __ksm_exit(struct mm_struct *mm) +void __ksm_exit(struct mm_struct *mm, int flag) { struct ksm_mm_slot *mm_slot; struct mm_slot *slot; int easy_to_free = 0; + if (!(current->flags & PF_EXITING) && flag == MMF_VM_MERGE_ANY && + test_bit(MMF_VM_MERGE_ANY, &mm->flags)) + clear_bit(MMF_VM_MERGE_ANY, &mm->flags); + /* * This process is exiting: if it's straightforward (as is the * case when ksmd was never running), free mm_slot immediately. @@ -2697,7 +2701,7 @@ void __ksm_exit(struct mm_struct *mm) if (easy_to_free) { mm_slot_free(mm_slot_cache, mm_slot); - clear_bit(MMF_VM_MERGEABLE, &mm->flags); + clear_bit(flag, &mm->flags); mmdrop(mm); } else if (mm_slot) { mmap_write_lock(mm); From patchwork Fri Feb 10 21:50:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136497 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 1F548C64ED6 for ; Fri, 10 Feb 2023 21:50:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8B4C280017; Fri, 10 Feb 2023 16:50:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A3AC7280018; Fri, 10 Feb 2023 16:50:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88DA8280017; Fri, 10 Feb 2023 16:50:58 -0500 (EST) 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 7979D280003 for ; Fri, 10 Feb 2023 16:50:58 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 48607C0593 for ; Fri, 10 Feb 2023 21:50:58 +0000 (UTC) X-FDA: 80452727796.11.1188BFC Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf17.hostedemail.com (Postfix) with ESMTP id B0E8540014 for ; Fri, 10 Feb 2023 21:50:56 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf17.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676065856; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+brPVytaIQDhhMS0knuSwcFcU5Audg9n97LzFvDzgjA=; b=tmwYqQfz3hezfCOh6kDeL9f85FamXKpIcWl73ADNu18nXWR1rR2/WGzNN/sby+dlIYOM1H h5hZcxD2wRi8bsApB8N8cNpJ6Xzh+A/tM8vR/E9C+Ig95PjL/gYpAi5Y9v+KlecpjhHoZV DbGxnwjcGLjrz+IFINvzmPaPBJx/r60= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf17.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676065856; a=rsa-sha256; cv=none; b=RrCL5cFCFCVF56duCCycyvZzYXDqoRvBd09sXDhSu7g+1DbFKjNO2BT5BFrM+Ug/Kkv2Zl VF71RroIWEpkhBrm7Xnb4ppQtXJAKZNZFdP0e3D0bnpcnJlA0BQAJnygLTL+Z45idrbCAY lzJn4s1jPpi0RciZkMv0W2DRLHvzroE= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 72D2E6BFC2CB; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 04/19] mm: invoke madvise for all vmas in scan_get_next_rmap_item Date: Fri, 10 Feb 2023 13:50:08 -0800 Message-Id: <20230210215023.2740545-5-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B0E8540014 X-Stat-Signature: 6rysn7m1apby4gu14ibtn48zg318eamt X-HE-Tag: 1676065856-596030 X-HE-Meta: U2FsdGVkX199yWISi2PywjKM67mazLWVIPkBYnPPnJJayCKUCJ3RVq1hRumaKwSs6c/wjMooB1CEPrB5XOGZEkpbdP+lCQxf9fjBlymgvdKAw28QwHZ4AjXZUODMmi0OWU5BAtjWpuVPcx0Z9MZsFV6LHqZ4R0y/88sUchfd9AhrKm7/dvQYmAf4vsOlJFvzZw02OzPYVv2lZoKKdNHrhQzTx07DQOIhRy1nkvKVaA08elMfKdBY/NLyIEI50VfLE5hTEYTrdRlaI3I0ArS0UQxlgPnHbRMFcW6EnIIurfdU5Qp0htEx44JTmqDtzSNTiz4tJvagWmkkLG+uKhVaTVy2bGtgar42nuXJuppC9MfuqISJtGVMII9+koMfR4XcVyJ0UKQDRZHXNN7+wKC04kgeP2Y8gJ3VuvUWPF5NVh0aJ5J/Zz+NJ1axpAcAZTELBdqhazzBEBA7hFwJHYMjuUVF4u6xSfzjySTDappLkVIgmxwMwzg8hfsFFNEOf2hWh6bGKVXCKRtRBf87MhL8h+Vs0LPgzfXXcHnnzq2hSs1s7Egu77EBTZAQzCXH5h9bhoZ/pnXCp08sbBHsWzVcSdj95jtcILSl26hnnYyxeBbO3QS/X7DR1+BHoSj3zdjM17AC086YkyW1VwOLfj+2xR0pdsMCP4IRenkN8z8xEWHvlM4j5C0Hs+qsdopvIujjtpGHy335cM3dEayVxOEAIpA59bDqGT2lJAB3FkAKWegVN/XD52YVvr7GalHFS1OK6BxAww23B253A6qu00dkuQ6Q9bZ+L7wtHMHbPeS0NMVbwGO3wcsxcwDqRiQLFuVd0dgFpLCfd7dw1YCu1Ozea2ZXFwOEmfUNVWd/GNdedF6ZJ53uEJoLwmQdFt0L9Y1LtHnoeQeuYWd7b2UFjmBCkPuxtb+4bl/gRzYMvyTSzm4JF9TbU2kjMqUHNNMzFZtLlth3MC0KmUCUY7toDT+ lcjmzp/5 nA0ksbHV0lMgMWLdmT0/E35fvKXyDe6KbKvgkK02qYCZr0SFyq+HRQ1Vn5lA6tcAiZoPF/DX+2RT00mH1qNC6hIce/+AvoyhdA8pd 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: If the new flag MMF_VM_MERGE_ANY has been set for a process, iterate over all the vmas and enable ksm if possible. For the vmas that can be ksm enabled this is only done once. Signed-off-by: Stefan Roesch --- mm/ksm.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/mm/ksm.c b/mm/ksm.c index 3597ae52fe7b..efd8d3804de3 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1063,6 +1063,7 @@ static int unmerge_and_remove_all_rmap_items(void) mm_slot_free(mm_slot_cache, mm_slot); clear_bit(MMF_VM_MERGEABLE, &mm->flags); + clear_bit(MMF_VM_MERGE_ANY, &mm->flags); mmdrop(mm); } else spin_unlock(&ksm_mmlist_lock); @@ -2329,6 +2330,17 @@ static struct ksm_rmap_item *get_next_rmap_item(struct ksm_mm_slot *mm_slot, return rmap_item; } +static bool vma_ksm_mergeable(struct vm_area_struct *vma) +{ + if (vma->vm_flags & VM_MERGEABLE) + return true; + + if (test_bit(MMF_VM_MERGE_ANY, &vma->vm_mm->flags)) + return true; + + return false; +} + static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) { struct mm_struct *mm; @@ -2405,8 +2417,20 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) goto no_vmas; for_each_vma(vmi, vma) { - if (!(vma->vm_flags & VM_MERGEABLE)) + if (!vma_ksm_mergeable(vma)) continue; + if (!(vma->vm_flags & VM_MERGEABLE)) { + unsigned long flags = vma->vm_flags; + + /* madvise failed, use next vma */ + if (ksm_madvise(vma, vma->vm_start, vma->vm_end, MADV_MERGEABLE, &flags)) + continue; + /* vma, not supported as being mergeable */ + if (!(flags & VM_MERGEABLE)) + continue; + + vm_flags_set(vma, VM_MERGEABLE); + } if (ksm_scan.address < vma->vm_start) ksm_scan.address = vma->vm_start; if (!vma->anon_vma) @@ -2491,6 +2515,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) mm_slot_free(mm_slot_cache, mm_slot); clear_bit(MMF_VM_MERGEABLE, &mm->flags); + clear_bit(MMF_VM_MERGE_ANY, &mm->flags); mmap_read_unlock(mm); mmdrop(mm); } else { From patchwork Fri Feb 10 21:50:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136499 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 523F4C636D4 for ; Fri, 10 Feb 2023 21:51:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CD98280019; Fri, 10 Feb 2023 16:50:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 75580280003; Fri, 10 Feb 2023 16:50:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58293280019; Fri, 10 Feb 2023 16:50:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3C5B7280003 for ; Fri, 10 Feb 2023 16:50:59 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EFAA4AB897 for ; Fri, 10 Feb 2023 21:50:58 +0000 (UTC) X-FDA: 80452727796.07.DE128D0 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf01.hostedemail.com (Postfix) with ESMTP id 6D8DC40013 for ; Fri, 10 Feb 2023 21:50:57 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=neutral (imf01.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676065857; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=chvrXV9yZzpHfS2K0VAXtwsTCxlMcxeeH9oMULv/YAE=; b=0bhg7R1v+b0rCjAj+FJA6EvI+6AVgmJgAz+mO6ly9TdqdPAWOmdNNTyJ8unhHgKTTIbpoq Ouhbz0OAcNRC9lquoINy+4KOVCS8vAJMuL+QC977/uNqCCajLJnsPvgC3ck54RV99ajJRw IB5SJXZeSo0IJkhfSJMiiCd4+9aAg7w= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=neutral (imf01.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676065857; a=rsa-sha256; cv=none; b=LLR3K5Z+wPPNcEymh7c60ZstVk93qnrvPDlVUXMGPhx4IoFZehRfaFumHDVd5NQkCbJ+V2 Hpsr35Sk6xTLr/kKxMLYHXNQNlcPU16I/XM3+HfqZVlbuexxoHqzdr8k+FKjiWdXCOAYf2 djaYjlXGNbMinid5azlM1xHnaYdt5KM= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 776656BFC2CF; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 05/19] mm: support disabling of ksm for a process Date: Fri, 10 Feb 2023 13:50:09 -0800 Message-Id: <20230210215023.2740545-6-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Stat-Signature: mugau6ynycdkwo94ah16icpo3ecz349z X-Rspam-User: X-Rspamd-Queue-Id: 6D8DC40013 X-Rspamd-Server: rspam06 X-HE-Tag: 1676065857-754589 X-HE-Meta: U2FsdGVkX19YN0WMxIRRZ4LNmvebztPEqbOgvc3rI0va+YAcqOuI4vls0wbJ0hxWhQ+OYxzmKwq1slYWDNBj6DpJMfhvOK2mIlrZi6RZYfaVkpVD3MdGPD/wCNznBq1tPVvpVl5CIN9UAe7MIilySU5humyNiUkP0gGK3SLUMy58Bjb+VCg1li/qYLDZPif/8i7Y3s8AUGduFMKSMLtAPRL9Lth1oalPlHAhW7nKlp9kX7xPJvOi5hanshn7eySosXYnB4zC5flmXA5JqXsBhFeTsqYFrK1CuBNSbkqRFor0wk4xa+hFrqM3xFaETDqJs0su7gBhlaS49HUPiD6SzsKDze7OeJslDNKlO9aaht4KxZEyJXshq97Y7TdGv3ILtyL400RjSaUvp/WzSIcTyy9Z3TmPjBfceGoe3UvR5m6Io99j2DtESsYKuv71DBZSTQ+cM7PKX4y0IxIMdyxLniUwprb30sJyXKo+rrGAZRyaNRx2RbWf7FWFSHD5ODfIGd3zTycgUxiwVkMM6vYPedWau05xWh8sqa8sdT6ISdU2k4DtTJcyLtwGVSyihSCqmBk7rHEEE+9fYM0F5Sg1DDyMOsvz8RjRlJyuH/HQF51nc4jPd+qPhcb2C1sbXu0BUz7/Ksp0dUvuxtjWUc/0Twnxlf+6Mwkf3ItK1W/0Omyp0tyPRaal4wb9lTA528f0s9DmCcm+OE3iozl6Mv216ieOaxWtDjY9qwqABWagRrIP5JgHqdTN6Bm3nVJTtgOoMwx8qx5Jy3U0lzN/Q1cOrBgzh6SUZCngopEKxPDZLnF1JKwrn1g6lDo/avgFmPMHLGzgKUphyWxg1Z0CcN3rcB72urBuspaKyhFJDQCciiXsjZXi9FVcvf3amrsri554CquytG5fcqQCCrcWKl+WO4XkdMcQJ/aOEXajBKhu/sZG7aQhloPNI1UYqxVnGdYT1TK8rMCTsh5J6tcWqLF pRNT+V7k iSpPtef7A6VOWoUGVrzqQxTXdLn71j2CF9QqXKwNn4Xk9AvY= 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: This adds the ability to disable ksm for a process if ksm has been enabled for the process. Signed-off-by: Stefan Roesch --- mm/ksm.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mm/ksm.c b/mm/ksm.c index efd8d3804de3..23d6944f78ad 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2690,6 +2690,27 @@ int __ksm_enter(struct mm_struct *mm, int flag) return 0; } +static void unmerge_vmas(struct mm_struct *mm) +{ + struct vm_area_struct *vma; + struct vma_iterator vmi; + + vma_iter_init(&vmi, mm, 0); + + mmap_read_lock(mm); + for_each_vma(vmi, vma) { + if (vma->vm_flags & VM_MERGEABLE) { + unsigned long flags = vma->vm_flags; + + if (ksm_madvise(vma, vma->vm_start, vma->vm_end, MADV_UNMERGEABLE, &flags)) + continue; + + vm_flags_clear(vma, VM_MERGEABLE); + } + } + mmap_read_unlock(mm); +} + void __ksm_exit(struct mm_struct *mm, int flag) { struct ksm_mm_slot *mm_slot; @@ -2697,8 +2718,10 @@ void __ksm_exit(struct mm_struct *mm, int flag) int easy_to_free = 0; if (!(current->flags & PF_EXITING) && flag == MMF_VM_MERGE_ANY && - test_bit(MMF_VM_MERGE_ANY, &mm->flags)) + test_bit(MMF_VM_MERGE_ANY, &mm->flags)) { clear_bit(MMF_VM_MERGE_ANY, &mm->flags); + unmerge_vmas(mm); + } /* * This process is exiting: if it's straightforward (as is the From patchwork Fri Feb 10 21:50:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136500 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 DDBF9C636D7 for ; Fri, 10 Feb 2023 21:53:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 705EC28001B; Fri, 10 Feb 2023 16:53:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B678280003; Fri, 10 Feb 2023 16:53:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A56028001B; Fri, 10 Feb 2023 16:53:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4E705280003 for ; Fri, 10 Feb 2023 16:53:51 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2EA2A12069E for ; Fri, 10 Feb 2023 21:53:51 +0000 (UTC) X-FDA: 80452735062.16.D7AD7A6 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf28.hostedemail.com (Postfix) with ESMTP id 8C33FC0010 for ; Fri, 10 Feb 2023 21:53:49 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf28.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066029; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F3ntdbs+KWymOd0gbDPBwV5xBWcXawh1LGHRDxPKvoI=; b=aUX0E5V/glT3qlU28hTJG+ms/aYKL/vuHK4DrLw/ZHRUY5AYyAylfpyD7Xdf55zhtCAScH bgzTvo5WzUobm/ONEr7o+pbpQ1dmiUxse0Gl63nJbfbiHoTb9YeJ5tDasJEgXCEvHSiWvJ VYzDytJVZBZ10R3APuN8PV3MYlaWWrk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf28.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066029; a=rsa-sha256; cv=none; b=pOO1vIkGEtLNWDqL87uLkxi3uqz6dG+oOsGZTesCNFPL8+CewBPU4ABrZjaAuxU7LAa0K+ gaF2Vxx4O3/YfCoXg+xrdPdwhaq1acI9kuLIlYNB2rNApAM5dOjMcKxxntkNxZbcjvNs4e i3F3zkQsQcnSXOEm2M0HxnYuvWd+hgI= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 7BD896BFC2D1; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 06/19] mm: add new prctl option to get and set ksm for a process Date: Fri, 10 Feb 2023 13:50:10 -0800 Message-Id: <20230210215023.2740545-7-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8C33FC0010 X-Stat-Signature: es6r53fype1hmm9ua8wz7wfbirz7bmik X-HE-Tag: 1676066029-462578 X-HE-Meta: U2FsdGVkX1/j33MUC/DjTyqFxQpVAdp2IONYSe5bewIFrAuzrxrj0OPLHt8mAPqVIlgeIqUnF2g9lWWnDKdd5hOKbIUYTo979z36yDQFKr1h9Xa3ABobmhfsi8IL5YnidpGq0T2O9i056fNGE5QmaBKBRke7VfKJjWFLmzHuUBpHEcDP1wrZUXptcujAE9/oo/RqL+kJiSXn5D+A5h4nRffmfGdiPERrbM49jVYfiacKU8Qbw9CxzN7u44uOGfszjknU2/QORBOumblVOndRCgi6Y40zgwrhj2Se4iE1AEDva58uWcx0eULc3r2LGjmXYOxfXRA0FxbmNWgzf5DiYKngi3YenjE0F+uq0+GinVuyA+C/3j5jgMK4TON/GWBmROUNbfZJLonOaN3sciydIztGAtQpAkroUZF2iP25Xk50+1oJILK0uNw4QUTe9doFMTT3WqeOJKnjj6H2vYnuGC3UqrKFU7n9pP779/8uaV9pX+azMtyg3dAFpwJC4eqiCP41nAN5K/04vDiUVUraXpe8vdF4IO/V3MnQ4k2JMwVVDLlbDyG9GbUTYJRnWCbm4tOJxnkggsG+n1Dgp51oEA0dptYThHstozmXZSITvoUFnZHqTZ51mmLxsHamqsW9gd6/eFUNX93mLDsxcf1ahUy7lcGfm77iEnbWJeBKoF+YOt+QHuruqGv11Es8vhbSKy2xScPtvX4o0qTe5+sYNacBjhGUziLsZZkjkvYg0AJvHp3y4/jCqbmogA+wBeYqR6Tw85gUIyfWfKEqXNr2LuVjZ6BeoMmoRs2tVkHdJE3L37GZ5ZR1n9JDvFfwliRZig3vRubG+nswWDEjAOH1/N7oJWBLY1jMeC+XuMvBpOq1V3XuZ3d4OEXYXjwdgtiCncrK0c5msf5/qM8PGUAzKCdRHURjPWwkN9k+ZC02tvaHPtxDX7uCLZ8pgWO1DAmlX9edPJYM02hWayedXmc sPnIMGYo KH+8rdqSVaTH/UT8tZihikEtPogRD8f/xFVinEAU0zKvyaPPjg5s8ZLZQ45rwsWEIAW3CMMMFo4bGK48= 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: This adds two new options to the prctl system call - enable ksm for all vmas of a process (if the vmas support it). - query if ksm has been enabled for a process. Signed-off-by: Stefan Roesch --- include/uapi/linux/prctl.h | 2 ++ kernel/sys.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index 1312a137f7fb..759b3f53e53f 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -290,4 +290,6 @@ struct prctl_mm_map { #define PR_SET_VMA 0x53564d41 # define PR_SET_VMA_ANON_NAME 0 +#define PR_SET_MEMORY_MERGE 67 +#define PR_GET_MEMORY_MERGE 68 #endif /* _LINUX_PRCTL_H */ diff --git a/kernel/sys.c b/kernel/sys.c index b3cab94545ed..495bab3ed2ad 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -2659,6 +2660,34 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, case PR_SET_VMA: error = prctl_set_vma(arg2, arg3, arg4, arg5); break; +#ifdef CONFIG_KSM + case PR_SET_MEMORY_MERGE: + if (!capable(CAP_SYS_RESOURCE)) + return -EPERM; + + if (arg2) { + if (mmap_write_lock_killable(me->mm)) + return -EINTR; + + if (test_bit(MMF_VM_MERGEABLE, &me->mm->flags)) + error = -EINVAL; + else if (!test_bit(MMF_VM_MERGE_ANY, &me->mm->flags)) + error = __ksm_enter(me->mm, MMF_VM_MERGE_ANY); + mmap_write_unlock(me->mm); + } else { + __ksm_exit(me->mm, MMF_VM_MERGE_ANY); + } + break; + case PR_GET_MEMORY_MERGE: + if (!capable(CAP_SYS_RESOURCE)) + return -EPERM; + + if (arg2 || arg3 || arg4 || arg5) + return -EINVAL; + + error = !!test_bit(MMF_VM_MERGE_ANY, &me->mm->flags); + break; +#endif default: error = -EINVAL; break; From patchwork Fri Feb 10 21:50:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136494 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 BB3BEC6379F for ; Fri, 10 Feb 2023 21:50:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 497A96B01B3; Fri, 10 Feb 2023 16:50:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 44A856B01AE; Fri, 10 Feb 2023 16:50:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CC0F6B01F1; Fri, 10 Feb 2023 16:50:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1581A6B01AE for ; Fri, 10 Feb 2023 16:50:52 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DD747AB85A for ; Fri, 10 Feb 2023 21:50:51 +0000 (UTC) X-FDA: 80452727502.23.B97A7EA Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf25.hostedemail.com (Postfix) with ESMTP id 4D3F6A0013 for ; Fri, 10 Feb 2023 21:50:50 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf25.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676065850; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UIkG2ZgW7UEdf64bDBkmG7zVyIev4Y/Do9OCfavY/qY=; b=inwhhVLhhC3LAAufeFxuvTohJzTvxlU3SXpV+K+F4bE5vVoXjdVb8P5J5OHnYf+RnJcsZx yNqNUELWfr/hi1xR4xLLKQ1Lv7aV4BV+oLYF79bc55TJLe5ZPCXurZT5az4/9hRxdDzR80 xfTo0LiWhLpUNSn4+RA9dB77QPGRmsI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf25.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676065850; a=rsa-sha256; cv=none; b=23PF1P9DYXIA3US3ZIo+B4RREVP74lxfzspCdTeJ5tt3psBPjTpxDeytbxYEa2y8oLb5W9 8Mkp+cMz+csLuO47x78CpIUHn4xbZ0uuytAKR4ljCUeFhUl3rlGDMmpkT95RZ08k9tXBHV PHfMwGXartpgPRWV/PX0KIynreJmsdA= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 803B06BFC2D3; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 07/19] mm: split off pages_volatile function Date: Fri, 10 Feb 2023 13:50:11 -0800 Message-Id: <20230210215023.2740545-8-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4D3F6A0013 X-Stat-Signature: txnejdr6kmgu8nxqopxbx7p9q998p7uc X-Rspam-User: X-HE-Tag: 1676065850-104603 X-HE-Meta: U2FsdGVkX1+n1d6mfifX7C65hies3ZPuJT3f3LiwTNmnExhq/AQPCgxtriaQJ1SvA0bSnkTne49ccv0MmnKkIfiDQeznTGuIH/DIv6Rg69B1BPym6LMK9CWbU2n1p7NE4b15PyMapARyGG0ZuMHUqduFX/V3Nhis1kXd0AEXBtwfq+AYwBjkCX7toFWY8Nn43/8nAeF7IEOp7F/lvS3KLZUTyIk6G0S6xH7Dih6mpdWVvKIliWZR1OB6Tp18MvL/VsS+8TL6f+2TfVEHC6+H2OMBBjN4HDRAI8pe+JFYTSFE2VxkApSt2xET/zwSVs+IRr6kRGpR3d4qE+qP8pNZuMUVKE7o6u86u5rj6zWz9B4mrGR3MFO+okGr/1/6++Qau9g0zHGMuZ8bfI2efH7hV6epPElHk7sSsbuHs4vV2AmV654NXpJhJlmLP1q06zJklcv1nQ2Kp2O54mNQoI1dCbh9jF9IZ8w2QvO2MEYaB5HrlUgu4lAuRQnhPlf17rBPZbjO7W4ffKSbt7H48Et3ydaIBipU3IdPvwhN4B6+AunHFPi3tyas4Ow6AgDdp3Nckguljz845UEP6pG3ZxWPizueBW56oZ4y8VrEGFYyGDv1Go9z0Kh/91+CE7hRK6rsY6PFsQXRKpjmHWJozPbUcItbko3hOxTcgo5Y/bn/n9WL6T5HqEU1zoNpkA1D/YjDieF2ek/GnMva7KbhlhgF+cTU9WazMELMOD7rM0Y0gX1TIJmKTb9gvuDypzoo3aAo/10bxJguZW7Op2OCMvWxpvjPf980W/efBSBQAvy5JZ8vJwZLZfw7ZTBpy92OmOHOWBr00efu3TI4tQ3Rb8b1iDtUKc+VaSWNQ8cp2CkXcH0qOug96B8/3ROEYvjM06bHDPKCyYT/SrzacXbuRP/7tm+ZEMatzp2q6omKPgKhYPoKqg8DCtDVkIxZyquEtZHm8onIrJ3KNOAhg1cQXBH J9FOXOl1 4oPUekB1f4AWzklRezPBdB99skqaMxnUxg8PHVwgCQ64HZ61XzF2U4Nrld9RgWfMvm9yoz3GWAB62D2V04sO0MsQqdbF/NPYJDnI9 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: This splits off the pages_volatile function. The next patch will use this function. Signed-off-by: Stefan Roesch --- mm/ksm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 23d6944f78ad..7f3b28b7536e 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3271,8 +3271,7 @@ static ssize_t pages_unshared_show(struct kobject *kobj, } KSM_ATTR_RO(pages_unshared); -static ssize_t pages_volatile_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) +static long pages_volatile(void) { long ksm_pages_volatile; @@ -3284,7 +3283,14 @@ static ssize_t pages_volatile_show(struct kobject *kobj, */ if (ksm_pages_volatile < 0) ksm_pages_volatile = 0; - return sysfs_emit(buf, "%ld\n", ksm_pages_volatile); + + return ksm_pages_volatile; +} + +static ssize_t pages_volatile_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%ld\n", pages_volatile()); } KSM_ATTR_RO(pages_volatile); From patchwork Fri Feb 10 21:50:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136501 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 74E39C636D4 for ; Fri, 10 Feb 2023 21:53:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 112C428001C; Fri, 10 Feb 2023 16:53:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C350280003; Fri, 10 Feb 2023 16:53:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF49A28001C; Fri, 10 Feb 2023 16:53:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E51EF280003 for ; Fri, 10 Feb 2023 16:53:54 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BF83BC056B for ; Fri, 10 Feb 2023 21:53:54 +0000 (UTC) X-FDA: 80452735188.26.31728F5 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf03.hostedemail.com (Postfix) with ESMTP id 167C920005 for ; Fri, 10 Feb 2023 21:53:52 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf03.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066033; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dp79YSgRwaUp2aprA+6ueDKaYGfQaoLR/Om6v/6itTU=; b=7u/EBLS0RiUoorEucdJk/YczYCietkGSRA2OPlB0T4Qqy0hZw4v7KNy6lENAng3Rp6RK96 c8pH8khGULdpG/pM+7x/lz5SXNNnhPYvl8eV9h9WDl32gVoCDOkCPZyMspHuEF9J1KyGd0 shc65CPCXijeYs1DvvQaipphRYflG/I= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf03.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066033; a=rsa-sha256; cv=none; b=v8l+GY5kIFUp1C5WQYoDUcbC7yVNysLwIjxbEGWkl8MFGa+FXsey4SlpozoLwl8lOiCEcl JKPXHsZsf5aMFf3meS6BSpdYesmwo/Se92s3uKfAf08tliTityt3ix0bx6IOcQ9wQ32O0t 1Ibwhp7nx5M3ZAmfvaVrFpJMQZlP8pY= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 849216BFC2D5; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 08/19] mm: expose general_profit metric Date: Fri, 10 Feb 2023 13:50:12 -0800 Message-Id: <20230210215023.2740545-9-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 167C920005 X-Stat-Signature: wmttxd4cnskffch874rytnx785adxrqu X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1676066032-609499 X-HE-Meta: U2FsdGVkX1/HOo0nkKDbaLrMRfW/2PqLQavdREjIxjuSV9EKozUbPTB4Z4nkwMcmax95/yYQ6zVZkMVhSiN3PvwdWlLfQ9zuRjkCSfyYozggaXNV7dfF4B3vIAnabxvF1VO0OqaMOZAEnnpjJ3SjJjTyoxkbDdXTy/u5FHSB6kx9sk8M2gBu2xhPflKJ8cFTlvig3XVSdMFXbsLAs0xfbFhmYi9uxv60HkMLwlvI91UG+8kt8kW2/NTHdNuN7BnTlzqMrOKhOhRwZ5Tksfkinz0KgAuqXkdzCOcBwobQBb2nzEBnTyVU4d5/fUBo2jTPhn7evmAlEtb+46xL17lYxFItLVCxX1fzyzfY8ySWCgjRJe+4tSNmpP99Ie8xTj3zlW9TWDLPG91ejht8b/mw/VrVdZbN0EmOI+C/0qw0yITo1LJpaziikv/kCIyrfOb43kAp8OWAbofqkeFGKqF0o/dUPJnZTUQy+UPTNts3ly++7ZXLbczgGHc83JgxQ6Y+EzI6oG2NYENVODtAsksmVBn2jKka7n/n6tCU46RoJGdCghvzkQ631TemrmAnrZYdAJObrKMZp9HX+KMejTtrpHZUjrVl4ND5Fwr0cw0FrCqi2MjdC2DUW2cFv/jrjsEL/lzBivSao/rNRe9J4a8KQq920zXPys/Av6Ue0j7wgHoA++KC40VvRG37uquSU2yHdKwACzpUKm8Vg8lN2rV8yNhHv5eRAsHlbsN4cbh+K0qHaHOq7aEsR6EvJ3dI2KAyKGvtgT9l5ZLQdVq6GcL4sczDQY7B+A0Z3JUwGRm6v6E2SbToUt3LkURgcWfjTw09kWwDO6nx1ZwW1eCL5z3x3XLDeQnlJa+qtJhyeXxVy9+brmJfdE1YELdMcn5pilHnbEMuw8mixAynshbiGmNUUftxxL0cZUQzL6GxirqKw1mECCJf12+uqVuXSLrRiJ+LU5pag3XJfPN+VhUD6Y1 tAgVHTl+ Bk7/FDaiAQRwD8w/J/l7Hml5FsFZRV2fNBoqL1WLtORLI+7GlgAwr45e0bJdgonrnI9YWf96zudn9qheAEq2BxwmmxDik4XxZbd0X 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: 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. Signed-off-by: Stefan Roesch --- mm/ksm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index 7f3b28b7536e..a0b4611112c0 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3301,6 +3301,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(); + 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) { @@ -3366,6 +3381,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, }; From patchwork Fri Feb 10 21:50:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136513 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 00FABC05027 for ; Fri, 10 Feb 2023 21:53:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CA76280020; Fri, 10 Feb 2023 16:53:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 752F028001E; Fri, 10 Feb 2023 16:53:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 641C7280020; Fri, 10 Feb 2023 16:53:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5131528001E for ; Fri, 10 Feb 2023 16:53:58 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 32145C0516 for ; Fri, 10 Feb 2023 21:53:58 +0000 (UTC) X-FDA: 80452735356.30.97F70C5 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf30.hostedemail.com (Postfix) with ESMTP id 90F008001E for ; Fri, 10 Feb 2023 21:53:56 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf30.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066036; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IXSxKrUDcAbXS8356/EQMi0aH0JKwDm5Qwr1vy1Hj/w=; b=jKNBF1wKtsavEFpvoglmFgG1iM0A6xwXu9ifmzsC6zWmc/CH9vbzIaIHpZq/UUuPNYQBJz nxlqSN6RhhHLu+SzXfnK+XAVml4MOxNgAOAZFl/rv9cJwyc18AoJrlJ1AwMqXV45EXKWjw EjuFfPaQbous3F+z+J10dlMAJmMNbI4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf30.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066036; a=rsa-sha256; cv=none; b=1/kQi9EUZ22RFGC+sbNWYUPB/YhWefDrkiiSEaYzfvaH4bXFQjHBG12BolPIvKa2NCsqGm eaRP0vIwthB9daibKj3F15jVVnZfX6+W4DyLRXcJHg7p3AtrnYWA5BfomAFY+z+fYog9Z8 kINHqzSlU5t7EmVWh6Ti+mDyvVWP+ns= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 88E346BFC2D7; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 09/19] docs: document general_profit sysfs knob Date: Fri, 10 Feb 2023 13:50:13 -0800 Message-Id: <20230210215023.2740545-10-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 90F008001E X-Stat-Signature: jkbk3ccojh4wg6oha7jnprzixftmrdwi X-Rspam-User: X-HE-Tag: 1676066036-887246 X-HE-Meta: U2FsdGVkX19k9VIDSB6ZO+1lGpUcihTooD+OlUKY82XIFXjYekvMYi2WjI/51n01/Ca0OLhVsYifOWXLlN134v4O+9FA1hBHf9OuqQDtZHeNRR7c+OlOMcKELhkNfUbnWEhxsuPi0sHyD8+1v84woYa4UCSAngHR1sONxA2CsqUDhbjp2haZ+opeNU7Lv+rR3IXMhu2GAEBwaeBlNDOUzH1ywHVu8rbDfZNr3LGL2d8T9aVYwFh16ZjIbt33AKyTwhfR3AnpbNZdZKwmRXdn/8YvGgYABmDxtGK8dMbLGcnZHeEv/SRouMiownF2cz5F8SAPkvrR0gwrQRDmGYw8CuHTx7nAKDq4RyERvMxTchS5T6do8IbWSNtNkcA3THVgk0dmU+x7l5jx9iCi7fCPiq9C0Q4pVNqgg1LM4D+LoUFG0N0dZfHiz5mW0Qxlsrfv9GXZbk7JOBpnqlaHddoIBhhkW9cxIqJHRkp0TGZkpnjR9/zYXe/01NA/JeZQTWro39vZw+BG85/xU+vLJJ9Ojyrm0Qs+wxaOC6bWhr1tj6JQ0B/jyr9wcvEuET6Qr0H18Uv4RalXzXDLSAdoOH0rKiqZn3nSp68r0jGYKMfzGdcNrCWnzOEWCUeYxwn0OAFEK+f1wASHpgTULcRthpBOg9901lvHJphcNZqmzCErG3rev8oOb9ojkg5VucfbdXovjjpTUEVTU+KbKgGgFQ+3rFcs9JrUuja1cq0Uo1Yfyh0/buhqWN27LHVGOMFTt6OTNAs4xEMQuudfKcyFfcqe+nzW32Fg6sP2pD1+7OChzeFWmWm4sbh8JCcI2zWWAz8AVlDhY+RVs5MZNHS5PMzHNM3gJrR8frUulsetDk8tVy+PHaw8ar/j6jri6XDOFbs1MRD7OBAglFgLc0Zxmr5i7Fx3kk4/uyTN06ASbOuNw7FjL0bQfQj6GavTqA9E+pB1NPIsiiS7oQ0iYZOwSVZ 2j0djSMi jL/XSjZBLzBE7d/6O6j8Hz3Bn9SSzBOH77yXaYViuRc+tLoipuYFPY4spzTZFnsBZmGak5oqXUPTVGaFIoSSgQuuufiZh8RzA2S2TsBb7+bfv6klqHULkjpzy2svoS81LGvW2sowkT/mWnQ+8RCVZXVfETCjMwzTmx2ri7YeA9d/rV07p4hWMa3PJRQ== 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: Document general_progit knob. Signed-off-by: Stefan Roesch Reviewed-by: Bagas Sanjaya --- Documentation/ABI/testing/sysfs-kernel-mm-ksm | 8 ++++++++ Documentation/admin-guide/mm/ksm.rst | 2 ++ 2 files changed, 10 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-ksm b/Documentation/ABI/testing/sysfs-kernel-mm-ksm index d244674a9480..7768e90f7a8f 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-ksm +++ b/Documentation/ABI/testing/sysfs-kernel-mm-ksm @@ -51,3 +51,11 @@ Description: Control merging pages across different NUMA nodes. When it is set to 0 only pages from the same node are merged, otherwise pages from all nodes can be merged together (default). + +What: /sys/kernel/mm/ksm/general_profit +Date: January 2023 +KernelVersion: 6.1 +Contact: Linux memory management mailing list +Description: Measure how effective KSM is. + general_profit: how effective is KSM. The formula for the + calculation is in Documentation/admin-guide/mm/ksm.rst. diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst index f160f9487a90..5c4daf44d79d 100644 --- a/Documentation/admin-guide/mm/ksm.rst +++ b/Documentation/admin-guide/mm/ksm.rst @@ -159,6 +159,8 @@ stable_node_chains_prune_millisecs The effectiveness of KSM and MADV_MERGEABLE is shown in ``/sys/kernel/mm/ksm/``: +general_profit + how effective is KSM. The calculation is explained below. pages_shared how many shared pages are being used pages_sharing From patchwork Fri Feb 10 21:50:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136502 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 7559FC636D7 for ; Fri, 10 Feb 2023 21:53:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C5E928001D; Fri, 10 Feb 2023 16:53:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0019E280003; Fri, 10 Feb 2023 16:53:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E30E428001D; Fri, 10 Feb 2023 16:53:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D5663280003 for ; Fri, 10 Feb 2023 16:53:56 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A73C21404C1 for ; Fri, 10 Feb 2023 21:53:56 +0000 (UTC) X-FDA: 80452735272.10.7FFCAE1 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf20.hostedemail.com (Postfix) with ESMTP id 170741C0012 for ; Fri, 10 Feb 2023 21:53:54 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf20.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066035; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qoDCnA3OIyYoGrZnZvSN6iClB0BUnKy9hnpZKbMb2eA=; b=Nfjp1fsgeloKHgfxOlaq/ylNkB687sEvZHDo06Lw/BLlU+oZ07DBA6303ktv9GkWvb6Nb0 QZvHjSlqkkmtt9O+NoJ1DsjqPYA637+hkLihadVUzVpkWwXj8Qjm327gEQGYv3cQ5U/po4 VhZA5siA5yxqi1AX5zbMSsedbUNDKu4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf20.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066035; a=rsa-sha256; cv=none; b=dRemHK4hy65N0w1EYDIIJpQEMhWeLkbh2Geg6k/4WH0AqBX4QloBpAWlpQODAsDmKrlWcQ 3B9gnOQ7MjzRDgKyRPnTq8RICtER0TF6WC37uoo2zkOxkZoXZSnEu7Ov2A/3mXdWnyvLgr bIUtUw0D+nsCRxizWjL6iqjXvqw3icM= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 8D1306BFC2D9; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 10/19] mm: calculate ksm process profit metric Date: Fri, 10 Feb 2023 13:50:14 -0800 Message-Id: <20230210215023.2740545-11-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 170741C0012 X-Stat-Signature: 5o41xdegk17szqazzycw4kwxdsjhiwz6 X-HE-Tag: 1676066034-361267 X-HE-Meta: U2FsdGVkX19MavYpQ6x/9wAAYUkydrfwIMT/GXEfgecRYtKO7bAcSvjLEHRRbl1+ZKa7dyRP7HsRvcd3qBeLjhWeUjw6fDj8FHDjhauro66etRzW+BEbucVd5NKMhYQCDXMtPXeaVvqEfe1gNtvNpDtUbbp7BVUgqy5hIh7JHnJ1GMwDZ3/y64gv9mq9iFwfyDe2aTJ5v7tRlhyDCDy3m/i2p3BYbJKUGoq/APpbKPjs+bsaEoubgQ47lQCMC3CztiIbD30qjf3TIEDd12imgyuWwGbsASB1cSutgiRfsELIkTJCo3JoN6OBmnkHAzcC3n+8pUqylPZw6Bho7fM3uv66IGzjicP4B99fNbdKePfAiuv28UaXwYpRDfMH65q/2Z003ANABfzhl0IWcHPkXZ9Yb7A/uA4a/N4l7DRN+WN0Yrw3tmpHbTnYWxD88DwwSpZmtgZY9f6ww94DAWKO6WwzowwPvFQvQuE6YlPrzS+YeL4HNQXd8F68FMSWTvFMlrObyz0Olc5de7hOUIT+JBWKc1Xp7BwPwYgOqKEabLaTniWi6jZHUalEL9scSMy33xUr2EvQLbp8Jatu6Nz97+dMAQSFvXLGCcXVcfa7Z92QucKSRtoNt6PCFPdveBhOaDxwaXQJPgxCE/NRKWvaL6OWYXag9GlxxvYq5Rll/yJ4RuHKDVum26bUcjspdS+43Cvpg+7Wg2NVYxoeVEv1l9NL1MVdmoLoeLaEJaJM2e7pIuzzHMohF44o7SLZt9vGQJ8p9vu6dcVEdHc0AkFoq9Ul12Veuli1Po4TTB+BK6WF2YE5GcamMqhwqc18jwUsbbzyCnmADkNOTsyeKYY5EN7j5/beSIuY3EfRpIL+wrwBT8zYstMvC1MxLkLIZgHpVNwAx6cSyksgR5OtP3sfaP6Yt/bxbK02bwuJOLhqEChOgZhbuRMYRGLMhGN7UGKRfIfmjcHLSTaO7iZzEzU dyerTkZC Qp+ynCxpv6dgepQu4Zhx8Rc6xm7Tfi01NGc3ROkzidObUcNfPvZAnSRt1qw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The ksm documentation mentions the process profit metric and how to calculate it. This adds the calculation of the metric. Signed-off-by: Stefan Roesch --- include/linux/ksm.h | 4 ++++ mm/ksm.c | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index d38a05a36298..a18cd03efcfb 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -55,6 +55,10 @@ struct page *ksm_might_need_to_copy(struct page *page, void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc); void folio_migrate_ksm(struct folio *newfolio, struct folio *folio); +#ifdef CONFIG_PROC_FS +long ksm_process_profit(struct mm_struct *); +#endif /* CONFIG_PROC_FS */ + #else /* !CONFIG_KSM */ static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) diff --git a/mm/ksm.c b/mm/ksm.c index a0b4611112c0..b3db29605303 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3024,6 +3024,14 @@ static void wait_while_offlining(void) } #endif /* CONFIG_MEMORY_HOTREMOVE */ +#ifdef CONFIG_PROC_FS +long ksm_process_profit(struct mm_struct *mm) +{ + return (long)mm->ksm_merging_pages * PAGE_SIZE - + mm->ksm_rmap_items * sizeof(struct ksm_rmap_item); +} +#endif /* CONFIG_PROC_FS */ + #ifdef CONFIG_SYSFS /* * This all compiles without CONFIG_SYSFS, but is a waste of space. From patchwork Fri Feb 10 21:50:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136517 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 D7513C636D7 for ; Fri, 10 Feb 2023 21:58:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68E96280026; Fri, 10 Feb 2023 16:58:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63F09280027; Fri, 10 Feb 2023 16:58:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52D2A280026; Fri, 10 Feb 2023 16:58:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 43772280021 for ; Fri, 10 Feb 2023 16:58:02 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 24210C055F for ; Fri, 10 Feb 2023 21:58:02 +0000 (UTC) X-FDA: 80452745604.04.1FF2794 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf16.hostedemail.com (Postfix) with ESMTP id 86ABD180008 for ; Fri, 10 Feb 2023 21:58:00 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf16.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066280; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HecBqyzdPVfVOZLrZ7DgKpBJ1v8oqJWfpqRSd/dw0a4=; b=07TbtfWR2b4S/PqLGcm+Y2q7MVXLcaj5P8PvL7ybY8xxpR64Lx24t7KPe4KkOxemE+f6tH WtM0BAriZ8MbaM1UwhSbcGGtZ3TiO9Wid5t4tmeQ/1AdHb52MiayfLhAWDtB9gaez5poJR B2b4r/ixj9qOb2af5+wCHLbnxuZNfco= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf16.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066280; a=rsa-sha256; cv=none; b=Pv/LyACWfy4877dkOK0scFFmo1Ur7EiAvWkpIDuCsgJEHwpyU4Vqqzfe2R6y4/TyQCApVS 4S6LEZ2bsR6o8Cs8Bw9fewn3Ja6qjevaJ6PRzXh3MzOLjONs8xaKtophkPVEWsXwXw4DJu atxCY2WrZrS/iYWlILY3q5FMFGYnh3Q= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 914026BFC2DB; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 11/19] mm: add ksm_merge_type() function Date: Fri, 10 Feb 2023 13:50:15 -0800 Message-Id: <20230210215023.2740545-12-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 86ABD180008 X-Rspam-User: X-Stat-Signature: i9y1nrmp9nc73ojmkm7ey5teeq5ur43h X-HE-Tag: 1676066280-553338 X-HE-Meta: U2FsdGVkX188idR0VQTRlGTpfj+MkJ0Xh8QbxzK7P43HeRTZBOks/2wE+oa14aXpMkbt8qKwUiQfA15qDmZIVi60P2KfuEUwjunBMxgwumLeApVMK8H5BSJtqDFi012rdPHqK7Zp2kkxaQAEi8C/wMx5li+KsIJW0w0r3tWNaYUadaiBliw/1Xygqxfkq6J88hPIhYbq5WR9jOc3mpyXI88P9nMbfKgHz/irt70P5Yfj9kauG1bZ4Ms4+WJBV+07eRRjbmvrHuUS2ETkOLMVYVWPTsOu+xg65uEtxDLGaT1oRsL+6S21oHRdrK/mHXx14oEsgXAE8n46B+vn79QGiz4bw+iW5AH7bGoAi055CJzDRwcw+/xRAcjgUrWTM7bPLXIOZAWItdqOgrZk6L6vj9jqN54OiApBdxg32h9PyOUUoUvSNYZkUBg0j/q9OGJexf2i9RTj194PGkiVQc8tsTtBYT4WGVhBHId/Uc7gTNEt60qMyO3bWwrGQr1fjfWpDzmcZA/6kkQza9Zfjd6VA8hKJZC+4Nl3l2BXOP9rbdydnmGCfIhuqV+NCNlbm4gM35gcUO2WbjimCEKLBEEFOLwuBDI9Kmdw/gcQF6vf2nPYxR3yYCYoVGnS7GjPn480GRfmOXIFT5HFcod0jyi+8VlPHQ0dgLcS4m9+X2n1TZAJtCfrfTH4QiW/Zv76+PYna0dCjOVH0b4uMiLa7TNaUQW+syMYP2jE63a0LTWd4HIDwOurH75aQ7sbyvNk1a6TuL/K4dTubm+SUcqzBgohJgHZGv/08yU2cQyP6kkTStgW5ABOdoSIay8KpT66yiteZ8V6Ju6x2E68wJfDbwFgWC18IaRWEpK/74xTlAZ9+q3aY+lVxg8Du5PyseOUTRe2wWmtLpmpGOa8Q8OzSqkAOuAUMp34biEwdEkzYt++sC1a/ZPPyyQDl5/9GQs1Vv0YJTfiTNbi71eYTRUhgRj Tm573Ti4 LU5go29TQu/43PQAb29T0NVYXk19epOwpFN/qwdJIb9CODnKmAW7iNvsRw/10XVuyXOPiFV7XjfuhOz5zvgVtHh9xaR8D3gi4c1vV 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: 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". Signed-off-by: Stefan Roesch --- include/linux/ksm.h | 1 + mm/ksm.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index a18cd03efcfb..d5f69f18ee5a 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -57,6 +57,7 @@ void folio_migrate_ksm(struct folio *newfolio, struct folio *folio); #ifdef CONFIG_PROC_FS long ksm_process_profit(struct mm_struct *); +const char *ksm_merge_type(struct mm_struct *mm); #endif /* CONFIG_PROC_FS */ #else /* !CONFIG_KSM */ diff --git a/mm/ksm.c b/mm/ksm.c index b3db29605303..3121bc0f48f3 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3030,6 +3030,17 @@ long ksm_process_profit(struct mm_struct *mm) return (long)mm->ksm_merging_pages * PAGE_SIZE - mm->ksm_rmap_items * sizeof(struct ksm_rmap_item); } + +/* Return merge type name as string. */ +const char *ksm_merge_type(struct mm_struct *mm) +{ + if (test_bit(MMF_VM_MERGE_ANY, &mm->flags)) + return "process"; + else if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) + return "madvise"; + else + return "none"; +} #endif /* CONFIG_PROC_FS */ #ifdef CONFIG_SYSFS From patchwork Fri Feb 10 21:50:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136516 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 9D6AAC05027 for ; Fri, 10 Feb 2023 21:57:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30CD8280025; Fri, 10 Feb 2023 16:57:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2BC4A280021; Fri, 10 Feb 2023 16:57:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 137C4280025; Fri, 10 Feb 2023 16:57:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F1586280021 for ; Fri, 10 Feb 2023 16:57:58 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CDDEBC056D for ; Fri, 10 Feb 2023 21:57:58 +0000 (UTC) X-FDA: 80452745436.21.9830775 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf18.hostedemail.com (Postfix) with ESMTP id 36E121C0012 for ; Fri, 10 Feb 2023 21:57:56 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf18.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066277; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KOSmZ5knDgHSl76RDDlt1TUiSdpuev+T40nmiawnyCE=; b=tHPRHqQ7kBPpdQ5CJsB76AdoeX5r3k/3XS9J2iex0z/WiOFL4PARZdH4gzWH+UUnpIsIN/ eViLvbnAijaxUtDUXWuYW29SRUFYFDGnI1OjG/05m8C7csLoeQg9AEmC8qPs9l/2vte5Og Tt6Qlkt3sc/tBIT64G3SCAdxmGlvbVY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf18.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066277; a=rsa-sha256; cv=none; b=snf5WTqyPb8vHw212RG3TIu/4+EQedtkelf6SjDKKgT1V6a9uvxgxHGPJc8CuZSRHMUMHn o2xkFuh700ucpPsY7sNS6a03/UztFvJs5s0C/pa4wJAfo4WDGpfsQo4uPwSdmcsQwXnzvZ yoBrDQGlFHnBW/nVvH2VWExjVE1emjU= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 959DE6BFC2DD; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 12/19] mm: expose ksm process profit metric in ksm_stat Date: Fri, 10 Feb 2023 13:50:16 -0800 Message-Id: <20230210215023.2740545-13-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 36E121C0012 X-Stat-Signature: bgsk5qabskw4i79d1uqfdhdwixogh5uw X-HE-Tag: 1676066276-79427 X-HE-Meta: U2FsdGVkX1847hy33jpOGnJIoPiWdz4qPyj3NxDZZLeEjwpQSHCXDKrXxzHjHESBV/FFcRx6IpXhy8HazOE0ITO4+C43NEekHKh+BF+G/vlL6oQ31ONxoHyjVqNyJvtRMa7JaY2ChZSdtPg/guM59vPTxkvMuFuXxqIee+O6I9PlWFOLSq+Zxt2nP2qiJpjfEvAlatuiSnNHuw3kk8HotZGBC1v74c+mZzDRwvPouv3wO8EKA034tWYk+kwkJh1JlMCmLa3/Lrys2je24y4KMnw+6J7qhf9bnjZwH3LuE7zkYXYn985tkON6icRjfQcCNC5JMLB13IYLAMxisiIJ/apBl0AXwHVEKoqRIT9qcB4le2Uw+AxcSuOeEm2yb/Uasr2ZjuFGcnzDnJ5GoowBK6fstsyGQLVA1mQIPcIb+OqEkMoltJIAVFXPderwvt5xdjamvslI/6H+2oNBHOeMfaeMNqOHSBkYkhPsJlY+TmMsfdEZA+jQTDDOzpkAt8F3HhEG7hoXlhIWCUH8PkwcytlNvNiFtppdwhzelKQJMzM/49gOI60lgMAFMfpXnrsdE7SbKqUQaqCyMmgSPpDfjj76T9k/jhrEhTSFR6l0XlnA1/0sD315Zd2k0FSkuZhG8F6PMskQPioCyt5OF1lIdlTXY+cSkxXuJm3fkGcApe5n3w1NXe050fCh9dt5ST3E1Y+WoL7Aaa1ftSSj3MUTUEpPbj/M2w/EK0nxY1qDNGGlSicunbygjU6uZi8iQwgOq37b3plnE6TQjzYywFbI/cS9xGG+ISj9L4BUMSTE/Tq0dKMwmpR8F4FZgqBnSWGjibXM1mGQ1HCjXYE6fyQ59KImVop1qSFirywxbk91F+ytUnONQxkIQbhK4aYSXXi9O5/E4/bM1R9Juo3ieuHmcfonIISlJUTR8c8U3OuYtnelVN++OnYkE83GyMJUW1IOPfqOx8PF3jQQ1dHxHlG L822ojYg ggKj/Y63LVtJVaoHLFjvBF7eTzOYv66V9Djn4epz28WHRjB/IJCv7upE1E22PNYSZhCYzc3WufeO+g8sffyd8mIjbic65PkHkxZjO X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This exposes the ksm process profit metric in /proc//ksm_stat. 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. Signed-off-by: Stefan Roesch --- fs/proc/base.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/proc/base.c b/fs/proc/base.c index ac9ebe972be0..fb9567bc42a4 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -96,6 +96,7 @@ #include #include #include +#include #include #include "internal.h" #include "fd.h" @@ -3208,6 +3209,8 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns, if (mm) { seq_printf(m, "ksm_rmap_items %lu\n", mm->ksm_rmap_items); seq_printf(m, "zero_pages_sharing %lu\n", mm->ksm_zero_pages_sharing); + seq_printf(m, "ksm_merging_pages %lu\n", mm->ksm_merging_pages); + seq_printf(m, "ksm_process_profit %ld\n", ksm_process_profit(mm)); mmput(mm); } From patchwork Fri Feb 10 21:50:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136514 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 AC825C636D7 for ; Fri, 10 Feb 2023 21:57:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B727328001E; Fri, 10 Feb 2023 16:57:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0EC4280023; Fri, 10 Feb 2023 16:57:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79F1E280021; Fri, 10 Feb 2023 16:57:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5F0CC28001E for ; Fri, 10 Feb 2023 16:57:51 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 33F5D1A05F6 for ; Fri, 10 Feb 2023 21:57:51 +0000 (UTC) X-FDA: 80452745142.05.5718F24 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf08.hostedemail.com (Postfix) with ESMTP id 8DCA4160015 for ; Fri, 10 Feb 2023 21:57:49 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf08.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066269; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8hIhmYmoyvXJfCY+787/qNEg0vVbqxyyc+jduo0tMNc=; b=nL8Kk1sl5fYkrwtrtiuSzcocWsN50iJ74oz83WNqyRp38ryVN0E+oCUqR/YR+BHOESIIgB npHuhVJeRQ9RsuqE1RdLo+ZN72z/NeLLza7NAIC18G0FsFPTyY2Ww2XC2G5U1qU9DTGXNa iUCoaPFgspFm2jeWSGBn4qOMGtj6h1Q= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf08.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066269; a=rsa-sha256; cv=none; b=SclgGDfRywWIQeeRZWUtSbKi+x5R+wSBNjnP0Nj9BASJhblpc+jho8mYw85nt4PE1MeA6w 4giHxfTsUPHvS5aJ45SqaQvEtutU5MSoFeFaxND03LzXPqMRjAuJglGImWFcxyg86s+Fbm aw0xe4xz9eIYxY9/1QQzLlF/B3jT9O4= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 9A29F6BFC2E1; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 13/19] mm: expose ksm merge type in ksm_stat Date: Fri, 10 Feb 2023 13:50:17 -0800 Message-Id: <20230210215023.2740545-14-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8DCA4160015 X-Stat-Signature: 7ftuib6kg1jk8saejj91caqxaakdpczb X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1676066269-13578 X-HE-Meta: U2FsdGVkX198MWY8SMTBKGsnSzBsA9bbjwsOnNf+Q315ygKSjNoDaEHJVgA62sYfHD+VmJiRpsPjUHBgc7OySQbbdQ5sF6/ONKBt6FECNPMN6qaMT7khQeGka0gnBwMw3HVg8ynbngQ9BEY/5V0QI4hAYymCJrFav38lpRfKDzn8WmImb9wB9/x5saBJxYfCDhMuoXFlAdSRz5V9HedTKE83B023dp4ZH5v4cQ+jYFiRzDWw9gEO9ga3W5Lgw5o2BubuTWuHEsrGRHgo3VZE1NDy/0fAmw+G9ytuS9G+NFHgqxc+3sdworT8iY12DT2n40w7WrdljTTYcKY446iWByWzsFg7KrJOvgzPe4G7pcmZeDNdvWGeQ4gy41ZD+j09GwkM2i0gfjirQmdm3Uyqu2nuURE7ZtbPKTzOWcF9Eui3ANIRI0IeaZEdIhumWI+scHqN2k3F3nNltGX/7D9dCHIM/dC71zMEOZmEY3CxjHTB0PmlSnvWrgkBHrVQbJaLWID9X5agXRx67gesH1JdM4SU7oXUsBjj70QcWkmWX0bY0M+a7V0BUnF9eJpAfFJ0dK7bpvdAU+jQHOTBy6EjeefNkaRW7jrCwoXNccDZAAfvPBvsBQsUKOecMqxwm5eZw96pU3CZMs3kTsc1rrnwViSTT4mH/boYNuftJL1c3dn8bJvGGmwF1Xnn0yDAjbTxsMP0pGcymB+SKiFcjzYw4VE3Bk8K86uTpT6dmw7Cku/AnrADT+8XY75GMLb0r162h6l7xZf9rAK+mB0DjE/lDtBEgw0Bbtem0RjX8TlshjvAVnPb1f07V85UwMIhRI5wL0raZ5+xgmiPiWavFYbNAivbn4Wmw3wzjOLJd9pAV0k282sdoJNWHMHT1cQenPB63qzJIxho95dfkTsKd811c7kZJfm68HWKfY3Hc37wtLyTwOJzdLAQbU0ttY8PfjwFEQzsG5tYNk4kOxkmyYn Q4SVznSp DUd2ucXm+x4c4XhFPIas1qlEA1ewa9ch1mzE8avgbQ8B+K7Mkfnlq50bAIQGzKwe1n3E+r/wokBSDoYvbDo9k/zAedciXFc/0aIRf 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: This exposes the ksm process type in /proc//ksm_stat. The name of the value is ksm_merge_type. Signed-off-by: Stefan Roesch --- fs/proc/base.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/proc/base.c b/fs/proc/base.c index fb9567bc42a4..45749051e53b 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3200,6 +3200,7 @@ static int proc_pid_ksm_merging_pages(struct seq_file *m, struct pid_namespace * return 0; } + static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task) { @@ -3210,6 +3211,7 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns, seq_printf(m, "ksm_rmap_items %lu\n", mm->ksm_rmap_items); seq_printf(m, "zero_pages_sharing %lu\n", mm->ksm_zero_pages_sharing); seq_printf(m, "ksm_merging_pages %lu\n", mm->ksm_merging_pages); + seq_printf(m, "ksm_merge_type %s\n", ksm_merge_type(mm)); seq_printf(m, "ksm_process_profit %ld\n", ksm_process_profit(mm)); mmput(mm); } From patchwork Fri Feb 10 21:50:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136515 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 76C3FC64ED9 for ; Fri, 10 Feb 2023 21:57:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E959280024; Fri, 10 Feb 2023 16:57:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 09955280021; Fri, 10 Feb 2023 16:57:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA2AF280024; Fri, 10 Feb 2023 16:57:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CEA53280021 for ; Fri, 10 Feb 2023 16:57:56 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A61191C6191 for ; Fri, 10 Feb 2023 21:57:56 +0000 (UTC) X-FDA: 80452745352.06.95F90B2 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf05.hostedemail.com (Postfix) with ESMTP id 0D2EC100004 for ; Fri, 10 Feb 2023 21:57:54 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf05.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066275; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sqqwEo3HJ9745cc6ZGRbD2GEHTwsqkH5y3UC7Zft/Hg=; b=ka3ryXkwxrpzLYUByCPatnqRerDhbrPnnx09xkwaXk1d6b2lJdp5fTIgQ6mxZzXB7axPcV V3Abq0fpY7U5SId8RNTiy1aNmb7/z8AfbOPn7p9W8c+3ar/fti9A+RPm9IwqS50ODzs8ku 5bWw0KbaF8WKDRYmBBSeqx82YNxzVX4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf05.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066275; a=rsa-sha256; cv=none; b=W2i73Nhj6jnjZKes0zijFx2j5WDNsq5M/LJOi4jIhrX3M0HTLBz2Tsx9jJEsG4YhDKksuj XqSmyF9AlKLfEbi80x8GT3uhxSEz18fDKeJFrC7Le3bEDjnVxERQJzfH0cN/7cl1sLXUnM PVzSbCEkwdGxJd2TNvHdaaW265++gxw= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 9EAD76BFC2E3; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org, Bagas Sanjaya Subject: [RFC PATCH v2 14/19] docs: document new procfs ksm knobs Date: Fri, 10 Feb 2023 13:50:18 -0800 Message-Id: <20230210215023.2740545-15-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0D2EC100004 X-Stat-Signature: uwkitsmyabtxwkifsum1jswmjrf1i7gg X-HE-Tag: 1676066274-581832 X-HE-Meta: U2FsdGVkX18VJ21KavaktjvMOCLICHFuh96WDZF5cab9PNzj29Xy0lI5LQBCxpc6Svh1w0QtBwet0OCCHJN2xLXWgH2OxdLiDH6zzPYerVvnAssKfBVYCRmVbStbZloaQ/Ol9NDZoil6XA4uyJU72yCt+FRDyQEvszit/pJmUERCS9cFfLxi6s5iIAxqxX6Z7YZVdjJbc6W6kMfaRsvOirzWqpnbkahHF6DSeo0T2DJcFGQoqpwbLG2Z1z2ZSgk/NM+TXTOccApthnohxv5slVg2O9gAZfHCtybr2DTrbQKg/A43od/mfy+jNKJayO73xgLJ1b4L9cXI650r4pzSkT24pZ5aTwnO+ZWEZRGCNmggtEWKNFgQ+Q6MdWceMs59paNeyMWO92t9EKw3UL/FoJRzdmck7571OrOstsVVG2r3nJzK5itq7IgHKMJw2mItpafevytVbcxprfTzcCCOJRIlUlepBKWsWnEVP85zTtj5AmKN42ImOoVzMuTpjErLB9om0ZqjW2zqXIjsB7tz/A9QFCDRkI/7V4JPItXIhxHelThVqU68vMiHsBav351D5vIBOuiVTV/AiF28Ad91uuiTjmgNXdUN9WFGwmOgNPpaUBOpB/BFKwnHFF5QUp68fpN6OITN/R6WAluJmLPZA8UgCroqWy/1VWPlOfkauJhg/8dc3gq+CX7h8XpepGBPtqojgWkSeKpXMX8MA9VJ8jBoVLnn4RSbtt13zBk8wYs3jxjfjUigRPXjrlLk90S1llQfuEV0pee3LQcFslzcW70QDQGDxtqr5TK8voG+lZwfoGPjuYhDciLnEnxNFHdoSvUTCJ3rUDsXFmp3BsDIsImPd87tHnNHu3owcSr+lf5uzD5eDNa1P/7Ywi8tGHfqDhTzmXNJviOYSpb0JYPYGnoNI2bLxlaT2Tdzo2SjyjOaIqc6LiBzZHcpNqCXQwB5juPQv1fhXp/54zQIdEN Ox9MvjMo 7nuREhyGXYbr81Dtm/rwCXIZEz0HN37JoyzV67pY93o5n/wq5lW0PRSKCDrqiWkcJSuEmt0vb11Z9Q/Q= 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: Document both ksm_process_profit and ksm_merge_type proc settings. Signed-off-by: Stefan Roesch Reviewed-By: Bagas Sanjaya Reviewed-by: Bagas Sanjaya --- Documentation/admin-guide/mm/ksm.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst index 5c4daf44d79d..34f1d0396eee 100644 --- a/Documentation/admin-guide/mm/ksm.rst +++ b/Documentation/admin-guide/mm/ksm.rst @@ -218,7 +218,8 @@ several times, which are unprofitable memory consumed. ksm_rmap_items * sizeof(rmap_item). where ksm_merging_pages is shown under the directory ``/proc//``, - and ksm_rmap_items is shown in ``/proc//ksm_stat``. + and ksm_rmap_items is shown in ``/proc//ksm_stat``. The process profit + is also shown in ``/proc//ksm_stat`` as ksm_process_profit. From the perspective of application, a high ratio of ``ksm_rmap_items`` to ``ksm_merging_pages`` means a bad madvise-applied policy, so developers or @@ -229,6 +230,9 @@ so if the ``ksm_rmap_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. +The ksm_merge_type in ``/proc//ksm_stat`` shows the merge type of the +process. Valid values are ``none``, ``madvise`` and ``process``. + Monitoring KSM events ===================== From patchwork Fri Feb 10 21:50:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136525 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 32DB1C64ED8 for ; Fri, 10 Feb 2023 22:04:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B92DF280030; Fri, 10 Feb 2023 17:04:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AF54728002F; Fri, 10 Feb 2023 17:04:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96FD3280030; Fri, 10 Feb 2023 17:04:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6D475280021 for ; Fri, 10 Feb 2023 17:04:01 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3B753A05CD for ; Fri, 10 Feb 2023 22:04:01 +0000 (UTC) X-FDA: 80452760682.01.DC1995E Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf16.hostedemail.com (Postfix) with ESMTP id 90741180018 for ; Fri, 10 Feb 2023 22:03:59 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf16.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066639; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M6Oo6aoakYXCEgYPgkANDFzHLQCHHEya9CaFxZk6M78=; b=RL7naguGJH/xULqGtnkOiYnvIdiTnVdTxs3Pcc3CASt4JFwXUySqELHxjDdBt3qdepSUhj Pk+HzFg0VkYGvHDtvBXuQTJib2IjrsUxTrWt8xKCAdPkpPFqfE8YoEBdFd0cAbxIv5KZHF kMwvlIKuR4u7t78x96TJaQqAICvQlbk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf16.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066639; a=rsa-sha256; cv=none; b=a7WnNZKHqN16FZf9X3fAq66jbhjhef8MYwhw5nKRNBckHn0gy2QIDQO+u9hjyjB4as3Gn2 MImVJ0CeTt4KbhJ4bjimx3NqESR4sNnpBmLzK3DDSnR4gmqmlrGu0Qmh/RTDIv5MBmIX+6 sBy2DBfec/Oqr3oqOGwvU6VVxhP65g4= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id A31F86BFC2E5; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 15/19] tools: add new prctl flags to prctl in tools dir Date: Fri, 10 Feb 2023 13:50:19 -0800 Message-Id: <20230210215023.2740545-16-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 90741180018 X-Stat-Signature: wy8yinae83bigiy9rfro3wpweao8ybqd X-Rspam-User: X-HE-Tag: 1676066639-394111 X-HE-Meta: U2FsdGVkX1+OhYIsB/Hncsar9WszmlwV9V4n8LoVtTT2fCstlCW8MyePZX+i1484VtIcWrwKal2riEoGo01c2IcHrOWB3lhEz9bNgob3GYOVcLrtGZ8nw6vFyThoUnpoMXUcI4fYvGqL/t2xAY24QzwJpBcPGdW3lt28rx1Pjsm6TRSvCrbZlVu1tDBWkRjG5UpvIbXvh+Lf4cyt16gDvuQURzLwW5Y2Uo5r5hLVoztS6Ujze9d7pDLxtYAf5Cg6FDGBDGX7AwhzbH/AETSKlE0ijo66uj2RsvWQL1lO1+6uHmvFDmisJthN2JK/cvjxKrHA9fSU0HDRXdrZWJCpAhkWwmssp9V3yDrcwXmLRmpYRlUKW3B8gIs7dsk1i+LpxjurZOQr39jgPZeb1oyE69U7iojy2lZ52LrJyB0XnFLRUJtkEkCLwxXlq9tSNSh+6GVtd69J9FuUSnKvozYkS12J5f1txCTB/k7+z39KJppuX17DW8cfa3R6wYYFDIvzh5DDj1j9slVXEfu/m3KJWpIV7QwBWw77L5OQ11/39raUpEAOYD27FLHF60JOO6hmw0XR+PYc7xfWzYwX6/baMAF24DmjSJvS91OiGNQRLwe85vFXLfO1ghTEMR4yqD7tYN57JRNQ8NH1aPhhTM05Aw8EE2rarY5APN350cSK8UF/sG8ARjMr1Y02jrSuysfRl7Asm4GGqt9TmSk6XUwe837xF0hvEDYju3pR7dBJOik+vcI1fOzUYtATitl0mqTeaSfhktu/+OaWPwhVyoYlL8zvcN6D0VHN/bVcW72DAZbbnbbIDHhe75coauWMxjXehG2+sG37xq9t49QdJwt1vhxk6S4QS3HQXymcFPxiz/5aPq18zIUXdgupA5qAfW7xhjdHIa28ajAKisKBv0+vLVvtXb1Iyddx5oBoD0/Dzu2nCLhHJ21aQGpxJtZnuRky/i7GnT1JFJ/PN+8+7Bs LoyIbpGa 4sjFPgV8n5WS1HfDrtXXRhV9Gp0M7QRi9JvozTmR/HSXGYFAVlpGUuwQP6A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This adds the new prctl flags to the include file prct.h in the tools directory. This makes sure they are available for testing. Signed-off-by: Stefan Roesch --- tools/include/uapi/linux/prctl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/include/uapi/linux/prctl.h b/tools/include/uapi/linux/prctl.h index a5e06dcbba13..e4c629c1f1b0 100644 --- a/tools/include/uapi/linux/prctl.h +++ b/tools/include/uapi/linux/prctl.h @@ -284,4 +284,6 @@ struct prctl_mm_map { #define PR_SET_VMA 0x53564d41 # define PR_SET_VMA_ANON_NAME 0 +#define PR_SET_MEMORY_MERGE 67 +#define PR_GET_MEMORY_MERGE 68 #endif /* _LINUX_PRCTL_H */ From patchwork Fri Feb 10 21:50:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136524 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 CB83AC05027 for ; Fri, 10 Feb 2023 22:03:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 243EA28002E; Fri, 10 Feb 2023 17:03:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CCF7280021; Fri, 10 Feb 2023 17:03:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01FB528002E; Fri, 10 Feb 2023 17:03:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E1B44280021 for ; Fri, 10 Feb 2023 17:03:58 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C3FFA1C5C1D for ; Fri, 10 Feb 2023 22:03:58 +0000 (UTC) X-FDA: 80452760556.02.BD657DE Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf13.hostedemail.com (Postfix) with ESMTP id 1ECEE20019 for ; Fri, 10 Feb 2023 22:03:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf13.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066637; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lrFBGefAdU1da45ueJHuB0uXK3bnpFgZEJdJ1VidviE=; b=ve02Vf/Q/6eOe+UF6MPvl0VxRjMyXWXVzZ+lXQqCVcmFyyMnByGTxKOw1DZg2ONH+8m75r 5+x091NAWWZGgXjGe5/+QFvNlS8VEiTcrGaNOXTnYG5THfDd5CCc7a+r7JKQhFqNK5CcZg pD9TLTWdByG5pyFtZigI2U1vJJVB64I= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf13.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066637; a=rsa-sha256; cv=none; b=OoGuZtwQrShLOVf/GmSQAj0Kih4VDQuGDTuA5Gcapyl1TFl5Qs4sHpjdAr47NTsmdvLtSG phv/rPqBUryLfUXjPebKh7VBfHnFOE+hd+j5VHL0erIbCc2AnXBJx/PeHJc9jwW6AHoV5Z N8mLBAE+80BaNe9RRUNbq7WbkLHF1uQ= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id A7E6B6BFC2E9; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 16/19] selftests/vm: add KSM prctl merge test Date: Fri, 10 Feb 2023 13:50:20 -0800 Message-Id: <20230210215023.2740545-17-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1ECEE20019 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: mxmir74sb8ncynbnscpdjqburanumdia X-HE-Tag: 1676066636-563250 X-HE-Meta: U2FsdGVkX197ch7qKXyVKL01Rk938B5Cnp2gG6GPPwcAbphlfrbxEIO+0kr3HHS5i7zmkCZUX/yfb+77qkiluX1CcWrZlUOQNdxUIzIroYhhXW4m3zqW1yDyXQXvrrxpsn8p0C2EIbLEfHHy1sh/gkGTVKKBgoAaSMN7lp1XT0YtXPW/Kc/Fd0dRgwxtvdrS0v4fC6VHt3wr+d3gS1QYfx65j88wbJ15BdRcMiFxNgHqf3IEOaMM/sTkH0r2akJI/gLsHmpcjf6MiKWBYLdnNRO2Cg/QddHeXzLvJy9/CSasPNx+hUcyGLX3uQ8o2LV1e2ZtskEGARxQz/VhiA1hawhUJHhn810GMX8Jb7tAYKRypLu/ecpqN2WQYaMT8WU3gDsqJJiEwfPegofJHULmW7p6j+O9Ad+5317r+NRsXTYqejNxUGVcLF9AVdge38xxnFahdGpgZH9rkpPb2djp899FsCYw4yPLs+uxyvMwo0HYFAbMlF6Jknn7o7SUEILHqmBEQ5GxhOzkx76EakUcFUQcSd7H95n9svNMGrWeWTkDB0CMbLLvoMT9fPPFJ8jIJYhtoI1Nad0Gyzl2X57CIF2as9BYy49lteLh0oJxHTc1B+VWG+yVUEow0ekZznV2u7dLly2if17URWDqIQLcPSS5mj87J+j9qLPISdOcP9tNOpti9r4gVx4kI1COAQJ3kJNJW0n5CBSvG3Pk8O1PFpTiu1V6UFeiWFVMVjlFt32+85bql97ClQg5qQ6pzehVCNTG/L7Nz39+Bc8FoagdjDZthGmkAwX2Bo7j4HWTedW/92N40rTK0bcKO4Kf1wS6LdPmueYwHurmEFawTIavtzk8wXDSFg4w7y9Ih02I70X7UmvAyOjdaQitNRmUuupi0dwclMRg33QW6rZBa3pyFXUy8wAFGOL4+toWiu8DCLks1TScqy4YxYc7+xLrjfh4XasuuC21lmi4YfuQvj2 m+dsrUI7 Eo+icFt6chhewYWSu3gAyCX+TV3tmXsY2F3pz/e9v3EnAdaA= 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: This adds the -t option to the ksm_tests program. The -t flag allows to specify if it should use madvise or prctl ksm merging. Signed-off-by: Stefan Roesch --- tools/testing/selftests/mm/Makefile | 3 +- tools/testing/selftests/mm/ksm_tests.c | 116 +++++++++++++++++-------- 2 files changed, 80 insertions(+), 39 deletions(-) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index d90cdc06aa59..507cb22bdebd 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -29,7 +29,8 @@ MACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/p # LDLIBS. MAKEFLAGS += --no-builtin-rules -CFLAGS = -Wall -I $(top_srcdir) -I $(top_srcdir)/usr/include $(EXTRA_CFLAGS) $(KHDR_INCLUDES) +CFLAGS = -Wall -I $(top_srcdir)/tools/include/uapi +CFLAGS += -I $(top_srcdir) -I $(top_srcdir)/usr/include $(EXTRA_CFLAGS) $(KHDR_INCLUDES) LDLIBS = -lrt -lpthread TEST_GEN_FILES = cow TEST_GEN_FILES += compaction_test diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c index f9eb4d67e0dd..386a0929c8a3 100644 --- a/tools/testing/selftests/mm/ksm_tests.c +++ b/tools/testing/selftests/mm/ksm_tests.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include +#include #include #include #include @@ -21,6 +23,7 @@ #define KSM_PROT_STR_DEFAULT "rw" #define KSM_USE_ZERO_PAGES_DEFAULT false #define KSM_MERGE_ACROSS_NODES_DEFAULT true +#define KSM_MERGE_TYPE_DEFAULT 0 #define MB (1ul << 20) struct ksm_sysfs { @@ -33,6 +36,12 @@ struct ksm_sysfs { unsigned long use_zero_pages; }; +enum ksm_merge_type { + KSM_MERGE_MADVISE, + KSM_MERGE_PRCTL, + KSM_MERGE_LAST = KSM_MERGE_PRCTL +}; + enum ksm_test_name { CHECK_KSM_MERGE, CHECK_KSM_UNMERGE, @@ -129,6 +138,10 @@ static void print_help(void) printf(" -m: change merge_across_nodes tunable\n" " Default: %d\n", KSM_MERGE_ACROSS_NODES_DEFAULT); printf(" -s: the size of duplicated memory area (in MiB)\n"); + printf(" -t: KSM merge type\n" + " Default: 0\n" + " 0: madvise merging\n" + " 1: prctl merging\n"); exit(0); } @@ -176,12 +189,21 @@ static int ksm_do_scan(int scan_count, struct timespec start_time, int timeout) return 0; } -static int ksm_merge_pages(void *addr, size_t size, struct timespec start_time, int timeout) +static int ksm_merge_pages(int merge_type, void *addr, size_t size, + struct timespec start_time, int timeout) { - if (madvise(addr, size, MADV_MERGEABLE)) { - perror("madvise"); - return 1; + if (merge_type == KSM_MERGE_MADVISE) { + if (madvise(addr, size, MADV_MERGEABLE)) { + perror("madvise"); + return 1; + } + } else if (merge_type == KSM_MERGE_PRCTL) { + if (prctl(PR_SET_MEMORY_MERGE, 1)) { + perror("prctl"); + return 1; + } } + if (ksm_write_sysfs(KSM_FP("run"), 1)) return 1; @@ -266,7 +288,8 @@ static int ksm_restore(struct ksm_sysfs *ksm_sysfs) return 0; } -static int check_ksm_merge(int mapping, int prot, long page_count, int timeout, size_t page_size) +static int check_ksm_merge(int merge_type, int mapping, int prot, + long page_count, int timeout, size_t page_size) { void *map_ptr; struct timespec start_time; @@ -281,13 +304,16 @@ static int check_ksm_merge(int mapping, int prot, long page_count, int timeout, if (!map_ptr) return KSFT_FAIL; - if (ksm_merge_pages(map_ptr, page_size * page_count, start_time, timeout)) + if (ksm_merge_pages(merge_type, map_ptr, page_size * page_count, start_time, timeout)) goto err_out; /* verify that the right number of pages are merged */ if (assert_ksm_pages_count(page_count)) { printf("OK\n"); - munmap(map_ptr, page_size * page_count); + if (merge_type == KSM_MERGE_MADVISE) + munmap(map_ptr, page_size * page_count); + else if (merge_type == KSM_MERGE_PRCTL) + prctl(PR_SET_MEMORY_MERGE, 0); return KSFT_PASS; } @@ -297,7 +323,7 @@ static int check_ksm_merge(int mapping, int prot, long page_count, int timeout, return KSFT_FAIL; } -static int check_ksm_unmerge(int mapping, int prot, int timeout, size_t page_size) +static int check_ksm_unmerge(int merge_type, int mapping, int prot, int timeout, size_t page_size) { void *map_ptr; struct timespec start_time; @@ -313,7 +339,7 @@ static int check_ksm_unmerge(int mapping, int prot, int timeout, size_t page_siz if (!map_ptr) return KSFT_FAIL; - if (ksm_merge_pages(map_ptr, page_size * page_count, start_time, timeout)) + if (ksm_merge_pages(merge_type, map_ptr, page_size * page_count, start_time, timeout)) goto err_out; /* change 1 byte in each of the 2 pages -- KSM must automatically unmerge them */ @@ -337,8 +363,8 @@ static int check_ksm_unmerge(int mapping, int prot, int timeout, size_t page_siz return KSFT_FAIL; } -static int check_ksm_zero_page_merge(int mapping, int prot, long page_count, int timeout, - bool use_zero_pages, size_t page_size) +static int check_ksm_zero_page_merge(int merge_type, int mapping, int prot, long page_count, + int timeout, bool use_zero_pages, size_t page_size) { void *map_ptr; struct timespec start_time; @@ -356,7 +382,7 @@ static int check_ksm_zero_page_merge(int mapping, int prot, long page_count, int if (!map_ptr) return KSFT_FAIL; - if (ksm_merge_pages(map_ptr, page_size * page_count, start_time, timeout)) + if (ksm_merge_pages(merge_type, map_ptr, page_size * page_count, start_time, timeout)) goto err_out; /* @@ -402,8 +428,8 @@ static int get_first_mem_node(void) return get_next_mem_node(numa_max_node()); } -static int check_ksm_numa_merge(int mapping, int prot, int timeout, bool merge_across_nodes, - size_t page_size) +static int check_ksm_numa_merge(int merge_type, int mapping, int prot, int timeout, + bool merge_across_nodes, size_t page_size) { void *numa1_map_ptr, *numa2_map_ptr; struct timespec start_time; @@ -439,8 +465,8 @@ static int check_ksm_numa_merge(int mapping, int prot, int timeout, bool merge_a memset(numa2_map_ptr, '*', page_size); /* try to merge the pages */ - if (ksm_merge_pages(numa1_map_ptr, page_size, start_time, timeout) || - ksm_merge_pages(numa2_map_ptr, page_size, start_time, timeout)) + if (ksm_merge_pages(merge_type, numa1_map_ptr, page_size, start_time, timeout) || + ksm_merge_pages(merge_type, numa2_map_ptr, page_size, start_time, timeout)) goto err_out; /* @@ -466,7 +492,8 @@ static int check_ksm_numa_merge(int mapping, int prot, int timeout, bool merge_a return KSFT_FAIL; } -static int ksm_merge_hugepages_time(int mapping, int prot, int timeout, size_t map_size) +static int ksm_merge_hugepages_time(int merge_type, int mapping, int prot, + int timeout, size_t map_size) { void *map_ptr, *map_ptr_orig; struct timespec start_time, end_time; @@ -508,7 +535,7 @@ static int ksm_merge_hugepages_time(int mapping, int prot, int timeout, size_t m perror("clock_gettime"); goto err_out; } - if (ksm_merge_pages(map_ptr, map_size, start_time, timeout)) + if (ksm_merge_pages(merge_type, map_ptr, map_size, start_time, timeout)) goto err_out; if (clock_gettime(CLOCK_MONOTONIC_RAW, &end_time)) { perror("clock_gettime"); @@ -533,7 +560,7 @@ static int ksm_merge_hugepages_time(int mapping, int prot, int timeout, size_t m return KSFT_FAIL; } -static int ksm_merge_time(int mapping, int prot, int timeout, size_t map_size) +static int ksm_merge_time(int merge_type, int mapping, int prot, int timeout, size_t map_size) { void *map_ptr; struct timespec start_time, end_time; @@ -549,7 +576,7 @@ static int ksm_merge_time(int mapping, int prot, int timeout, size_t map_size) perror("clock_gettime"); goto err_out; } - if (ksm_merge_pages(map_ptr, map_size, start_time, timeout)) + if (ksm_merge_pages(merge_type, map_ptr, map_size, start_time, timeout)) goto err_out; if (clock_gettime(CLOCK_MONOTONIC_RAW, &end_time)) { perror("clock_gettime"); @@ -574,7 +601,7 @@ static int ksm_merge_time(int mapping, int prot, int timeout, size_t map_size) return KSFT_FAIL; } -static int ksm_unmerge_time(int mapping, int prot, int timeout, size_t map_size) +static int ksm_unmerge_time(int merge_type, int mapping, int prot, int timeout, size_t map_size) { void *map_ptr; struct timespec start_time, end_time; @@ -589,7 +616,7 @@ static int ksm_unmerge_time(int mapping, int prot, int timeout, size_t map_size) perror("clock_gettime"); goto err_out; } - if (ksm_merge_pages(map_ptr, map_size, start_time, timeout)) + if (ksm_merge_pages(merge_type, map_ptr, map_size, start_time, timeout)) goto err_out; if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { @@ -621,7 +648,7 @@ static int ksm_unmerge_time(int mapping, int prot, int timeout, size_t map_size) return KSFT_FAIL; } -static int ksm_cow_time(int mapping, int prot, int timeout, size_t page_size) +static int ksm_cow_time(int merge_type, int mapping, int prot, int timeout, size_t page_size) { void *map_ptr; struct timespec start_time, end_time; @@ -660,7 +687,7 @@ static int ksm_cow_time(int mapping, int prot, int timeout, size_t page_size) memset(map_ptr + page_size * i, '+', i / 2 + 1); memset(map_ptr + page_size * (i + 1), '+', i / 2 + 1); } - if (ksm_merge_pages(map_ptr, page_size * page_count, start_time, timeout)) + if (ksm_merge_pages(merge_type, map_ptr, page_size * page_count, start_time, timeout)) goto err_out; if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { @@ -697,6 +724,7 @@ int main(int argc, char *argv[]) int ret, opt; int prot = 0; int ksm_scan_limit_sec = KSM_SCAN_LIMIT_SEC_DEFAULT; + int merge_type = KSM_MERGE_TYPE_DEFAULT; long page_count = KSM_PAGE_COUNT_DEFAULT; size_t page_size = sysconf(_SC_PAGESIZE); struct ksm_sysfs ksm_sysfs_old; @@ -705,7 +733,7 @@ int main(int argc, char *argv[]) bool merge_across_nodes = KSM_MERGE_ACROSS_NODES_DEFAULT; long size_MB = 0; - while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:MUZNPCHD")) != -1) { + while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:t:MUZNPCHD")) != -1) { switch (opt) { case 'a': prot = str_to_prot(optarg); @@ -745,6 +773,17 @@ int main(int argc, char *argv[]) printf("Size must be greater than 0\n"); return KSFT_FAIL; } + case 't': + { + int tmp = atoi(optarg); + + if (tmp < 0 || tmp > KSM_MERGE_LAST) { + printf("Invalid merge type\n"); + return KSFT_FAIL; + } + merge_type = atoi(optarg); + } + break; case 'M': break; case 'U': @@ -795,35 +834,36 @@ int main(int argc, char *argv[]) switch (test_name) { case CHECK_KSM_MERGE: - ret = check_ksm_merge(MAP_PRIVATE | MAP_ANONYMOUS, prot, page_count, + ret = check_ksm_merge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, page_count, ksm_scan_limit_sec, page_size); break; case CHECK_KSM_UNMERGE: - ret = check_ksm_unmerge(MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, - page_size); + ret = check_ksm_unmerge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, + ksm_scan_limit_sec, page_size); break; case CHECK_KSM_ZERO_PAGE_MERGE: - ret = check_ksm_zero_page_merge(MAP_PRIVATE | MAP_ANONYMOUS, prot, page_count, - ksm_scan_limit_sec, use_zero_pages, page_size); + ret = check_ksm_zero_page_merge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, + page_count, ksm_scan_limit_sec, use_zero_pages, + page_size); break; case CHECK_KSM_NUMA_MERGE: - ret = check_ksm_numa_merge(MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, - merge_across_nodes, page_size); + ret = check_ksm_numa_merge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, + ksm_scan_limit_sec, merge_across_nodes, page_size); break; case KSM_MERGE_TIME: if (size_MB == 0) { printf("Option '-s' is required.\n"); return KSFT_FAIL; } - ret = ksm_merge_time(MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, - size_MB); + ret = ksm_merge_time(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, + ksm_scan_limit_sec, size_MB); break; case KSM_MERGE_TIME_HUGE_PAGES: if (size_MB == 0) { printf("Option '-s' is required.\n"); return KSFT_FAIL; } - ret = ksm_merge_hugepages_time(MAP_PRIVATE | MAP_ANONYMOUS, prot, + ret = ksm_merge_hugepages_time(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, size_MB); break; case KSM_UNMERGE_TIME: @@ -831,12 +871,12 @@ int main(int argc, char *argv[]) printf("Option '-s' is required.\n"); return KSFT_FAIL; } - ret = ksm_unmerge_time(MAP_PRIVATE | MAP_ANONYMOUS, prot, + ret = ksm_unmerge_time(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, size_MB); break; case KSM_COW_TIME: - ret = ksm_cow_time(MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, - page_size); + ret = ksm_cow_time(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, + ksm_scan_limit_sec, page_size); break; } From patchwork Fri Feb 10 21:50:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136526 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 196DBC636D7 for ; Fri, 10 Feb 2023 22:04:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFB9A280021; Fri, 10 Feb 2023 17:04:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1DD1280031; Fri, 10 Feb 2023 17:04:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0E4B280021; Fri, 10 Feb 2023 17:04:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8567A28002F for ; Fri, 10 Feb 2023 17:04:01 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4B0FA1A05CA for ; Fri, 10 Feb 2023 22:04:01 +0000 (UTC) X-FDA: 80452760682.29.E081287 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf15.hostedemail.com (Postfix) with ESMTP id 92316A0017 for ; Fri, 10 Feb 2023 22:03:59 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf15.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066639; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0woeEgTWPevZl2H3kVJMxHO/DdZzzJ/9L78algaS/2E=; b=soRl6lAj+hDMITgN68IwCabUuYcK1ekGtGSLrw7TaiakJidxn6doFQXHTt/Z+faGjcByeM 7jxchuMryFMkIv5EIz55JY9XLe7Ih+nNNDdhPwsTS/tCeQwPsNnICB+LEPPTkUspxuqxfz Bn8qM4kMC6C0TGBbu/kG5FmJtDuVsx4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf15.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066639; a=rsa-sha256; cv=none; b=JP2vJmGlxajkHx4RrLyygcDTEeew/cpQHexwj7prTexAHJFpSNYYlPCXhDOHvFAFKtF6J4 km2wm/UPWLar409j7ThuUX+UbFJyf+CkPvE+/0AHWtVMgSZX78GsIcKd9GJd3PzN9bxw/d LER8h7WuMZtr05fdGnUpu8t7ixVyRHU= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id AC6A26BFC2EB; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 17/19] selftests/vm: add KSM get merge type test Date: Fri, 10 Feb 2023 13:50:21 -0800 Message-Id: <20230210215023.2740545-18-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 92316A0017 X-Stat-Signature: hce7knj3ppsxipszx7dmw3bw8owd3by4 X-HE-Tag: 1676066639-490441 X-HE-Meta: U2FsdGVkX18DUL8/woiFARpXTblxCHpLPw87H3O6KYhFPjxSpbAKJXu94GgaQmxpxhBRbRtp7Q4PXm+/PB/2V9K4WZTyiglRDZrMFagDR6PSSYej2tRdudJbihygnRTP7l3LW6vR8rl0cmlYSJHuOODmr9/Ytflqiz/iWAoUzHMdNLwPedAjYeWf9NoX5Nba65nocjrG6J1c60lAcUC0KrjpPAyfk8TmwO3zExDvQXRxPHlupoPD6IDbp49QbZ/KJSOICf0PUUqMVioYwEvJ79mfZK73XpSXNDhBuEoDNdLPcUATzJ0sniRCYBz/QuOX70gXZHthd42A8PAczMrthL/n9b5ufXztjWAL8p6KwB91YWMty/4wfoA4VhOc7L0kn5ZSp7GuYtyNULUfaKu1tjr6jRBDT9QLqOBLP1VsGIv8KRfGcIRLuV+RBugMNLy4D3VA0SpfFNUxhuVUIzg1PM2GkM89zbgp00Qf4phWcwCCC0+h9IhWed8pXL/YXRov7YEfUEVA9YwEqDxzzZ+/8gQraNQr+gfbmirAIc4DfTlg64/rI+Vq8671m3AOxur02Yd/uWPYod4dEO3AXKIPcJA/rnjl3RmrWfzOdmSFnM0qkywSLeU/XVNpsbk3W+86p9FIaRX67mffgl+uqzH4JuYEwKFuJim2d/HN2ZPNdrcHHs8iP1FFH7qjiJhC5WPPG911f9ZQ/k2n656G20oAd8dbMEmKeSOk1knI8B2A2wyZcMpin/zMLj+ipSvmuclgkWw09ih+O3FxP/rJpclSBnPAn2oz3WQyypuzU44m/4XArUpcSeDlFkWhgRRmZqtH2gXXt1ZBn0Stl05XlmdffQlTu+8RL2q+U0Qeg91PcrSRcWVAz3/jFE43rd4YFoPQNBMp/fi7JWjZCeGBmczDyALcFjbTtWMYiiKa5QlFOV70FJw78sj/YuFmD24ctYBkyP1lphrVmNiD80dRM56 v8592gWl 34DYhTpEpYEohOxZed9M2d91yxR3bUU51KwRn4TV832oqgFk= 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: This adds the -G flag to the ksm_tests to query if prctl has been used to enable ksm merging. Signed-off-by: Stefan Roesch --- tools/testing/selftests/mm/ksm_tests.c | 37 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c index 386a0929c8a3..9667cb3b8c6a 100644 --- a/tools/testing/selftests/mm/ksm_tests.c +++ b/tools/testing/selftests/mm/ksm_tests.c @@ -45,6 +45,7 @@ enum ksm_merge_type { enum ksm_test_name { CHECK_KSM_MERGE, CHECK_KSM_UNMERGE, + CHECK_KSM_GET_MERGE_TYPE, CHECK_KSM_ZERO_PAGE_MERGE, CHECK_KSM_NUMA_MERGE, KSM_MERGE_TIME, @@ -124,7 +125,8 @@ static void print_help(void) " -D evaluate unmerging time and speed when disabling KSM.\n" " For this test, the size of duplicated memory area (in MiB)\n" " must be provided using -s option\n" - " -C evaluate the time required to break COW of merged pages.\n\n"); + " -C evaluate the time required to break COW of merged pages.\n" + " -G query merge mode\n\n"); printf(" -a: specify the access protections of pages.\n" " must be of the form [rwx].\n" @@ -323,6 +325,31 @@ static int check_ksm_merge(int merge_type, int mapping, int prot, return KSFT_FAIL; } +static int check_ksm_get_merge_type(void) +{ + if (prctl(PR_SET_MEMORY_MERGE, 1)) { + perror("prctl set"); + return 1; + } + + int is_on = prctl(PR_GET_MEMORY_MERGE, 0); + + if (prctl(PR_SET_MEMORY_MERGE, 0)) { + perror("prctl set"); + return 1; + } + + int is_off = prctl(PR_GET_MEMORY_MERGE, 0); + + if (is_on && is_off) { + printf("OK\n"); + return KSFT_PASS; + } + + printf("Not OK\n"); + return KSFT_FAIL; +} + static int check_ksm_unmerge(int merge_type, int mapping, int prot, int timeout, size_t page_size) { void *map_ptr; @@ -733,7 +760,7 @@ int main(int argc, char *argv[]) bool merge_across_nodes = KSM_MERGE_ACROSS_NODES_DEFAULT; long size_MB = 0; - while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:t:MUZNPCHD")) != -1) { + while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:t:GMUZNPCHD")) != -1) { switch (opt) { case 'a': prot = str_to_prot(optarg); @@ -792,6 +819,9 @@ int main(int argc, char *argv[]) case 'Z': test_name = CHECK_KSM_ZERO_PAGE_MERGE; break; + case 'G': + test_name = CHECK_KSM_GET_MERGE_TYPE; + break; case 'N': test_name = CHECK_KSM_NUMA_MERGE; break; @@ -841,6 +871,9 @@ int main(int argc, char *argv[]) ret = check_ksm_unmerge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, page_size); break; + case CHECK_KSM_GET_MERGE_TYPE: + ret = check_ksm_get_merge_type(); + break; case CHECK_KSM_ZERO_PAGE_MERGE: ret = check_ksm_zero_page_merge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, page_count, ksm_scan_limit_sec, use_zero_pages, From patchwork Fri Feb 10 21:50:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136518 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 A7FC2C64EC7 for ; Fri, 10 Feb 2023 21:58:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3854280027; Fri, 10 Feb 2023 16:58:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0F45280021; Fri, 10 Feb 2023 16:58:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 812EB280028; Fri, 10 Feb 2023 16:58:02 -0500 (EST) 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 60188280021 for ; Fri, 10 Feb 2023 16:58:02 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3668CA4711 for ; Fri, 10 Feb 2023 21:58:02 +0000 (UTC) X-FDA: 80452745604.01.7853BFE Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf13.hostedemail.com (Postfix) with ESMTP id 9B78A20003 for ; Fri, 10 Feb 2023 21:58:00 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=neutral (imf13.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066280; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b/a3zZcwonpyVTXPUun7YKpCdEO8aJBBt3fEU+mRk60=; b=u/5dFUpPl6nkle3KmC7wi39NaqdTUbw82n8+KPufz8FnxlVxNq1riOQEe6hVtLU1L8sErp kf/QfeN2km1oOQCMnIQ3cfz4AWgfD7aDBrruPi8Aym0Ig+dfbWFDuuOsB8FqzCvK48IYxc cygza4YPAEPsWT0mXHhLUicM1LnmmfM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=neutral (imf13.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066280; a=rsa-sha256; cv=none; b=KHZLXFBlg2w/iTvvgyNQq4/9DubPFldvdQpQgR6UZr39qXNZfGvxW0cqKE3uFdihWLkToJ Mfau0WzSpr3Gs/z8DYoqv2s65Sp29aeFWGt3OIDL1krRbqMZ43aGx5R3A8FZ5fPxfT084v 6pzECJPTYhwCG1vkBIYQfGEVejAIokQ= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id B0F636BFC2ED; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 18/19] selftests/vm: add KSM fork test Date: Fri, 10 Feb 2023 13:50:22 -0800 Message-Id: <20230210215023.2740545-19-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Stat-Signature: 3w3j3iioj85sk6mq4q5mph5sgpi785ar X-Rspam-User: X-Rspamd-Queue-Id: 9B78A20003 X-Rspamd-Server: rspam06 X-HE-Tag: 1676066280-696512 X-HE-Meta: U2FsdGVkX18+UJsAkMqprNO+206haRMulcDFHs5edYeMuXlORpyKxnfE3OfWodFe20wgEY2FrsYAr91Xvaevnc/iOaayouHXloW4/xdrznOJdH0mZYMMLji24RDHG/VUz2za59DljjtIWuQB+wYoSW3/lbxYYc/aGM4nKDxyYaJOZQSImOAKKISwc5UOLFN4NRQyXvpdVz9k+9i4i3kIgc79ewqQiH1Au/Lut7lBxzhvl6gRZGj8H9OGveGq9CUsFXhk0YTjno/Qs2ICIuP33FnbpKQlQqDws4DftFZh5C6zFm3KU0PlGCkPjhmsDdhSYfOtfvj78GMKcW9GaufdYkobocRIJA+WDYCfUB/Uu/hheeSBgcb/okoZC5SHgxFA+CkxqGx9aceDVsd7F+FnZFTOChZDWzo7lLSwQFXU8JTXaC2c+SlxDc/y4+fkgyoJziHJekvGi3bCtzT6orftxKyD7wu9SN2HxTdXRJJ4dtYt8FiI64DRyhsoDPJ+YDIQaniZgi7QbD/ByVhQoEs3HNMyM2zoRkcxWTpdDIqBHDDiPNvLn6Np2VNrEuDPNZp56jblkcwV1Ls16mu4UU4urkA2UoUwE+bRJWGXSX9Hd85mcaZcPYDbT8Ditejd7ZhPS0eEhLwcBJFPlptZ65bEEk03T31f9NHbT7/aUSd3FBhWBdCytKKSfkfL8Q7e3wu7426D/HxORZ33Oo3chtoTIM7wGOIzbIj/FJbxYi0MZuXZUIKJjDDZzOQgpuYEz9JcxV/f4Sa7sRTbxvj1+Sz5e/epBdd1pw48YdqBzGa4WM9YRndwMflvP2XAv70eHnD3+tZsHRkYX4qscmlMW3LyQ+RgfNsjpTziW78YFUxNlgJSC23+03n/pvZQR68lyxQccesUjnD8LS4Qju9lKgZ5U2uUjHGf1DIXeyfDQ7rVgVcbjujjanFo7kR80dzfiHqnwX1usITYeVIC0B7wpej wUwfz3xd cs41d2p5dznIa/govorumE974dek4nc4yepqdTSB6xPE/dw4= 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: Add fork test to verify that the MMF_VM_MERGE_ANY flag is inherited by the child process. Signed-off-by: Stefan Roesch --- tools/testing/selftests/mm/ksm_tests.c | 53 +++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c index 9667cb3b8c6a..a0a48ac43b29 100644 --- a/tools/testing/selftests/mm/ksm_tests.c +++ b/tools/testing/selftests/mm/ksm_tests.c @@ -44,6 +44,7 @@ enum ksm_merge_type { enum ksm_test_name { CHECK_KSM_MERGE, + CHECK_KSM_MERGE_FORK, CHECK_KSM_UNMERGE, CHECK_KSM_GET_MERGE_TYPE, CHECK_KSM_ZERO_PAGE_MERGE, @@ -126,7 +127,8 @@ static void print_help(void) " For this test, the size of duplicated memory area (in MiB)\n" " must be provided using -s option\n" " -C evaluate the time required to break COW of merged pages.\n" - " -G query merge mode\n\n"); + " -G query merge mode\n" + " -F evaluate that the KSM process flag is inherited\n\n"); printf(" -a: specify the access protections of pages.\n" " must be of the form [rwx].\n" @@ -325,6 +327,47 @@ static int check_ksm_merge(int merge_type, int mapping, int prot, return KSFT_FAIL; } +/* Verify that prctl ksm flag is inherited. */ +static int check_ksm_fork(void) +{ + int rc = KSFT_FAIL; + pid_t child_pid; + + if (prctl(PR_SET_MEMORY_MERGE, 1)) { + perror("prctl"); + return KSFT_FAIL; + } + + child_pid = fork(); + if (child_pid == 0) { + int is_on = prctl(PR_GET_MEMORY_MERGE, 0); + + if (!is_on) + exit(KSFT_FAIL); + + exit(KSFT_PASS); + } + + if (child_pid < 0) + goto out; + + if (waitpid(child_pid, &rc, 0) < 0) + rc = KSFT_FAIL; + + if (prctl(PR_SET_MEMORY_MERGE, 0)) { + perror("prctl"); + rc = KSFT_FAIL; + } + +out: + if (rc == KSFT_PASS) + printf("OK\n"); + else + printf("Not OK\n"); + + return rc; +} + static int check_ksm_get_merge_type(void) { if (prctl(PR_SET_MEMORY_MERGE, 1)) { @@ -760,7 +803,7 @@ int main(int argc, char *argv[]) bool merge_across_nodes = KSM_MERGE_ACROSS_NODES_DEFAULT; long size_MB = 0; - while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:t:GMUZNPCHD")) != -1) { + while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:t:FGMUZNPCHD")) != -1) { switch (opt) { case 'a': prot = str_to_prot(optarg); @@ -811,6 +854,9 @@ int main(int argc, char *argv[]) merge_type = atoi(optarg); } break; + case 'F': + test_name = CHECK_KSM_MERGE_FORK; + break; case 'M': break; case 'U': @@ -867,6 +913,9 @@ int main(int argc, char *argv[]) ret = check_ksm_merge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, page_count, ksm_scan_limit_sec, page_size); break; + case CHECK_KSM_MERGE_FORK: + ret = check_ksm_fork(); + break; case CHECK_KSM_UNMERGE: ret = check_ksm_unmerge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, page_size); From patchwork Fri Feb 10 21:50:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136523 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 A05A3C05027 for ; Fri, 10 Feb 2023 22:03:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F28028002D; Fri, 10 Feb 2023 17:03:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 37A74280021; Fri, 10 Feb 2023 17:03:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2424B28002D; Fri, 10 Feb 2023 17:03:56 -0500 (EST) 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 105D7280021 for ; Fri, 10 Feb 2023 17:03:56 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D210CA05CD for ; Fri, 10 Feb 2023 22:03:55 +0000 (UTC) X-FDA: 80452760430.02.E0D908C Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf08.hostedemail.com (Postfix) with ESMTP id 397BD16000D for ; Fri, 10 Feb 2023 22:03:54 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf08.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676066634; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lYZPAbA8/2LUhgIkdki1Csd+oR7SNQbSRnZP6E0ICtA=; b=QKQKRgLawbLXQguWdv2rVceU+4gEE07SklgoZFMweZUwT835Q0onfU4l1owSN+d9y5oklV ILSaVUsipszwDsm7RghKw8PL4rm+XLAVe0b+8tpeF9IJ94fB5RHEk7Wo9Qfd5+8e//M6Zq b+MQZBaIEfQRHgoxxd61YM9bVMMkJ1s= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf08.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676066634; a=rsa-sha256; cv=none; b=VhcbxgzWNgkWuqVh5c8YmKqVBE4rRkk3jCyZ3Xutdwc7O5+xbAXvOI4+Y01Edz5X5Z5C9j iRYsuBPA2n1GTL+Uh03HMlKPSJmLdvw3miv93ZEl7dmCQqiMFJM70sy2j+AE4ZDdQg7E7V jPl1+htRz+C4u2Jct7gFIb2ORyqRK1k= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id B58206BFC2EF; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 19/19] selftests/vm: add two functions for debugging merge outcome Date: Fri, 10 Feb 2023 13:50:23 -0800 Message-Id: <20230210215023.2740545-20-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 397BD16000D X-Stat-Signature: 1u5t3sc7cma1jq8gs9wo8nf4awr19ff9 X-HE-Tag: 1676066634-744770 X-HE-Meta: U2FsdGVkX1+MXSNILYCchEuvMQeWekFjbi45BwEY9NDmgCZfA6WULf3EIclPbBC0IT+53cgKTyMAPDUQ91wq3nAxC1fOTXMN9AZEdSyezl6kS1vUfSfoVJj5IGFoHRYhfccX2SNXJec8WjCIFOdV1Tqf4CNHgn+7M5tfG8y4yzRnyGUUXmEg0q5Ahoi+mhwkCF2MMqKMlVOeZIJCBv3h4c+/vXLZziMbwfoG0QhFQHLNCX9+ROBtRGMiOBp/1J6VmsRqBEmROUhCefteNyZcDosflckti/Byu+VZjyXWRK/MRoVkyA9MMKbybw6EwhRS2FOsaC1v9O+rFj8TVhJr6ww4vWq7RPNMhim8lddWlpX2xLkZUThsmwLkTs6arbEo3/CpLDGB3Lghs2HTX8gpyw2k+yPxklg1xu6EeVYug8KOEzq4M1kXageyiR37yengdxp0VZSRLtVAlVVhdfOm2pN0HfdAtuod+CKbZxceGYaTnGAqwkTM3aAxdnTUo6aeVFmgCwEkO6yMl7DywtUupF48SJjfGgmnkEnM11x1cFb34NPfxNm4Vd7HF2jSaJjJwkxO6sGnHCiUOwNZJhsBrmYch3uqYL+gstuNayBTqT+Q4yzOvitZPPkIiABGwwSJ8p65u9tls0pZkJaOsALpOUQ8N6KEnrqDxIObqXvfp5CjBtGU+UC6HBnbukyCTq5F5wQISrY5EeQcjd02CnsS0klIt26aj3BtzbEI0yIaQ9OceqNY7zafo7YGiZbpndO1sslfUvchLdGG08D5Iwq+RfvwokgTrs9OFR8z7ZD1gE13I5ntZ+80VrvbcAX5wB7YBHaJOMzsGfd04U5Iu5NVlQy33p+wgejIFU6wktY9/I3Bagq8Nhi8wYypdigxh1lzHjw4c8uBXrGB8UEzKDv6C9wrB8qBtCyFKmMK+CG3l2VCilBfe+2hgDEg63ZdRifyHN+4FQtN3Exe5szFWKn e0AaZJdU NOmduTdeTbek6UUB+wKewVKK1xpsajWbcMWeNpxOOdpgyPlY= 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: This adds two functions to report the metrics in /proc/self/ksm_stat and /sys/kernel/debug/mm/ksm. The debugging can be enabled with the following command line: make -C tools/testing/selftests TARGETS="vm" --keep-going \ EXTRA_CFLAGS=-DDEBUG=1 Signed-off-by: Stefan Roesch --- tools/testing/selftests/mm/ksm_tests.c | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c index a0a48ac43b29..9fb21b982dc9 100644 --- a/tools/testing/selftests/mm/ksm_tests.c +++ b/tools/testing/selftests/mm/ksm_tests.c @@ -93,6 +93,55 @@ static int ksm_read_sysfs(const char *file_path, unsigned long *val) return 0; } +#ifdef DEBUG +static void ksm_print_sysfs(void) +{ + unsigned long max_page_sharing, pages_sharing, pages_shared; + unsigned long full_scans, pages_unshared, pages_volatile; + unsigned long stable_node_chains, stable_node_dups; + long general_profit; + + if (ksm_read_sysfs(KSM_FP("pages_shared"), &pages_shared) || + ksm_read_sysfs(KSM_FP("pages_sharing"), &pages_sharing) || + ksm_read_sysfs(KSM_FP("max_page_sharing"), &max_page_sharing) || + ksm_read_sysfs(KSM_FP("full_scans"), &full_scans) || + ksm_read_sysfs(KSM_FP("pages_unshared"), &pages_unshared) || + ksm_read_sysfs(KSM_FP("pages_volatile"), &pages_volatile) || + ksm_read_sysfs(KSM_FP("stable_node_chains"), &stable_node_chains) || + ksm_read_sysfs(KSM_FP("stable_node_dups"), &stable_node_dups) || + ksm_read_sysfs(KSM_FP("general_profit"), (unsigned long *)&general_profit)) + return; + + printf("pages_shared : %lu\n", pages_shared); + printf("pages_sharing : %lu\n", pages_sharing); + printf("max_page_sharing : %lu\n", max_page_sharing); + printf("full_scans : %lu\n", full_scans); + printf("pages_unshared : %lu\n", pages_unshared); + printf("pages_volatile : %lu\n", pages_volatile); + printf("stable_node_chains: %lu\n", stable_node_chains); + printf("stable_node_dups : %lu\n", stable_node_dups); + printf("general_profit : %ld\n", general_profit); +} + +static void ksm_print_procfs(void) +{ + const char *file_name = "/proc/self/ksm_stat"; + char buffer[512]; + FILE *f = fopen(file_name, "r"); + + if (!f) { + fprintf(stderr, "f %s\n", file_name); + perror("fopen"); + return; + } + + while (fgets(buffer, sizeof(buffer), f)) + printf("%s", buffer); + + fclose(f); +} +#endif + static int str_to_prot(char *prot_str) { int prot = 0; @@ -237,6 +286,11 @@ static bool assert_ksm_pages_count(long dupl_page_count) ksm_read_sysfs(KSM_FP("max_page_sharing"), &max_page_sharing)) return false; +#ifdef DEBUG + ksm_print_sysfs(); + ksm_print_procfs(); +#endif + /* * Since there must be at least 2 pages for merging and 1 page can be * shared with the limited number of pages (max_page_sharing), sometimes