lib: limit the size of tmpfs in LTP
PATCH v2 1/2 lib: limit the size of tmpfs in LTP
LTP mount and make use of the whole tmpfs of the test system, generally, it's fine. But if a test (e.g fallocate06) try to fill full in the filesystem, it takes too long to complete testing on a large memory system.
This patch adds a new function limit_tmpfs_mount_size with appending '-o size=xxM' to the mount options in prepare_device() which helps limit the tmpfs mount size.
---
Notes:
V1 --> V2
* state limit_tmpfs_mount_size as a static function
* make use of the loop device size directly since it already gets a proper size in tst_acquire_device_
* do NOT modify the tst_test->mnt_data
lib/tst_test.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
lib/tst_test.c +31 -1
@@ -882,8 +882,35 @@ static void prepare_and_mount_dev_fs(const char *mntpoint) } } +static char *limit_tmpfs_mount_size (const char *mnt_data, +char *buf,size_t buf_size,const char *fs_type) +{ +int fd; +uint64_t dev_size; + +if (strcmp (fs_type,"tmpfs" )) +return mnt_data; + + fd =SAFE_OPEN (tdev.dev,O_RDONLY ); +SAFE_IOCTL (fd,BLKGETSIZE64 , &dev_size); +SAFE_CLOSE (fd); + + dev_size = dev_size/1024 /1024 ; + +if (mnt_data) +snprintf (buf, buf_size,"%s,size=%luM" , mnt_data, dev_size); +else +snprintf (buf, buf_size,"size=%luM" , dev_size); + +tst_res (TINFO ,"Limiting tmpfs size to %luMB" , dev_size); + +return buf; +} +static void prepare_device (void ) { +char *mnt_data, buf[1024 ]; +if (tst_test->format_device) {SAFE_MKFS (tdev.dev, tdev.fs_type, tst_test->dev_fs_opts, tst_test->dev_extra_opts);
@@ -896,8 +923,11 @@ static void prepare_device(void) }if (tst_test->mount_device) { + mnt_data =limit_tmpfs_mount_size (tst_test->mnt_data, + buf,sizeof (buf), tdev.fs_type); +SAFE_MOUNT (tdev.dev, tst_test->mntpoint, tdev.fs_type, - tst_test->mnt_flags, tst_test->mnt_data); + tst_test->mnt_flags, mnt_data); mntpoint_mounted =1 ; } }
Signature · 1 line
2.31.1
PATCH v2 2/2 lib: mount tmpfs name as ltp-tmpfs
Given a specific name as "ltp-tmpfs" instead of the "/dev/loopX" string in order to make "tmpfs" filesystem more evident.
Achieve that in get_device_name() function.
---
Notes:
V1 --> V2
* create a function get_device_name()
lib/tst_test.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
lib/tst_test.c +10 -2
@@ -907,6 +907,14 @@ static char *limit_tmpfs_mount_size(const char *mnt_data,return buf; } +static const char *get_device_name (const char *fs_type) +{ +if (!strcmp (fs_type,"tmpfs" )) +return "ltp-tmpfs" ; +else +return tdev.dev; +} +static void prepare_device (void ) {char *mnt_data, buf[1024 ];
@@ -926,8 +934,8 @@ static void prepare_device(void) mnt_data =limit_tmpfs_mount_size (tst_test->mnt_data, buf,sizeof (buf), tdev.fs_type); -SAFE_MOUNT (tdev.dev, tst_test->mntpoint, tdev.fs_type, - tst_test->mnt_flags, mnt_data); +SAFE_MOUNT (get_device_name (tdev.fs_type), tst_test->mntpoint, + tdev.fs_type, tst_test->mnt_flags, mnt_data); mntpoint_mounted =1 ; } }
Signature · 1 line
2.31.1
PATCH v2 2/2 lib: mount tmpfs name as ltp-tmpfs
PATCH v2 1/2 lib: limit the size of tmpfs in LTP
In reply to Li WangHi!
Quoted 13 lines
lib/tst_test.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)lib/tst_test.c +2
-0@@ -882,8 +882,35 @@ static void prepare_and_mount_dev_fs(const char *mntpoint) } } +static char *limit_tmpfs_mount_size (const char *mnt_data, +char *buf,size_t buf_size,const char *fs_type)
lib/tst_test.c static void prepare_and_mount_dev_fs(const char *mntpoint) · line 896
Quoted 10 lines
lib/tst_test.c +10
-0+{ +int fd; +uint64_t dev_size; + +if (strcmp (fs_type,"tmpfs" )) +return mnt_data; + + fd =SAFE_OPEN (tdev.dev,O_RDONLY ); +SAFE_IOCTL (fd,BLKGETSIZE64 , &dev_size); +SAFE_CLOSE (fd);
We can as well add size to the struct tst_device and fill it in when device is created, that would be a slightly cleaner solution.
Other than this the rest looks good.
Quoted 35 lines
lib/tst_test.c +18
-1+ dev_size = dev_size/1024 /1024 ; + +if (mnt_data) +snprintf (buf, buf_size,"%s,size=%luM" , mnt_data, dev_size); +else +snprintf (buf, buf_size,"size=%luM" , dev_size); + +tst_res (TINFO ,"Limiting tmpfs size to %luMB" , dev_size); + +return buf; +} +static void prepare_device (void ) { +char *mnt_data, buf[1024 ]; +if (tst_test->format_device) {SAFE_MKFS (tdev.dev, tdev.fs_type, tst_test->dev_fs_opts, tst_test->dev_extra_opts);@@ -896,8 +923,11 @@ static void prepare_device(void) }if (tst_test->mount_device) { + mnt_data =limit_tmpfs_mount_size (tst_test->mnt_data, + buf,sizeof (buf), tdev.fs_type); +SAFE_MOUNT (tdev.dev, tst_test->mntpoint, tdev.fs_type, - tst_test->mnt_flags, tst_test->mnt_data); + tst_test->mnt_flags, mnt_data); mntpoint_mounted =1 ; } }Signature · 1 line
2.31.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 lib: limit the size of tmpfs in LTP
Quoted 17 lines · Cyril Hrubis
lib/tst_test.c static void prepare_and_mount_dev_fs(const char *mntpoint) · line 896
Quoted 13 lines
lib/tst_test.c +12
-0+static char *limit_tmpfs_mount_size (const char *mnt_data, +char *buf,size_t buf_size,const char *fs_type) +{ +int fd; +uint64_t dev_size; + +if (strcmp (fs_type,"tmpfs" )) +return mnt_data; + + fd =SAFE_OPEN (tdev.dev,O_RDONLY ); +SAFE_IOCTL (fd,BLKGETSIZE64 , &dev_size); +SAFE_CLOSE (fd);We can as well add size to the struct
tst_deviceand fill it in when device is created, that would be a slightly cleaner solution.
That should be fine. But I'm afraid we have to change the return type for many functions in tst_device.c, because currently most of them only return a path to the test device. And that will affect more tests.
Or, maybe just create a function to get the device size and pass it to tdev.size simply?
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210708/5ddf761e/attachment.htm>
PATCH v2 1/2 lib: limit the size of tmpfs in LTP
Quoted 22 lines · Li Wang
Quoted 17 lines · Cyril Hrubis
lib/tst_test.c static void prepare_and_mount_dev_fs(const char *mntpoint) · line 896
Quoted 13 lines
lib/tst_test.c +12
-0+static char *limit_tmpfs_mount_size (const char *mnt_data, +char *buf,size_t buf_size,const char *fs_type) +{ +int fd; +uint64_t dev_size; + +if (strcmp (fs_type,"tmpfs" )) +return mnt_data; + + fd =SAFE_OPEN (tdev.dev,O_RDONLY ); +SAFE_IOCTL (fd,BLKGETSIZE64 , &dev_size); +SAFE_CLOSE (fd);We can as well add size to the struct
tst_deviceand fill it in when device is created, that would be a slightly cleaner solution.
Quoted 7 lines
That should be fine. But I'm afraid we have to change the return type for many functions in
tst_device.c, because currently most of them only return a path to the test device. And that will affect more tests.Or, maybe just create a function to get the device size and pass it to tdev.size simply?
With adding new field 'size' in struct tst_device, I'm also planning to extract that from tst_acquire_device__ and export it as a global function:
uint64_t tst_get_device_size(const char *dev_path);
then reuse of it to get block device size in more places, like:
tdev.size = tst_get_device_size(tdev.dev); <-- in prepare_device
and
ltp_dev_size = tst_get_device_size(dev); <-- in tst_acquire_device__
That would keep most of the function API no change and save the tdev.size. Is this way OK, or any else?
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210708/f5cb6423/attachment.htm>