ASSERT(page_offset(page) <= start &&
               start + len <= page_offset(page) + PAGE_SIZE);
 
-       /*
-        * For subapge metadata case, all btrfs_page_* helpers need page to
-        * have page::private populated.
-        * But we can have rare case where the last eb in the page is only
-        * referred by the IO, and it gets released immedately after it's
-        * read and verified.
-        *
-        * This can detach the page private completely.
-        * In that case, we can just skip the page status update completely,
-        * as the page has no eb anymore.
-        */
-       if (fs_info->sectorsize < PAGE_SIZE && unlikely(!PagePrivate(page))) {
-               ASSERT(!is_data_inode(page->mapping->host));
-               return;
-       }
        if (uptodate) {
                btrfs_page_set_uptodate(fs_info, page, start, len);
        } else {
 
        if (fs_info->sectorsize == PAGE_SIZE)
                unlock_page(page);
-       else if (is_data_inode(page->mapping->host))
-               /*
-                * For subpage data, unlock the page if we're the last reader.
-                * For subpage metadata, page lock is not utilized for read.
-                */
+       else
                btrfs_subpage_end_reader(fs_info, page, start, len);
 }
 
                subpage = (struct btrfs_subpage *)page->private;
                if (atomic_read(&subpage->eb_refs))
                        return true;
+               /*
+                * Even there is no eb refs here, we may still have
+                * end_page_read() call relying on page::private.
+                */
+               if (atomic_read(&subpage->readers))
+                       return true;
        }
        return false;
 }
 
        /*
         * We can only detach the page private if there are no other ebs in the
-        * page range.
+        * page range and no unfinished IO.
         */
        if (!page_range_has_eb(fs_info, page))
                btrfs_detach_subpage(fs_info, page);
        check_buffer_tree_ref(eb);
        btrfs_subpage_clear_error(fs_info, page, eb->start, eb->len);
 
+       btrfs_subpage_start_reader(fs_info, page, eb->start, eb->len);
        ret = submit_extent_page(REQ_OP_READ | REQ_META, NULL, &bio_ctrl,
                                 page, eb->start, eb->len,
                                 eb->start - page_offset(page),
 
 #include <linux/slab.h>
 #include "ctree.h"
 #include "subpage.h"
+#include "btrfs_inode.h"
 
 /*
  * Subpage (sectorsize < PAGE_SIZE) support overview:
 {
        struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private;
        const int nbits = len >> fs_info->sectorsize_bits;
-       int ret;
 
        btrfs_subpage_assert(fs_info, page, start, len);
 
-       ret = atomic_add_return(nbits, &subpage->readers);
-       ASSERT(ret == nbits);
+       atomic_add(nbits, &subpage->readers);
 }
 
 void btrfs_subpage_end_reader(const struct btrfs_fs_info *fs_info,
 {
        struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private;
        const int nbits = len >> fs_info->sectorsize_bits;
+       bool is_data;
+       bool last;
 
        btrfs_subpage_assert(fs_info, page, start, len);
+       is_data = is_data_inode(page->mapping->host);
        ASSERT(atomic_read(&subpage->readers) >= nbits);
-       if (atomic_sub_and_test(nbits, &subpage->readers))
+       last = atomic_sub_and_test(nbits, &subpage->readers);
+
+       /*
+        * For data we need to unlock the page if the last read has finished.
+        *
+        * And please don't replace @last with atomic_sub_and_test() call
+        * inside if () condition.
+        * As we want the atomic_sub_and_test() to be always executed.
+        */
+       if (is_data && last)
                unlock_page(page);
 }
 
 
        u16 error_bitmap;
        u16 dirty_bitmap;
        u16 writeback_bitmap;
+       /*
+        * Both data and metadata needs to track how many readers are for the
+        * page.
+        * Data relies on @readers to unlock the page when last reader finished.
+        * While metadata doesn't need page unlock, it needs to prevent
+        * page::private get cleared before the last end_page_read().
+        */
+       atomic_t readers;
        union {
                /*
                 * Structures only used by metadata
                atomic_t eb_refs;
                /* Structures only used by data */
                struct {
-                       atomic_t readers;
                        atomic_t writers;
 
                        /* Tracke pending ordered extent in this sector */