* [PATCH v1] mm/ksm: add pages scanned metric
@ 2023-08-11 19:36 Stefan Roesch
2023-08-15 7:26 ` David Hildenbrand
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Roesch @ 2023-08-11 19:36 UTC (permalink / raw)
To: kernel-team
Cc: shr, akpm, david, hannes, riel, linux-kernel, linux-mm, linux-doc
ksm currently maintains several statistics, which let you determine how
successful KSM is at sharing pages. However it does not contain a metric
to determine how much work it does.
This commit adds the pages scanned metric. This allows the administrator
to determine how many pages have been scanned over a period of time.
Signed-off-by: Stefan Roesch <shr@devkernel.io>
---
Documentation/admin-guide/mm/ksm.rst | 2 ++
mm/ksm.c | 16 +++++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst
index 5c5be7bd84b8..776f244bdae4 100644
--- a/Documentation/admin-guide/mm/ksm.rst
+++ b/Documentation/admin-guide/mm/ksm.rst
@@ -159,6 +159,8 @@ 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_scanned
+ how many pages are being scanned for ksm
pages_shared
how many shared pages are being used
pages_sharing
diff --git a/mm/ksm.c b/mm/ksm.c
index 6b7b8928fb96..8d6aee05421d 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -242,6 +242,9 @@ static struct kmem_cache *rmap_item_cache;
static struct kmem_cache *stable_node_cache;
static struct kmem_cache *mm_slot_cache;
+/* The number of pages scanned */
+static unsigned long ksm_pages_scanned;
+
/* The number of nodes in the stable tree */
static unsigned long ksm_pages_shared;
@@ -2483,8 +2486,9 @@ static void ksm_do_scan(unsigned int scan_npages)
{
struct ksm_rmap_item *rmap_item;
struct page *page;
+ unsigned int npages = scan_npages;
- while (scan_npages-- && likely(!freezing(current))) {
+ while (npages-- && likely(!freezing(current))) {
cond_resched();
rmap_item = scan_get_next_rmap_item(&page);
if (!rmap_item)
@@ -2492,6 +2496,8 @@ static void ksm_do_scan(unsigned int scan_npages)
cmp_and_merge_page(page, rmap_item);
put_page(page);
}
+
+ ksm_pages_scanned += scan_npages - npages;
}
static int ksmd_should_run(void)
@@ -3332,6 +3338,13 @@ static ssize_t max_page_sharing_store(struct kobject *kobj,
}
KSM_ATTR(max_page_sharing);
+static ssize_t pages_scanned_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "%lu\n", ksm_pages_scanned);
+}
+KSM_ATTR_RO(pages_scanned);
+
static ssize_t pages_shared_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
@@ -3440,6 +3453,7 @@ static struct attribute *ksm_attrs[] = {
&sleep_millisecs_attr.attr,
&pages_to_scan_attr.attr,
&run_attr.attr,
+ &pages_scanned_attr.attr,
&pages_shared_attr.attr,
&pages_sharing_attr.attr,
&pages_unshared_attr.attr,
base-commit: f4a280e5bb4a764a75d3215b61bc0f02b4c26417
--
2.39.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] mm/ksm: add pages scanned metric
2023-08-11 19:36 [PATCH v1] mm/ksm: add pages scanned metric Stefan Roesch
@ 2023-08-15 7:26 ` David Hildenbrand
0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2023-08-15 7:26 UTC (permalink / raw)
To: Stefan Roesch, kernel-team
Cc: akpm, hannes, riel, linux-kernel, linux-mm, linux-doc
On 11.08.23 21:36, Stefan Roesch wrote:
> ksm currently maintains several statistics, which let you determine how
> successful KSM is at sharing pages. However it does not contain a metric
> to determine how much work it does.
>
> This commit adds the pages scanned metric. This allows the administrator
> to determine how many pages have been scanned over a period of time.
>
> Signed-off-by: Stefan Roesch <shr@devkernel.io>
> ---
> Documentation/admin-guide/mm/ksm.rst | 2 ++
> mm/ksm.c | 16 +++++++++++++++-
> 2 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst
> index 5c5be7bd84b8..776f244bdae4 100644
> --- a/Documentation/admin-guide/mm/ksm.rst
> +++ b/Documentation/admin-guide/mm/ksm.rst
> @@ -159,6 +159,8 @@ 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_scanned
> + how many pages are being scanned for ksm
> pages_shared
> how many shared pages are being used
> pages_sharing
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 6b7b8928fb96..8d6aee05421d 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -242,6 +242,9 @@ static struct kmem_cache *rmap_item_cache;
> static struct kmem_cache *stable_node_cache;
> static struct kmem_cache *mm_slot_cache;
>
> +/* The number of pages scanned */
> +static unsigned long ksm_pages_scanned;
> +
LGTM
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-15 7:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-11 19:36 [PATCH v1] mm/ksm: add pages scanned metric Stefan Roesch
2023-08-15 7:26 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).