All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Roberto Bergantinos Corpas <rbergant@redhat.com>
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH] sunrpc : make RPC channel buffer dynamic for slow case
Date: Mon, 23 Nov 2020 10:36:27 -0500	[thread overview]
Message-ID: <20201123153627.GD32599@fieldses.org> (raw)
In-Reply-To: <CACWnjLxiCTAkxBca_NFrUSPCq_g4y0yNaHuNKX+Rwr=-xPhibw@mail.gmail.com>

On Sat, Nov 21, 2020 at 11:54:30AM +0100, Roberto Bergantinos Corpas wrote:
> Hi Bruce,
> 
>   Sorry for late response as well.
> 
>     Ok, here's a possible patch, let me know your thoughts

Looks good to me!  Could you just submit with changelog and
Signed-off-by?

--b.

> 
> diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
> index baef5ee43dbb..1347ecae9c84 100644
> --- a/net/sunrpc/cache.c
> +++ b/net/sunrpc/cache.c
> @@ -777,7 +777,6 @@ void cache_clean_deferred(void *owner)
>   */
> 
>  static DEFINE_SPINLOCK(queue_lock);
> -static DEFINE_MUTEX(queue_io_mutex);
> 
>  struct cache_queue {
>         struct list_head        list;
> @@ -905,44 +904,26 @@ static ssize_t cache_do_downcall(char *kaddr,
> const char __user *buf,
>         return ret;
>  }
> 
> -static ssize_t cache_slow_downcall(const char __user *buf,
> -                                  size_t count, struct cache_detail *cd)
> -{
> -       static char write_buf[8192]; /* protected by queue_io_mutex */
> -       ssize_t ret = -EINVAL;
> -
> -       if (count >= sizeof(write_buf))
> -               goto out;
> -       mutex_lock(&queue_io_mutex);
> -       ret = cache_do_downcall(write_buf, buf, count, cd);
> -       mutex_unlock(&queue_io_mutex);
> -out:
> -       return ret;
> -}
> -
>  static ssize_t cache_downcall(struct address_space *mapping,
>                               const char __user *buf,
>                               size_t count, struct cache_detail *cd)
>  {
> -       struct page *page;
> -       char *kaddr;
> +       char *write_buf;
>         ssize_t ret = -ENOMEM;
> 
> -       if (count >= PAGE_SIZE)
> -               goto out_slow;
> +       if (count >= 32768) { /* 32k is max userland buffer, lets
> check anyway */
> +               ret = -EINVAL;
> +               goto out;
> +       }
> 
> -       page = find_or_create_page(mapping, 0, GFP_KERNEL);
> -       if (!page)
> -               goto out_slow;
> +       write_buf = kvmalloc(count + 1, GFP_KERNEL);
> +       if (!write_buf)
> +               goto out;
> 
> -       kaddr = kmap(page);
> -       ret = cache_do_downcall(kaddr, buf, count, cd);
> -       kunmap(page);
> -       unlock_page(page);
> -       put_page(page);
> +       ret = cache_do_downcall(write_buf, buf, count, cd);
> +       kvfree(write_buf);
> +out:
>         return ret;
> -out_slow:
> -       return cache_slow_downcall(buf, count, cd);
>  }
> 
>  static ssize_t cache_write(struct file *filp, const char __user *buf,
> 
> On Fri, Nov 6, 2020 at 10:51 PM J. Bruce Fields <bfields@fieldses.org> wrote:
> >
> > On Mon, Oct 26, 2020 at 04:05:30PM +0100, Roberto Bergantinos Corpas wrote:
> > > RPC channel buffer size for slow case (user buffer bigger than
> > > one page) can be converted into dymanic and also allows us to
> > > prescind from queue_io_mutex
> >
> > Sorry for the slow response.
> >
> > Let's just remove cache_slow_downcall and the find_or_create_page()
> > thing and just do a kvmalloc() from the start.  I don't understand why
> > we need to be more complicated.
> >
> > --b.
> >
> > >
> > > Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com>
> > > ---
> > >  net/sunrpc/cache.c | 13 ++++++++-----
> > >  1 file changed, 8 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
> > > index baef5ee43dbb..325393f75e17 100644
> > > --- a/net/sunrpc/cache.c
> > > +++ b/net/sunrpc/cache.c
> > > @@ -777,7 +777,6 @@ void cache_clean_deferred(void *owner)
> > >   */
> > >
> > >  static DEFINE_SPINLOCK(queue_lock);
> > > -static DEFINE_MUTEX(queue_io_mutex);
> > >
> > >  struct cache_queue {
> > >       struct list_head        list;
> > > @@ -908,14 +907,18 @@ static ssize_t cache_do_downcall(char *kaddr, const char __user *buf,
> > >  static ssize_t cache_slow_downcall(const char __user *buf,
> > >                                  size_t count, struct cache_detail *cd)
> > >  {
> > > -     static char write_buf[8192]; /* protected by queue_io_mutex */
> > > +     char *write_buf;
> > >       ssize_t ret = -EINVAL;
> > >
> > > -     if (count >= sizeof(write_buf))
> > > +     if (count >= 32768) /* 32k is max userland buffer, lets check anyway */
> > >               goto out;
> > > -     mutex_lock(&queue_io_mutex);
> > > +
> > > +     write_buf = kvmalloc(count + 1, GFP_KERNEL);
> > > +     if (!write_buf)
> > > +             return -ENOMEM;
> > > +
> > >       ret = cache_do_downcall(write_buf, buf, count, cd);
> > > -     mutex_unlock(&queue_io_mutex);
> > > +     kvfree(write_buf);
> > >  out:
> > >       return ret;
> > >  }
> > > --
> > > 2.21.0
> >

  reply	other threads:[~2020-11-23 15:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 15:05 [PATCH] sunrpc : make RPC channel buffer dynamic for slow case Roberto Bergantinos Corpas
2020-11-06 21:51 ` J. Bruce Fields
2020-11-21 10:54   ` Roberto Bergantinos Corpas
2020-11-23 15:36     ` J. Bruce Fields [this message]
2020-11-23 15:48       ` Chuck Lever
2020-11-23 16:05         ` Bruce Fields

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=20201123153627.GD32599@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=rbergant@redhat.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.