From: Caspar Z. <ca...@ca...> - 2012-04-02 08:45:39
|
On 04/02/2012 04:34 PM, Wanlong Gao wrote: > add a lib function to check the shm_size, make sure it's not > bigger than shmmax. > > Signed-off-by: Wanlong Gao <gao...@cn...> > --- > testcases/kernel/mem/include/mem.h | 6 ++++++ > testcases/kernel/mem/lib/mem.c | 13 +++++++++++++ > 2 files changed, 19 insertions(+) > > diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h > index 4c568cd..8f59483 100644 > --- a/testcases/kernel/mem/include/mem.h > +++ b/testcases/kernel/mem/include/mem.h > @@ -32,6 +32,10 @@ void testoom(int mempolicy, int lite, int numa); > > #define PATH_KSM "/sys/kernel/mm/ksm/" > > +/* HUGETLB */ > + > +#define PATH_SHMMAX "/proc/sys/kernel/shmmax" > + > /* > * memory pointer to identify per process, MB unit, and byte like > * memory[process No.][MB unit No.][byte No.]. > @@ -73,4 +77,6 @@ void read_file(char *filename, char *retbuf); > void cleanup(void); > void setup(void); > > +void check_shmmax(size_t *shm_size); Hmmm, in this function, shm_size might be changed, while the name "check_shmmax" looks more likely to be a read-only behavior. Would it better be something like "update_shm_size"? Anyway, others look good. Reviewed-by: Caspar Zhang <ca...@ca...> Thanks, Caspar > + > #endif > diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c > index 35932af..8fd8c09 100644 > --- a/testcases/kernel/mem/lib/mem.c > +++ b/testcases/kernel/mem/lib/mem.c > @@ -786,3 +786,16 @@ void read_file(char *filename, char *retbuf) > tst_brkm(TBROK|TERRNO, cleanup, "read %s", filename); > close(fd); > } > + > +void check_shmmax(size_t *shm_size) > +{ > + char buf[BUFSIZ]; > + size_t shmmax; > + > + read_file(PATH_SHMMAX, buf); > + shmmax = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX); > + if (*shm_size > shmmax) { > + tst_resm(TINFO, "Set shm_size to shmmax: %ld", shmmax); > + *shm_size = shmmax; > + } > +} |