From: David Hildenbrand <david@redhat.com>
To: Sung-hun Kim <sfoon.kim@samsung.com>,
akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Cc: sungguk.na@samsung.com, sw0312.kim@samsung.com, sebuns@gmail.com
Subject: Re: [PATCH v2] mm: ksm: Consider the number of ksm_mm_slot in the general_profit calculation
Date: Thu, 20 Jun 2024 21:38:21 +0200 [thread overview]
Message-ID: <254bf3e0-0056-4593-94ee-8431a1bfc430@redhat.com> (raw)
In-Reply-To: <20240620043914.249768-1-sfoon.kim@samsung.com>
On 20.06.24 06:39, Sung-hun Kim wrote:
> The current version of KSM does not take into account the number of
> used ksm_mm_slot. Therefore, when users want to obtain profits of
> KSM, KSM omits the memory used for allocating ksm_mm_slots.
>
> This patch introduces a new variable to keep track of the number of
> allocated ksm_mm_slots. By doing so, KSM will be able to provide a
> more accurate number of the gains made.
If you take a look at the calculation explained in
Documentation/admin-guide/mm/ksm.rst, we only care about rmap_items,
which can grow rather substantially in size.
We also don't consider other metadata, such as the size of the stable
nodes etc. So why should the ksm_mm_slots matter that much that we
should track them and account them?
Any real life examples where this is relevant / a problem.
>
> Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
> ---
> Changelog in V2:
> - Add an MMF_VM_MERGEABLE flag check in ksm_process_profit for
> untracked processes
> ---
> mm/ksm.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 34c4820e0d3d..c8ced991ccda 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -267,6 +267,9 @@ static unsigned long ksm_pages_unshared;
> /* The number of rmap_items in use: to calculate pages_volatile */
> static unsigned long ksm_rmap_items;
>
> +/* The number of ksm_mm_slot in use */
> +static atomic_long_t ksm_mm_slots = ATOMIC_LONG_INIT(0);
> +
> /* The number of stable_node chains */
> static unsigned long ksm_stable_node_chains;
>
> @@ -1245,6 +1248,7 @@ static int unmerge_and_remove_all_rmap_items(void)
> spin_unlock(&ksm_mmlist_lock);
>
> mm_slot_free(mm_slot_cache, mm_slot);
> + atomic_long_dec(&ksm_mm_slots);
> clear_bit(MMF_VM_MERGEABLE, &mm->flags);
> clear_bit(MMF_VM_MERGE_ANY, &mm->flags);
> mmdrop(mm);
> @@ -2717,6 +2721,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
> spin_unlock(&ksm_mmlist_lock);
>
> mm_slot_free(mm_slot_cache, mm_slot);
> + atomic_long_dec(&ksm_mm_slots);
> clear_bit(MMF_VM_MERGEABLE, &mm->flags);
> clear_bit(MMF_VM_MERGE_ANY, &mm->flags);
> mmap_read_unlock(mm);
> @@ -3000,6 +3005,7 @@ int __ksm_enter(struct mm_struct *mm)
> list_add_tail(&slot->mm_node, &ksm_scan.mm_slot->slot.mm_node);
> spin_unlock(&ksm_mmlist_lock);
>
> + atomic_long_inc(&ksm_mm_slots);
> set_bit(MMF_VM_MERGEABLE, &mm->flags);
> mmgrab(mm);
>
> @@ -3042,6 +3048,7 @@ void __ksm_exit(struct mm_struct *mm)
>
> if (easy_to_free) {
> mm_slot_free(mm_slot_cache, mm_slot);
> + atomic_long_dec(&ksm_mm_slots);
> clear_bit(MMF_VM_MERGE_ANY, &mm->flags);
> clear_bit(MMF_VM_MERGEABLE, &mm->flags);
> mmdrop(mm);
> @@ -3374,7 +3381,8 @@ static void wait_while_offlining(void)
> long ksm_process_profit(struct mm_struct *mm)
> {
> return (long)(mm->ksm_merging_pages + mm_ksm_zero_pages(mm)) * PAGE_SIZE -
> - mm->ksm_rmap_items * sizeof(struct ksm_rmap_item);
> + mm->ksm_rmap_items * sizeof(struct ksm_rmap_item) -
> + (test_bit(MMF_VM_MERGEABLE, &mm->flags) ? sizeof(struct ksm_mm_slot) : 0);
> }
> #endif /* CONFIG_PROC_FS */
>
> @@ -3672,7 +3680,8 @@ static ssize_t general_profit_show(struct kobject *kobj,
> long general_profit;
>
> general_profit = (ksm_pages_sharing + atomic_long_read(&ksm_zero_pages)) * PAGE_SIZE -
> - ksm_rmap_items * sizeof(struct ksm_rmap_item);
> + ksm_rmap_items * sizeof(struct ksm_rmap_item) -
> + atomic_long_read(&ksm_mm_slots) * sizeof(struct ksm_mm_slot);
>
> return sysfs_emit(buf, "%ld\n", general_profit);
> }
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2024-06-20 19:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20240620043920epcas1p1b57dce789304aa96fd83e5b2b194d244@epcas1p1.samsung.com>
2024-06-20 4:39 ` Sung-hun Kim
2024-06-20 19:38 ` David Hildenbrand [this message]
2024-06-21 2:30 ` Chengming Zhou
2024-07-11 5:19 ` Sung-hun Kim
2024-07-11 6:32 ` Chengming Zhou
2024-06-20 20:47 ` Andrew Morton
2024-07-11 5:25 ` Sung-hun Kim
2024-07-11 6:10 ` Sung-hun Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=254bf3e0-0056-4593-94ee-8431a1bfc430@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sebuns@gmail.com \
--cc=sfoon.kim@samsung.com \
--cc=sungguk.na@samsung.com \
--cc=sw0312.kim@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox