Thread (31 messages) 31 messages, 7 authors, 2023-01-30

[RESEND RFC PATCH v1 09/20] mm: expose general_profit metric

From: Stefan Roesch <hidden>
Date: 2023-01-23 18:03:27
Also in: linux-doc, linux-fsdevel, linux-kselftest, linux-mm, lkml
Subsystem: memory management, memory management - ksm (kernel samepage merging), the rest · Maintainers: Andrew Morton, David Hildenbrand, Linus Torvalds

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 <redacted>
---
 mm/ksm.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff --git a/mm/ksm.c b/mm/ksm.c
index 19f434f97dc1..d29454a802a0 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -3205,6 +3205,21 @@ static ssize_t pages_volatile_show(struct kobject *kobj,
 }
 KSM_ATTR_RO(pages_volatile);
 
+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)
 {
@@ -3269,6 +3284,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,
 };
 
-- 
2.30.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help