From: Ian Wienand <iwienand@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Minchan Kim <minchan@kernel.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Jonathan Corbet <corbet@lwn.net>,
linux-doc@vger.kernel.org, Ian Wienand <iwienand@redhat.com>
Subject: [PATCH] selftests/zram : add non-zero data
Date: Thu, 10 Aug 2023 11:03:14 +1000 [thread overview]
Message-ID: <20230810010313.493384-2-iwienand@redhat.com> (raw)
In diagnosing some issues with the partner test in LTP I noticed that
because this fills the device with zeros, it doesn't really activate
the compressed allocator path as it is designed to do. This is a
"lite" version of the LTP patch that simply perturbs the zero writes to
avoid having all pages hit the same-page detection, and adds a sync so
that we're looking at a more quiescent system to get the final stats.
While we're here, this rewords and expands some of the mm_stat flag
docs to be a bit more explicit about what's going on.
Link: https://lore.kernel.org/ltp/20230808035641.364676-2-iwienand@redhat.com/T/#u
Signed-off-by: Ian Wienand <iwienand@redhat.com>
---
Documentation/admin-guide/blockdev/zram.rst | 22 ++++++++++++++-------
tools/testing/selftests/zram/zram01.sh | 18 +++++++++++++++--
2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst
index e4551579cb12..a39a01870f40 100644
--- a/Documentation/admin-guide/blockdev/zram.rst
+++ b/Documentation/admin-guide/blockdev/zram.rst
@@ -253,17 +253,25 @@ line of text and contains the following stats separated by whitespace:
orig_data_size uncompressed size of data stored in this disk.
Unit: bytes
compr_data_size compressed size of data stored in this disk
- mem_used_total the amount of memory allocated for this disk. This
- includes allocator fragmentation and metadata overhead,
- allocated for this disk. So, allocator space efficiency
- can be calculated using compr_data_size and this statistic.
- Unit: bytes
+ mem_used_total the amount of memory currently used by the compressed
+ memory allocator to hold compressed data. This
+ includes allocator fragmentation and metadata
+ overhead. The device space efficiency can be
+ calculated as a ratio of the compr_data_size /
+ mem_used_total. Note this value may be zero;
+ particularly if all pages are filled with identical
+ data (see same_pages).
mem_limit the maximum amount of memory ZRAM can use to store
the compressed data
mem_used_max the maximum amount of memory zram has consumed to
store the data
- same_pages the number of same element filled pages written to this disk.
- No memory is allocated for such pages.
+ same_pages pages identified as being filled exclusivley with an
+ identicial unsigned-long value are recorded
+ specially by zram and thus are not stored via the
+ compression allocator. This avoids fragmentation
+ and metadata overheads for common cases such as
+ zeroed or poision data. same_pages is the current
+ number of pages kept in this de-duplicated form.
pages_compacted the number of pages freed during compaction
huge_pages the number of incompressible pages
huge_pages_since the number of incompressible pages since zram set up
diff --git a/tools/testing/selftests/zram/zram01.sh b/tools/testing/selftests/zram/zram01.sh
index 8f4affe34f3e..122625d744c2 100755
--- a/tools/testing/selftests/zram/zram01.sh
+++ b/tools/testing/selftests/zram/zram01.sh
@@ -33,16 +33,30 @@ zram_algs="lzo"
zram_fill_fs()
{
+ local page_size=$(getconf PAGE_SIZE)
for i in $(seq $dev_start $dev_end); do
echo "fill zram$i..."
local b=0
while [ true ]; do
- dd conv=notrunc if=/dev/zero of=zram${i}/file \
+ # If we fill with all zeros, every page hits
+ # the same-page detection and never makes it
+ # to compressed backing. Filling the first 1K
+ # of the page with (likely lowly compressible)
+ # random data ensures we hit the compression
+ # paths, but the highly compressible rest of
+ # the page also ensures we get a sufficiently
+ # high ratio to assert on below.
+ local input_file='/dev/zero'
+ if [ $(( (b * 1024) % page_size )) -eq 0 ]; then
+ input_file='/dev/urandom'
+ fi
+ dd conv=notrunc if=${input_file} of=zram${i}/file \
oflag=append count=1 bs=1024 status=none \
> /dev/null 2>&1 || break
b=$(($b + 1))
done
- echo "zram$i can be filled with '$b' KB"
+ echo "zram$i was filled with '$b' KB"
+ sync
local mem_used_total=`awk '{print $3}' "/sys/block/zram$i/mm_stat"`
local v=$((100 * 1024 * $b / $mem_used_total))
--
2.41.0
reply other threads:[~2023-08-10 1:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230810010313.493384-2-iwienand@redhat.com \
--to=iwienand@redhat.com \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=senozhatsky@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).