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

Commit 12562145 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "zram: Register with show_mem notification framework"

parents 7e74edd0 e5bc0581
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;