All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] swapping01.c: Add sleeps in the loop that dirties the memory
Date: Thu, 9 May 2024 14:57:14 +0200	[thread overview]
Message-ID: <20240509125714.GA291089@pevik> (raw)
In-Reply-To: <20240422124050.3598-1-wegao@suse.com>

Hi Wei,

> +++ b/testcases/kernel/mem/swapping/swapping01.c
> @@ -47,6 +47,7 @@
>  #define COE_DELTA       1
>  /* will try to alloc 1.3 * phy_mem */
>  #define COE_SLIGHT_OVER 0.3
> +#define MEM_SIZE 1024 * 1024

>  static void init_meminfo(void);
>  static void do_alloc(int allow_raise);
> @@ -101,6 +102,13 @@ static void init_meminfo(void)
>  				swap_free_init, mem_over_max);
>  }

> +static void memset_blocks(char *ptr, int mem_count, int sleep_time_ms) {
> +	for (int i = 0; i < mem_count / 1024; i++) {
> +		memset(ptr + (i * MEM_SIZE), 1, MEM_SIZE);
> +		usleep(sleep_time_ms * 1000);
> +	}
> +}
> +
>  static void do_alloc(int allow_raise)
>  {
>  	long mem_count;
> @@ -115,7 +123,7 @@ static void do_alloc(int allow_raise)
>  	if (allow_raise == 1)
>  		tst_res(TINFO, "try to allocate: %ld MB", mem_count / 1024);
>  	s = SAFE_MALLOC(mem_count * 1024);
> -	memset(s, 1, mem_count * 1024);
> +	memset_blocks(s, mem_count, 1);
nit: Actually when we have custom function used on single place, we might want
to avoid the last parameter 1, right? We could usleep(1000) directly.

We use MEM_SIZE definition outside of the function anyway.

I can change it before merge:

diff --git testcases/kernel/mem/swapping/swapping01.c testcases/kernel/mem/swapping/swapping01.c
index 79dd2b4d5..09820e3d9 100644
--- testcases/kernel/mem/swapping/swapping01.c
+++ testcases/kernel/mem/swapping/swapping01.c
@@ -102,10 +102,10 @@ static void init_meminfo(void)
 				swap_free_init, mem_over_max);
 }
 
-static void memset_blocks(char *ptr, int mem_count, int sleep_time_ms) {
+static void memset_blocks(char *ptr, int mem_count) {
 	for (int i = 0; i < mem_count / 1024; i++) {
 		memset(ptr + (i * MEM_SIZE), 1, MEM_SIZE);
-		usleep(sleep_time_ms * 1000);
+		usleep(1000);
 	}
 }
 
@@ -123,7 +123,7 @@ static void do_alloc(int allow_raise)
 	if (allow_raise == 1)
 		tst_res(TINFO, "try to allocate: %ld MB", mem_count / 1024);
 	s = SAFE_MALLOC(mem_count * 1024);
-	memset_blocks(s, mem_count, 1);
+	memset_blocks(s, mem_count);
 
 	if ((allow_raise == 1) && (raise(SIGSTOP) == -1)) {
 		tst_res(TINFO, "memory allocated: %ld MB", mem_count / 1024);

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

  parent reply	other threads:[~2024-05-09 12:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18  7:14 [LTP] [PATCH v1] swapping01.c: Add sleeps in the loop that dirties the memory Wei Gao via ltp
2024-04-18 16:34 ` Cyril Hrubis
2024-04-19  8:11   ` Vlastimil Babka via ltp
2024-04-19  8:36     ` Cyril Hrubis
2024-04-22 12:39       ` Wei Gao via ltp
2024-04-22 12:40 ` [LTP] [PATCH v2] " Wei Gao via ltp
2024-05-09 12:51   ` Petr Vorel
2024-05-09 12:57   ` Petr Vorel [this message]
2024-05-09 13:04   ` Cyril Hrubis
2024-05-09 13:51     ` Petr Vorel

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=20240509125714.GA291089@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=wegao@suse.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.