+/**
+ * @brief A leaflet represent a bunch 4k ppage
+ * as single multi-ordered page, as such
+ * big page can seen as an unfolded version
+ * of these small 4k ppages hence the name.
+ * It is introduced to solve the issue that
+ * is discovered during refactoring - It is
+ * jolly unclear whether the ppage is a head,
+ * tail, or even worse, the middle one, when
+ * passing around between functions.
+ * This concept is surprisingly similar to
+ * Linux's struct folio (I swear to the
+ * Almighty Princess of the Sun, Celestia,
+ * that I don't quite understand what folio
+ * is until I've wrote the conceptually same
+ * thing)
+ *
+ */
+struct leaflet
+{
+ struct ppage lead_page;
+};
+
+static inline struct leaflet*
+get_leaflet(struct ppage* page)
+{
+ return (struct leaflet*)leading_page(page);
+}
+
+static inline struct ppage*
+get_ppage(struct leaflet* leaflet)
+{
+ return (struct ppage*)leaflet;
+}
+
+static inline struct leaflet*
+alloc_leaflet(int order)
+{
+ return (struct leaflet*)pmm_alloc_napot_type(POOL_UNIFIED, order, 0);
+}
+
+static inline struct leaflet*
+alloc_leaflet_pinned(int order)
+{
+ return (struct leaflet*)pmm_alloc_napot_type(POOL_UNIFIED, order, PP_FGLOCKED);
+}
+
+static inline void
+leaflet_borrow(struct leaflet* leaflet)
+{
+ struct ppage* const page = get_ppage(leaflet);
+ assert(page->refs);
+ if (reserved_page(page)) {
+ return;
+ }
+
+ page->refs++;
+}
+
+static inline void
+leaflet_return(struct leaflet* leaflet)
+{
+ struct ppage* const page = get_ppage(leaflet);
+ assert(page->refs);
+ pmm_free_one(page, 0);
+}
+
+static inline unsigned int
+leaflet_refcount(struct leaflet* leaflet)
+{
+ return get_ppage(leaflet)->refs;
+}
+
+static inline int
+leaflet_order(struct leaflet* leaflet)
+{
+ return ppage_order(get_ppage(leaflet));
+}
+
+static inline int
+leaflet_size(struct leaflet* leaflet)
+{
+ return PAGE_SIZE << leaflet_order(leaflet);
+}
+
+static inline int
+leaflet_nfold(struct leaflet* leaflet)
+{
+ return 1 << leaflet_order(leaflet);
+}
+
+static inline struct leaflet*
+ppfn_leaflet(pfn_t ppfn)
+{
+ return get_leaflet(ppage(ppfn));
+}
+
+static inline struct leaflet*
+pte_leaflet(pte_t pte)
+{
+ struct ppage* ppfn = ppage(pfn(pte_paddr(pte)));
+ return get_leaflet(ppfn);
+}