public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: liuxp11@chinatelecom.cn <liuxp11@chinatelecom.cn>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] syscalls/ioctl: ioctl_sg01.c: ioctl_sg01 invoked oom-killer
Date: Wed, 27 Jan 2021 19:50:02 +0800	[thread overview]
Message-ID: <2021012719500196319832@chinatelecom.cn> (raw)
In-Reply-To: 3b9e2152-95ed-ee2a-6b30-180255330188@suse.cz

available memory can avoid to oom-killer.

#man free
available
              Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by  the  cache  or
              free  fields,  this  field  takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items
              being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)


[root@bogon ltp]# cat my.diff
commit eb28176a3351c6854620aaa8248bf17edea210ae
Author: Xinpeng Liu <liuxp11@chinatelecom.cn>
Date:   Mon Jan 25 20:58:20 2021 +0800

    syscalls/ioctl: ioctl_sg01.c: ioctl_sg01 invoked oom-killer

    Kernel version is 5.4.81+,the available RAM is less than free,as follow:
    [root@liuxp mywork]# head /proc/meminfo
    MemTotal:       198101744 kB
    MemFree:        189303148 kB
    MemAvailable:   188566732 kB

    So use available RAM to avoid OOM killer.

diff --git a/include/tst_memutils.h b/include/tst_memutils.h
index 91dad07..3fd70b2 100644
--- a/include/tst_memutils.h
+++ b/include/tst_memutils.h
@@ -6,6 +6,8 @@
 #ifndef TST_MEMUTILS_H__
 #define TST_MEMUTILS_H__

+unsigned long tst_get_mem_available(void);
+
 /*
  * Fill up to maxsize physical memory with fillchar, then free it for reuse.
  * If maxsize is zero, fill as much memory as possible. This function is
diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index dd09db4..9408b37 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -13,11 +13,21 @@

 #define BLOCKSIZE (16 * 1024 * 1024)

+unsigned long tst_get_mem_available(void)
+{
+       unsigned long available_kb = 0;
+
+       FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %lu", &available_kb);
+
+       return available_kb;
+}
+
 void tst_pollute_memory(size_t maxsize, int fillchar)
 {
        size_t i, map_count = 0, safety = 0, blocksize = BLOCKSIZE;
        void **map_blocks;
        struct sysinfo info;
+       unsigned long available_ram;

        SAFE_SYSINFO(&info);
        safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), 128 * 1024 * 1024);
@@ -26,15 +36,22 @@ void tst_pollute_memory(size_t maxsize, int fillchar)
        if (info.freeswap > safety)
                safety = 0;

+       available_ram = 1024 * tst_get_mem_available();
+       available_ram /= info.mem_unit;
+
+       /*"MemAvailable" field maybe not exist, or freeram less than available_ram*/
+       if(available_ram == 0 || info.freeram < available_ram)
+               available_ram = info.freeram;
+
        /* Not enough free memory to avoid invoking OOM killer */
-       if (info.freeram <= safety)
+       if (available_ram <= safety)
                return;

        if (!maxsize)
                maxsize = SIZE_MAX;

-       if (info.freeram - safety < maxsize / info.mem_unit)
-               maxsize = (info.freeram - safety) * info.mem_unit;
+       if (available_ram - safety < maxsize / info.mem_unit)
+               maxsize = (available_ram - safety) * info.mem_unit;

        blocksize = MIN(maxsize, blocksize);
        map_count = maxsize / blocksize;



From: Martin Doucha
Date: 2021-01-27 19:46
To: liuxp11@chinatelecom.cn; Cyril Hrubis
CC: ltp
Subject: Re: [LTP] [PATCH 1/2] syscalls/ioctl: ioctl_sg01.c: ioctl_sg01 invoked oom-killer
On 27. 01. 21 12:41, liuxp11@chinatelecom.cn wrote:
>     safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), 128 * 1024 * 1024);
>     now safety margin is 128MB,not 64MB. Right?
 
Yes, right, sorry.
 
-- 
Martin Doucha   mdoucha@suse.cz
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210127/182cafa3/attachment.htm>

  reply	other threads:[~2021-01-27 11:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25 10:24 [LTP] [PATCH 1/2] syscalls/ioctl: ioctl_sg01.c: ioctl_sg01 invoked oom-killer Xinpeng Liu
2021-01-25 10:24 ` [LTP] [PATCH 2/2] syscalls/ioctl: ioctl_sg01.c:TBROK: Test killed! Xinpeng Liu
2021-01-27  4:41   ` Li Wang
2021-01-27  4:27 ` [LTP] [PATCH 1/2] syscalls/ioctl: ioctl_sg01.c: ioctl_sg01 invoked oom-killer Li Wang
2021-01-27  5:42   ` liuxp11
2021-01-27  6:54   ` liuxp11
2021-01-27  7:58     ` Li Wang
2021-01-27  8:05       ` Li Wang
2021-01-27  9:24         ` Cyril Hrubis
2021-01-27 10:03           ` Li Wang
2021-01-27  8:49       ` liuxp11
2021-01-27  9:50         ` Cyril Hrubis
2021-01-27  9:39 ` Cyril Hrubis
2021-01-27  9:53   ` Martin Doucha
2021-01-27 10:07     ` liuxp11
2021-01-27 10:04   ` liuxp11
2021-01-27 11:28     ` Martin Doucha
2021-01-27 11:41       ` liuxp11
2021-01-27 11:46         ` Martin Doucha
2021-01-27 11:50           ` liuxp11 [this message]
2021-03-04  7:52     ` Li Wang
2021-03-05  5:52       ` liuxp11
2021-03-05  9:02         ` Li Wang
2021-03-24  9:26           ` liuxp11
2021-04-11  5:01             ` Li Wang

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=2021012719500196319832@chinatelecom.cn \
    --to=liuxp11@chinatelecom.cn \
    --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