[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQKXC_xA3UrqvckS9SSs=jtyHjfb50znOON98XqinkZ2VA@mail.gmail.com>
Date: Tue, 1 Oct 2024 11:23:46 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Namhyung Kim <namhyung@...nel.org>
Cc: Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>, Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>, John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>, LKML <linux-kernel@...r.kernel.org>,
bpf <bpf@...r.kernel.org>, Andrew Morton <akpm@...ux-foundation.org>,
Christoph Lameter <cl@...ux.com>, Pekka Enberg <penberg@...nel.org>, David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>, Vlastimil Babka <vbabka@...e.cz>,
Roman Gushchin <roman.gushchin@...ux.dev>, Hyeonggon Yoo <42.hyeyoo@...il.com>,
linux-mm <linux-mm@...ck.org>, Arnaldo Carvalho de Melo <acme@...nel.org>
Subject: Re: [RFC/PATCH bpf-next 1/3] bpf: Add kmem_cache iterator
On Sun, Sep 29, 2024 at 7:08 PM Namhyung Kim <namhyung@...nel.org> wrote:
>
> On Sun, Sep 29, 2024 at 10:04:00AM -0700, Alexei Starovoitov wrote:
> > On Fri, Sep 27, 2024 at 11:41 AM Namhyung Kim <namhyung@...nel.org> wrote:
> > > +static void *kmem_cache_iter_seq_start(struct seq_file *seq, loff_t *pos)
> > > +{
> > > + loff_t cnt = 0;
> > > + struct kmem_cache *s = NULL;
> > > +
> > > + mutex_lock(&slab_mutex);
> >
> > It would be better to find a way to iterate slabs without holding
> > the mutex for the duration of the loop.
> > Maybe use refcnt to hold the kmem_cache while bpf prog is looking at it?
>
> Do you mean that you want to not hold slab_mutex while BPF program is
> running?
yes.
> Maybe we can allocates an arary of pointers to the slab cahe
> (with refcounts) at the beginning and iterate them instead. And call
> kmem_cache_destroy() for each entry at the end. Is it ok to you?
That doesn't sound efficient.
Just grab a refcnt on kmem_cache before running the prog ?
Drop refcnt, and grab a mutex again to do a next step.
kmem_cache_iter_seq_next() will be running with mutex held, of course.
Powered by blists - more mailing lists