linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] samples: introduce cgroup events listeners
@ 2023-11-23  7:19 Dmitry Rokosov
  2023-11-23  7:19 ` [PATCH v3 1/3] samples: introduce new samples subdir for cgroup Dmitry Rokosov
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Dmitry Rokosov @ 2023-11-23  7:19 UTC (permalink / raw)
  To: hannes, mhocko, roman.gushchin, shakeelb, muchun.song, akpm
  Cc: kernel, rockosov, cgroups, linux-mm, linux-kernel, bpf, Dmitry Rokosov

To begin with, this patch series relocates the cgroup example code to
the samples/cgroup directory, which is the appropriate location for such
code snippets.

Furthermore, a new memcg events listener is introduced. This
listener is a simple yet effective tool for monitoring memory events and
managing counter changes during runtime.

Additionally, as per Andrew Morton's suggestion, a helpful reminder
comment is included in the memcontrol implementation. This comment
serves to ensure that the samples code is updated whenever new events
are added.

Changes v3 since v2 at [2]:
    - rename cgroup_v2_event_listener to memcg_event_listener per
      Andrew's suggestion

Changes v2 since v1 at [1]:
    - create new samples subdir - cgroup
    - move cgroup_event_listener for cgroup v1 to samples/cgroup
    - add a reminder comment to memcontrol implementation

Links:
    [1] - https://lore.kernel.org/all/20231013184107.28734-1-ddrokosov@salutedevices.com/
    [2] - https://lore.kernel.org/all/20231110082045.19407-1-ddrokosov@salutedevices.com/

Dmitry Rokosov (3):
  samples: introduce new samples subdir for cgroup
  samples/cgroup: introduce memcg memory.events listener
  mm: memcg: add reminder comment for the memcg v2 events

 MAINTAINERS                                   |   1 +
 mm/memcontrol.c                               |   4 +
 samples/Kconfig                               |   6 +
 samples/Makefile                              |   1 +
 samples/cgroup/Makefile                       |   5 +
 .../cgroup/cgroup_event_listener.c            |   0
 samples/cgroup/memcg_event_listener.c         | 330 ++++++++++++++++++
 tools/cgroup/Makefile                         |  11 -
 8 files changed, 347 insertions(+), 11 deletions(-)
 create mode 100644 samples/cgroup/Makefile
 rename {tools => samples}/cgroup/cgroup_event_listener.c (100%)
 create mode 100644 samples/cgroup/memcg_event_listener.c
 delete mode 100644 tools/cgroup/Makefile

-- 
2.36.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/3] samples: introduce new samples subdir for cgroup
  2023-11-23  7:19 [PATCH v3 0/3] samples: introduce cgroup events listeners Dmitry Rokosov
@ 2023-11-23  7:19 ` Dmitry Rokosov
  2023-11-23  7:19 ` [PATCH v3 2/3] samples/cgroup: introduce memcg memory.events listener Dmitry Rokosov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Dmitry Rokosov @ 2023-11-23  7:19 UTC (permalink / raw)
  To: hannes, mhocko, roman.gushchin, shakeelb, muchun.song, akpm
  Cc: kernel, rockosov, cgroups, linux-mm, linux-kernel, bpf, Dmitry Rokosov

Move the cgroup_event_listener for cgroup v1 to the samples directory.
This suggestion was proposed by Andrew Morton during the discussion [1].

Links:
    [1] - https://lore.kernel.org/all/20231106140934.3f5d4960141562fe8da53906@linux-foundation.org/

Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com>
---
 MAINTAINERS                                       |  1 +
 samples/Kconfig                                   |  6 ++++++
 samples/Makefile                                  |  1 +
 samples/cgroup/Makefile                           |  5 +++++
 {tools => samples}/cgroup/cgroup_event_listener.c |  0
 tools/cgroup/Makefile                             | 11 -----------
 6 files changed, 13 insertions(+), 11 deletions(-)
 create mode 100644 samples/cgroup/Makefile
 rename {tools => samples}/cgroup/cgroup_event_listener.c (100%)
 delete mode 100644 tools/cgroup/Makefile

diff --git a/MAINTAINERS b/MAINTAINERS
index d516295978a4..6a0a580c34dc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5243,6 +5243,7 @@ L:	linux-mm@kvack.org
 S:	Maintained
 F:	mm/memcontrol.c
 F:	mm/swap_cgroup.c
+F:	samples/cgroup/*
 F:	tools/testing/selftests/cgroup/memcg_protection.m
 F:	tools/testing/selftests/cgroup/test_kmem.c
 F:	tools/testing/selftests/cgroup/test_memcontrol.c
diff --git a/samples/Kconfig b/samples/Kconfig
index bf49ed0d7362..339c8e2ee749 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -287,6 +287,12 @@ config SAMPLE_KMEMLEAK
           Build a sample program which have explicitly leaks memory to test
           kmemleak
 
+config SAMPLE_CGROUP
+	bool "Build cgroup sample code"
+	depends on CGROUPS && CC_CAN_LINK && HEADERS_INSTALL
+	help
+	  Build samples that demonstrate the usage of the cgroup API.
+
 source "samples/rust/Kconfig"
 
 endif # SAMPLES
diff --git a/samples/Makefile b/samples/Makefile
index 0a551c2b33f4..b85fa64390c5 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -3,6 +3,7 @@
 
 subdir-$(CONFIG_SAMPLE_AUXDISPLAY)	+= auxdisplay
 subdir-$(CONFIG_SAMPLE_ANDROID_BINDERFS) += binderfs
+subdir-$(CONFIG_SAMPLE_CGROUP) += cgroup
 obj-$(CONFIG_SAMPLE_CONFIGFS)		+= configfs/
 obj-$(CONFIG_SAMPLE_CONNECTOR)		+= connector/
 obj-$(CONFIG_SAMPLE_FANOTIFY_ERROR)	+= fanotify/
diff --git a/samples/cgroup/Makefile b/samples/cgroup/Makefile
new file mode 100644
index 000000000000..deef4530f5e7
--- /dev/null
+++ b/samples/cgroup/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+userprogs-always-y += cgroup_event_listener
+
+userccflags += -I usr/include
diff --git a/tools/cgroup/cgroup_event_listener.c b/samples/cgroup/cgroup_event_listener.c
similarity index 100%
rename from tools/cgroup/cgroup_event_listener.c
rename to samples/cgroup/cgroup_event_listener.c
diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile
deleted file mode 100644
index ffca068e4a76..000000000000
--- a/tools/cgroup/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-# Makefile for cgroup tools
-
-CFLAGS = -Wall -Wextra
-
-all: cgroup_event_listener
-%: %.c
-	$(CC) $(CFLAGS) -o $@ $^
-
-clean:
-	$(RM) cgroup_event_listener
-- 
2.36.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 2/3] samples/cgroup: introduce memcg memory.events listener
  2023-11-23  7:19 [PATCH v3 0/3] samples: introduce cgroup events listeners Dmitry Rokosov
  2023-11-23  7:19 ` [PATCH v3 1/3] samples: introduce new samples subdir for cgroup Dmitry Rokosov
