All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zdenek Kabelac <zkabelac@sourceware.org>
To: lvm-devel@redhat.com
Subject: stable-2.02 - memlock: allocate at most halve of rlimit stack
Date: Tue, 20 Oct 2020 21:25:11 +0000 (GMT)	[thread overview]
Message-ID: <20201020212511.1EC3B3950C27@sourceware.org> (raw)

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9690193ce08854c56663bcbbe7da4c720c78be07
Commit:        9690193ce08854c56663bcbbe7da4c720c78be07
Parent:        511cd6adb7756301ca0a2c2b153696a71a3f4423
Author:        Zdenek Kabelac <zkabelac@redhat.com>
AuthorDate:    Tue Oct 20 22:26:44 2020 +0200
Committer:     Zdenek Kabelac <zkabelac@redhat.com>
CommitterDate: Tue Oct 20 22:49:55 2020 +0200

memlock: allocate at most halve of rlimit stack

Touch of stack allocation validated given size with rlimit
and if the reserved_stack was above rlimit, its been completely
ignored - now we will always touch stack upto rlimit/2 size.
---
 lib/mm/memlock.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
index 7eee399b4..b1e5eb91b 100644
--- a/lib/mm/memlock.c
+++ b/lib/mm/memlock.c
@@ -167,10 +167,13 @@ static void _allocate_memory(void)
 	char *areas[max_areas];
 
 	/* Check if we could preallocate requested stack */
-	if ((getrlimit (RLIMIT_STACK, &limit) == 0) &&
-	    ((_size_stack * 2) < limit.rlim_cur) &&
-	    ((stack_mem = alloca(_size_stack))))
-		_touch_memory(stack_mem, _size_stack);
+	if (getrlimit(RLIMIT_STACK, &limit) == 0) {
+		limit.rlim_cur /= 2;
+		if (_size_stack > limit.rlim_cur)
+			_size_stack = limit.rlim_cur;
+		if ((stack_mem = alloca(_size_stack)))
+			_touch_memory(stack_mem, _size_stack);
+	}
 	/* FIXME else warn user setting got ignored */
 
         /*



                 reply	other threads:[~2020-10-20 21:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201020212511.1EC3B3950C27@sourceware.org \
    --to=zkabelac@sourceware.org \
    --cc=lvm-devel@redhat.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.