mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-26 22:20:56 +07:00
zram: remove zram stats code duplication
Introduce ZRAM_ATTR_RO macro that generates device_attribute and default ATTR show() function for existing atomic64_t zram stats. Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Acked-by: Minchan Kim <minchan@kernel.org> Cc: Jerome Marchand <jmarchan@redhat.com> Cc: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
90a7806ea9
commit
a68eb3b65e
@ -42,6 +42,17 @@ static struct zram *zram_devices;
|
||||
/* Module params (documentation at end) */
|
||||
static unsigned int num_devices = 1;
|
||||
|
||||
#define ZRAM_ATTR_RO(name) \
|
||||
static ssize_t zram_attr_##name##_show(struct device *d, \
|
||||
struct device_attribute *attr, char *b) \
|
||||
{ \
|
||||
struct zram *zram = dev_to_zram(d); \
|
||||
return sprintf(b, "%llu\n", \
|
||||
(u64)atomic64_read(&zram->stats.name)); \
|
||||
} \
|
||||
static struct device_attribute dev_attr_##name = \
|
||||
__ATTR(name, S_IRUGO, zram_attr_##name##_show, NULL);
|
||||
|
||||
static inline int init_done(struct zram *zram)
|
||||
{
|
||||
return zram->meta != NULL;
|
||||
@ -63,53 +74,14 @@ static ssize_t disksize_show(struct device *dev,
|
||||
static ssize_t initstate_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
u32 val;
|
||||
struct zram *zram = dev_to_zram(dev);
|
||||
|
||||
return sprintf(buf, "%u\n", init_done(zram));
|
||||
}
|
||||
down_read(&zram->init_lock);
|
||||
val = init_done(zram);
|
||||
up_read(&zram->init_lock);
|
||||
|
||||
static ssize_t num_reads_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct zram *zram = dev_to_zram(dev);
|
||||
|
||||
return sprintf(buf, "%llu\n",
|
||||
(u64)atomic64_read(&zram->stats.num_reads));
|
||||
}
|
||||
|
||||
static ssize_t num_writes_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct zram *zram = dev_to_zram(dev);
|
||||
|
||||
return sprintf(buf, "%llu\n",
|
||||
(u64)atomic64_read(&zram->stats.num_writes));
|
||||
}
|
||||
|
||||
static ssize_t invalid_io_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct zram *zram = dev_to_zram(dev);
|
||||
|
||||
return sprintf(buf, "%llu\n",
|
||||
(u64)atomic64_read(&zram->stats.invalid_io));
|
||||
}
|
||||
|
||||
static ssize_t notify_free_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct zram *zram = dev_to_zram(dev);
|
||||
|
||||
return sprintf(buf, "%llu\n",
|
||||
(u64)atomic64_read(&zram->stats.notify_free));
|
||||
}
|
||||
|
||||
static ssize_t zero_pages_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct zram *zram = dev_to_zram(dev);
|
||||
|
||||
return sprintf(buf, "%llu\n", (u64)atomic64_read(&zram->stats.zero_pages));
|
||||
return sprintf(buf, "%u\n", val);
|
||||
}
|
||||
|
||||
static ssize_t orig_data_size_show(struct device *dev,
|
||||
@ -121,15 +93,6 @@ static ssize_t orig_data_size_show(struct device *dev,
|
||||
(u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
|
||||
}
|
||||
|
||||
static ssize_t compr_data_size_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct zram *zram = dev_to_zram(dev);
|
||||
|
||||
return sprintf(buf, "%llu\n",
|
||||
(u64)atomic64_read(&zram->stats.compr_data_size));
|
||||
}
|
||||
|
||||
static ssize_t mem_used_total_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
@ -762,15 +725,16 @@ static DEVICE_ATTR(disksize, S_IRUGO | S_IWUSR,
|
||||
disksize_show, disksize_store);
|
||||
static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL);
|
||||
static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store);
|
||||
static DEVICE_ATTR(num_reads, S_IRUGO, num_reads_show, NULL);
|
||||
static DEVICE_ATTR(num_writes, S_IRUGO, num_writes_show, NULL);
|
||||
static DEVICE_ATTR(invalid_io, S_IRUGO, invalid_io_show, NULL);
|
||||
static DEVICE_ATTR(notify_free, S_IRUGO, notify_free_show, NULL);
|
||||
static DEVICE_ATTR(zero_pages, S_IRUGO, zero_pages_show, NULL);
|
||||
static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL);
|
||||
static DEVICE_ATTR(compr_data_size, S_IRUGO, compr_data_size_show, NULL);
|
||||
static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL);
|
||||
|
||||
ZRAM_ATTR_RO(num_reads);
|
||||
ZRAM_ATTR_RO(num_writes);
|
||||
ZRAM_ATTR_RO(invalid_io);
|
||||
ZRAM_ATTR_RO(notify_free);
|
||||
ZRAM_ATTR_RO(zero_pages);
|
||||
ZRAM_ATTR_RO(compr_data_size);
|
||||
|
||||
static struct attribute *zram_disk_attrs[] = {
|
||||
&dev_attr_disksize.attr,
|
||||
&dev_attr_initstate.attr,
|
||||
|
Loading…
Reference in New Issue
Block a user