@ 2023-11-23  7:19 ` Dmitry Rokosov
  2023-11-23  7:19 ` [PATCH v3 3/3] mm: memcg: add reminder comment for the memcg v2 events Dmitry Rokosov
  2023-11-24 19:42 ` [PATCH v3 0/3] samples: introduce cgroup events listeners Andrew Morton
  3 siblings, 0 replies; 7+ messages in thread
From: Dmitry Rokosov @ 2023-11-23  7:19 UTC (permalink / raw)
  To: hannes, mhocko, roman.gushchin, shakeelb, muchun.song, akpm
  Cc: kernel, rockosov, cgroups, linux-mm, linux-kernel, bpf, Dmitry Rokosov

This is a simple listener for memory events that handles counter
changes in runtime. It can be set up for a specific memory cgroup v2.

The output example:
=====
$ /tmp/memcg_event_listener test
Initialized MEMCG events with counters:
MEMCG events:
	low: 0
	high: 0
	max: 0
	oom: 0
	oom_kill: 0
	oom_group_kill: 0
Started monitoring memory events from '/sys/fs/cgroup/test/memory.events'...
Received event in /sys/fs/cgroup/test/memory.events:
*** 1 MEMCG oom_kill event, change counter 0 => 1
Received event in /sys/fs/cgroup/test/memory.events:
*** 1 MEMCG oom_kill event, change counter 1 => 2
Received event in /sys/fs/cgroup/test/memory.events:
*** 1 MEMCG oom_kill event, change counter 2 => 3
Received event in /sys/fs/cgroup/test/memory.events:
*** 1 MEMCG oom_kill event, change counter 3 => 4
Received event in /sys/fs/cgroup/test/memory.events:
*** 2 MEMCG max events, change counter 0 => 2
Received event in /sys/fs/cgroup/test/memory.events:
*** 8 MEMCG max events, change counter 2 => 10
*** 1 MEMCG oom event, change counter 0 => 1
Received event in /sys/fs/cgroup/test/memory.events:
*** 1 MEMCG oom_kill event, change counter 4 => 5
^CExiting memcg event listener...
=====

Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com>
---
 samples/cgroup/Makefile               |   2 +-
 samples/cgroup/memcg_event_listener.c | 330 ++++++++++++++++++++++++++
 2 files changed, 331 insertions(+), 1 deletion(-)
 create mode 100644 samples/cgroup/memcg_event_listener.c

diff --git a/samples/cgroup/Makefile b/samples/cgroup/Makefile
index deef4530f5e7..526c8569707c 100644
--- a/samples/cgroup/Makefile
+++ b/samples/cgroup/Makefile
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 
-userprogs-always-y += cgroup_event_listener
+userprogs-always-y += cgroup_event_listener memcg_event_listener
 
 userccflags += -I usr/include
diff --git a/samples/cgroup/memcg_event_listener.c b/samples/cgroup/memcg_event_listener.c
new file mode 100644
index 000000000000..a1667fe2489a
--- /dev/null
+++ b/samples/cgroup/memcg_event_listener.c
@@ -0,0 +1,330 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * memcg_event_listener.c - Simple listener of memcg memory.events
+ *
+ * Copyright (c) 2023, SaluteDevices. All Rights Reserved.
+ *
+ * Author: Dmitry Rokosov <ddrokosov@salutedevices.com>
+ */
+
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <poll.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/inotify.h>
+#include <unistd.h>
+
+#define MEMCG_EVENTS "memory.events"
+
+/* Size of buffer to use when reading inotify events */
+#define INOTIFY_BUFFER_SIZE 8192
+
+#define INOTIFY_EVENT_NEXT(event, length) ({         \
+	(length) -= sizeof(*(event)) + (event)->len; \
+	(event)++;                                   \
+})
+
+#define INOTIFY_EVENT_OK(event, length) ((length) >= (ssize_t)sizeof(*(event)))
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
+
+struct memcg_counters {
+	long low;
+	long high;
+	long max;
+	long oom;
+	long oom_kill;
+	long oom_group_kill;
+};
+
+struct memcg_events {
+	struct memcg_counters counters;
+	char path[PATH_MAX];
+	int inotify_fd;
+	int inotify_wd;
+};
+
+static void print_memcg_counters(const struct memcg_counters *counters)
+{
+	printf("MEMCG events:\n");
+	printf("\tlow: %ld\n", counters->low);
+	printf("\thigh: %ld\n", counters->high);
+	printf("\tmax: %ld\n", counters->max);
+	printf("\toom: %ld\n", counters->oom);
+	printf("\toom_kill: %ld\n", counters->oom_kill);
+	printf("\toom_group_kill: %ld\n", counters->oom_group_kill);
+}
+
+static int get_memcg_counter(char *line, const char *name, long *counter)
+{
+	size_t len = strlen(name);
+	char *endptr;
+	long tmp;
+
+	if (memcmp(line, name, len)) {
+		warnx("Counter line %s has wrong name, %s is expected",
+		      line, name);
+		return -EINVAL;
+	}
+
+	/* skip the whitespace delimiter */
+	len += 1;
+
+	errno = 0;
+	tmp = strtol(&line[len], &endptr, 10);
+	if (((tmp == LONG_MAX || tmp == LONG_MIN) && errno == ERANGE) ||
+	    (errno && !tmp)) {
+		warnx("Failed to parse: %s", &line[len]);
+		return -ERANGE;
+	}
+
+	if (endptr == &line[len]) {
+		warnx("Not digits were found in line %s", &line[len]);
+		return -EINVAL;
+	}
+
+	if (!(*endptr == '\0' || (*endptr == '\n' && *++endptr == '\0'))) {
+		warnx("Further characters after number: %s", endptr);
+		return -EINVAL;
+	}
+
+	*counter = tmp;
+
+	return 0;
+}
+
+static int read_memcg_events(struct memcg_events *events, bool show_diff)
+{
+	FILE *fp = fopen(events->path, "re");
+	size_t i;
+	int ret = 0;
+	bool any_new_events = false;
+	char *line = NULL;
+	size_t len = 0;
+	struct memcg_counters new_counters;
+	struct memcg_counters *counters = &events->counters;
+	struct {
+		const char *name;
+		long *new;
+		long *old;
+	} map[] = {
+		{
+			.name = "low",
+			.new = &new_counters.low,
+			.old = &counters->low,
+		},
+		{
+			.name = "high",
+			.new = &new_counters.high,
+			.old = &counters->high,
+		},
+		{
+			.name = "max",
+			.new = &new_counters.max,
+			.old = &counters->max,
+		},
+		{
+			.name = "oom",
+			.new = &new_counters.oom,
+			.old = &counters->oom,
+		},
+		{
+			.name = "oom_kill",
+			.new = &new_counters.oom_kill,
+			.old = &counters->oom_kill,
+		},
+		{
+			.name = "oom_group_kill",
+			.new = &new_counters.oom_group_kill,
+			.old = &counters->oom_group_kill,
+		},
+	};
+
+	if (!fp) {
+		warn("Failed to open memcg events file %s", events->path);
+		return -EBADF;
+	}
+
+	/* Read new values for memcg counters */
+	for (i = 0; i < ARRAY_SIZE(map); ++i) {
+		ssize_t nread;
+
+		errno = 0;
+		nread = getline(&line, &len, fp);
+		if (nread == -1) {
+			if (errno) {
+				warn("Failed to read line for counter %s",
+				     map[i].name);
+				ret = -EIO;
+				goto exit;
+			}
+
+			break;
+		}
+
+		ret = get_memcg_counter(line, map[i].name, map[i].new);
+		if (ret) {
+			warnx("Failed to get counter value from line %s", line);
+			goto exit;
+		}
+	}
+
+	for (i = 0; i < ARRAY_SIZE(map); ++i) {
+		long diff;
+
+		if (*map[i].new > *map[i].old) {
+			diff = *map[i].new - *map[i].old;
+
+			if (show_diff)
+				printf("*** %ld MEMCG %s event%s, "
+				       "change counter %ld => %ld\n",
+				       diff, map[i].name,
+				       (diff == 1) ? "" : "s",
+				       *map[i].old, *map[i].new);
+
+			*map[i].old += diff;
+			any_new_events = true;
+		}
+	}
+
+	if (show_diff && !any_new_events)
+		printf("*** No new untracked memcg events available\n");
+
+exit:
+	free(line);
+	fclose(fp);
+
+	return ret;
+}
+
+static void process_memcg_events(struct memcg_events *events,
+				 struct inotify_event *event)
+{
+	int ret;
+
+	if (events->inotify_wd != event->wd) {
+		warnx("Unknown inotify event %d, should be %d", event->wd,
+		      events->inotify_wd);
+		return;
+	}
+
+	printf("Received event in %s:\n", events->path);
+
+	if (!(event->mask & IN_MODIFY)) {
+		warnx("No IN_MODIFY event, skip it");
+		return;
+	}
+
+	ret = read_memcg_events(events, /* show_diff = */true);
+	if (ret)
+		warnx("Can't read memcg events");
+}
+
+static void monitor_events(struct memcg_events *events)
+{
+	struct pollfd fds[1];
+	int ret;
+
+	printf("Started monitoring memory events from '%s'...\n", events->path);
+
+	fds[0].fd = events->inotify_fd;
+	fds[0].events = POLLIN;
+
+	for (;;) {
+		ret = poll(fds, ARRAY_SIZE(fds), -1);
+		if (ret < 0 && errno != EAGAIN)
+			err(EXIT_FAILURE, "Can't poll memcg events (%d)", ret);
+
+		if (fds[0].revents & POLLERR)
+			err(EXIT_FAILURE, "Got POLLERR during monitor events");
+
+		if (fds[0].revents & POLLIN) {
+			struct inotify_event *event;
+			char buffer[INOTIFY_BUFFER_SIZE];
+			ssize_t length;
+
+			length = read(fds[0].fd, buffer, INOTIFY_BUFFER_SIZE);
+			if (length <= 0)
+				continue;
+
+			event = (struct inotify_event *)buffer;
+			while (INOTIFY_EVENT_OK(event, length)) {
+				process_memcg_events(events, event);
+				event = INOTIFY_EVENT_NEXT(event, length);
+			}
+		}
+	}
+}
+
+static int initialize_memcg_events(struct memcg_events *events,
+				   const char *cgroup)
+{
+	int ret;
+
+	memset(events, 0, sizeof(struct memcg_events));
+
+	ret = snprintf(events->path, PATH_MAX,
+		       "/sys/fs/cgroup/%s/memory.events", cgroup);
+	if (ret >= PATH_MAX) {
+		warnx("Path to cgroup memory.events is too long");
+		return -EMSGSIZE;
+	} else if (ret < 0) {
+		warn("Can't generate cgroup event full name");
+		return ret;
+	}
+
+	ret = read_memcg_events(events, /* show_diff = */false);
+	if (ret) {
+		warnx("Failed to read initial memcg events state (%d)", ret);
+		return ret;
+	}
+
+	events->inotify_fd = inotify_init();
+	if (events->inotify_fd < 0) {
+		warn("Failed to setup new inotify device");
+		return -EMFILE;
+	}
+
+	events->inotify_wd = inotify_add_watch(events->inotify_fd,
+					       events->path, IN_MODIFY);
+	if (events->inotify_wd < 0) {
+		warn("Couldn't add monitor in dir %s", events->path);
+		return -EIO;
+	}
+
+	printf("Initialized MEMCG events with counters:\n");
+	print_memcg_counters(&events->counters);
+
+	return 0;
+}
+
+static void cleanup_memcg_events(struct memcg_events *events)
+{
+	inotify_rm_watch(events->inotify_fd, events->inotify_wd);
+	close(events->inotify_fd);
+}
+
+int main(int argc, const char **argv)
+{
+	struct memcg_events events;
+	ssize_t ret;
+
+	if (argc != 2)
+		errx(EXIT_FAILURE, "Usage: %s <cgroup>", argv[0]);
+
+	ret = initialize_memcg_events(&events, argv[1]);
+	if (ret)
+		errx(EXIT_FAILURE, "Can't initialize memcg events (%zd)", ret);
+
+	monitor_events(&events);
+
+	cleanup_memcg_events(&events);
+
+	printf("Exiting memcg event listener...\n");
+
+	return EXIT_SUCCESS;
+}
-- 
2.36.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 3/3] mm: memcg: add reminder comment for the memcg v2 events
  2023-11-23  7:19 [PATCH v3 0/3] samples: introduce cgroup events listeners Dmitry Rokosov
  2023-11-23  7:19 ` [PATCH v3 1/3] samples: introduce new samples subdir for cgroup Dmitry Rokosov
  2023-11-23  7:19 ` [PATCH v3 2/3] samples/cgroup: introduce memcg memory.events listener Dmitry Rokosov
@ 2023-11-23  7:19 ` Dmitry Rokosov
  2023-11-24 19:42 ` [PATCH v3 0/3] samples: introduce cgroup events listeners Andrew Morton
  3 siblings, 0 replies; 7+ messages in thread
From: Dmitry Rokosov @ 2023-11-23  7:19 UTC (permalink / raw)
  To: hannes, mhocko, roman.gushchin, shakeelb, muchun.song, akpm
  Cc: kernel, rockosov, cgroups, linux-mm, linux-kernel, bpf, Dmitry Rokosov

To maintain the correct state, it is important to ensure that events for
the memory cgroup v2 are aligned with the sample cgroup codes.

Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com>
---
 mm/memcontrol.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e8ca4bdcb03c..a75c4584f58f 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6555,6 +6555,10 @@ static ssize_t memory_max_write(struct kernfs_open_file *of,
 	return nbytes;
 }
 
+/*
+ * Note: don't forget to update the 'samples/cgroup/memcg_event_listener'
+ * if any new events become available.
+ */
 static void __memory_events_show(struct seq_file *m, atomic_long_t *events)
 {
 	seq_printf(m, "low %lu\n", atomic_long_read(&events[MEMCG_LOW]));
-- 
2.36.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/3] samples: introduce cgroup events listeners
  2023-11-23  7:19 [PATCH v3 0/3] samples: introduce cgroup events listeners Dmitry Rokosov
                   ` (2 preceding siblings ...)
  2023-11-23  7:19 ` [PATCH v3 3/3] mm: memcg: add reminder comment for the memcg v2 events Dmitry Rokosov
@ 2023-11-24 19:42 ` Andrew Morton
  2023-11-24 20:06   ` Dmitry Rokosov
  3 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2023-11-24 19:42 UTC (permalink / raw)
  To: Dmitry Rokosov
  Cc: hannes, mhocko, roman.gushchin, shakeelb, muchun.song, kernel,
	rockosov, cgroups, linux-mm, linux-kernel, bpf

On Thu, 23 Nov 2023 10:19:42 +0300 Dmitry Rokosov <ddrokosov@salutedevices.com> wrote:

> To begin with, this patch series relocates the cgroup example code to
> the samples/cgroup directory, which is the appropriate location for such
> code snippets.

butbut.  Didn't we decide to do s/cgroup/memcg/ throughout?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/3] samples: introduce cgroup events listeners
  2023-11-24 19:42 ` [PATCH v3 0/3] samples: introduce cgroup events listeners Andrew Morton
