[From nobody Thu Jun 25 05:55:59 2020
Received: from delta.hotplug.ru ([2a04:ac00:1:3dd8::10])
 by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux))
 id 1joNow-0003qW-BU
 for openwrt-devel@lists.openwrt.org; Thu, 25 Jun 2020 09:05:23 +0000
Received: from [192.168.168.60] (0890868029.static.corbina.ru [89.179.126.107])
 by delta.hotplug.ru (Postfix) with ESMTPSA id AC5AE105617;
 Thu, 25 Jun 2020 12:05:07 +0300 (MSK)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hotplug.ru; s=mx;
 t=1593075907; bh=ou4YNMTkMTFUEm0dSUCCwJfk8SfbXoabvYzJpCj/FJ4=;
 h=Subject:To:Cc:References:From:Date:In-Reply-To;
 b=EU4qvcewpfhjn52QHLUcttIsY2XxxnBNq3O+NGpn6L+6aOXcIHLi+7NMiCDRF2d3T
 DugkytGrZyK49oRNB4uPXuVpr/afYw2ZwiqTwYv5L3YHdZ0XKOXuu1zJr3s39WhSjI
 b3Xp1e1soAqj+29+OD4JTlrPvHIE1CUrmiXFPcrc=
Subject: Re: [PATCH] zram-swap: enable swap discard
To: Rui Salvaterra &lt;rsalvaterra@gmail.com&gt;
Cc: openwrt-devel@lists.openwrt.org, john@phrozen.org
References: &lt;20200623112953.3454-1-rsalvaterra@gmail.com&gt;
 &lt;c4539e18-8d09-3e22-055c-502465252e43@hotplug.ru&gt;
 &lt;CALjTZvbX-Nt5umO1iprg-JVo2TR+u8TM2f7DY7gQJ25VNQW7fg@mail.gmail.com&gt;
From: Emil Muratov &lt;gpm@hotplug.ru&gt;
Message-ID: &lt;9948ad5b-26d1-446e-cbe6-d66bca677721@hotplug.ru&gt;
Date: Thu, 25 Jun 2020 12:05:07 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.8.0
MIME-Version: 1.0
In-Reply-To: &lt;CALjTZvbX-Nt5umO1iprg-JVo2TR+u8TM2f7DY7gQJ25VNQW7fg@mail.gmail.com&gt;
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Language: en-GB
X-Spam-Note: CRM114 invocation failed
X-Spam-Score: -0.2 (/)
X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary:
 Content analysis details:   (-0.2 points)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_PASS               SPF: sender matches SPF record
 -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record
 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature
 0.1 DKIM_SIGNED            Message has a DKIM or DK signature, not necessarily
 valid
 -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from
 envelope-from domain
 -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from
 author's domain


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?
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!


On 25.06.2020 01:39, Rui Salvaterra wrote:
&gt; Hi, Emil,
&gt;
&gt; On Wed, 24 Jun 2020 at 20:30, Emil Muratov &lt;gpm@hotplug.ru&gt; wrote:
&gt;&gt; zram swap discard is enabled by default, no need to specify additional
&gt;&gt; option. Pls, check for example info output in
&gt;&gt; https://github.com/openwrt/openwrt/pull/1515
&gt; Unfortunately, that's not quite right. This has nothing to do with
&gt; zram itself, but with the way swapon syscall works. Yes, both discard
&gt; *policies* are enabled by default if, *and only if* the syscall is
&gt; invoked with *only* the SWAP_FLAG_DISCARD flag set [1].
&gt; Anyway, it's easy to see if the swap device is issuing trim/discard
&gt; commands. For example, on my router, with my patch:
&gt;
&gt; root@heimdal:~# dmesg | grep swap
&gt; [   12.302928] Adding 1036284k swap on /dev/zram0.  Priority:-2
&gt; extents:1 across:1036284k SSDsc
&gt; root@heimdal:~#
&gt;
&gt; According to the relevant section of the kernel source code [2], The
&gt; last letters, SSDsc mean:
&gt; SS: solid state (obviously, it's a RAM-based device)
&gt; D: supports discard
&gt; s: area-based discard is enabled
&gt; c: page-based discard is enabled
&gt;
&gt; Consequently, if a system only shows SS, discard commands aren't being issued.
&gt;
&gt; [1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/linux/swap.h?h=linux-4.14.y#n24
&gt; [2] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/mm/swapfile.c?h=linux-4.14.y#n3283
&gt;
&gt; Cheers,
&gt; Rui



]