All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Tesarik <ptesarik@suse.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	linux-kernel@vger.kernel.org,
	Mel Gorman <mgorman@techsingularity.net>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Kemi Wang <kemi.wang@intel.com>,
	YASUAKI ISHIMATSU <yasu.isimatu@gmail.com>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Nikolay Borisov <nborisov@suse.com>
Subject: Re: [PATCH] Fix explanation of lower bits in the SPARSEMEM mem_map pointer
Date: Wed, 24 Jan 2018 14:57:11 +0100	[thread overview]
Message-ID: <20180124145711.4f3f219d@ezekiel.suse.cz> (raw)
In-Reply-To: <20180124124353.GE28465@dhcp22.suse.cz>

On Wed, 24 Jan 2018 13:43:53 +0100
Michal Hocko <mhocko@kernel.org> wrote:

> On Fri 19-01-18 14:21:33, Petr Tesarik wrote:
> > On Fri, 19 Jan 2018 13:39:56 +0100
> > Michal Hocko <mhocko@kernel.org> wrote:
> >   
> > > On Fri 19-01-18 08:09:08, Petr Tesarik wrote:
> > > [...]  
> > > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> > > > index 67f2e3c38939..7522a6987595 100644
> > > > --- a/include/linux/mmzone.h
> > > > +++ b/include/linux/mmzone.h
> > > > @@ -1166,8 +1166,16 @@ extern unsigned long usemap_size(void);
> > > >  
> > > >  /*
> > > >   * We use the lower bits of the mem_map pointer to store
> > > > - * a little bit of information.  There should be at least
> > > > - * 3 bits here due to 32-bit alignment.
> > > > + * a little bit of information.  The pointer is calculated
> > > > + * as mem_map - section_nr_to_pfn(pnum).  The result is
> > > > + * aligned to the minimum alignment of the two values:
> > > > + *   1. All mem_map arrays are page-aligned.
> > > > + *   2. section_nr_to_pfn() always clears PFN_SECTION_SHIFT
> > > > + *      lowest bits.  PFN_SECTION_SHIFT is arch-specific
> > > > + *      (equal SECTION_SIZE_BITS - PAGE_SHIFT), and the
> > > > + *      worst combination is powerpc with 256k pages,
> > > > + *      which results in PFN_SECTION_SHIFT equal 6.
> > > > + * To sum it up, at least 6 bits are available.
> > > >   */    
> > > 
> > > This is _much_ better indeed. Do you think we can go one step further
> > > and add BUG_ON into the sparse code to guarantee that every mmemap
> > > is indeed aligned properly so that SECTION_MAP_LAST_BIT-1 bits are never
> > > used?  
> > 
> > This is easy for the section_nr_to_pfn() part. I'd just add:
> > 
> >   BUILD_BUG_ON(PFN_SECTION_SHIFT < SECTION_MAP_LAST_BIT);
> > 
> > But for the mem_map arrays... Do you mean adding a run-time BUG_ON into
> > all allocation paths?
> > 
> > Note that mem_map arrays can be allocated by:
> > 
> >   a) __earlyonly_bootmem_alloc
> >   b) memblock_virt_alloc_try_nid
> >   c) memblock_virt_alloc_try_nid_raw
> >   d) alloc_remap (only arch/tile still has it)
> > 
> > Some allocation paths are in mm/sparse.c, others are
> > mm/sparse-vmemmap.c, so it becomes a bit messy, but since it's
> > a single line in each, it may work.  
> 
> Yeah, it is a mess. So I will leave it up to you. I do not want to block
> your comment update which is a nice improvement. So with or without the
> runtime check feel free to add

Hell, since I have already taken the time to review all the allocation
paths, I can just also add those BUG_ONs. I was just curious if you had
a better idea than spraying them all around the place, but it seems you
don't. ;-)

In short, stay tuned for v2, which is now WIP.

Petr T

WARNING: multiple messages have this Message-ID
From: Petr Tesarik <ptesarik@suse.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	linux-kernel@vger.kernel.org,
	Mel Gorman <mgorman@techsingularity.net>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Kemi Wang <kemi.wang@intel.com>,
	YASUAKI ISHIMATSU <yasu.isimatu@gmail.com>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Nikolay Borisov <nborisov@suse.com>
Subject: Re: [PATCH] Fix explanation of lower bits in the SPARSEMEM mem_map pointer
Date: Wed, 24 Jan 2018 14:57:11 +0100	[thread overview]
Message-ID: <20180124145711.4f3f219d@ezekiel.suse.cz> (raw)
In-Reply-To: <20180124124353.GE28465@dhcp22.suse.cz>