@ 2023-11-24 20:06   ` Dmitry Rokosov
  2023-11-25  8:07     ` Dmitry Rokosov
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Rokosov @ 2023-11-24 20:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: hannes, mhocko, roman.gushchin, shakeelb, muchun.song, kernel,
	rockosov, cgroups, linux-mm, linux-kernel, bpf

On Fri, Nov 24, 2023 at 11:42:30AM -0800, Andrew Morton wrote:
> On Thu, 23 Nov 2023 10:19:42 +0300 Dmitry Rokosov <ddrokosov@salutedevices.com> wrote:
> 
> > To begin with, this patch series relocates the cgroup example code to
> > the samples/cgroup directory, which is the appropriate location for such
> > code snippets.
> 
> butbut.  Didn't we decide to do s/cgroup/memcg/ throughout?

I believe the samples directory should be named "samples/cgroup" instead
of "memcg" because the cgroup v1 event listener cannot be renamed to
"memcg" due to the common naming of cgroup v1 event_control (this sample
uses that control to access eventfd).

Additionally, I think it would be a good idea to add the new samples for
cgroup helpers in that directory.

That's why I have only renamed the new memcg listener.

-- 
Thank you,
Dmitry


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/3] samples: introduce cgroup events listeners
  2023-11-24 20:06   ` Dmitry Rokosov
@ 2023-11-25  8:07     ` Dmitry Rokosov
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry Rokosov @ 2023-11-25  8:07 UTC (permalink / raw)
  To: Andrew Morton
  Cc: hannes, mhocko, roman.gushchin, shakeelb, muchun.song, kernel,
	rockosov, cgroups, linux-mm, linux-kernel, bpf

