Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp496173lqb; Thu, 29 Feb 2024 07:03:01 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUrobYeMrdhlxhiwzeTTS4rFLOomm/lCCFLEHrLejTJuJLgJuJ2QBPdmIlZwww+VqzQjGeNx1j8kGTs/8Z8pL+NY3Lk0HaXlfRO0BFdaA== X-Google-Smtp-Source: AGHT+IEiqQYdeyjfE1mCOCZtGc0BfdNvHk6w61KdmQae/DAHuo0/fmHommWbmV8AoDuqna+C621S X-Received: by 2002:a17:902:a384:b0:1dc:e26f:d8f8 with SMTP id x4-20020a170902a38400b001dce26fd8f8mr638911pla.14.1709218981166; Thu, 29 Feb 2024 07:03:01 -0800 (PST) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m12-20020a170902f64c00b001dca87344b8si1483456plg.597.2024.02.29.07.03.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 07:03:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@redhat.com header.s=mimecast20190719 header.b=JJSnjjKl; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-86887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86887-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E3B2EB2447D for ; Thu, 29 Feb 2024 15:00:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BABB61384A8; Thu, 29 Feb 2024 15:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JJSnjjKl" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E601137774 for ; Thu, 29 Feb 2024 15:00:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709218810; cv=none; b=AwA9wfwpZ00Qadr/jVoopGwPFIQZikNoVeWgGolebEaveE0d8z+vSqoGjHG7F89pSJfkUky9DhmfkzNPtkONLfa6qr9CQaXAl7CLvzEL34apyhUv2xQGDHAVYwWPsWySa9tuyQ/9h3b7ReTSmIfauWjqsVpMWAftGWSoPb3buws= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709218810; c=relaxed/simple; bh=bzsLAiCQthrVFAfhIeoz62wmMKFtw1xDTxQwvoxknAM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oDpyTFjVnchbqf3x7paZX7SIwLiVq+EmKgsHkBtYxm0xXodK2GCn9fT+YqLHTeA+XIFe2KoaYtHYCiwL+udiFhFyHxFKVIGTLjppGOSYum/j5RWlElQ2RTL97hEeA2u5V+qezuGf+BvLsIdOkLdjCKF442VPj7lsgf7NbCeyskw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JJSnjjKl; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709218807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6egRvLYRkiVfRFj4cN+8vcXUmac/AnmcaQNAMGAMNAg=; b=JJSnjjKlg4iyXtO29AjYhbmIDlzfqJMrbLy1HtEvX5/i4Zjz70Noxg1AO5WmRzae7OdkTu acDCeuQ8UwsgAX8/NmQg2V+yJ9fC1hQYj6DWP4z3LiIv0oX5rir50QEH5bD2WxwcacQPBZ kKDnTFbH0Psk9S7uBItpBnc//KV72YE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-422-i8F5JyzwPvWRc0Tt_-tQzw-1; Thu, 29 Feb 2024 10:00:04 -0500 X-MC-Unique: i8F5JyzwPvWRc0Tt_-tQzw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C5BC33C14955; Thu, 29 Feb 2024 15:00:03 +0000 (UTC) Received: from bfoster (unknown [10.22.32.137]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76A79112132A; Thu, 29 Feb 2024 15:00:01 +0000 (UTC) Date: Thu, 29 Feb 2024 10:01:43 -0500 From: Brian Foster To: Hou Tao Cc: linux-fsdevel@vger.kernel.org, Miklos Szeredi , Vivek Goyal , Stefan Hajnoczi , Bernd Schubert , "Michael S . Tsirkin" , Matthew Wilcox , Benjamin Coddington , linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, houtao1@huawei.com Subject: Re: [PATCH v2 4/6] virtiofs: support bounce buffer backed by scattered pages Message-ID: References: <20240228144126.2864064-1-houtao@huaweicloud.com> <20240228144126.2864064-5-houtao@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240228144126.2864064-5-houtao@huaweicloud.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 On Wed, Feb 28, 2024 at 10:41:24PM +0800, Hou Tao wrote: > From: Hou Tao > > When reading a file kept in virtiofs from kernel (e.g., insmod a kernel > module), if the cache of virtiofs is disabled, the read buffer will be > passed to virtiofs through out_args[0].value instead of pages. Because > virtiofs can't get the pages for the read buffer, virtio_fs_argbuf_new() > will create a bounce buffer for the read buffer by using kmalloc() and > copy the read buffer into bounce buffer. If the read buffer is large > (e.g., 1MB), the allocation will incur significant stress on the memory > subsystem. > > So instead of allocating bounce buffer by using kmalloc(), allocate a > bounce buffer which is backed by scattered pages. The original idea is > to use vmap(), but the use of GFP_ATOMIC is no possible for vmap(). To > simplify the copy operations in the bounce buffer, use a bio_vec flex > array to represent the argbuf. Also add an is_flat field in struct > virtio_fs_argbuf to distinguish between kmalloc-ed and scattered bounce > buffer. > > Signed-off-by: Hou Tao > --- > fs/fuse/virtio_fs.c | 163 ++++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 149 insertions(+), 14 deletions(-) > > diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c > index f10fff7f23a0f..ffea684bd100d 100644 > --- a/fs/fuse/virtio_fs.c > +++ b/fs/fuse/virtio_fs.c .. > @@ -408,42 +425,143 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work) > } > } > .. > static void virtio_fs_argbuf_copy_from_in_arg(struct virtio_fs_argbuf *argbuf, > unsigned int offset, > const void *src, unsigned int len) > { > - memcpy(argbuf->buf + offset, src, len); > + struct iov_iter iter; > + unsigned int copied; > + > + if (argbuf->is_flat) { > + memcpy(argbuf->f.buf + offset, src, len); > + return; > + } > + > + iov_iter_bvec(&iter, ITER_DEST, argbuf->s.bvec, > + argbuf->s.nr, argbuf->s.size); > + iov_iter_advance(&iter, offset); Hi Hou, Just a random comment, but it seems a little inefficient to reinit and readvance the iter like this on every copy/call. It looks like offset is already incremented in the callers of the argbuf copy helpers. Perhaps iov_iter could be lifted into the callers and passed down, or even just include it in the argbuf structure and init it at alloc time? Brian > + > + copied = _copy_to_iter(src, len, &iter); > + WARN_ON_ONCE(copied != len); > } > > static unsigned int > @@ -451,15 +569,32 @@ virtio_fs_argbuf_out_args_offset(struct virtio_fs_argbuf *argbuf, > const struct fuse_args *args) > { > unsigned int num_in = args->in_numargs - args->in_pages; > + unsigned int offset = fuse_len_args(num_in, > + (struct fuse_arg *)args->in_args); > > - return fuse_len_args(num_in, (struct fuse_arg *)args->in_args); > + if (argbuf->is_flat) > + return offset; > + return round_up(offset, PAGE_SIZE); > } > > static void virtio_fs_argbuf_copy_to_out_arg(struct virtio_fs_argbuf *argbuf, > unsigned int offset, void *dst, > unsigned int len) > { > - memcpy(dst, argbuf->buf + offset, len); > + struct iov_iter iter; > + unsigned int copied; > + > + if (argbuf->is_flat) { > + memcpy(dst, argbuf->f.buf + offset, len); > + return; > + } > + > + iov_iter_bvec(&iter, ITER_SOURCE, argbuf->s.bvec, > + argbuf->s.nr, argbuf->s.size); > + iov_iter_advance(&iter, offset); > + > + copied = _copy_from_iter(dst, len, &iter); > + WARN_ON_ONCE(copied != len); > } > > /* > @@ -1154,7 +1289,7 @@ static unsigned int sg_init_fuse_args(struct scatterlist *sg, > len = fuse_len_args(numargs - argpages, args); > if (len) > total_sgs += virtio_fs_argbuf_setup_sg(req->argbuf, *len_used, > - len, &sg[total_sgs]); > + &len, &sg[total_sgs]); > > if (argpages) > total_sgs += sg_init_fuse_pages(&sg[total_sgs], > @@ -1199,7 +1334,7 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq, > } > > /* Use a bounce buffer since stack args cannot be mapped */ > - req->argbuf = virtio_fs_argbuf_new(args, GFP_ATOMIC); > + req->argbuf = virtio_fs_argbuf_new(args, GFP_ATOMIC, true); > if (!req->argbuf) { > ret = -ENOMEM; > goto out; > -- > 2.29.2 > >