public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] madvise06: wait a bit after madvise() call
Date: Fri, 22 Jul 2016 11:46:03 +0800	[thread overview]
Message-ID: <20160722034603.GA15996@gmail.com> (raw)
In-Reply-To: <5790DADF.8000506@redhat.com>

On Thu, Jul 21, 2016 at 04:23:27PM +0200, Jan Stancek wrote:
> 
> I'm starting to run out of ideas how we can test this somewhat reliably.
> 
> Attached is approach v3, which sets up memory cgroup:
> - memory.limit_in_bytes is 128M
> - we allocate 512M
> - as consequence ~384M should be swapped while system should still have
>   plenty of free memory, which should be available for cache

Drop caches before testing is really good, we think the same!

And setting cgroup shorten the test time, if there could guarantee
cgroup OOM is off and swappiness is a little larger, that would
be more reliable I think.

One question is that you wrote function count_swapped_pages() but
didn't using it, seems forgot to put somewhere?

Anyway, V3 is strong enough expecially it combines the two method
together.


> #include <errno.h>
> #include <stdio.h>
> #include <sys/mount.h>
> #include <sys/sysinfo.h>
> #include "tst_test.h"
> 
> #define CHUNK_SZ (512*1024*1024L)
> #define CHUNK_PAGES (CHUNK_SZ / pg_sz)
> #define PASS_THRESHOLD (CHUNK_SZ / 4)
> 
> static const char drop_caches_fname[] = "/proc/sys/vm/drop_caches";
> static int pg_sz;
> 
> static void drop_caches(void)
> {
> 	int ret;
> 	FILE *f;
> 
> 	f = fopen(drop_caches_fname, "w");
> 	if (f) {
> 		ret = fprintf(f, "1");
> 		fclose(f);
> 		if (ret < 1)
> 			tst_brk(TBROK, "Failed to drop caches");
> 	} else {
> 		tst_brk(TBROK, "Failed to open drop_caches");
> 	}
> }
> 
> static void setup(void)
> {
> 	struct sysinfo sys_buf_start;
> 
> 	pg_sz = getpagesize();
> 
> 	if (access(drop_caches_fname, R_OK | W_OK))
> 		tst_brk(TCONF, "needed: %s\n", drop_caches_fname);
> 	tst_res(TINFO, "dropping caches");
> 	drop_caches();

save this function by oneline:

 /* drop caches*/
 SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "1");

> 
> 	sysinfo(&sys_buf_start);
> 	if (sys_buf_start.freeram < 2 * CHUNK_SZ)
> 		tst_brk(TCONF, "System RAM is too small, skip test");
> 	if (sys_buf_start.freeswap < 2 * CHUNK_SZ)
> 		tst_brk(TCONF, "System swap is too small");
> 
> 	SAFE_MKDIR("memory", 0700);
> 	SAFE_MOUNT("memory", "memory", "cgroup", 0, "memory");
> 	if (access("memory/memory.limit_in_bytes", R_OK | W_OK))
> 		tst_brk(TCONF, "cgroup memory.limit_in_bytes needed");
> 
> 	SAFE_MKDIR("memory/madvise06", 0700);
> 	SAFE_FILE_PRINTF("memory/madvise06/memory.limit_in_bytes", "%ld\n",
> 		PASS_THRESHOLD);

Turn off oom, enlarge swappiness

 SAFE_FILE_PRINTF("memory/madvise06/memory.oom_control", "0");
 SAFE_FILE_PRINTF("memory/madvise06/memory.swappiness", "60");

> 	SAFE_FILE_PRINTF("memory/madvise06/tasks", "%d\n", getpid());
> }
> 
> static void cleanup(void)
> {
> 	FILE *f = fopen("memory/tasks", "w");
> 
> 	if (f) {
> 		fprintf(f, "%d\n", getpid());
> 		fclose(f);
> 	}
> 	rmdir("memory/madvise06");
> 	umount("memory");
> }
> 
> static long count_swapped_pages(void *ptr, long pg_count)

A compile Warnning:

madvise06.c:94:13: warning: ‘count_swapped_pages’ defined but not used
[-Wunused-function]
static long count_swapped_pages(void *ptr, long pg_count)


Regards,
Li Wang

  reply	other threads:[~2016-07-22  3:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-18 13:37 [LTP] [PATCH] madvise06: wait a bit after madvise() call Jan Stancek
2016-07-18 14:03 ` Cyril Hrubis
2016-07-18 14:22   ` Jan Stancek
2016-07-18 14:49     ` Cyril Hrubis
2016-07-19  5:58 ` Li Wang
2016-07-19  6:56   ` Jan Stancek
2016-07-19  8:57     ` Li Wang
2016-07-20 14:37       ` Jan Stancek
2016-07-21  5:33         ` Li Wang
2016-07-21 10:31         ` Chunyu Hu
2016-07-21 11:02           ` Li Wang
2016-07-21 14:23             ` Jan Stancek
2016-07-22  3:46               ` Li Wang [this message]
2016-07-22  6:59                 ` Jan Stancek
2016-07-22 10:49               ` Chunyu Hu
2016-07-22 10:54                 ` Chunyu Hu
2016-07-22 11:02                   ` Jan Stancek

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=20160722034603.GA15996@gmail.com \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /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