Andrew,

On Fri, Nov 24, 2023 at 11:06:33PM +0300, Dmitry Rokosov wrote:
> On Fri, Nov 24, 2023 at 11:42:30AM -0800, Andrew Morton wrote:
> > On Thu, 23 Nov 2023 10:19:42 +0300 Dmitry Rokosov <ddrokosov@salutedevices.com> wrote:
> > 
> > > To begin with, this patch series relocates the cgroup example code to
> > > the samples/cgroup directory, which is the appropriate location for such
> > > code snippets.
> > 
> > butbut.  Didn't we decide to do s/cgroup/memcg/ throughout?
> 
> I believe the samples directory should be named "samples/cgroup" instead
> of "memcg" because the cgroup v1 event listener cannot be renamed to
> "memcg" due to the common naming of cgroup v1 event_control (this sample
> uses that control to access eventfd).
> 
> Additionally, I think it would be a good idea to add the new samples for
> cgroup helpers in that directory.
> 
> That's why I have only renamed the new memcg listener.

I looked into this more deeply. And yes, the old cgroup.event_control
has the common name, but it's used in the memcg implementation only.

So, if we plan to introduce new samples for cgroup, I suggest we use the
following naming convention:

1) Directory: samples/cgroup
2) V1 sample: memcg_v1_event_listener
3) V2 sample: memcg_v2_event_listener

Please let me know what you think about this. If it's okay with you, I
will prepare the v4 version with the above changes. I would appreciate
any feedback on that!"

-- 
Thank you,
Dmitry


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-11-25  8:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-23  7:19 [PATCH v3 0/3] samples: introduce cgroup events listeners Dmitry Rokosov
2023-11-23  7:19 ` [PATCH v3 1/3] samples: introduce new samples subdir for cgroup Dmitry Rokosov
2023-11-23  7:19 ` [PATCH v3 2/3] samples/cgroup: introduce memcg memory.events listener Dmitry Rokosov
2023-11-23  7:19 ` [PATCH v3 3/3] mm: memcg: add reminder comment for the memcg v2 events Dmitry Rokosov
2023-11-24 19:42 ` [PATCH v3 0/3] samples: introduce cgroup events listeners Andrew Morton
2023-11-24 20:06   ` Dmitry Rokosov
2023-11-25  8:07     ` Dmitry Rokosov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox