[PATCH 20/26] cgroup/misc: allow users of misc cgroup to read specific cgroup usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a function to return the current usage of the specified cgroup.
The SGX driver will need this information to decide whether to
reclaim EPC pages from a cgroup.

Signed-off-by: Kristen Carlson Accardi <kristen@xxxxxxxxxxxxxxx>
---
 include/linux/misc_cgroup.h |  6 ++++++
 kernel/cgroup/misc.c        | 19 +++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
index d1aeb85f2ed6..a9dd087132dc 100644
--- a/include/linux/misc_cgroup.h
+++ b/include/linux/misc_cgroup.h
@@ -61,6 +61,7 @@ struct misc_cg {
 
 struct misc_cg *root_misc(void);
 struct misc_cg *parent_misc(struct misc_cg *cg);
+unsigned long misc_cg_read(enum misc_res_type type, struct misc_cg *cg);
 unsigned long misc_cg_res_total_usage(enum misc_res_type type);
 int misc_cg_set_capacity(enum misc_res_type type, unsigned long capacity);
 int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
@@ -118,6 +119,11 @@ static inline struct misc_cg *parent_misc(struct misc_cg *cg)
 	return NULL;
 }
 
+static inline unsigned long misc_cg_read(enum misc_res_type type, struct misc_cg *cg)
+{
+	return 0;
+}
+
 static inline unsigned long misc_cg_res_total_usage(enum misc_res_type type)
 {
 	return 0;
diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
index b22a055af9ad..e2c99fdc1d40 100644
--- a/kernel/cgroup/misc.c
+++ b/kernel/cgroup/misc.c
@@ -213,6 +213,25 @@ void misc_cg_uncharge(enum misc_res_type type, struct misc_cg *cg,
 }
 EXPORT_SYMBOL_GPL(misc_cg_uncharge);
 
+/**
+ * misc_cg_read() - Return the current usage of the misc cgroup res.
+ * @type: Type of the misc res.
+ * @cg: Misc cgroup whose usage will be read
+ *
+ * Context: Any context.
+ * Return:
+ * 	The current total usage of the specified misc cgroup.
+ * 	If an invalid misc_res_type is given, zero will be returned.
+ */
+unsigned long misc_cg_read(enum misc_res_type type, struct misc_cg *cg)
+{
+	if (!(valid_type(type) && cg))
+		return 0;
+
+	return atomic_long_read(&cg->res[type].usage);
+}
+EXPORT_SYMBOL_GPL(misc_cg_read);
+
 /**
  * misc_cg_max_show() - Show the misc cgroup max limit.
  * @sf: Interface file
-- 
2.37.3




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux