spin_unlock_irqrestore(&subpage->lock, flags);
 }
 
+void btrfs_subpage_set_ordered(const struct btrfs_fs_info *fs_info,
+               struct page *page, u64 start, u32 len)
+{
+       struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private;
+       const u16 tmp = btrfs_subpage_calc_bitmap(fs_info, page, start, len);
+       unsigned long flags;
+
+       spin_lock_irqsave(&subpage->lock, flags);
+       subpage->ordered_bitmap |= tmp;
+       SetPageOrdered(page);
+       spin_unlock_irqrestore(&subpage->lock, flags);
+}
+
+void btrfs_subpage_clear_ordered(const struct btrfs_fs_info *fs_info,
+               struct page *page, u64 start, u32 len)
+{
+       struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private;
+       const u16 tmp = btrfs_subpage_calc_bitmap(fs_info, page, start, len);
+       unsigned long flags;
+
+       spin_lock_irqsave(&subpage->lock, flags);
+       subpage->ordered_bitmap &= ~tmp;
+       if (subpage->ordered_bitmap == 0)
+               ClearPageOrdered(page);
+       spin_unlock_irqrestore(&subpage->lock, flags);
+}
 /*
  * Unlike set/clear which is dependent on each page status, for test all bits
  * are tested in the same way.
 IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(error);
 IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(dirty);
 IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(writeback);
+IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(ordered);
 
 /*
  * Note that, in selftests (extent-io-tests), we can have empty fs_info passed
                         PageDirty);
 IMPLEMENT_BTRFS_PAGE_OPS(writeback, set_page_writeback, end_page_writeback,
                         PageWriteback);
+IMPLEMENT_BTRFS_PAGE_OPS(ordered, SetPageOrdered, ClearPageOrdered,
+                        PageOrdered);
 
                struct {
                        atomic_t readers;
                        atomic_t writers;
+
+                       /* Tracke pending ordered extent in this sector */
+                       u16 ordered_bitmap;
                };
        };
 };
 DECLARE_BTRFS_SUBPAGE_OPS(error);
 DECLARE_BTRFS_SUBPAGE_OPS(dirty);
 DECLARE_BTRFS_SUBPAGE_OPS(writeback);
+DECLARE_BTRFS_SUBPAGE_OPS(ordered);
 
 bool btrfs_subpage_clear_and_test_dirty(const struct btrfs_fs_info *fs_info,
                struct page *page, u64 start, u32 len);