From: Matthew Wilcox <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Subject: [PATCH v2 2/3] mm: Introduce page_shift()
Date: Sun, 21 Jul 2019 03:46:11 -0700 [thread overview]
Message-ID: <20190721104612.19120-3-willy@infradead.org> (raw)
In-Reply-To: <20190721104612.19120-1-willy@infradead.org>
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Replace PAGE_SHIFT + compound_order(page) with the new page_shift()
function. Minor improvements in readability.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
arch/powerpc/mm/book3s64/iommu_api.c | 7 ++-----
drivers/vfio/vfio_iommu_spapr_tce.c | 2 +-
include/linux/mm.h | 6 ++++++
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s64/iommu_api.c
index b056cae3388b..56cc84520577 100644
--- a/arch/powerpc/mm/book3s64/iommu_api.c
+++ b/arch/powerpc/mm/book3s64/iommu_api.c
@@ -129,11 +129,8 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua,
* Allow to use larger than 64k IOMMU pages. Only do that
* if we are backed by hugetlb.
*/
- if ((mem->pageshift > PAGE_SHIFT) && PageHuge(page)) {
- struct page *head = compound_head(page);
-
- pageshift = compound_order(head) + PAGE_SHIFT;
- }
+ if ((mem->pageshift > PAGE_SHIFT) && PageHuge(page))
+ pageshift = page_shift(compound_head(page));
mem->pageshift = min(mem->pageshift, pageshift);
/*
* We don't need struct page reference any more, switch
diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
index 8ce9ad21129f..1883fd2901b2 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -190,7 +190,7 @@ static bool tce_page_is_contained(struct mm_struct *mm, unsigned long hpa,
* a page we just found. Otherwise the hardware can get access to
* a bigger memory chunk that it should.
*/
- return (PAGE_SHIFT + compound_order(compound_head(page))) >= page_shift;
+ return page_shift(compound_head(page)) >= page_shift;
}
static inline bool tce_groups_attached(struct tce_container *container)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 899dfcf7c23d..64762559885f 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -811,6 +811,12 @@ static inline unsigned long page_size(struct page *page)
return PAGE_SIZE << compound_order(page);
}
+/* Returns the number of bits needed for the number of bytes in a page */
+static inline unsigned int page_shift(struct page *page)
+{
+ return PAGE_SHIFT + compound_order(page);
+}
+
void free_compound_page(struct page *page);
#ifdef CONFIG_MMU
--
2.20.1
next prev parent reply other threads:[~2019-07-21 10:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-21 10:46 [PATCH v2 0/3] Make working with compound pages easier Matthew Wilcox
2019-07-21 10:46 ` [PATCH v2 1/3] mm: Introduce page_size() Matthew Wilcox
2019-07-23 0:43 ` Ira Weiny
2019-07-23 16:02 ` Matthew Wilcox
2019-07-23 17:58 ` Ira Weiny
2019-07-23 18:14 ` Matthew Wilcox
2019-07-23 20:44 ` Ira Weiny
2019-07-23 21:03 ` Matthew Wilcox
2019-09-20 23:28 ` Andrew Morton
2019-09-21 1:09 ` Matthew Wilcox
2019-09-22 2:13 ` Weiny, Ira
2019-07-21 10:46 ` Matthew Wilcox [this message]
2019-07-23 0:44 ` [PATCH v2 2/3] mm: Introduce page_shift() Ira Weiny
2019-07-24 10:40 ` kbuild test robot
2019-07-25 0:30 ` Andrew Morton
2019-07-25 20:30 ` Ira Weiny
2019-09-23 20:30 ` Matthew Wilcox
2019-07-21 10:46 ` [PATCH v2 3/3] mm: Introduce compound_nr() Matthew Wilcox
2019-07-23 0:46 ` Ira Weiny
2019-07-23 12:55 ` [PATCH v2 0/3] Make working with compound pages easier Kirill A. Shutemov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190721104612.19120-3-willy@infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).