All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martynas Pumputis <m@lambda.lt>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, mhocko@suse.com, m@lambda.lt
Subject: [PATCH] bpf: Try harder when allocating memory for maps
Date: Fri,  8 Mar 2019 09:08:57 +0100	[thread overview]
Message-ID: <20190308080857.12005-1-m@lambda.lt> (raw)

It has been observed that sometimes memory allocation for BPF maps
fails when there is no obvious memory pressure in a system.

E.g. the map (BPF_MAP_TYPE_LRU_HASH, key=38, value=56, max_elems=524288)
could not be created due to due to vmalloc unable to allocate 75497472B,
when the system's memory consumption (in MB) was the following:

    Total: 3942 Used: 837 (21.24%) Free: 138 Buffers: 239 Cached: 2727

Considering dcda9b0471 ("mm, tree wide: replace __GFP_REPEAT by
__GFP_RETRY_MAYFAIL with more useful semantic") we can replace
__GFP_NORETRY with __GFP_RETRY_MAYFAIL, as it won't invoke OOM killer
and will try harder to fulfil allocation requests.

The change has been tested with the workloads mentioned above and by
observing oom_kill value from /proc/vmstat.

Signed-off-by: Martynas Pumputis <m@lambda.lt>
---
 kernel/bpf/syscall.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 62f6bced3a3c..eb5cefe44af3 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -136,11 +136,11 @@ static struct bpf_map *find_and_alloc_map(union bpf_attr *attr)
 
 void *bpf_map_area_alloc(size_t size, int numa_node)
 {
-	/* We definitely need __GFP_NORETRY, so OOM killer doesn't
-	 * trigger under memory pressure as we really just want to
-	 * fail instead.
+	/* We definitely need __GFP_NORETRY or __GFP_RETRY_MAYFAIL, so
+	 * OOM killer doesn't trigger under memory pressure as we really
+	 * just want to fail instead.
 	 */
-	const gfp_t flags = __GFP_NOWARN | __GFP_NORETRY | __GFP_ZERO;
+	const gfp_t flags = __GFP_NOWARN | __GFP_RETRY_MAYFAIL | __GFP_ZERO;
 	void *area;
 
 	if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) {
-- 
2.21.0


             reply	other threads:[~2019-03-08  8:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08  8:08 Martynas Pumputis [this message]
2019-03-08  8:44 ` [PATCH] bpf: Try harder when allocating memory for maps Michal Hocko
2019-03-08 10:33   ` Daniel Borkmann
2019-03-08 10:55     ` Michal Hocko
2019-03-08 11:30       ` Daniel Borkmann
2019-03-08 12:00         ` Michal Hocko
2019-03-08 11:14   ` Martynas Pumputis
2019-03-08 11:20     ` Michal Hocko
2019-03-08 20:02       ` Martynas Pumputis
2019-03-10  7:13         ` Michal Hocko
2019-03-11 19:33           ` Martynas Pumputis

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=20190308080857.12005-1-m@lambda.lt \
    --to=m@lambda.lt \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=mhocko@suse.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.