Linux Test Project
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Martin Doucha <mdoucha@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] mmap_24-1: Change vm.max_map_count if needed
Date: Fri, 9 May 2025 11:58:53 +0200	[thread overview]
Message-ID: <aB3R3YFumeKXYVKZ@yuki.lan> (raw)
In-Reply-To: <20250507154543.22309-1-mdoucha@suse.cz>

Hi!
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-1.c
> index 6cc8349e1..91677d289 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-1.c
> @@ -31,12 +31,40 @@
>  #include <stdint.h>
>  #include "posixtest.h"
>  
> +#define MAX_MAP_COUNT_PATH "/proc/sys/vm/max_map_count"
> +#define MAP_COUNT_LIMIT 65530
> +
> +void proc_write_val(const char *path, size_t val)
> +{
> +	FILE *procfile;
> +
> +	procfile = fopen(path, "r+");
> +
> +	if (!procfile)
> +		return;

We should print a message that we failed to open the file for the update
here, otherwise it's not clear if we managed to update the limit or not.

> +	fprintf(procfile, "%zu", val);
> +	fclose(procfile);
> +}
> +
>  int main(void)
>  {
>  	char tmpfname[256];
>  	void *pa;
> -	size_t len;
> +	size_t len, max_map_count = 0;
>  	int fd;
> +	FILE *procfile;
> +
> +	/* Change vm.max_map_count to avoid OOM */
> +	procfile = fopen(MAX_MAP_COUNT_PATH, "r+");
> +
> +	if (procfile) {
> +		fscanf(procfile, "%zu", &max_map_count);
> +		fclose(procfile);
> +	}
> +
> +	if (max_map_count > MAP_COUNT_LIMIT)
> +		proc_write_val(MAX_MAP_COUNT_PATH, MAP_COUNT_LIMIT);
>  
>  	/* Size of the shared memory object */
>  	size_t shm_size = 1024;
> @@ -78,5 +106,10 @@ int main(void)
>  
>  	close(fd);
>  	printf("Test FAILED: Did not get ENOMEM as expected\n");
> +
> +	/* Restore original vm.max_map_count */
> +	if (max_map_count > MAP_COUNT_LIMIT)
> +		proc_write_val(MAX_MAP_COUNT_PATH, max_map_count);


Otherwise it looks good:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

      parent reply	other threads:[~2025-05-09  9:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 15:45 [LTP] [PATCH] mmap_24-1: Change vm.max_map_count if needed Martin Doucha
2025-05-07 17:53 ` Petr Vorel
2025-05-09  4:03   ` Li Wang via ltp
2025-05-09 11:34     ` Martin Doucha
2025-05-09 12:00       ` Li Wang via ltp
2025-05-09 10:15   ` Martin Doucha
2025-05-09 10:52     ` Petr Vorel
2025-05-09  9:58 ` Cyril Hrubis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aB3R3YFumeKXYVKZ@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=mdoucha@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox