From: Miklos Szeredi <miklos@szeredi.hu>
To: Vasily Averin <vvs@virtuozzo.com>
Cc: linux-fsdevel@vger.kernel.org, Maxim Patlasov <maximvp@gmail.com>,
Kirill Tkhai <ktkhai@virtuozzo.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] fuse_writepages_fill: simplified "if-else if" constuction
Date: Tue, 14 Jul 2020 14:24:33 +0200 [thread overview]
Message-ID: <CAJfpegv_7nvWoigY-eCX0ny+phWYOz3kEZvYsuGb=u65yMLGHg@mail.gmail.com> (raw)
In-Reply-To: <446f0df5-798d-ab3a-e773-39d9f202c092@virtuozzo.com>
[-- Attachment #1: Type: text/plain, Size: 545 bytes --]
On Thu, Jun 25, 2020 at 11:30 AM Vasily Averin <vvs@virtuozzo.com> wrote:
>
> fuse_writepages_fill uses following construction:
> if (wpa && ap->num_pages &&
> (A || B || C)) {
> action;
> } else if (wpa && D) {
> if (E) {
> the same action;
> }
> }
>
> - ap->num_pages check is always true and can be removed
> - "if" and "else if" calls the same action and can be merged.
Makes sense. Attached patch goes further and moves checking the
conditions to a separate helper for clarity.
Thanks,
Miklos
[-- Attachment #2: fuse-clean-up-writepage-sending.patch --]
[-- Type: text/x-patch, Size: 3058 bytes --]
From: Miklos Szeredi <mszeredi@redhat.com>
Subject: fuse: clean up condition for writepage sending
fuse_writepages_fill uses following construction:
if (wpa && ap->num_pages &&
(A || B || C)) {
action;
} else if (wpa && D) {
if (E) {
the same action;
}
}
- ap->num_pages check is always true and can be removed
- "if" and "else if" calls the same action and can be merged.
Move checking A, B, C, D, E conditions to a helper, add comments.
Original-patch-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
fs/fuse/file.c | 51 +++++++++++++++++++++++++++++++++------------------
1 file changed, 33 insertions(+), 18 deletions(-)
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2015,6 +2015,38 @@ static bool fuse_writepage_add(struct fu
return false;
}
+static bool fuse_writepage_need_send(struct fuse_conn *fc, struct page *page,
+ struct fuse_args_pages *ap,
+ struct fuse_fill_wb_data *data)
+{
+ /*
+ * Being under writeback is unlikely but possible. For example direct
+ * read to an mmaped fuse file will set the page dirty twice; once when
+ * the pages are faulted with get_user_pages(), and then after the read
+ * completed.
+ */
+ if (fuse_page_is_writeback(data->inode, page->index))
+ return true;
+
+ /* Reached max pages */
+ if (ap->num_pages == fc->max_pages)
+ return true;
+
+ /* Reached max write bytes */
+ if ((ap->num_pages + 1) * PAGE_SIZE > fc->max_write)
+ return true;
+
+ /* Discontinuity */
+ if (data->orig_pages[ap->num_pages - 1]->index + 1 != page->index)
+ return true;
+
+ /* Need to grow the pages array? If so, did the expansion fail? */
+ if (ap->num_pages == data->max_pages && !fuse_pages_realloc(data))
+ return true;
+
+ return false;
+}
+
static int fuse_writepages_fill(struct page *page,
struct writeback_control *wbc, void *_data)
{
@@ -2025,7 +2057,6 @@ static int fuse_writepages_fill(struct p
struct fuse_inode *fi = get_fuse_inode(inode);
struct fuse_conn *fc = get_fuse_conn(inode);
struct page *tmp_page;
- bool is_writeback;
int err;
if (!data->ff) {
@@ -2035,25 +2066,9 @@ static int fuse_writepages_fill(struct p
goto out_unlock;
}
- /*
- * Being under writeback is unlikely but possible. For example direct
- * read to an mmaped fuse file will set the page dirty twice; once when
- * the pages are faulted with get_user_pages(), and then after the read
- * completed.
- */
- is_writeback = fuse_page_is_writeback(inode, page->index);
-
- if (wpa && ap->num_pages &&
- (is_writeback || ap->num_pages == fc->max_pages ||
- (ap->num_pages + 1) * PAGE_SIZE > fc->max_write ||
- data->orig_pages[ap->num_pages - 1]->index + 1 != page->index)) {
+ if (wpa && fuse_writepage_need_send(fc, page, ap, data)) {
fuse_writepages_send(data);
data->wpa = NULL;
- } else if (wpa && ap->num_pages == data->max_pages) {
- if (!fuse_pages_realloc(data)) {
- fuse_writepages_send(data);
- data->wpa = NULL;
- }
}
err = -ENOMEM;
next prev parent reply other threads:[~2020-07-14 12:24 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-15 0:50 [LTP] [fuse] 6b2fb79963: WARNING:at_fs/fuse/file.c:#tree_insert[fuse] kernel test robot
2020-06-15 0:50 ` kernel test robot
2020-06-15 5:59 ` Vasily Averin
2020-06-15 7:19 ` [PATCH] fuse: fixed WARNING:at_fs/fuse/file.c:#tree_insert[fuse] Vasily Averin
2020-06-16 12:35 ` [fuse] 6b2fb79963: WARNING:at_fs/fuse/file.c:#tree_insert[fuse] Miklos Szeredi
2020-06-18 10:29 ` Kirill Tkhai
2020-06-25 7:48 ` Vasily Averin
2020-06-25 9:02 ` [PATCH] fuse_writepages_fill() optimization to avoid WARN_ON in tree_insert Vasily Averin
2020-06-27 10:31 ` Sedat Dilek
2020-06-29 21:11 ` Vivek Goyal
2020-07-11 4:01 ` Miklos Szeredi
2020-07-13 8:02 ` Vasily Averin
2020-07-13 16:14 ` Miklos Szeredi
2020-07-14 6:18 ` Vasily Averin
2020-07-14 12:40 ` Sedat Dilek
2020-07-14 12:52 ` Miklos Szeredi
2020-07-14 12:57 ` Sedat Dilek
2020-07-15 7:48 ` Sedat Dilek
2020-06-25 9:30 ` [PATCH] fuse_writepages_fill: simplified "if-else if" constuction Vasily Averin
2020-07-14 12:24 ` Miklos Szeredi [this message]
2020-07-14 18:53 ` Vasily Averin
2020-06-25 9:39 ` [PATCH] fuse_writepages ignores errors from fuse_writepages_fill Vasily Averin
2020-07-14 12:44 ` Miklos Szeredi
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='CAJfpegv_7nvWoigY-eCX0ny+phWYOz3kEZvYsuGb=u65yMLGHg@mail.gmail.com' \
--to=miklos@szeredi.hu \
--cc=ktkhai@virtuozzo.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maximvp@gmail.com \
--cc=vvs@virtuozzo.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.