On 2022/7/17 13:32, Fengnan Chang wrote:
From: Fengnan Chang <[email protected]>

When write total cluster, all pages is uptodate, there is no need to call
f2fs_prepare_compress_overwrite, intorduce f2fs_all_cluster_page_ready
to avoid this.

Signed-off-by: Fengnan Chang <[email protected]>
---
  fs/f2fs/compress.c | 17 +++++++++++++----
  fs/f2fs/data.c     |  8 ++++++--
  fs/f2fs/f2fs.h     |  4 ++--
  3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 24824cd96f36..28619d45b5c9 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -871,20 +871,29 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, 
pgoff_t index)
        return is_page_in_cluster(cc, index);
  }
-bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
-                               int index, int nr_pages)
+bool f2fs_all_cluster_page_ready(struct compress_ctx *cc, struct pagevec *pvec,
+                               int index, int nr_pages, bool uptodate)
  {
        unsigned long pgidx;
-       int i;
+       int i = uptodate ? 0 : 1;
+
+       /*
+        * when uptodate set to true, try to check all pages in cluster is
+        * uptodate or not.
+        */
+       if (uptodate && (pgidx % cc->cluster_size))

pgidx is uninitialized...

Thanks,

+               return false;
if (nr_pages - index < cc->cluster_size)
                return false;
pgidx = pvec->pages[index]->index; - for (i = 1; i < cc->cluster_size; i++) {
+       for (; i < cc->cluster_size; i++) {
                if (pvec->pages[index + i]->index != pgidx + i)
                        return false;
+               if (uptodate && !PageUptodate(pvec->pages[index + i]))
+                       return false;
        }
return true;
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 7fcbcf979737..022d0a8715c5 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2996,6 +2996,10 @@ static int f2fs_write_cache_pages(struct address_space 
*mapping,
                                if (!f2fs_cluster_is_empty(&cc))
                                        goto lock_page;
+ if (f2fs_all_cluster_page_ready(&cc,
+                                       &pvec, i, nr_pages, true))
+                                       goto lock_page;
+
                                ret2 = f2fs_prepare_compress_overwrite(
                                                        inode, &pagep,
                                                        page->index, &fsdata);
@@ -3006,8 +3010,8 @@ static int f2fs_write_cache_pages(struct address_space 
*mapping,
                                } else if (ret2 &&
                                        (!f2fs_compress_write_end(inode,
                                                fsdata, page->index, 1) ||
-                                        !f2fs_all_cluster_page_loaded(&cc,
-                                               &pvec, i, nr_pages))) {
+                                        !f2fs_all_cluster_page_ready(&cc,
+                                               &pvec, i, nr_pages, false))) {
                                        retry = 1;
                                        break;
                                }
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index d9bbecd008d2..df07c15a5202 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4163,8 +4163,8 @@ void f2fs_end_read_compressed_page(struct page *page, 
bool failed,
                                                        block_t blkaddr);
  bool f2fs_cluster_is_empty(struct compress_ctx *cc);
  bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index);
-bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec 
*pvec,
-                               int index, int nr_pages);
+bool f2fs_all_cluster_page_ready(struct compress_ctx *cc, struct pagevec *pvec,
+                               int index, int nr_pages, bool uptodate);
  bool f2fs_sanity_check_cluster(struct dnode_of_data *dn);
  void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page);
  int f2fs_write_multi_pages(struct compress_ctx *cc,


_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to