On Wed, 24 Jan 2018 13:43:53 +0100
Michal Hocko <mhocko@kernel.org> wrote:

> On Fri 19-01-18 14:21:33, Petr Tesarik wrote:
> > On Fri, 19 Jan 2018 13:39:56 +0100
> > Michal Hocko <mhocko@kernel.org> wrote:
> >   
> > > On Fri 19-01-18 08:09:08, Petr Tesarik wrote:
> > > [...]  
> > > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> > > > index 67f2e3c38939..7522a6987595 100644
> > > > --- a/include/linux/mmzone.h
> > > > +++ b/include/linux/mmzone.h
> > > > @@ -1166,8 +1166,16 @@ extern unsigned long usemap_size(void);
> > > >  
> > > >  /*
> > > >   * We use the lower bits of the mem_map pointer to store
> > > > - * a little bit of information.  There should be at least
> > > > - * 3 bits here due to 32-bit alignment.
> > > > + * a little bit of information.  The pointer is calculated
> > > > + * as mem_map - section_nr_to_pfn(pnum).  The result is
> > > > + * aligned to the minimum alignment of the two values:
> > > > + *   1. All mem_map arrays are page-aligned.
> > > > + *   2. section_nr_to_pfn() always clears PFN_SECTION_SHIFT
> > > > + *      lowest bits.  PFN_SECTION_SHIFT is arch-specific
> > > > + *      (equal SECTION_SIZE_BITS - PAGE_SHIFT), and the
> > > > + *      worst combination is powerpc with 256k pages,
> > > > + *      which results in PFN_SECTION_SHIFT equal 6.
> > > > + * To sum it up, at least 6 bits are available.
> > > >   */    
> > > 
> > > This is _much_ better indeed. Do you think we can go one step further
> > > and add BUG_ON into the sparse code to guarantee that every mmemap
> > > is indeed aligned properly so that SECTION_MAP_LAST_BIT-1 bits are never
> > > used?  
> > 
> > This is easy for the section_nr_to_pfn() part. I'd just add:
> > 
> >   BUILD_BUG_ON(PFN_SECTION_SHIFT < SECTION_MAP_LAST_BIT);
> > 
> > But for the mem_map arrays... Do you mean adding a run-time BUG_ON into
> > all allocation paths?
> > 
> > Note that mem_map arrays can be allocated by:
> > 
> >   a) __earlyonly_bootmem_alloc
> >   b) memblock_virt_alloc_try_nid
> >   c) memblock_virt_alloc_try_nid_raw
> >   d) alloc_remap (only arch/tile still has it)
> > 
> > Some allocation paths are in mm/sparse.c, others are
> > mm/sparse-vmemmap.c, so it becomes a bit messy, but since it's
> > a single line in each, it may work.  
> 
> Yeah, it is a mess. So I will leave it up to you. I do not want to block
> your comment update which is a nice improvement. So with or without the
> runtime check feel free to add

Hell, since I have already taken the time to review all the allocation
paths, I can just also add those BUG_ONs. I was just curious if you had
a better idea than spraying them all around the place, but it seems you
don't. ;-)

In short, stay tuned for v2, which is now WIP.

Petr T

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2018-01-24 13:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-19  7:09 Petr Tesarik
2018-01-19  7:09 ` Petr Tesarik
2018-01-19 12:39 ` Michal Hocko
2018-01-19 12:39   ` Michal Hocko
2018-01-19 13:21   ` Petr Tesarik
2018-01-19 13:21     ` Petr Tesarik
2018-01-24 12:43     ` Michal Hocko
2018-01-24 12:43       ` Michal Hocko
2018-01-24 13:57       ` Petr Tesarik [this message]
2018-01-24 13:57         ` Petr Tesarik
2018-01-25  9:05         ` [PATCH v2] " Petr Tesarik
2018-01-25  9:05           ` Petr Tesarik
2018-01-25 11:46           ` Michal Hocko
2018-01-25 11:46             ` Michal Hocko

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=20180124145711.4f3f219d@ezekiel.suse.cz \
    --to=ptesarik@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=hannes@cmpxchg.org \
    --cc=kemi.wang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@kernel.org \
    --cc=nborisov@suse.com \
    --cc=vbabka@suse.cz \
    --cc=yasu.isimatu@gmail.com \
    --subject='Re: [PATCH] Fix explanation of lower bits in the SPARSEMEM mem_map pointer' \
    /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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.