[PATCH] zram-swap: enable swap discard
Rui Salvaterra
rsalvaterra at gmail.com
Thu Jun 25 05:55:22 EDT 2020
Hi, Emil,
On Thu, 25 Jun 2020 at 10:05, Emil Muratov <gpm at hotplug.ru> wrote:
>
> Hmm... that looks weird at first,
> I was checking kernel counters at /sys/block/zram0/io_stat,
> which is zram device for swap. And if there was positive counter for
> discards for zram device while swap was not sending any discards than
> what is that counter is about?
The number you see in io_stat doesn't reflect only pages freed due to
discard/trim requests. From the zram documentation itself [1]:
File /sys/block/zram<id>/io_stat
The stat file represents device's I/O statistics not accounted by block
layer and, thus, not available in zram<id>/stat file. It consists of a
single line of text and contains the following stats separated by
whitespace:
failed_reads the number of failed reads
failed_writes the number of failed writes
invalid_io the number of non-page-size-aligned I/O requests
notify_free Depending on device usage scenario it may account
a) the number of pages freed because of swap slot free
notifications or b) the number of pages freed because of
REQ_OP_DISCARD requests sent by bio. The former ones are
sent to a swap block device when a swap slot is freed,
which implies that this disk is being used as a swap disk.
The latter ones are sent by filesystem mounted with
discard option, whenever some data blocks are getting
discarded.
What you are seeing is the number of freed pages due to swap slot free
notifications. This means the swap "filesystem" is marking the swap
slots as free (metadata), but the underlying zram device is not
returning the memory to the kernel.
> Have you checked if stressing swap with some push/pull paging load
> indeed keeps ram occupied at max level?
> Analyzing /sys/block/$zdev/mm_stat could also help there. I do not
> remember mem leaks issues when tested stats script, but who knows...
> Need to take a closer look into this.
> Thanks!
The thing is, there are no memory leaks from the kernel point of view.
The kernel thinks zram needs the memory it has allocated, the problem
is that it actually doesn't and also doesn't tell the kernel that it
can reclaim it.
So, indeed, we need to explicitly tell swapon we want to issue discard commands.
[1] https://www.kernel.org/doc/Documentation/blockdev/zram.txt
Thanks,
Rui
More information about the openwrt-devel
mailing list