Skip to content

Commit a7a0350

Browse files
sergey-senozhatskyakpm00
authored andcommitted
zram: split memory-tracking and ac-time tracking
ZRAM_MEMORY_TRACKING enables two features: - per-entry ac-time tracking - debugfs interface The latter one is the reason why memory-tracking depends on DEBUG_FS, while the former one is used far beyond debugging these days. Namely ac-time is used for fine grained writeback of idle entries (pages). Move ac-time tracking under its own config option so that it can be enabled (along with writeback) on systems without DEBUG_FS. [[email protected]: ifdef fixup, per Dmytro] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sergey Senozhatsky <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Dmytro Maluka <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1b5c65b commit a7a0350

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

Documentation/admin-guide/blockdev/zram.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ as idle::
328328
From now on, any pages on zram are idle pages. The idle mark
329329
will be removed until someone requests access of the block.
330330
IOW, unless there is access request, those pages are still idle pages.
331-
Additionally, when CONFIG_ZRAM_MEMORY_TRACKING is enabled pages can be
331+
Additionally, when CONFIG_ZRAM_TRACK_ENTRY_ACTIME is enabled pages can be
332332
marked as idle based on how long (in seconds) it's been since they were
333333
last accessed::
334334

drivers/block/zram/Kconfig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,18 @@ config ZRAM_WRITEBACK
6969

7070
See Documentation/admin-guide/blockdev/zram.rst for more information.
7171

72+
config ZRAM_TRACK_ENTRY_ACTIME
73+
bool "Track access time of zram entries"
74+
depends on ZRAM
75+
help
76+
With this feature zram tracks access time of every stored
77+
entry (page), which can be used for a more fine grained IDLE
78+
pages writeback.
79+
7280
config ZRAM_MEMORY_TRACKING
7381
bool "Track zRam block status"
7482
depends on ZRAM && DEBUG_FS
83+
select ZRAM_TRACK_ENTRY_ACTIME
7584
help
7685
With this feature, admin can track the state of allocated blocks
7786
of zRAM. Admin could see the information via
@@ -86,4 +95,4 @@ config ZRAM_MULTI_COMP
8695
This will enable multi-compression streams, so that ZRAM can
8796
re-compress pages using a potentially slower but more effective
8897
compression algorithm. Note, that IDLE page recompression
89-
requires ZRAM_MEMORY_TRACKING.
98+
requires ZRAM_TRACK_ENTRY_ACTIME.

drivers/block/zram/zram_drv.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ static inline u32 zram_get_priority(struct zram *zram, u32 index)
174174
return prio & ZRAM_COMP_PRIORITY_MASK;
175175
}
176176

177+
static void zram_accessed(struct zram *zram, u32 index)
178+
{
179+
zram_clear_flag(zram, index, ZRAM_IDLE);
180+
#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
181+
zram->table[index].ac_time = ktime_get_boottime();
182+
#endif
183+
}
184+
177185
static inline void update_used_max(struct zram *zram,
178186
const unsigned long pages)
179187
{
@@ -293,8 +301,9 @@ static void mark_idle(struct zram *zram, ktime_t cutoff)
293301
zram_slot_lock(zram, index);
294302
if (zram_allocated(zram, index) &&
295303
!zram_test_flag(zram, index, ZRAM_UNDER_WB)) {
296-
#ifdef CONFIG_ZRAM_MEMORY_TRACKING
297-
is_idle = !cutoff || ktime_after(cutoff, zram->table[index].ac_time);
304+
#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
305+
is_idle = !cutoff || ktime_after(cutoff,
306+
zram->table[index].ac_time);
298307
#endif
299308
if (is_idle)
300309
zram_set_flag(zram, index, ZRAM_IDLE);
@@ -317,7 +326,7 @@ static ssize_t idle_store(struct device *dev,
317326
*/
318327
u64 age_sec;
319328

320-
if (IS_ENABLED(CONFIG_ZRAM_MEMORY_TRACKING) && !kstrtoull(buf, 0, &age_sec))
329+
if (IS_ENABLED(CONFIG_ZRAM_TRACK_ENTRY_ACTIME) && !kstrtoull(buf, 0, &age_sec))
321330
cutoff_time = ktime_sub(ktime_get_boottime(),
322331
ns_to_ktime(age_sec * NSEC_PER_SEC));
323332
else
@@ -841,12 +850,6 @@ static void zram_debugfs_destroy(void)
841850
debugfs_remove_recursive(zram_debugfs_root);
842851
}
843852

844-
static void zram_accessed(struct zram *zram, u32 index)
845-
{
846-
zram_clear_flag(zram, index, ZRAM_IDLE);
847-
zram->table[index].ac_time = ktime_get_boottime();
848-
}
849-
850853
static ssize_t read_block_state(struct file *file, char __user *buf,
851854
size_t count, loff_t *ppos)
852855
{
@@ -930,10 +933,6 @@ static void zram_debugfs_unregister(struct zram *zram)
930933
#else
931934
static void zram_debugfs_create(void) {};
932935
static void zram_debugfs_destroy(void) {};
933-
static void zram_accessed(struct zram *zram, u32 index)
934-
{
935-
zram_clear_flag(zram, index, ZRAM_IDLE);
936-
};
937936
static void zram_debugfs_register(struct zram *zram) {};
938937
static void zram_debugfs_unregister(struct zram *zram) {};
939938
#endif
@@ -1254,7 +1253,7 @@ static void zram_free_page(struct zram *zram, size_t index)
12541253
{
12551254
unsigned long handle;
12561255

1257-
#ifdef CONFIG_ZRAM_MEMORY_TRACKING
1256+
#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
12581257
zram->table[index].ac_time = 0;
12591258
#endif
12601259
if (zram_test_flag(zram, index, ZRAM_IDLE))

drivers/block/zram/zram_drv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct zram_table_entry {
6969
unsigned long element;
7070
};
7171
unsigned long flags;
72-
#ifdef CONFIG_ZRAM_MEMORY_TRACKING
72+
#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
7373
ktime_t ac_time;
7474
#endif
7575
};

0 commit comments

Comments
 (0)