From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Minchan Kim <minchan@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: [PATCH 2/3] zram: make compact a read-write sysfs node
Date: Sat, 11 Jul 2015 18:45:31 +0900 [thread overview]
Message-ID: <1436607932-7116-3-git-send-email-sergey.senozhatsky@gmail.com> (raw)
In-Reply-To: <1436607932-7116-1-git-send-email-sergey.senozhatsky@gmail.com>
Change zram's `compact' sysfs node to be a read-write attribute.
Write triggers zsmalloc compaction, just as before, read returns
the number of pages that zsmalloc can potentially compact.
User space now has a chance to estimate possible compaction memory
savings and avoid unnecessary compactions.
Example:
if [ `cat /sys/block/zram<id>/compact` -gt 10 ]; then
echo 1 > /sys/block/zram<id>/compact;
fi
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
Documentation/ABI/testing/sysfs-block-zram | 7 ++++---
Documentation/blockdev/zram.txt | 4 +++-
drivers/block/zram/zram_drv.c | 16 +++++++++++++++-
3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-block-zram b/Documentation/ABI/testing/sysfs-block-zram
index 2e69e83..0093998 100644
--- a/Documentation/ABI/testing/sysfs-block-zram
+++ b/Documentation/ABI/testing/sysfs-block-zram
@@ -146,9 +146,10 @@ What: /sys/block/zram<id>/compact
Date: August 2015
Contact: Minchan Kim <minchan@kernel.org>
Description:
- The compact file is write-only and trigger compaction for
- allocator zrm uses. The allocator moves some objects so that
- it could free fragment space.
+ The compact file is read/write. Write triggers underlying
+ allocator's memory compaction, which may result in memory
+ savings. Read returns the number of pages that compaction
+ can potentially (but not guaranteed to) free.
What: /sys/block/zram<id>/io_stat
Date: August 2015
diff --git a/Documentation/blockdev/zram.txt b/Documentation/blockdev/zram.txt
index 62435bb..1854f62 100644
--- a/Documentation/blockdev/zram.txt
+++ b/Documentation/blockdev/zram.txt
@@ -146,7 +146,9 @@ mem_limit RW the maximum amount of memory ZRAM can use to store
the compressed data
pages_compacted RO the number of pages freed during compaction
(available only via zram<id>/mm_stat node)
-compact WO trigger memory compaction
+compact RW write triggers memory compaction, read shows how many
+ pages can potentially (but not necessarily will) be
+ compacted
WARNING
=======
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index f5ef9e0..def9b8a 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -404,6 +404,20 @@ static ssize_t compact_store(struct device *dev,
return len;
}
+static ssize_t compact_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct zram *zram = dev_to_zram(dev);
+ unsigned long num_pages = 0;
+
+ down_read(&zram->init_lock);
+ if (init_done(zram))
+ num_pages = zs_pages_to_compact(zram->meta->mem_pool);
+ up_read(&zram->init_lock);
+
+ return scnprintf(buf, PAGE_SIZE, "%lu\n", num_pages);
+}
+
static ssize_t io_stat_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1145,7 +1159,7 @@ static const struct block_device_operations zram_devops = {
.owner = THIS_MODULE
};
-static DEVICE_ATTR_WO(compact);
+static DEVICE_ATTR_RW(compact);
static DEVICE_ATTR_RW(disksize);
static DEVICE_ATTR_RO(initstate);
static DEVICE_ATTR_WO(reset);
--
2.4.5
next prev parent reply other threads:[~2015-07-11 9:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-11 9:45 [PATCH 0/3] zsmalloc: small compaction improvements Sergey Senozhatsky
2015-07-11 9:45 ` [PATCH 1/3] zsmalloc: factor out zs_pages_to_compact() Sergey Senozhatsky
2015-07-11 9:45 ` Sergey Senozhatsky [this message]
2015-07-11 9:45 ` [PATCH 3/3] zsmalloc: do not take class lock in zs_pages_to_compact() Sergey Senozhatsky
2015-07-15 4:07 ` Sergey Senozhatsky
2015-07-15 23:38 ` Minchan Kim
2015-07-15 23:59 ` Sergey Senozhatsky
2015-07-13 23:36 ` [PATCH 0/3] zsmalloc: small compaction improvements Minchan Kim
2015-07-14 0:31 ` Sergey Senozhatsky
2015-07-14 0:55 ` Minchan Kim
2015-07-14 12:29 ` Sergey Senozhatsky
2015-07-14 16:52 ` Minchan Kim
2015-07-15 0:21 ` Sergey Senozhatsky
2015-07-15 0:24 ` Minchan Kim
2015-07-15 11:16 ` Sergey Senozhatsky
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=1436607932-7116-3-git-send-email-sergey.senozhatsky@gmail.com \
--to=sergey.senozhatsky@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=sergey.senozhatsky.work@gmail.com \
/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).