Skip to contentSkip to conversation

hugetlb: Initialize orig_shmmax and orig_shmmni value

PATCH New Eric Lin 2 participants 3 messages Oct 31, 2019 – Nov 1, 2019

lore
Share & tools
lore

Eric Lin

author
#0 lore raw

PATCH 1/1 hugetlb: Initialize orig_shmmax and orig_shmmni value

When doing save_nr_hugepages() in setup() and there is no Huge page support in system, it will call cleanup() and write wrong orig_shmmax and orig_shmmni value back to file.

To fix it, we initialize the orig_shmmax and orig_shmmni to -1 and check it in cleanup().

---
 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c   | 5 +++--
 testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c +3 -2
index d375810cb..c76e4167f 100644
@@ -38,7 +38,7 @@
 static long huge_free;
 static long huge_free2;
 static long hugepages;
-static long orig_shmmax, new_shmmax;
+static long orig_shmmax = -1, new_shmmax;
 
 static void shared_hugepage(void);
 
@@ -106,7 +106,8 @@ static void setup(void)
 static void cleanup(void)
 {
 	restore_nr_hugepages();
-	SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);
+	if (orig_shmmax != -1)
+		SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);
 }
 
 static struct tst_test test = {
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c +3 -2
index d5255228b..f2ecc465d 100644
@@ -39,7 +39,7 @@ static int num_shms;
 static int shm_id_arr[MAXIDS];
 
 static long hugepages = 128;
-static long orig_shmmni;
+static long orig_shmmni = -1;
 static struct tst_option options[] = {
 	{"s:", &nr_opt, "-s   num  Set the number of the been allocated hugepages"},
 	{NULL, NULL, NULL}
@@ -105,7 +105,8 @@ static void cleanup(void)
 	for (i = 0; i < num_shms; i++)
 		rm_shm(shm_id_arr[i]);
 
-	FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
+	if (orig_shmmni != -1)
+		FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
 	restore_nr_hugepages();
 }
 
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/1 hugetlb: Initialize orig_shmmax and orig_shmmni value

Quoted 10 lines · Eric Lin

When doing save_nr_hugepages() in setup() and there is no Huge page support in system, it will call cleanup() and write wrong orig_shmmax and orig_shmmni value back to file.

To fix it, we initialize the orig_shmmax and orig_shmmni to -1 and check it in cleanup().

Quoted 61 lines
---
 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c   | 5 +++--
 testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c +3 -2
index d375810cb..c76e4167f 100644
@@ -38,7 +38,7 @@
 static long huge_free;
 static long huge_free2;
 static long hugepages;
-static long orig_shmmax, new_shmmax;
+static long orig_shmmax = -1, new_shmmax;
 
 static void shared_hugepage(void);
 
@@ -106,7 +106,8 @@ static void setup(void)
 static void cleanup(void)
 {
        restore_nr_hugepages();
-       SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);
+       if (orig_shmmax != -1)
+               SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);
 }
 
 static struct tst_test test = {
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c +1 -1
index d5255228b..f2ecc465d 100644
@@ -39,7 +39,7 @@ static int num_shms;
 static int shm_id_arr[MAXIDS];
 
 static long hugepages = 128;
-static long orig_shmmni;
+static long orig_shmmni = -1;
 static struct tst_option options[] = {
        {"s:", &nr_opt, "-s   num  Set the number of the been allocated
 hugepages"},
        {NULL, NULL, NULL}
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c +2 -2
@@ -105,7 +105,8 @@ static void cleanup(void)
        for (i = 0; i < num_shms; i++)
                rm_shm(shm_id_arr[i]);
 
-       FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
+       if (orig_shmmni != -1)
+               FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
        restore_nr_hugepages();
 }
 
--

2.17.0

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

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191031/8515c390/attachment-0001.htm>
#2 lore raw

PATCH 1/1 hugetlb: Initialize orig_shmmax and orig_shmmni value

Quoted 9 lines · Li Wang
Quoted 5 lines · Eric Lin

When doing save_nr_hugepages() in setup() and there is no Huge page support in system, it will call cleanup() and write wrong orig_shmmax and orig_shmmni value back to file.

Quoted 7 lines
Quoted 4 lines

To fix it, we initialize the orig_shmmax and orig_shmmni to -1 and check it in cleanup().

Pushed.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191101/3ce2e419/attachment.htm>