From: Sumitra Sharma <sumitraartsy@gmail.com>
To: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
Ira Weiny <ira.weiny@intel.com>, Deepak R Varma <drv@mailo.com>
Subject: Re: [PATCH] lib/test_bpf: Replace kmap() with kmap_local_page()
Date: Tue, 13 Jun 2023 00:30:20 -0700 [thread overview]
Message-ID: <20230613073020.GA359792@sumitra.com> (raw)
In-Reply-To: <3744835.kQq0lBPeGt@suse>
On Mon, Jun 12, 2023 at 01:49:56PM +0200, Fabio M. De Francesco wrote:
> On lunedì 12 giugno 2023 12:33:41 CEST Sumitra Sharma wrote:
> > kmap() has been deprecated in favor of the kmap_local_page()
> > due to high cost, restricted mapping space, the overhead of
> > a global lock for synchronization, and making the process
> > sleep in the absence of free slots.
> >
> > kmap_local_page() is faster than kmap() and offers thread-local
> > and CPU-local mappings, take pagefaults in a local kmap region
> > and preserves preemption by saving the mappings of outgoing
> > tasks and restoring those of the incoming one during a context
> > switch.
> >
> > The mapping is kept thread local in the function
> > “generate_test_data” in test_bpf.c
> >
> > Therefore, replace kmap() with kmap_local_page() and use
> > memcpy_to_page() to avoid open coding kmap_local_page()
> > + memcpy() + kunmap_local().
> >
> > Remove the unused variable “ptr”.
>
> Sumitra,
>
> Please Cc your mentors while in the internship.
> It's not mandatory but it would expedite comments and reviews :-)
>
Hi Fabio,
I will take care of it.
> >
> > Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
> > ---
> > lib/test_bpf.c | 10 +---------
> > 1 file changed, 1 insertion(+), 9 deletions(-)
> >
> > diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> > index ade9ac672adb..3bb94727d83b 100644
> > --- a/lib/test_bpf.c
> > +++ b/lib/test_bpf.c
> > @@ -14381,25 +14381,17 @@ static void *generate_test_data(struct bpf_test
> > *test, int sub) * single fragment to the skb, filled with
> > * test->frag_data.
> > */
> > - void *ptr;
> > -
> > page = alloc_page(GFP_KERNEL);
> >
> > if (!page)
> > goto err_kfree_skb;
> >
> > - ptr = kmap(page);
> > - if (!ptr)
> > - goto err_free_page;
> > - memcpy(ptr, test->frag_data, MAX_DATA);
> > - kunmap(page);
> > + memcpy_to_page(page, 0, test->frag_data, MAX_DATA);
>
> Why are you temporary mapping a page allocated with the GFP_KERNEL flag?
> It cannot come from ZONE_HIGHMEM.
>
Fabio, I somewhere _wrongly_ read that "GFP_KERNEL may allocate pages from
highmem". However, with further readings and checking the GFP_KERNEL
definition in gfp_types.h
#define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS)
I have got that with the GFP_KERNEL flag, pages can never come
from ZONE_HIGHMEM.
Apologise.
Thanks & regards
Sumitra
> Fabio
>
> > skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
> > }
> >
> > return skb;
> >
> > -err_free_page:
> > - __free_page(page);
> > err_kfree_skb:
> > kfree_skb(skb);
> > return NULL;
> > --
> > 2.25.1
>
>
>
prev parent reply other threads:[~2023-06-13 7:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-12 10:33 [PATCH] lib/test_bpf: Replace kmap() with kmap_local_page() Sumitra Sharma
2023-06-12 11:49 ` Fabio M. De Francesco
2023-06-13 7:30 ` Sumitra Sharma [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=20230613073020.GA359792@sumitra.com \
--to=sumitraartsy@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=drv@mailo.com \
--cc=fmdefrancesco@gmail.com \
--cc=haoluo@google.com \
--cc=ira.weiny@intel.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@fb.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.