hugetlb/hugemmap: add hugemmap33 to test hugetlbfs quota accounting
PATCH v4 1/1 hugetlb/hugemmap: add hugemmap33 to test hugetlbfs quota accounting
Test hugetlbfs quota accounting with filesystem size limits to check for regressions in quota handling for MAP_PRIVATE and MAP_SHARED pages.
---
v3 -> v4:
- Check only ENOMEM for quota exhaustion in mmap() and COW mmap()
error paths;
- Use TESTPTR() for both mmap() calls to capture return value and
errno consistently via TST_RET_PTR and TST_ERR
- Use PATH_MAX instead of PATH_MAX + 32 for the path buffer
Link to v3: https://lore.kernel.org/ltp/[email protected]/
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap33.c | 222 ++++++++++++++++++ 3 files changed, 224 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c
runtest/hugetlb +1 -0
@@ -35,6 +35,7 @@ hugemmap29 hugemmap29 hugemmap30 hugemmap30 hugemmap31 hugemmap31 hugemmap32 hugemmap32 +hugemmap33 hugemmap33 hugemmap34 hugemmap34 hugemmap35 hugemmap35 hugemmap36 hugemmap36
testcases/kernel/mem/.gitignore +1 -0
@@ -35,6 +35,7 @@ /hugetlb/hugemmap/hugemmap30 /hugetlb/hugemmap/hugemmap31 /hugetlb/hugemmap/hugemmap32 +/hugetlb/hugemmap/hugemmap33 /hugetlb/hugemmap/hugemmap34 /hugetlb/hugemmap/hugemmap35 /hugetlb/hugemmap/hugemmap36
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +222 -0
222 lines not on this page · raw message
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Pavithra,
Quoted 3 lines · Pavithra
hugetlb/hugemmap: add hugemmap33 to test hugetlbfs quota accounting
+/hugetlb/hugemmap/hugemmap33
Could this entry be placed in testcases/kernel/mem/hugetlb/hugemmap/.gitignore instead? New test binaries are required to be ignored in their own test directory rather than in the parent mem ignore file.
Quoted 5 lines
+ *
MAP_PRIVATEpages andMAP_SHAREDreservations.
+ *
+ * Commita1e78772d72bintroducedMAP_PRIVATEreservations atmmap()time,
+ * so quota is checked upfront andmmap()fails with ENOMEM when over quota.
+ * Before this, quota was only checked at fault time resulting in SIGBUS.
Could these exported documentation identifiers use reStructuredText formatting? MAP_PRIVATE, MAP_SHARED, ENOMEM, and SIGBUS should be enclosed in double backticks, and mmap should be written as :manpage:mmap(2).
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 78 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +78
-0+static void verify_quota_stat (long tot,long free,long avail) +{ +struct statfs s; + +SAFE_STATFS (MNTPOINT , &s); + +if ((long )s.f_blocks != tot || (long )s.f_bfree != free || (long )s.f_bavail != avail) { +tst_res (TFAIL ,"Bad quota counters: total=%li free=%li avail=%li, expected %li %li %li" , + (long )s.f_blocks, (long )s.f_bfree, (long )s.f_bavail, + tot, free, avail); +return ; + } +tst_res (TPASS ,"Quota counters are correct: total=%li free=%li avail=%li" , + tot, free, avail); +} + +static void do_map (unsigned long size,int mmap_flags,int action_flags, +int expected) +{ +int fd; +char *a =MAP_FAILED , *b, *c =MAP_FAILED ; +char path[PATH_MAX ]; + +snprintf (path,sizeof (path),"%s/test_file_%d" ,MNTPOINT ,getpid ()); + fd =SAFE_OPEN (path,O_CREAT |O_RDWR ,0600 ); +SAFE_UNLINK (path); + +TESTPTR (mmap (NULL , size,PROT_READ |PROT_WRITE , mmap_flags, fd,0 )); + a =TST_RET_PTR ; +if (a ==MAP_FAILED ) { +if (expected ==QUOTA_FAIL &&TST_ERR ==ENOMEM ) { +tst_res (TPASS |TERRNO ,"mmap failed as expected due to quota" ); +SAFE_CLOSE (fd); +return ; + } +tst_res (TFAIL |TERRNO ,"mmap failed unexpectedly" ); +SAFE_CLOSE (fd); +return ; + } + +if (expected ==QUOTA_FAIL ) { +tst_res (TFAIL ,"mmap succeeded but quota exhaustion was expected" ); + goto cleanup_a; + } + +if (action_flags &ACTION_TOUCH ) { +for (b = a; b < a + size; b += hpage_size) + *b =1 ; + } + +if (action_flags &ACTION_COW ) { +TESTPTR (mmap (NULL , size,PROT_READ |PROT_WRITE ,MAP_PRIVATE , fd,0 )); + c =TST_RET_PTR ; +if (c ==MAP_FAILED ) { +if (expected ==QUOTA_COW_FAIL &&TST_ERR ==ENOMEM ) { +tst_res (TPASS |TERRNO ,"COW mmap failed as expected due to quota" ); + goto cleanup_a; + } +tst_res (TFAIL |TERRNO ,"COW mmap failed unexpectedly" ); + goto cleanup_a; + } + +if (expected ==QUOTA_COW_FAIL ) { +tst_res (TFAIL ,"COW mmap succeeded but quota exhaustion was expected" ); + goto cleanup_c; + } + +if (*c !=1 ) { +tst_res (TFAIL ,"Data mismatch when setting up COW" ); + goto cleanup_c; + } + *c =0 ; +SAFE_MUNMAP (c, size); + } + +if (expected ==QUOTA_OK ) +tst_res (TPASS ,"Quota test passed as expected" ); +
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 134
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +10
-0+SAFE_MUNMAP (a, size); +SAFE_CLOSE (fd); +return ; + +cleanup_c: +SAFE_MUNMAP (c, size); +cleanup_a: +SAFE_MUNMAP (a, size); +SAFE_CLOSE (fd); +}
I think that it would be much more readable if this was split into several functions. It would make sense to split this into three different functions one function verify_quota_ok() verify_quota_fail() and verify_quota_cow_fail().
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp