Re: [PATCH 3/3] 9p: Add mempools for RPCs

Dominique Martinet
2022-07-04T03:39:17Z

+Christian, sorry I just noticed you weren't in Ccs again --
the patches are currently there if you want a look:
https://evilpiepirate.org/git/bcachefs.git/log/?h=9p_mempool

I think it'll conflict a bit with your 8k non-read/write RPCs but I'll
take care of that when checking it this weekend.

Kent Overstreet wrote on Sun, Jul 03, 2022 at 11:05:57PM -0400:
> > We shouldn't have any user calling with more at this point (the
> > user-provided size comes from p9_client_prepare_req arguments and it's
> > either msize or header size constants); and it probably makes sense to
> > check and error out rather than cap it.
>
> If that's the case I think we should just switch the warning to a BUG_ON() - I
> just wasn't sure from reading the code if that was really guarded against.

yes, BUG_ON is good for me.

> > > - if (p9_fcall_init(c, &req->tc, alloc_msize))
> > > + if (p9_fcall_init(c, &req->tc, 0, alloc_msize))
> > > goto free_req;
> > > - if (p9_fcall_init(c, &req->rc, alloc_msize))
> > > + if (p9_fcall_init(c, &req->rc, 1, alloc_msize))
> >
> > given the two rc/tc buffers are of same size I don't see the point of
> > using two caches either, you could just double the min number of
> > elements to the same effect?
>
> You can't double allocate from the same mempool, that will deadlock if multiple
> threads need the last element at the same time - I should've left a comment for
> that.

hmm, looking at the code as long as min elements is big enough the
deadlock becomes increasingly difficult to hit -- but I guess there's no
guarantee we won't get 8 threads each getting their first item from the
pool and starving each other on the second... Fair enough, thank you for
the comment.

> @@ -270,10 +276,8 @@ p9_tag_alloc(struct p9_client *c, int8_t type, unsigned int max_size)
> if (!req)
> return ERR_PTR(-ENOMEM);
>
> - if (p9_fcall_init(c, &req->tc, alloc_msize))
> - goto free_req;
> - if (p9_fcall_init(c, &req->rc, alloc_msize))
> - goto free;
> + p9_fcall_init(c, &req->tc, 0, alloc_msize);
> + p9_fcall_init(c, &req->rc, 1, alloc_msize);

mempool allocation never fails, correct?

(don't think this needs a comment, just making sure here)

This all looks good to me, will queue it up in my -next branch after
running some tests next weekend and hopefully submit when 5.20 opens
with the code making smaller allocs more common.

--
Dominique