linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Tobin C. Harding" <me@tobin.cc>
To: Roman Gushchin <guro@fb.com>
Cc: "Tobin C. Harding" <tobin@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Matthew Wilcox <willy@infradead.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 2/7] slob: Respect list_head abstraction layer
Date: Thu, 4 Apr 2019 09:14:31 +1100	[thread overview]
Message-ID: <20190403221431.GA5025@eros.localdomain> (raw)
In-Reply-To: <20190403212322.GA5116@tower.DHCP.thefacebook.com>

On Wed, Apr 03, 2019 at 09:23:28PM +0000, Roman Gushchin wrote:
> On Thu, Apr 04, 2019 at 08:03:27AM +1100, Tobin C. Harding wrote:
> > On Wed, Apr 03, 2019 at 06:00:30PM +0000, Roman Gushchin wrote:
> > > On Wed, Apr 03, 2019 at 10:05:40AM +1100, Tobin C. Harding wrote:
> > > > Currently we reach inside the list_head.  This is a violation of the
> > > > layer of abstraction provided by the list_head.  It makes the code
> > > > fragile.  More importantly it makes the code wicked hard to understand.
> > > > 
> > > > The code reaches into the list_head structure to counteract the fact
> > > > that the list _may_ have been changed during slob_page_alloc().  Instead
> > > > of this we can add a return parameter to slob_page_alloc() to signal
> > > > that the list was modified (list_del() called with page->lru to remove
> > > > page from the freelist).
> > > > 
> > > > This code is concerned with an optimisation that counters the tendency
> > > > for first fit allocation algorithm to fragment memory into many small
> > > > chunks at the front of the memory pool.  Since the page is only removed
> > > > from the list when an allocation uses _all_ the remaining memory in the
> > > > page then in this special case fragmentation does not occur and we
> > > > therefore do not need the optimisation.
> > > > 
> > > > Add a return parameter to slob_page_alloc() to signal that the
> > > > allocation used up the whole page and that the page was removed from the
> > > > free list.  After calling slob_page_alloc() check the return value just
> > > > added and only attempt optimisation if the page is still on the list.
> > > > 
> > > > Use list_head API instead of reaching into the list_head structure to
> > > > check if sp is at the front of the list.
> > > > 
> > > > Signed-off-by: Tobin C. Harding <tobin@kernel.org>
> > > > ---
> > > >  mm/slob.c | 51 +++++++++++++++++++++++++++++++++++++--------------
> > > >  1 file changed, 37 insertions(+), 14 deletions(-)
> > > > 
> > > > diff --git a/mm/slob.c b/mm/slob.c
> > > > index 307c2c9feb44..07356e9feaaa 100644
> > > > --- a/mm/slob.c
> > > > +++ b/mm/slob.c
> > > > @@ -213,13 +213,26 @@ static void slob_free_pages(void *b, int order)
> > > >  }
> > > >  
> > > >  /*
> > > > - * Allocate a slob block within a given slob_page sp.
> > > > + * slob_page_alloc() - Allocate a slob block within a given slob_page sp.
> > > > + * @sp: Page to look in.
> > > > + * @size: Size of the allocation.
> > > > + * @align: Allocation alignment.
> > > > + * @page_removed_from_list: Return parameter.
> > > > + *
> > > > + * Tries to find a chunk of memory at least @size bytes big within @page.
> > > > + *
> > > > + * Return: Pointer to memory if allocated, %NULL otherwise.  If the
> > > > + *         allocation fills up @page then the page is removed from the
> > > > + *         freelist, in this case @page_removed_from_list will be set to
> > > > + *         true (set to false otherwise).
> > > >   */
> > > > -static void *slob_page_alloc(struct page *sp, size_t size, int align)
> > > > +static void *slob_page_alloc(struct page *sp, size_t size, int align,
> > > > +			     bool *page_removed_from_list)
> > > 
> > > Hi Tobin!
> > > 
> > > Isn't it better to make slob_page_alloc() return a bool value?
> > > Then it's easier to ignore the returned value, no need to introduce "_unused".
> > 
> > We need a pointer to the memory allocated also so AFAICS its either a
> > return parameter for the memory pointer or a return parameter to
> > indicate the boolean value?  Open to any other ideas I'm missing.
> > 
> > In a previous crack at this I used a double pointer to the page struct
> > then set that to null to indicate the boolean value.  I think the
> > explicit boolean parameter is cleaner.
> 
> Yeah, sorry, it's my fault. Please, ignore this comment.
> Bool* argument is perfectly fine here.

Cheers man, no sweat.  I appreciate you looking at this stuff.

	Tobin


  reply	other threads:[~2019-04-03 22:15 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02 23:05 [PATCH v5 0/7] mm: Use slab_list list_head instead of lru Tobin C. Harding
2019-04-02 23:05 ` [PATCH v5 1/7] list: Add function list_rotate_to_front() Tobin C. Harding
2019-04-03 15:46   ` Christopher Lameter
2019-04-03 17:57   ` Roman Gushchin
2019-04-02 23:05 ` [PATCH v5 2/7] slob: Respect list_head abstraction layer Tobin C. Harding
2019-04-03 15:45   ` Christopher Lameter
2019-04-03 18:00   ` Roman Gushchin
2019-04-03 21:03     ` Tobin C. Harding
2019-04-03 21:23       ` Roman Gushchin
2019-04-03 22:14         ` Tobin C. Harding [this message]
2019-04-03 21:13     ` Tobin C. Harding
2019-04-09 12:59       ` Vlastimil Babka
2019-04-09 20:06         ` Tobin C. Harding
2019-04-09 22:25           ` Andrew Morton
2019-04-02 23:05 ` [PATCH v5 3/7] slob: Use slab_list instead of lru Tobin C. Harding
2019-04-03 15:47   ` Christopher Lameter
2019-04-02 23:05 ` [PATCH v5 4/7] slub: Add comments to endif pre-processor macros Tobin C. Harding
2019-04-03 18:42   ` Roman Gushchin
2019-04-02 23:05 ` [PATCH v5 5/7] slub: Use slab_list instead of lru Tobin C. Harding
2019-04-03 18:43   ` Roman Gushchin
2019-04-02 23:05 ` [PATCH v5 6/7] slab: " Tobin C. Harding
2019-04-03 15:48   ` Christopher Lameter
2019-04-03 18:44   ` Roman Gushchin
2019-04-02 23:05 ` [PATCH v5 7/7] mm: Remove stale comment from page struct Tobin C. Harding
2019-04-03 18:45   ` Roman Gushchin
2019-04-09 13:07 ` [PATCH v5 0/7] mm: Use slab_list list_head instead of lru Vlastimil Babka

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=20190403221431.GA5025@eros.localdomain \
    --to=me@tobin.cc \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=guro@fb.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=tobin@kernel.org \
    --cc=willy@infradead.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).