From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Srivats P <pstavirs@gmail.com>, xdp-newbies@vger.kernel.org
Subject: Re: AF_XDP - why setrlimit() ?
Date: Wed, 31 Mar 2021 14:51:30 +0200 [thread overview]
Message-ID: <87r1jvpju5.fsf@toke.dk> (raw)
In-Reply-To: <CANzUK5_NfMLh9+se3hdJ176Ow_At6bwPqUSUD8XOSO0yc4vYig@mail.gmail.com>
Srivats P <pstavirs@gmail.com> writes:
> Hi,
>
> The sample xdpsock_user.c program does a setrlimit(RLIMIT_MEMLOCK) but
> subsequently doesn't do a mlock or pass MAP_LOCKED flag to mmap().
> Same with xdp-tutorial which has the following comment but I don't see
> any locking happening anywhere in the code.
>
> /* Allow unlimited locking of memory, so all memory needed for packet
> * buffers can be locked.
> */
>
> What is the purpose behind this setrlimit? Does the libbpf/xdp library
> do a mlock internally?
>
> I came to know that BPF maps need the setrlimit and I assume the xsk
> APIs create a XSK map internally - so is that the only reason?
Yes, the setrlimit() is there because all BPF objects in the kernel
(including maps and programs) were accounted against that limit, and it
was a global limit, making it basically impossible to predict what a
good value was. Thankfully, this has since been fixed and maps are now
accounted using memcgs, as of commit: 97306be45fbe ("Merge branch
'switch to memcg-based memory accounting'") which was included in the
5.11 kernel release. So if your kernel is new enough you don't need the
setrlimit() anymore; but I guess no one has bothered to update the
samples yet :)
-Toke
prev parent reply other threads:[~2021-03-31 12:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-31 12:34 AF_XDP - why setrlimit() ? Srivats P
2021-03-31 12:51 ` Toke Høiland-Jørgensen [this message]
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=87r1jvpju5.fsf@toke.dk \
--to=toke@redhat.com \
--cc=pstavirs@gmail.com \
--cc=xdp-newbies@vger.kernel.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).