Skip to content

Commit 6e1fa55

Browse files
kparasurakpm00
authored andcommitted
mm: zswap: modify zswap_stored_pages to be atomic_long_t
For zswap_store() to support large folios, we need to be able to do a batch update of zswap_stored_pages upon successful store of all pages in the folio. For this, we need to add folio_nr_pages(), which returns a long, to zswap_stored_pages. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kanchana P Sridhar <[email protected]> Acked-by: Yosry Ahmed <[email protected]> Acked-by: Johannes Weiner <[email protected]> Reviewed-by: Nhat Pham <[email protected]> Cc: Chengming Zhou <[email protected]> Cc: "Huang, Ying" <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Usama Arif <[email protected]> Cc: Wajdi Feghali <[email protected]> Cc: "Zou, Nanhai" <[email protected]> Cc: Barry Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 0201c05 commit 6e1fa55

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

fs/proc/meminfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
9191
#ifdef CONFIG_ZSWAP
9292
show_val_kb(m, "Zswap: ", zswap_total_pages());
9393
seq_printf(m, "Zswapped: %8lu kB\n",
94-
(unsigned long)atomic_read(&zswap_stored_pages) <<
94+
(unsigned long)atomic_long_read(&zswap_stored_pages) <<
9595
(PAGE_SHIFT - 10));
9696
#endif
9797
show_val_kb(m, "Dirty: ",

include/linux/zswap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
struct lruvec;
99

10-
extern atomic_t zswap_stored_pages;
10+
extern atomic_long_t zswap_stored_pages;
1111

1212
#ifdef CONFIG_ZSWAP
1313

mm/zswap.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* statistics
4444
**********************************/
4545
/* The number of compressed pages currently stored in zswap */
46-
atomic_t zswap_stored_pages = ATOMIC_INIT(0);
46+
atomic_long_t zswap_stored_pages = ATOMIC_INIT(0);
4747

4848
/*
4949
* The statistics below are not protected from concurrent access for
@@ -802,7 +802,7 @@ static void zswap_entry_free(struct zswap_entry *entry)
802802
obj_cgroup_put(entry->objcg);
803803
}
804804
zswap_entry_cache_free(entry);
805-
atomic_dec(&zswap_stored_pages);
805+
atomic_long_dec(&zswap_stored_pages);
806806
}
807807

808808
/*********************************
@@ -1233,7 +1233,7 @@ static unsigned long zswap_shrinker_count(struct shrinker *shrinker,
12331233
nr_stored = memcg_page_state(memcg, MEMCG_ZSWAPPED);
12341234
} else {
12351235
nr_backing = zswap_total_pages();
1236-
nr_stored = atomic_read(&zswap_stored_pages);
1236+
nr_stored = atomic_long_read(&zswap_stored_pages);
12371237
}
12381238

12391239
if (!nr_stored)
@@ -1502,7 +1502,7 @@ bool zswap_store(struct folio *folio)
15021502
}
15031503

15041504
/* update stats */
1505-
atomic_inc(&zswap_stored_pages);
1505+
atomic_long_inc(&zswap_stored_pages);
15061506
count_vm_event(ZSWPOUT);
15071507

15081508
return true;
@@ -1654,6 +1654,13 @@ static int debugfs_get_total_size(void *data, u64 *val)
16541654
}
16551655
DEFINE_DEBUGFS_ATTRIBUTE(total_size_fops, debugfs_get_total_size, NULL, "%llu\n");
16561656

1657+
static int debugfs_get_stored_pages(void *data, u64 *val)
1658+
{
1659+
*val = atomic_long_read(&zswap_stored_pages);
1660+
return 0;
1661+
}
1662+
DEFINE_DEBUGFS_ATTRIBUTE(stored_pages_fops, debugfs_get_stored_pages, NULL, "%llu\n");
1663+
16571664
static int zswap_debugfs_init(void)
16581665
{
16591666
if (!debugfs_initialized())
@@ -1677,8 +1684,8 @@ static int zswap_debugfs_init(void)
16771684
zswap_debugfs_root, &zswap_written_back_pages);
16781685
debugfs_create_file("pool_total_size", 0444,
16791686
zswap_debugfs_root, NULL, &total_size_fops);
1680-
debugfs_create_atomic_t("stored_pages", 0444,
1681-
zswap_debugfs_root, &zswap_stored_pages);
1687+
debugfs_create_file("stored_pages", 0444,
1688+
zswap_debugfs_root, NULL, &stored_pages_fops);
16821689

16831690
return 0;
16841691
}

0 commit comments

Comments
 (0)