Skip to contentSkip to conversation

memcg_process: cleanup the SHM segment

PATCH New Stanislav Kholmanskikh 2 participants 3 messages Sep 2, 2016 – Sep 8, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memcg_process: cleanup the SHM segment

Let's mark the segment for removal right after we attach it. This way memcg* test cases will no longer leave unused segments after they finish.

---
 .../controllers/memcg/functional/memcg_process.c   |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_process.c +4 -5
index fbb76e2..e2c60de 100644
@@ -234,9 +234,6 @@ static void shm(void)
 		if (key == -1)
 			err(1, "ftok() failed");
 
-		shmid = shmget(key, memsize, flag);
-		if (shmid == -1)
-			err(1, "shmget() failed");
 		shmctl(shmid, IPC_RMID, NULL);
 
 		shmid = shmget(key, memsize, flag);
@@ -248,12 +245,14 @@ static void shm(void)
 			shmctl(shmid, IPC_RMID, NULL);
 			err(1, "shmat() failed");
 		}
+
+		if (shmctl(shmid, IPC_RMID, NULL) == -1)
+			err(1, "shmctl() failed");
+
 		touch_memory(p, memsize);
 	} else {
 		if (shmdt(p) == -1)
 			err(1, "shmdt() failed");
-		if (shmctl(shmid, IPC_RMID, NULL) == -1)
-			err(1, "shmctl() failed");
 	}
 }
 
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 memcg_process: cleanup the SHM segment

Hi!

Quoted 14 lines

Let's mark the segment for removal right after we attach it. This way memcg* test cases will no longer leave unused segments after they finish.

---
 .../controllers/memcg/functional/memcg_process.c   |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_process.c +0 -0
index fbb76e2..e2c60de 100644

testcases/kernel/controllers/memcg/functional/memcg_process.c static void shm(void) · line 237

Quoted 7 lines
testcases/kernel/controllers/memcg/functional/memcg_process.c +0 -3
@@ -234,9 +234,6 @@ static void shm(void)
 		if (key == -1)
 			err(1, "ftok() failed");
 
-		shmid = shmget(key, memsize, flag);
-		if (shmid == -1)
-			err(1, "shmget() failed");
 		shmctl(shmid, IPC_RMID, NULL);
                     ^

Shouldn't we remove this IPC_RMID as well?

Otherwise it looks fine.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 memcg_process: cleanup the SHM segment

Hi

Quoted 18 lines · Cyril Hrubis

Hi!

Quoted 17 lines

Let's mark the segment for removal right after we attach it. This way memcg* test cases will no longer leave unused segments after they finish.

---
 .../controllers/memcg/functional/memcg_process.c   |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_process.c +0 -0
index fbb76e2..e2c60de 100644
@@ -234,9 +234,6 @@ static void shm(void)
 		if (key == -1)
 			err(1, "ftok() failed");
 
Quoted 7 lines

testcases/kernel/controllers/memcg/functional/memcg_process.c static void shm(void) · line 237

Quoted 4 lines
testcases/kernel/controllers/memcg/functional/memcg_process.c +0 -3
-		shmid = shmget(key, memsize, flag);
-		if (shmid == -1)
-			err(1, "shmget() failed");
 		shmctl(shmid, IPC_RMID, NULL);
                     ^

Shouldn't we remove this IPC_RMID as well?

Agreed. It's better to remove it.

Quoted 3 lines

Otherwise it looks fine.

Pushed with the removal of the above IPC_RMID call.

Thank you.