btrfs: move kthread_associate_blkcg out of btrfs_submit_compressed_write
authorChristoph Hellwig <hch@lst.de>
Mon, 27 Mar 2023 00:49:47 +0000 (09:49 +0900)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Apr 2023 16:01:22 +0000 (18:01 +0200)
btrfs_submit_compressed_write should not have to care if it is called
from a helper thread or not.  Move the kthread_associate_blkcg handling
into submit_one_async_extent, as that is the one caller that needs it.
Also move the assignment of REQ_CGROUP_PUNT into cow_file_range_async,
as that is the routine that sets up the helper thread offload.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c
fs/btrfs/compression.h
fs/btrfs/inode.c

index 44c4276741ceda24ecde5e4ccef36a0cf68f53fe..d532a8c8c9d8c6df97463eb0aac57dfb29ce3bc6 100644 (file)
@@ -286,7 +286,6 @@ void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
                                 struct page **compressed_pages,
                                 unsigned int nr_pages,
                                 blk_opf_t write_flags,
-                                struct cgroup_subsys_state *blkcg_css,
                                 bool writeback)
 {
        struct btrfs_fs_info *fs_info = inode->root->fs_info;
@@ -295,10 +294,6 @@ void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
        ASSERT(IS_ALIGNED(start, fs_info->sectorsize) &&
               IS_ALIGNED(len, fs_info->sectorsize));
 
-       if (blkcg_css) {
-               kthread_associate_blkcg(blkcg_css);
-               write_flags |= REQ_CGROUP_PUNT;
-       }
        write_flags |= REQ_BTRFS_ONE_ORDERED;
 
        cb = alloc_compressed_bio(inode, start, REQ_OP_WRITE | write_flags,
@@ -314,9 +309,6 @@ void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
        btrfs_add_compressed_bio_pages(cb);
 
        btrfs_submit_bio(&cb->bbio, 0);
-
-       if (blkcg_css)
-               kthread_associate_blkcg(NULL);
 }
 
 /*
index 5d5146e72a860b423e9760ab2dfcbe0ea4008561..19ab2abeddc088c421c083a78b0b2cb179e3dea0 100644 (file)
@@ -92,7 +92,6 @@ void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
                                  struct page **compressed_pages,
                                  unsigned int nr_pages,
                                  blk_opf_t write_flags,
-                                 struct cgroup_subsys_state *blkcg_css,
                                  bool writeback);
 void btrfs_submit_compressed_read(struct btrfs_bio *bbio, int mirror_num);
 
index d069cde28af500baaa1670f1f1a4cdc743b7e10e..74d1a664b90fec5915d7de4c85003924f0e926f6 100644 (file)
@@ -1054,14 +1054,18 @@ static int submit_one_async_extent(struct btrfs_inode *inode,
        extent_clear_unlock_delalloc(inode, start, end,
                        NULL, EXTENT_LOCKED | EXTENT_DELALLOC,
                        PAGE_UNLOCK | PAGE_START_WRITEBACK);
+
+       if (async_chunk->blkcg_css)
+               kthread_associate_blkcg(async_chunk->blkcg_css);
        btrfs_submit_compressed_write(inode, start,     /* file_offset */
                            async_extent->ram_size,     /* num_bytes */
                            ins.objectid,               /* disk_bytenr */
                            ins.offset,                 /* compressed_len */
                            async_extent->pages,        /* compressed_pages */
                            async_extent->nr_pages,
-                           async_chunk->write_flags,
-                           async_chunk->blkcg_css, true);
+                           async_chunk->write_flags, true);
+       if (async_chunk->blkcg_css)
+               kthread_associate_blkcg(NULL);
        *alloc_hint = ins.objectid + ins.offset;
        kfree(async_extent);
        return ret;
@@ -1613,6 +1617,7 @@ static int cow_file_range_async(struct btrfs_inode *inode,
                if (blkcg_css != blkcg_root_css) {
                        css_get(blkcg_css);
                        async_chunk[i].blkcg_css = blkcg_css;
+                       async_chunk[i].write_flags |= REQ_CGROUP_PUNT;
                } else {
                        async_chunk[i].blkcg_css = NULL;
                }
@@ -10348,8 +10353,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
        btrfs_delalloc_release_extents(inode, num_bytes);
 
        btrfs_submit_compressed_write(inode, start, num_bytes, ins.objectid,
-                                         ins.offset, pages, nr_pages, 0, NULL,
-                                         false);
+                                         ins.offset, pages, nr_pages, 0, false);
        ret = orig_count;
        goto out;