Skip to contentSkip to conversation

vmpressure: implement strict mode

PATCH Superseded Luiz Capitulino 7 participants 17 messages Jun 25, 2013 – Jul 2, 2013

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmpressure: implement strict mode

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

---

PS: I'm following the discussion on the event storm problem, but I believe
strict mode is orthogonal to what has been suggested (although the patches conflict)

 Documentation/cgroups/memory.txt | 10 ++++++----
 mm/vmpressure.c                  | 19 +++++++++++++++++--
 2 files changed, 23 insertions(+), 6 deletions(-)
Documentation/cgroups/memory.txt +6 -4
index ddf4f93..3c589cf 100644
@@ -807,12 +807,14 @@ register a notification, an application must:
 
 - create an eventfd using eventfd(2);
 - open memory.pressure_level;
-- write string like "<event_fd> <fd of memory.pressure_level> <level>"
+- write string like "<event_fd> <fd of memory.pressure_level> <level> [strict]"
   to cgroup.event_control.
 
-Application will be notified through eventfd when memory pressure is at
-the specific level (or higher). Read/write operations to
-memory.pressure_level are no implemented.
+Applications will be notified through eventfd when memory pressure is at
+the specific level or higher. If strict is passed, then applications
+will only be notified when memory pressure reaches the specified level.
+
+Read/write operations to memory.pressure_level are no implemented.
 
 Test:
 
mm/vmpressure.c +17 -2
index 736a601..6289ede 100644
@@ -137,6 +137,7 @@ static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned,
 struct vmpressure_event {
 	struct eventfd_ctx *efd;
 	enum vmpressure_levels level;
+	bool strict_mode;
 	struct list_head node;
 };
 
