diff mbox series

[v2,01/33] mm: add virt_to_folio() and folio_address()

Message ID 20211201181510.18784-2-vbabka@suse.cz (mailing list archive)
State New
Headers show
Series Separate struct slab from struct page | expand

Commit Message

Vlastimil Babka Dec. 1, 2021, 6:14 p.m. UTC
These two wrappers around their respective struct page variants will be useful
in the following patches.

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
 include/linux/mm.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Johannes Weiner Dec. 14, 2021, 2:20 p.m. UTC | #1
On Wed, Dec 01, 2021 at 07:14:38PM +0100, Vlastimil Babka wrote:
> These two wrappers around their respective struct page variants will be useful
> in the following patches.
> 
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

Slight reviewer preference: introduce helpers when they're first used,
as it's a little easier to understand the application without having
to chase new folio_address() -> new slab_address() -> first user of
slab_address() through the patchset.
Vlastimil Babka Dec. 14, 2021, 2:27 p.m. UTC | #2
On 12/14/21 15:20, Johannes Weiner wrote:
> On Wed, Dec 01, 2021 at 07:14:38PM +0100, Vlastimil Babka wrote:
>> These two wrappers around their respective struct page variants will be useful
>> in the following patches.
>> 
>> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> 
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>

Thanks!

> Slight reviewer preference: introduce helpers when they're first used,
> as it's a little easier to understand the application without having
> to chase new folio_address() -> new slab_address() -> first user of
> slab_address() through the patchset.

Yeah would normally do that but with the current folio work going on there
was a chance the helpers would be useful to somebody else too and
cherry-picking a patch that adds them without user is simpler. And indeed
Matthew just asked about virt_to_folio() few days ago :)
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index a7e4a9e7d807..4a6cf22483da 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -863,6 +863,13 @@  static inline struct page *virt_to_head_page(const void *x)
 	return compound_head(page);
 }
 
+static inline struct folio *virt_to_folio(const void *x)
+{
+	struct page *page = virt_to_page(x);
+
+	return page_folio(page);
+}
+
 void __put_page(struct page *page);
 
 void put_pages_list(struct list_head *pages);
@@ -1753,6 +1760,11 @@  void page_address_init(void);
 #define page_address_init()  do { } while(0)
 #endif
 
+static inline void *folio_address(const struct folio *folio)
+{
+	return page_address(&folio->page);
+}
+
 extern void *page_rmapping(struct page *page);
 extern struct anon_vma *page_anon_vma(struct page *page);
 extern pgoff_t __page_file_index(struct page *page);