Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5bc0581 authored by Laura Abbott's avatar Laura Abbott
Browse files

zram: Register with show_mem notification framework



Zram data is useful when looking at memory related issues.
Register with the show_mem framework so data can be
dumped at convenient times.

Change-Id: I1709f1301edc705445f5fc288d9fc2455638e41a
Signed-off-by: default avatarLaura Abbott <lauraa@codeaurora.org>
parent d2da88f4
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <linux/string.h>
#include <linux/vmalloc.h>
#include <linux/ratelimit.h>
#include <linux/show_mem_notifier.h>

#include "zram_drv.h"

@@ -49,6 +50,43 @@ static struct zram *zram_devices;
/* Module params (documentation at end) */
static unsigned int num_devices = 1;

static int zram_show_mem_notifier(struct notifier_block *nb,
				unsigned long action,
				void *data)
{
	int i;

	if (!zram_devices)
		return 0;

	for (i = 0; i < num_devices; i++) {
		struct zram *zram = &zram_devices[i];
		struct zram_meta *meta = zram->meta;

		if (!down_read_trylock(&zram->init_lock))
			continue;

		if (zram->init_done) {
			u64 val;

			val = zs_get_total_size_bytes(meta->mem_pool);
			pr_info("Zram[%d] mem_used_total = %llu\n", i, val);
			pr_info("Zram[%d] compr_data_size = %llu\n", i,
				atomic64_read(&zram->stats.compr_size));
			pr_info("Zram[%d] orig_data_size = %u\n", i,
				zram->stats.pages_stored);
		}

		up_read(&zram->init_lock);
	}

	return 0;
}

static struct notifier_block zram_show_mem_notifier_block = {
	.notifier_call = zram_show_mem_notifier
};

static inline struct zram *dev_to_zram(struct device *dev)
{
	return (struct zram *)dev_to_disk(dev)->private_data;
@@ -947,6 +985,7 @@ static int __init zram_init(void)
			goto free_devices;
	}

	show_mem_notifier_register(&zram_show_mem_notifier_block);
	pr_info("Created %u device(s) ...\n", num_devices);

	return 0;