Add SECTION_ALIGN_UP() and SECTION_ALIGN_DOWN() macro which aligns
given pfn to upper section and lower section boundary accordingly.
Signed-off-by: Daniel Kiper <[email protected]>
---
include/linux/mmzone.h | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 02ecb01..d342820 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -931,6 +931,9 @@ static inline unsigned long early_pfn_to_nid(unsigned long pfn)
#define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT)
#define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT)
+#define SECTION_ALIGN_UP(pfn) (((pfn) + PAGES_PER_SECTION - 1) & PAGE_SECTION_MASK)
+#define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK)
+
#ifdef CONFIG_SPARSEMEM
/*
--
1.5.6.5
On Mon, 2011-03-28 at 11:24 +0200, Daniel Kiper wrote:
> Add SECTION_ALIGN_UP() and SECTION_ALIGN_DOWN() macro which aligns
> given pfn to upper section and lower section boundary accordingly.
>
> Signed-off-by: Daniel Kiper <[email protected]>
> ---
> include/linux/mmzone.h | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 02ecb01..d342820 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -931,6 +931,9 @@ static inline unsigned long early_pfn_to_nid(unsigned long pfn)
> #define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT)
> #define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT)
>
> +#define SECTION_ALIGN_UP(pfn) (((pfn) + PAGES_PER_SECTION - 1) & PAGE_SECTION_MASK)
> +#define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK)
There are certainly a lot of different ways to do this, including using
the existing ALIGN() macro, but you won't be the first to open-code
it. :)
Acked-by: Dave Hansen <[email protected]>
-- Dave
On Mon, 28 Mar 2011, Daniel Kiper wrote:
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 02ecb01..d342820 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -931,6 +931,9 @@ static inline unsigned long early_pfn_to_nid(unsigned long pfn)
> #define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT)
> #define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT)
>
> +#define SECTION_ALIGN_UP(pfn) (((pfn) + PAGES_PER_SECTION - 1) & PAGE_SECTION_MASK)
> +#define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK)
> +
> #ifdef CONFIG_SPARSEMEM
>
> /*
These are only valid for CONFIG_SPARSEMEM, so they need to be defined
conditionally.
On Mon, Mar 28, 2011 at 03:46:27PM -0700, David Rientjes wrote:
> On Mon, 28 Mar 2011, Daniel Kiper wrote:
>
> > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> > index 02ecb01..d342820 100644
> > --- a/include/linux/mmzone.h
> > +++ b/include/linux/mmzone.h
> > @@ -931,6 +931,9 @@ static inline unsigned long early_pfn_to_nid(unsigned long pfn)
> > #define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT)
> > #define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT)
> >
> > +#define SECTION_ALIGN_UP(pfn) (((pfn) + PAGES_PER_SECTION - 1) & PAGE_SECTION_MASK)
> > +#define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK)
> > +
> > #ifdef CONFIG_SPARSEMEM
> >
> > /*
>
> These are only valid for CONFIG_SPARSEMEM, so they need to be defined
> conditionally.
OK, however, I think that pfn_to_section_nr()/section_nr_to_pfn()
should be defined conditionally, too.
Daniel
On Mon, Mar 28, 2011 at 08:41:24AM -0700, Dave Hansen wrote:
> On Mon, 2011-03-28 at 11:24 +0200, Daniel Kiper wrote:
> > Add SECTION_ALIGN_UP() and SECTION_ALIGN_DOWN() macro which aligns
> > given pfn to upper section and lower section boundary accordingly.
> >
> > Signed-off-by: Daniel Kiper <[email protected]>
> > ---
> > include/linux/mmzone.h | 3 +++
> > 1 files changed, 3 insertions(+), 0 deletions(-)
> >
> > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> > index 02ecb01..d342820 100644
> > --- a/include/linux/mmzone.h
> > +++ b/include/linux/mmzone.h
> > @@ -931,6 +931,9 @@ static inline unsigned long early_pfn_to_nid(unsigned long pfn)
> > #define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT)
> > #define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT)
> >
> > +#define SECTION_ALIGN_UP(pfn) (((pfn) + PAGES_PER_SECTION - 1) & PAGE_SECTION_MASK)
> > +#define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK)
>
> There are certainly a lot of different ways to do this, including using
> the existing ALIGN() macro, but you won't be the first to open-code
> it. :)
Sorry, I forgot about ALIGN(). However, there is only up version available.
That is why I prefer open-code version here. It is clearer in both
cases what is going on.
Daniel
On Tue, 29 Mar 2011, Daniel Kiper wrote:
> > These are only valid for CONFIG_SPARSEMEM, so they need to be defined
> > conditionally.
>
> OK, however, I think that pfn_to_section_nr()/section_nr_to_pfn()
> should be defined conditionally, too.
>
Yes, and you could try removing this from include/linux/mm.h:
#ifndef PFN_SECTION_SHIFT
#define PFN_SECTION_SHIFT 0
#endif
then we'll reveal anything using these conversion macros that don't rely
on sparsemem.