@@ -153,6 +154,9 @@ static bool vmpressure_event(struct vmpressure *vmpr,
 
 	list_for_each_entry(ev, &vmpr->events, node) {
 		if (level >= ev->level) {
+			/* strict mode ensures level == ev->level */
+			if (ev->strict_mode && level != ev->level)
+				continue;
 			eventfd_signal(ev->efd, 1);
 			signalled = true;
 		}
@@ -292,7 +296,7 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
  * infrastructure, so that the notifications will be delivered to the
  * @eventfd. The @args parameter is a string that denotes pressure level
  * threshold (one of vmpressure_str_levels, i.e. "low", "medium", or
- * "critical").
+ * "critical") and optionally a different operating mode (i.e. "strict")
  *
  * This function should not be used directly, just pass it to (struct
  * cftype).register_event, and then cgroup core will handle everything by
@@ -303,22 +307,33 @@ int vmpressure_register_event(struct cgroup *cg, struct cftype *cft,
 {
 	struct vmpressure *vmpr = cg_to_vmpressure(cg);
 	struct vmpressure_event *ev;
+	bool smode = false;
+	const char *p;
 	int level;
 
 	for (level = 0; level < VMPRESSURE_NUM_LEVELS; level++) {
-		if (!strcmp(vmpressure_str_levels[level], args))
+		p = vmpressure_str_levels[level];
+		if (!strncmp(p, args, strlen(p)))
 			break;
 	}
 
 	if (level >= VMPRESSURE_NUM_LEVELS)
 		return -EINVAL;
 
+	p = strchr(args, ' ');
+	if (p) {
+		if (strncmp(++p, "strict", 6))
+			return -EINVAL;
+		smode = true;
+	}
+
 	ev = kzalloc(sizeof(*ev), GFP_KERNEL);
 	if (!ev)
 		return -ENOMEM;
 
 	ev->efd = eventfd;
 	ev->level = level;
+	ev->strict_mode = smode;
 
 	mutex_lock(&vmpr->events_lock);
 	list_add(&ev->node, &vmpr->events);
Signature · 7 lines
1.8.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

+ Ms. Kim,

she already raised this issue at another mail thread.

Thank you,
Kyungmin Park

Quoted 117 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

---

PS: I'm following the discussion on the event storm problem, but I believe
strict mode is orthogonal to what has been suggested (although the patches conflict)

 Documentation/cgroups/memory.txt | 10 ++++++----
 mm/vmpressure.c                  | 19 +++++++++++++++++--
 2 files changed, 23 insertions(+), 6 deletions(-)
Documentation/cgroups/memory.txt +6 -4
index ddf4f93..3c589cf 100644
@@ -807,12 +807,14 @@ register a notification, an application must:
 
 - create an eventfd using eventfd(2);
 - open memory.pressure_level;
-- write string like "<event_fd> <fd of memory.pressure_level> <level>"
+- write string like "<event_fd> <fd of memory.pressure_level> <level> [strict]"
   to cgroup.event_control.
 
-Application will be notified through eventfd when memory pressure is at
-the specific level (or higher). Read/write operations to
-memory.pressure_level are no implemented.
+Applications will be notified through eventfd when memory pressure is at
+the specific level or higher. If strict is passed, then applications
+will only be notified when memory pressure reaches the specified level.
+
+Read/write operations to memory.pressure_level are no implemented.
 
 Test:
 
mm/vmpressure.c +17 -3
index 736a601..6289ede 100644
@@ -137,6 +137,7 @@ static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned,
 struct vmpressure_event {
        struct eventfd_ctx *efd;
        enum vmpressure_levels level;
+       bool strict_mode;
        struct list_head node;
 };
 
@@ -153,6 +154,9 @@ static bool vmpressure_event(struct vmpressure *vmpr,
 
        list_for_each_entry(ev, &vmpr->events, node) {
                if (level >= ev->level) {
+                       /* strict mode ensures level == ev->level */
+                       if (ev->strict_mode && level != ev->level)
+                               continue;
                        eventfd_signal(ev->efd, 1);
                        signalled = true;
                }
@@ -292,7 +296,7 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
  * infrastructure, so that the notifications will be delivered to the
  * @eventfd. The @args parameter is a string that denotes pressure level
  * threshold (one of vmpressure_str_levels, i.e. "low", "medium", or
- * "critical").
+ * "critical") and optionally a different operating mode (i.e. "strict")
  *
  * This function should not be used directly, just pass it to (struct
  * cftype).register_event, and then cgroup core will handle everything by
@@ -303,22 +307,33 @@ int vmpressure_register_event(struct cgroup *cg, struct cftype *cft,
 {
        struct vmpressure *vmpr = cg_to_vmpressure(cg);
        struct vmpressure_event *ev;
+       bool smode = false;
+       const char *p;
        int level;
 
        for (level = 0; level < VMPRESSURE_NUM_LEVELS; level++) {
-               if (!strcmp(vmpressure_str_levels[level], args))
+               p = vmpressure_str_levels[level];
+               if (!strncmp(p, args, strlen(p)))
                        break;
        }
 
        if (level >= VMPRESSURE_NUM_LEVELS)
                return -EINVAL;
 
+       p = strchr(args, ' ');
+       if (p) {
+               if (strncmp(++p, "strict", 6))
+                       return -EINVAL;
+               smode = true;
+       }
+
        ev = kzalloc(sizeof(*ev), GFP_KERNEL);
        if (!ev)
                return -ENOMEM;
 
        ev->efd = eventfd;
        ev->level = level;
+       ev->strict_mode = smode;
 
        mutex_lock(&vmpr->events_lock);
        list_add(&ev->node, &vmpr->events);
--

1.8.1.4

Quoted 5 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

Please see "[PATCH v3] memcg: event control at vmpressure". mail thread. (and also the thread I sent last Saturday.)
There was discussion on this mode not sending lower events when "level != ev->level".

Thanks,
Hyunhee Kim.

2013/6/26 Kyungmin Park <[email protected]>:

Quoted 125 lines

+ Ms. Kim,

she already raised this issue at another mail thread.

Thank you,
Kyungmin Park

Quoted 117 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

---

PS: I'm following the discussion on the event storm problem, but I believe
strict mode is orthogonal to what has been suggested (although the patches conflict)

 Documentation/cgroups/memory.txt | 10 ++++++----
 mm/vmpressure.c                  | 19 +++++++++++++++++--
 2 files changed, 23 insertions(+), 6 deletions(-)
Documentation/cgroups/memory.txt +6 -4
index ddf4f93..3c589cf 100644
@@ -807,12 +807,14 @@ register a notification, an application must:
 
 - create an eventfd using eventfd(2);
 - open memory.pressure_level;
-- write string like "<event_fd> <fd of memory.pressure_level> <level>"
+- write string like "<event_fd> <fd of memory.pressure_level> <level> [strict]"
   to cgroup.event_control.
 
-Application will be notified through eventfd when memory pressure is at
-the specific level (or higher). Read/write operations to
-memory.pressure_level are no implemented.
+Applications will be notified through eventfd when memory pressure is at
+the specific level or higher. If strict is passed, then applications
+will only be notified when memory pressure reaches the specified level.
+
+Read/write operations to memory.pressure_level are no implemented.
 
 Test:
 
mm/vmpressure.c +17 -3
index 736a601..6289ede 100644
@@ -137,6 +137,7 @@ static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned,
 struct vmpressure_event {
        struct eventfd_ctx *efd;
        enum vmpressure_levels level;
+       bool strict_mode;
        struct list_head node;
 };
 
@@ -153,6 +154,9 @@ static bool vmpressure_event(struct vmpressure *vmpr,
 
        list_for_each_entry(ev, &vmpr->events, node) {
                if (level >= ev->level) {
+                       /* strict mode ensures level == ev->level */
+                       if (ev->strict_mode && level != ev->level)
+                               continue;
                        eventfd_signal(ev->efd, 1);
                        signalled = true;
                }
@@ -292,7 +296,7 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
  * infrastructure, so that the notifications will be delivered to the
  * @eventfd. The @args parameter is a string that denotes pressure level
  * threshold (one of vmpressure_str_levels, i.e. "low", "medium", or
- * "critical").
+ * "critical") and optionally a different operating mode (i.e. "strict")
  *
  * This function should not be used directly, just pass it to (struct
  * cftype).register_event, and then cgroup core will handle everything by
@@ -303,22 +307,33 @@ int vmpressure_register_event(struct cgroup *cg, struct cftype *cft,
 {
        struct vmpressure *vmpr = cg_to_vmpressure(cg);
        struct vmpressure_event *ev;
+       bool smode = false;
+       const char *p;
        int level;
 
        for (level = 0; level < VMPRESSURE_NUM_LEVELS; level++) {
-               if (!strcmp(vmpressure_str_levels[level], args))
+               p = vmpressure_str_levels[level];
+               if (!strncmp(p, args, strlen(p)))
                        break;
        }
 
        if (level >= VMPRESSURE_NUM_LEVELS)
                return -EINVAL;
 
+       p = strchr(args, ' ');
+       if (p) {
+               if (strncmp(++p, "strict", 6))
+                       return -EINVAL;
+               smode = true;
+       }
+
        ev = kzalloc(sizeof(*ev), GFP_KERNEL);
        if (!ev)
                return -ENOMEM;
 
        ev->efd = eventfd;
        ev->level = level;
+       ev->strict_mode = smode;
 
        mutex_lock(&vmpr->events_lock);
        list_add(&ev->node, &vmpr->events);
--

1.8.1.4

Quoted 11 lines
Quoted 5 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 4 lines · On Wed, 26 Jun 2013 10:12:15 +0900 Hyunhee Kim <[email protected]> wrote:

Please see "[PATCH v3] memcg: event control at vmpressure". mail thread. (and also the thread I sent last Saturday.)
There was discussion on this mode not sending lower events when "level != ev->level".

The new argument this patch adds should be orthogonal to what has been discussed and suggested in that thread. The patches conflict though, but it's just a matter of rebasing if both are ACKed.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by on v1 1/1
#4 lore raw
In reply to Luiz Capitulino
Quoted 10 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

Quoted 5 lines

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

In the documentation I would add more information about why exactly the strict mode makes sense.

For example, the non-strict fd listener hooked onto the low level makes sense for apps that just monitor reclaiming activity (like current Android Activity Manager), hooking onto 'medium' non-strict mode makes sense for simple load-balancing logic, and the new strict mode is for the cases when an application wants to implement some fancy logic as it makes a decision based on a concrete level.

Otherwise, it looks good.

Thanks!

Anton

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 20 lines · On Tue, 25 Jun 2013 21:03:31 -0700 Anton Vorontsov <[email protected]> wrote:
Quoted 10 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

Quoted 5 lines

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

In the documentation I would add more information about why exactly the strict mode makes sense.

Quoted 6 lines

For example, the non-strict fd listener hooked onto the low level makes sense for apps that just monitor reclaiming activity (like current Android Activity Manager), hooking onto 'medium' non-strict mode makes sense for simple load-balancing logic, and the new strict mode is for the cases when an application wants to implement some fancy logic as it makes a decision based on a concrete level.

OK, I'll respin. But you said it all already, so I'll base my text on on what you wrote.

Quoted 3 lines

Otherwise, it looks good.

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by on v1 1/1
#6 lore raw
In reply to Luiz Capitulino
Quoted 10 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

Quoted 5 lines

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

Shouldn't we make this default?
What do you think about it?

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw
Quoted 11 lines · Minchan Kim
Quoted 10 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

Quoted 8 lines
Quoted 5 lines

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

Shouldn't we make this default?

The interface is not there for long but still, changing it is always quite tricky. And the users who care can be modified really easily so I would stick with the original default.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#8 lore raw

Hello Michal,

Quoted 16 lines · Michal Hocko
Quoted 15 lines · Minchan Kim
Quoted 14 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Shouldn't we make this default?

The interface is not there for long but still, changing it is always quite tricky. And the users who care can be modified really easily so I would stick with the original default.

Yeb, I am not strong against to stick old at a moment but at least, this patch makes more sense to me so I'd like to know why we didn't do it from the beginning. Surely, Anton has a answer.

Quoted 10 lines
Signature · 9 lines
-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw
Quoted 24 lines · On Wed, 26 Jun 2013 17:20:40 +0900 Minchan Kim <[email protected]> wrote:

Hello Michal,

Quoted 21 lines · Michal Hocko
Quoted 19 lines · Minchan Kim
Quoted 10 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

Quoted 5 lines

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

Shouldn't we make this default?

Quoted 7 lines
Quoted 3 lines

The interface is not there for long but still, changing it is always quite tricky. And the users who care can be modified really easily so I would stick with the original default.

Yeb, I am not strong against to stick old at a moment but at least, this patch makes more sense to me so I'd like to know why we didn't do it from the beginning. Surely, Anton has a answer.

That's exactly my thinking too: I think strict mode should be the default mode, and the current mode should be optional. But it's not a big deal.

I've discussed this issue with Anton some weeks ago, and iirc (Anton, please correct/clarify where appropriate) the conclusion was that the current schema makes sense for apps monitoring reclaim activity, as they can hook on low only.

Hmm. Something just crossed my mind. Maybe we should have two notification schemas:

o memory.pressure_level: implements strict mode (this patch)

o memory.reclaim_activity: apps are notified whenever there's reclaim activity

As for changing applications, it's better to get some breakage while we're in -rc than regret the API later.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw
In reply to Minchan Kim
Quoted 15 lines · Minchan Kim
Quoted 14 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

Quoted 5 lines
Quoted 1 line

Shouldn't we make this default?
What do you think about it?

Either way works and both modes have their use-cases (as I have described in my previous mail). Changing the default mode is just unneeded churn, IMO. As long as things are documented properly, we are good. :)

Thanks,

Anton

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw
In reply to Luiz Capitulino
Quoted 9 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

OK, I am not user of this interface but I thought that the application would take an action of the highest level it gets notification. But yes this might get clumsy to implement.

Quoted 3 lines

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

OK, makes some sense to me and it should work with the proposed edge trigerring as well.

Quoted 19 lines

---

PS: I'm following the discussion on the event storm problem, but I believe
strict mode is orthogonal to what has been suggested (although the patches conflict)

 Documentation/cgroups/memory.txt | 10 ++++++----
 mm/vmpressure.c                  | 19 +++++++++++++++++--
 2 files changed, 23 insertions(+), 6 deletions(-)
Documentation/cgroups/memory.txt +0 -0
index ddf4f93..3c589cf 100644
@@ -807,12 +807,14 @@ register a notification, an application must:
 
 - create an eventfd using eventfd(2);
 - open memory.pressure_level;

Documentation/cgroups/memory.txt register a notification, an application must: · line 815

Quoted 10 lines
Documentation/cgroups/memory.txt +4 -4
-- write string like "<event_fd> <fd of memory.pressure_level> <level>"
+- write string like "<event_fd> <fd of memory.pressure_level> <level> [strict]"
   to cgroup.event_control.
 
-Application will be notified through eventfd when memory pressure is at
-the specific level (or higher). Read/write operations to
-memory.pressure_level are no implemented.
+Applications will be notified through eventfd when memory pressure is at
+the specific level or higher. If strict is passed, then applications
+will only be notified when memory pressure reaches the specified level.

It would be good to describe when is strick and when the default appropriate.

Quoted 10 lines
Documentation/cgroups/memory.txt +2 -0
+
+Read/write operations to memory.pressure_level are no implemented.
 
 Test:
 
mm/vmpressure.c +0 -0
index 736a601..6289ede 100644

mm/vmpressure.c static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned, · line 140

Quoted 4 lines
mm/vmpressure.c +1 -0
@@ -137,6 +137,7 @@ static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned,
 struct vmpressure_event {
 	struct eventfd_ctx *efd;
 	enum vmpressure_levels level;
+	bool strict_mode;

Any reason to not using a flag for this? If there are any other modes to come them we would end up with zilions of bools which is not very nice.

Quoted 65 lines
mm/vmpressure.c +16 -2
 	struct list_head node;
 };
 
@@ -153,6 +154,9 @@ static bool vmpressure_event(struct vmpressure *vmpr,
 
 	list_for_each_entry(ev, &vmpr->events, node) {
 		if (level >= ev->level) {
+			/* strict mode ensures level == ev->level */
+			if (ev->strict_mode && level != ev->level)
+				continue;
 			eventfd_signal(ev->efd, 1);
 			signalled = true;
 		}
@@ -292,7 +296,7 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
  * infrastructure, so that the notifications will be delivered to the
  * @eventfd. The @args parameter is a string that denotes pressure level
  * threshold (one of vmpressure_str_levels, i.e. "low", "medium", or
- * "critical").
+ * "critical") and optionally a different operating mode (i.e. "strict")
  *
  * This function should not be used directly, just pass it to (struct
  * cftype).register_event, and then cgroup core will handle everything by
@@ -303,22 +307,33 @@ int vmpressure_register_event(struct cgroup *cg, struct cftype *cft,
 {
 	struct vmpressure *vmpr = cg_to_vmpressure(cg);
 	struct vmpressure_event *ev;
+	bool smode = false;
+	const char *p;
 	int level;
 
 	for (level = 0; level < VMPRESSURE_NUM_LEVELS; level++) {
-		if (!strcmp(vmpressure_str_levels[level], args))
+		p = vmpressure_str_levels[level];
+		if (!strncmp(p, args, strlen(p)))
 			break;
 	}
 
 	if (level >= VMPRESSURE_NUM_LEVELS)
 		return -EINVAL;
 
+	p = strchr(args, ' ');
+	if (p) {
+		if (strncmp(++p, "strict", 6))
+			return -EINVAL;
+		smode = true;
+	}
+
 	ev = kzalloc(sizeof(*ev), GFP_KERNEL);
 	if (!ev)
 		return -ENOMEM;
 
 	ev->efd = eventfd;
 	ev->level = level;
+	ev->strict_mode = smode;
 
 	mutex_lock(&vmpr->events_lock);
 	list_add(&ev->node, &vmpr->events);
Signature · 7 lines
1.8.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#12 lore raw
Quoted 45 lines · On Wed, 26 Jun 2013 10:08:27 +0200 Michal Hocko <[email protected]> wrote:
Quoted 9 lines · Luiz Capitulino

Currently, applications are notified for the level they registered for _plus_ higher levels.

This is a problem if the application wants to implement different actions for different levels. For example, an application might want to release 10% of its cache on level low, 50% on medium and 100% on critical. To do this, the application has to register a different fd for each event. However, fd low is always going to be notified and and all fds are going to be notified on level critical.

OK, I am not user of this interface but I thought that the application would take an action of the highest level it gets notification. But yes this might get clumsy to implement.

Quoted 3 lines

Strict mode solves this problem by strictly notifiying the event an fd has registered for. It's optional. By default we still notify on higher levels.

OK, makes some sense to me and it should work with the proposed edge trigerring as well.

Quoted 23 lines

---

PS: I'm following the discussion on the event storm problem, but I believe
strict mode is orthogonal to what has been suggested (although the patches conflict)

 Documentation/cgroups/memory.txt | 10 ++++++----
 mm/vmpressure.c                  | 19 +++++++++++++++++--
 2 files changed, 23 insertions(+), 6 deletions(-)
Documentation/cgroups/memory.txt +1 -1
index ddf4f93..3c589cf 100644
@@ -807,12 +807,14 @@ register a notification, an application must:
 
 - create an eventfd using eventfd(2);
 - open memory.pressure_level;
-- write string like "<event_fd> <fd of memory.pressure_level> <level>"
+- write string like "<event_fd> <fd of memory.pressure_level> <level> [strict]"
   to cgroup.event_control.
 
Quoted 9 lines

Documentation/cgroups/memory.txt register a notification, an application must: · line 815

Quoted 6 lines
Documentation/cgroups/memory.txt +3 -3
-Application will be notified through eventfd when memory pressure is at
-the specific level (or higher). Read/write operations to
-memory.pressure_level are no implemented.
+Applications will be notified through eventfd when memory pressure is at
+the specific level or higher. If strict is passed, then applications
+will only be notified when memory pressure reaches the specified level.

It would be good to describe when is strick and when the default appropriate.

Yeah, Anton asked for the same thing. Will do it.

Quoted 5 lines
Quoted 5 lines
Documentation/cgroups/memory.txt +2 -0
+
+Read/write operations to memory.pressure_level are no implemented.
 
 Test:
 
Quoted 12 lines

mm/vmpressure.c static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned, · line 140

Quoted 9 lines
mm/vmpressure.c +1 -0
index 736a601..6289ede 100644
@@ -137,6 +137,7 @@ static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned,
 struct vmpressure_event {
 	struct eventfd_ctx *efd;
 	enum vmpressure_levels level;
+	bool strict_mode;

Any reason to not using a flag for this? If there are any other modes to come them we would end up with zilions of bools which is not very nice.

Good point, I'll change it.

Quoted 61 lines
Quoted 61 lines
mm/vmpressure.c +16 -2
 	struct list_head node;
 };
 
@@ -153,6 +154,9 @@ static bool vmpressure_event(struct vmpressure *vmpr,
 
 	list_for_each_entry(ev, &vmpr->events, node) {
 		if (level >= ev->level) {
+			/* strict mode ensures level == ev->level */
+			if (ev->strict_mode && level != ev->level)
+				continue;
 			eventfd_signal(ev->efd, 1);
 			signalled = true;
 		}
@@ -292,7 +296,7 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
  * infrastructure, so that the notifications will be delivered to the
  * @eventfd. The @args parameter is a string that denotes pressure level
  * threshold (one of vmpressure_str_levels, i.e. "low", "medium", or
- * "critical").
+ * "critical") and optionally a different operating mode (i.e. "strict")
  *
  * This function should not be used directly, just pass it to (struct
  * cftype).register_event, and then cgroup core will handle everything by
@@ -303,22 +307,33 @@ int vmpressure_register_event(struct cgroup *cg, struct cftype *cft,
 {
 	struct vmpressure *vmpr = cg_to_vmpressure(cg);
 	struct vmpressure_event *ev;
+	bool smode = false;
+	const char *p;
 	int level;
 
 	for (level = 0; level < VMPRESSURE_NUM_LEVELS; level++) {
-		if (!strcmp(vmpressure_str_levels[level], args))
+		p = vmpressure_str_levels[level];
+		if (!strncmp(p, args, strlen(p)))
 			break;
 	}
 
 	if (level >= VMPRESSURE_NUM_LEVELS)
 		return -EINVAL;
 
+	p = strchr(args, ' ');
+	if (p) {
+		if (strncmp(++p, "strict", 6))
+			return -EINVAL;
+		smode = true;
+	}
+
 	ev = kzalloc(sizeof(*ev), GFP_KERNEL);
 	if (!ev)
 		return -ENOMEM;
 
 	ev->efd = eventfd;
 	ev->level = level;
+	ev->strict_mode = smode;
 
 	mutex_lock(&vmpr->events_lock);
 	list_add(&ev->node, &vmpr->events);
Signature · 1 line
1.8.1.4
Quoted 6 lines
Quoted 5 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw
In reply to Luiz Capitulino

Hi!

Documentation/cgroups/memory.txt register a notification, an application must: · line 812

Quoted 12 lines
Documentation/cgroups/memory.txt +1 -1
index ddf4f93..3c589cf 100644
@@ -807,12 +807,14 @@ register a notification, an application must:
 
 - create an eventfd using eventfd(2);
 - open memory.pressure_level;
-- write string like "<event_fd> <fd of memory.pressure_level> <level>"
+- write string like "<event_fd> <fd of memory.pressure_level> <level> [strict]"
   to cgroup.event_control.
 

This is.. pretty strange interface. Would it be cleaner to do ioctl()? New syscall?

Quoted 15 lines
Documentation/cgroups/memory.txt +4 -1
@@ -303,22 +307,33 @@ int vmpressure_register_event(struct cgroup *cg, struct cftype *cft,
 {
 	struct vmpressure *vmpr = cg_to_vmpressure(cg);
 	struct vmpressure_event *ev;
+	bool smode = false;
+	const char *p;
 	int level;
 
 	for (level = 0; level < VMPRESSURE_NUM_LEVELS; level++) {
-		if (!strcmp(vmpressure_str_levels[level], args))
+		p = vmpressure_str_levels[level];
+		if (!strncmp(p, args, strlen(p)))
 			break;
 	}
 

Documentation/cgroups/memory.txt int vmpressure_register_event(struct cgroup *cg, struct cftype *cft, · line 329

Quoted 10 lines
Documentation/cgroups/memory.txt +7 -0
 	if (level >= VMPRESSURE_NUM_LEVELS)
 		return -EINVAL;
 
+	p = strchr(args, ' ');
+	if (p) {
+		if (strncmp(++p, "strict", 6))
+			return -EINVAL;
+		smode = true;
+	}
+

This looks like something for bash, not for kernel :-(.
Pavel

Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#14 lore raw
Quoted 8 lines · On Mon, 1 Jul 2013 10:51:03 +0200 Pavel Machek <[email protected]> wrote:

Hi!

Quoted 6 lines
Documentation/cgroups/memory.txt +0 -0
index ddf4f93..3c589cf 100644
@@ -807,12 +807,14 @@ register a notification, an application must:
 
Quoted 9 lines

Documentation/cgroups/memory.txt register a notification, an application must: · line 812

Quoted 6 lines
Documentation/cgroups/memory.txt +1 -1
 - create an eventfd using eventfd(2);
 - open memory.pressure_level;
-- write string like "<event_fd> <fd of memory.pressure_level> <level>"
+- write string like "<event_fd> <fd of memory.pressure_level> <level> [strict]"
   to cgroup.event_control.
 

This is.. pretty strange interface. Would it be cleaner to do ioctl()? New syscall?

Are you referring to my new mode or to the whole thing?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#15 lore raw
Quoted 21 lines · Luiz Capitulino
Quoted 8 lines · On Mon, 1 Jul 2013 10:51:03 +0200 Pavel Machek <[email protected]> wrote:

Hi!

Quoted 6 lines
Documentation/cgroups/memory.txt +0 -0
index ddf4f93..3c589cf 100644
@@ -807,12 +807,14 @@ register a notification, an application must:
 
Quoted 9 lines

Documentation/cgroups/memory.txt register a notification, an application must: · line 812

Quoted 6 lines
Documentation/cgroups/memory.txt +1 -1
 - create an eventfd using eventfd(2);
 - open memory.pressure_level;
-- write string like "<event_fd> <fd of memory.pressure_level> <level>"
+- write string like "<event_fd> <fd of memory.pressure_level> <level> [strict]"
   to cgroup.event_control.
 

This is.. pretty strange interface. Would it be cleaner to do ioctl()? New syscall?

Quoted 1 line

Are you referring to my new mode or to the whole thing?

Well. The interface was already very strange and you made it even worse.

For example... How is the string terminated? \0? \n? Not at all? Needs to be written in single write? How many spaces are allowed? Can I put there \t? How many leading zeros? How do you know that you can stop looking for "strict" string?

Dunno. Passing fd by writting it out in ascii is strange. (And writing fd in ascii to the same fd is ... very strange.)

Pavel

Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#16 lore raw
Quoted 22 lines · On Tue, 2 Jul 2013 21:47:03 +0200 Pavel Machek <[email protected]> wrote:
Quoted 21 lines · Luiz Capitulino
Quoted 17 lines · On Mon, 1 Jul 2013 10:51:03 +0200 Pavel Machek <[email protected]> wrote:

Hi!

Documentation/cgroups/memory.txt register a notification, an application must: · line 812

Quoted 12 lines
Documentation/cgroups/memory.txt +1 -1
index ddf4f93..3c589cf 100644
@@ -807,12 +807,14 @@ register a notification, an application must:
 
 - create an eventfd using eventfd(2);
 - open memory.pressure_level;
-- write string like "<event_fd> <fd of memory.pressure_level> <level>"
+- write string like "<event_fd> <fd of memory.pressure_level> <level> [strict]"
   to cgroup.event_control.
 

This is.. pretty strange interface. Would it be cleaner to do ioctl()? New syscall?

Quoted 4 lines
Quoted 1 line

Are you referring to my new mode or to the whole thing?

Well. The interface was already very strange and you made it even worse.

The existing interface is the cgroup's notification mechanism, I think discussing it is a bit out of scope for my extension.

Now, regarding my extension itself and the current vmpressure API, I believe that delivering all events to user-space (ie. w/o any filtering in the kernel) is a better solution.

Point is whether we can do it with the current vmpressure API (which is cgroup based) or whether we should move to something else.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>