Skip to contentSkip to conversation

lib/mem.c: handle the case oom0{3, 5} exit with 'EAGAIN' situation

PATCH Superseded Li Wang 2 participants 5 messages Sep 16, 2015 – Sep 22, 2015

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v2 1/1 lib/mem.c: handle the case oom0{3, 5} exit with 'EAGAIN' situation

v1 --> v2
1. limited the number of loops
2. added the usleep(300) to wait resource freed

Sometimes oom0{3,5} failed as the following results:

oom05       0  TINFO  :  start OOM testing for mlocked pages.
oom05       0  TINFO  :  expected victim is 3371.
oom05       0  TINFO  :  thread (3fff788ff1c0), allocating 3221225472 bytes.

...
oom05 5 TFAIL : mem.c:153: victim unexpectedly ended with retcode: 11, expected: 12

In the OOM test, that tries to consume all memory. But the test doesn't retry to mlock, it simply exits with errno returned by mlock. At the moment testcase is expecting either ENOMEM or getting killed by kernel.

Here do retry the function if mlock() fail with 'EAGAIN' errno.

---
 testcases/kernel/mem/lib/mem.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
testcases/kernel/mem/lib/mem.c +10 -2
index 8fe4bf0..b8a55e2 100644
@@ -30,6 +30,7 @@ static int alloc_mem(long int length, int testcase)
 {
 	char *s;
 	long i, pagesz = getpagesize();
+	int loop = 10;
 
 	tst_resm(TINFO, "thread (%lx), allocating %ld bytes.",
 		(unsigned long) pthread_self(), length);
@@ -39,8 +40,15 @@ static int alloc_mem(long int length, int testcase)
 	if (s == MAP_FAILED)
 		return errno;
 
-	if (testcase == MLOCK && mlock(s, length) == -1)
-		return errno;
+	if (testcase == MLOCK) {
+		while (mlock(s, length) == -1 && loop > 0) {
+			if (EAGAIN != errno)
+				return errno;
+			usleep(300);
+			loop--;
+		}
+	}
+
 #ifdef HAVE_MADV_MERGEABLE
 	if (testcase == KSM && madvise(s, length, MADV_MERGEABLE) == -1)
 		return errno;
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/1 lib/mem.c: handle the case oom0{3, 5} exit with 'EAGAIN' situation

----- Original Message -----

Quoted 44 lines

From: "Li Wang" <[email protected]>
To: [email protected]
Sent: Wednesday, 16 September, 2015 11:55:32 AM
Subject: [LTP] [PATCH v2] lib/mem.c: handle the case oom0{3, 5} exit with 'EAGAIN' situation

v1 --> v2
1. limited the number of loops
2. added the usleep(300) to wait resource freed

Sometimes oom0{3,5} failed as the following results:

oom05       0  TINFO  :  start OOM testing for mlocked pages.
oom05       0  TINFO  :  expected victim is 3371.
oom05       0  TINFO  :  thread (3fff788ff1c0), allocating 3221225472 bytes.

...
oom05 5 TFAIL : mem.c:153: victim unexpectedly ended with retcode:
11, expected: 12

In the OOM test, that tries to consume all memory. But the test doesn't retry to mlock, it simply
exits with errno returned by mlock. At the moment testcase is expecting either ENOMEM or getting
killed by kernel.

Here do retry the function if mlock() fail with 'EAGAIN' errno.

---
 testcases/kernel/mem/lib/mem.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
testcases/kernel/mem/lib/mem.c +1 -0
index 8fe4bf0..b8a55e2 100644
@@ -30,6 +30,7 @@ static int alloc_mem(long int length, int testcase)
 {
 	char *s;
 	long i, pagesz = getpagesize();
+	int loop = 10;
 
 	tst_resm(TINFO, "thread (%lx), allocating %ld bytes.",
 		(unsigned long) pthread_self(), length);

testcases/kernel/mem/lib/mem.c static int alloc_mem(long int length, int testcase) · line 47

Quoted 10 lines
testcases/kernel/mem/lib/mem.c +5 -2
@@ -39,8 +40,15 @@ static int alloc_mem(long int length, int testcase)
 	if (s == MAP_FAILED)
 		return errno;
 
-	if (testcase == MLOCK && mlock(s, length) == -1)
-		return errno;
+	if (testcase == MLOCK) {
+		while (mlock(s, length) == -1 && loop > 0) {
+			if (EAGAIN != errno)
+				return errno;
+			usleep(300);

usleep is in microseconds, so this wouldn't give system much time.

Other than that it looks good to me.

Regards,
Jan

Quoted 14 lines
testcases/kernel/mem/lib/mem.c +4 -1
+			loop--;
+		}
+	}
+
 #ifdef HAVE_MADV_MERGEABLE
 	if (testcase == KSM && madvise(s, length, MADV_MERGEABLE) == -1)
 		return errno;
--

1.8.3.1

--
Mailing list info: http://lists.linux.it/listinfo/ltp

author
#2 lore raw

PATCH v2 1/1 lib/mem.c: handle the case oom0{3, 5} exit with 'EAGAIN' situation

Hi,

Quoted 57 lines · Jan Stancek

----- Original Message -----

Quoted 4 lines

From: "Li Wang" <[email protected]>
To: [email protected]
Sent: Wednesday, 16 September, 2015 11:55:32 AM
Subject: [LTP] [PATCH v2] lib/mem.c: handle the case oom0{3, 5} exit

with 'EAGAIN' situation

Quoted 10 lines

v1 --> v2
1. limited the number of loops
2. added the usleep(300) to wait resource freed

Sometimes oom0{3,5} failed as the following results:

oom05       0  TINFO  :  start OOM testing for mlocked pages.
oom05       0  TINFO  :  expected victim is 3371.
oom05       0  TINFO  :  thread (3fff788ff1c0), allocating 3221225472

bytes.

Quoted 2 lines

...
oom05 5 TFAIL : mem.c:153: victim unexpectedly ended with

retcode:

Quoted 3 lines

11, expected: 12

In the OOM test, that tries to consume all memory. But the test doesn't

retry

Quoted 5 lines

to mlock, it simply
exits with errno returned by mlock. At the moment testcase is expecting either ENOMEM or getting
killed by kernel.

Review

Quoted 8 lines

Here do retry the function if mlock() fail with 'EAGAIN' errno.

---
 testcases/kernel/mem/lib/mem.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/testcases/kernel/mem/lib/mem.c

Quoted 15 lines

index 8fe4bf0..b8a55e2 100644

testcases/kernel/mem/lib/mem.c +1 -0
@@ -30,6 +30,7 @@ static int alloc_mem(long int length, int testcase)
 {
      char *s;
      long i, pagesz = getpagesize();
+     int loop = 10;
 
      tst_resm(TINFO, "thread (%lx), allocating %ld bytes.",
              (unsigned long) pthread_self(), length);
@@ -39,8 +40,15 @@ static int alloc_mem(long int length, int testcase)
      if (s == MAP_FAILED)
              return errno;
 
Quoted 10 lines

testcases/kernel/mem/lib/mem.c static int alloc_mem(long int length, int testcase) · line 47

Quoted 7 lines
testcases/kernel/mem/lib/mem.c +5 -2
-     if (testcase == MLOCK && mlock(s, length) == -1)
-             return errno;
+     if (testcase == MLOCK) {
+             while (mlock(s, length) == -1 && loop > 0) {
+                     if (EAGAIN != errno)
+                             return errno;
+                     usleep(300);

usleep is in microseconds, so this wouldn't give system much time.

Hmm, it has 10 times to attempt. Anyway, Feel free to modify the time to a proper size.

Quoted 3 lines

Other than that it looks good to me.

Thanks.

Quoted 19 lines

Regards,
Jan

Quoted 14 lines
testcases/kernel/mem/lib/mem.c +4 -1
+                     loop--;
+             }
+     }
+
 #ifdef HAVE_MADV_MERGEABLE
      if (testcase == KSM && madvise(s, length, MADV_MERGEABLE) == -1)
              return errno;
--

1.8.3.1

--
Mailing list info: http://lists.linux.it/listinfo/ltp

Signature · 6 lines
Regards,
Li Wang
Email: [email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20150917/dd3e64e5/attachment-0001.html>
author
#3 lore raw

PATCH v2 1/1 lib/mem.c: handle the case oom0{3, 5} exit with 'EAGAIN' situation

Hi,

Quoted 72 lines · Li Wang

Hi,

Quoted 67 lines · Jan Stancek

----- Original Message -----

Quoted 4 lines

From: "Li Wang" <[email protected]>
To: [email protected]
Sent: Wednesday, 16 September, 2015 11:55:32 AM
Subject: [LTP] [PATCH v2] lib/mem.c: handle the case oom0{3, 5} exit

with 'EAGAIN' situation

Quoted 10 lines

v1 --> v2
1. limited the number of loops
2. added the usleep(300) to wait resource freed

Sometimes oom0{3,5} failed as the following results:

oom05       0  TINFO  :  start OOM testing for mlocked pages.
oom05       0  TINFO  :  expected victim is 3371.
oom05       0  TINFO  :  thread (3fff788ff1c0), allocating 3221225472

bytes.

Quoted 2 lines

...
oom05 5 TFAIL : mem.c:153: victim unexpectedly ended with

retcode:

Quoted 3 lines

11, expected: 12

In the OOM test, that tries to consume all memory. But the test doesn't

retry

Quoted 5 lines

to mlock, it simply
exits with errno returned by mlock. At the moment testcase is expecting either ENOMEM or getting
killed by kernel.

Review

Quoted 8 lines

Here do retry the function if mlock() fail with 'EAGAIN' errno.

---
 testcases/kernel/mem/lib/mem.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/testcases/kernel/mem/lib/mem.c

Quoted 12 lines

index 8fe4bf0..b8a55e2 100644

testcases/kernel/mem/lib/mem.c +1 -0
@@ -30,6 +30,7 @@ static int alloc_mem(long int length, int testcase)
 {
      char *s;
      long i, pagesz = getpagesize();
+     int loop = 10;
 
      tst_resm(TINFO, "thread (%lx), allocating %ld bytes.",
              (unsigned long) pthread_self(), length);

testcases/kernel/mem/lib/mem.c static int alloc_mem(long int length, int testcase) · line 47

Quoted 10 lines
testcases/kernel/mem/lib/mem.c +5 -2
@@ -39,8 +40,15 @@ static int alloc_mem(long int length, int testcase)
      if (s == MAP_FAILED)
              return errno;
 
-     if (testcase == MLOCK && mlock(s, length) == -1)
-             return errno;
+     if (testcase == MLOCK) {
+             while (mlock(s, length) == -1 && loop > 0) {
+                     if (EAGAIN != errno)
+                             return errno;
+                     usleep(300);

usleep is in microseconds, so this wouldn't give system much time.

Sorry, Ping.

Would you mind if I sent V3 with usleep(300000)? or any other advice?

Signature · 6 lines
Regards,
Li Wang
Email: [email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20150922/f2c4849b/attachment-0001.html>
#4 lore raw

PATCH v2 1/1 lib/mem.c: handle the case oom0{3, 5} exit with 'EAGAIN' situation

----- Original Message -----

Quoted 83 lines

From: "Li Wang" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Tuesday, 22 September, 2015 9:50:39 AM
Subject: Re: [LTP] [PATCH v2] lib/mem.c: handle the case oom0{3, 5} exit with 'EAGAIN' situation

Hi,

Quoted 72 lines · Li Wang

Hi,

Quoted 67 lines · Jan Stancek

----- Original Message -----

Quoted 4 lines

From: "Li Wang" <[email protected]>
To: [email protected]
Sent: Wednesday, 16 September, 2015 11:55:32 AM
Subject: [LTP] [PATCH v2] lib/mem.c: handle the case oom0{3, 5} exit

with 'EAGAIN' situation

Quoted 10 lines

v1 --> v2
1. limited the number of loops
2. added the usleep(300) to wait resource freed

Sometimes oom0{3,5} failed as the following results:

oom05       0  TINFO  :  start OOM testing for mlocked pages.
oom05       0  TINFO  :  expected victim is 3371.
oom05       0  TINFO  :  thread (3fff788ff1c0), allocating 3221225472

bytes.

Quoted 2 lines

...
oom05 5 TFAIL : mem.c:153: victim unexpectedly ended with

retcode:

Quoted 3 lines

11, expected: 12

In the OOM test, that tries to consume all memory. But the test doesn't

retry

Quoted 5 lines

to mlock, it simply
exits with errno returned by mlock. At the moment testcase is expecting either ENOMEM or getting
killed by kernel.

Review

Quoted 8 lines

Here do retry the function if mlock() fail with 'EAGAIN' errno.

---
 testcases/kernel/mem/lib/mem.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/testcases/kernel/mem/lib/mem.c

Quoted 12 lines

index 8fe4bf0..b8a55e2 100644

testcases/kernel/mem/lib/mem.c +1 -0
@@ -30,6 +30,7 @@ static int alloc_mem(long int length, int testcase)
 {
      char *s;
      long i, pagesz = getpagesize();
+     int loop = 10;
 
      tst_resm(TINFO, "thread (%lx), allocating %ld bytes.",
              (unsigned long) pthread_self(), length);

testcases/kernel/mem/lib/mem.c static int alloc_mem(long int length, int testcase) · line 47

Quoted 10 lines
testcases/kernel/mem/lib/mem.c +5 -2
@@ -39,8 +40,15 @@ static int alloc_mem(long int length, int testcase)
      if (s == MAP_FAILED)
              return errno;
 
-     if (testcase == MLOCK && mlock(s, length) == -1)
-             return errno;
+     if (testcase == MLOCK) {
+             while (mlock(s, length) == -1 && loop > 0) {
+                     if (EAGAIN != errno)
+                             return errno;
+                     usleep(300);

usleep is in microseconds, so this wouldn't give system much time.

Quoted 3 lines

Sorry, Ping.

Would you mind if I sent V3 with usleep(300000)? or any other advice?

No need. I changed it (along with small changes to description) and pushed.

Regards,
Jan

Quoted 7 lines

--
Regards,
Li Wang
Email: [email protected]