Skip to content

Commit

Permalink
swapping01: Add sleeps in the loop that dirties the memory
Browse files Browse the repository at this point in the history
In our test env this case failed sporadically, we suspect swapout speed not fast enough
in some situation.

Fixes: https://bugzilla.suse.com/show_bug.cgi?id=1217850#c34
Link: https://lore.kernel.org/ltp/20240422124050.3598-1-wegao@suse.com/
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Wei Gao <wegao@suse.com>
  • Loading branch information
coolgw authored and pevik committed May 9, 2024
1 parent 0d9dc99 commit 7177279
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion testcases/kernel/mem/swapping/swapping01.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);

if ((allow_raise == 1) && (raise(SIGSTOP) == -1)) {
tst_res(TINFO, "memory allocated: %ld MB", mem_count / 1024);
Expand Down

0 comments on commit 7177279

Please sign in to comment.