[PATCH 1/3] Add r/w sysfs attribute for zcache_freeze
Florian Schmaus
fschmaus at gmail.com
Tue Mar 13 10:34:46 UTC 2012
From: Andor Daam <andor.daam at googlemail.com>
This patch makes dynamic enabling/disabling of zcache via a sysfsnode possible.
The node is used to toggle the preexisting zcache_freeze variable to
stop/start accepting pages by zcache.
Signed-off-by: Andor Daam <andor.daam at googlemail.com>
Signed-off-by: Florian Schmaus <fschmaus at gmail.com>
Signed-off-by: Stefan Hengelein <ilendir at googlemail.com>
---
drivers/staging/zcache/zcache-main.c | 57 +++++++++++++++++++++++++++++-----
1 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c
index 2734dac..1bece03 100644
--- a/drivers/staging/zcache/zcache-main.c
+++ b/drivers/staging/zcache/zcache-main.c
@@ -469,6 +469,15 @@ out:
}
/*
+ * When zcache is disabled ("frozen"), pools can be created and destroyed,
+ * but all puts (and thus all other operations that require memory allocation)
+ * must fail. If zcache is unfrozen, accepts puts, then frozen again,
+ * data consistency requires all puts while frozen to be converted into
+ * flushes.
+ */
+static bool zcache_freeze;
+
+/*
* The following routines handle shrinking of ephemeral pages by evicting
* pages "least valuable" first.
*/
@@ -913,6 +922,45 @@ static struct kobj_attribute zcache_zv_page_count_policy_percent_attr = {
.show = zv_page_count_policy_percent_show,
.store = zv_page_count_policy_percent_store,
};
+
+static ssize_t zcache_freeze_show(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ char *buf)
+{
+ if (zcache_freeze)
+ return sprintf(buf, "1\n");
+ else
+ return sprintf(buf, "0\n");
+}
+
+static ssize_t zcache_freeze_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ unsigned int val;
+ int err;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ err = kstrtouint(buf, 10, &val);
+ if (err)
+ return -EINVAL;
+
+ if (val > 0)
+ zcache_freeze = true;
+ else
+ zcache_freeze = false;
+
+ return count;
+}
+
+static struct kobj_attribute zcache_freeze_attr = {
+ .attr = { .name = "zcache_freeze", .mode = 0644 },
+ .show = zcache_freeze_show,
+ .store = zcache_freeze_store,
+};
+
#endif
/*
@@ -1515,6 +1563,7 @@ static struct attribute *zcache_attrs[] = {
&zcache_zv_max_zsize_attr.attr,
&zcache_zv_max_mean_zsize_attr.attr,
&zcache_zv_page_count_policy_percent_attr.attr,
+ &zcache_freeze_attr.attr,
NULL,
};
@@ -1524,14 +1573,6 @@ static struct attribute_group zcache_attr_group = {
};
#endif /* CONFIG_SYSFS */
-/*
- * When zcache is disabled ("frozen"), pools can be created and destroyed,
- * but all puts (and thus all other operations that require memory allocation)
- * must fail. If zcache is unfrozen, accepts puts, then frozen again,
- * data consistency requires all puts while frozen to be converted into
- * flushes.
- */
-static bool zcache_freeze;
/*
* zcache shrinker interface (only useful for ephemeral pages, so zbud only)
--
1.7.5.4
More information about the devel
mailing list