Re: [Nbd] [PATCH] nbd-client: adjust the oom-killer score in swap mode
- To: "Dmitry V. Levin" <ldv@...1147...>
- Cc: nbd-general@lists.sourceforge.net
- Subject: Re: [Nbd] [PATCH] nbd-client: adjust the oom-killer score in swap mode
- From: Wouter Verhelst <w@...112...>
- Date: Sun, 24 Jun 2012 01:29:31 +0200
- Message-id: <20120623232931.GJ7471@...3...>
- In-reply-to: <20120621205921.GA25989@...1147...>
- References: <20120621205921.GA25989@...1147...>
On Fri, Jun 22, 2012 at 12:59:22AM +0400, Dmitry V. Levin wrote:
> In swap mode, it is highly desirable to take all available measures that
> could help nbd-client survival in low memory conditions. One of such
> measures is to disable oom killing of nbd-client by adjusting the
> oom-killer score.
Make sense. But since nbd-client is linux-only, the #ifdef __linux__"
bits are redundant...
> Signed-off-by: Dmitry V. Levin <ldv@...1147...>
> ---
> man/nbd-client.8.in.sgml | 5 +++--
> nbd-client.c | 26 ++++++++++++++++++++++++++
> 2 files changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/man/nbd-client.8.in.sgml b/man/nbd-client.8.in.sgml
> index 4f24a61..8c862a1 100644
> --- a/man/nbd-client.8.in.sgml
> +++ b/man/nbd-client.8.in.sgml
> @@ -211,8 +211,9 @@ manpage.1: manpage.sgml
> <listitem>
> <para>Specifies that this NBD device will be used as
> swapspace. This option attempts to prevent deadlocks by
> - performing mlockall() at an appropriate time. It does not
> - however guarantee that such deadlocks can be avoided.</para>
> + performing mlockall() and adjusting the oom-killer score
> + at an appropriate time. It does not however guarantee
> + that such deadlocks can be avoided.</para>
> </listitem>
> </varlistentry>
> <varlistentry>
> diff --git a/nbd-client.c b/nbd-client.c
> index 2321e7b..5526db0 100644
> --- a/nbd-client.c
> +++ b/nbd-client.c
> @@ -372,6 +372,23 @@ void finish_sock(int sock, int nbd, int swap) {
> mlockall(MCL_CURRENT | MCL_FUTURE);
> }
>
> +#ifdef __linux__
> +static int
> +oom_adjust(const char *file, const char *value)
> +{
> + int fd, rc;
> + size_t len;
> +
> + fd = open(file, O_WRONLY);
> + if (fd < 0)
> + return -1;
> + len = strlen(value);
> + rc = write(fd, value, len) != (ssize_t) len;
> + close(fd);
> + return rc ? -1 : 0;
> +}
> +#endif
> +
> void usage(char* errmsg, ...) {
> if(errmsg) {
> char tmp[256];
> @@ -561,6 +578,15 @@ int main(int argc, char *argv[]) {
> setsizes(nbd, size64, blocksize, flags);
> set_timeout(nbd, timeout);
> finish_sock(sock, nbd, swap);
> +#ifdef __linux__
> + if (swap) {
> + /* try linux >= 2.6.36 interface first */
> + if (oom_adjust("/proc/self/oom_score_adj", "-1000")) {
> + /* fall back to linux <= 2.6.35 interface */
> + oom_adjust("/proc/self/oom_adj", "-17");
> + }
> + }
> +#endif
>
> /* Go daemon */
>
> --
> ldv
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Nbd-general mailing list
> Nbd-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nbd-general
>
--
The volume of a pizza of thickness a and radius z can be described by
the following formula:
pi zz a
Reply to: