linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mel Gorman <mgorman@suse.de>
To: JoonSoo Kim <js1304@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linux-MM <linux-mm@kvack.org>,
	Linux-Netdev <netdev@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	David Miller <davem@davemloft.net>,
	Chuck Lever <chuck.lever@oracle.com>,
	Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Christoph Lameter <cl@linux.com>
Subject: Re: [PATCH 1/4] slab: do ClearSlabPfmemalloc() for all pages of slab
Date: Fri, 7 Sep 2012 13:55:19 +0100	[thread overview]
Message-ID: <20120907125519.GB11266@suse.de> (raw)
In-Reply-To: <CAAmzW4MfFUH1Mi447sQvPNeae_BShEmbECUaK9eoX-8ughEdJw@mail.gmail.com>

On Fri, Sep 07, 2012 at 03:05:39AM +0900, JoonSoo Kim wrote:
> Correct Pekka's mail address and resend.
> Sorry.
> 
> Add "Cc" to "Christoph Lameter" <cl@linux.com>
> 
> 2012/9/5 Mel Gorman <mgorman@suse.de>:
> > Right now, we call ClearSlabPfmemalloc() for first page of slab when we
> > clear SlabPfmemalloc flag. This is fine for most swap-over-network use
> > cases as it is expected that order-0 pages are in use. Unfortunately it
> > is possible that that __ac_put_obj() checks SlabPfmemalloc on a tail page
> > and while this is harmless, it is sloppy. This patch ensures that the head
> > page is always used.
> >
> > This problem was originally identified by Joonsoo Kim.
> >
> > [js1304@gmail.com: Original implementation and problem identification]
> > Signed-off-by: Mel Gorman <mgorman@suse.de>
> > ---
> >  mm/slab.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/slab.c b/mm/slab.c
> > index 811af03..d34a903 100644
> > --- a/mm/slab.c
> > +++ b/mm/slab.c
> > @@ -1000,7 +1000,7 @@ static void *__ac_get_obj(struct kmem_cache *cachep, struct array_cache *ac,
> >                 l3 = cachep->nodelists[numa_mem_id()];
> >                 if (!list_empty(&l3->slabs_free) && force_refill) {
> >                         struct slab *slabp = virt_to_slab(objp);
> > -                       ClearPageSlabPfmemalloc(virt_to_page(slabp->s_mem));
> > +                       ClearPageSlabPfmemalloc(virt_to_head_page(slabp->s_mem));
> >                         clear_obj_pfmemalloc(&objp);
> >                         recheck_pfmemalloc_active(cachep, ac);
> >                         return objp;
> 
> We assume that slabp->s_mem's address is always in head page, so
> "virt_to_head_page" is not needed.
> 

Fair point. I thought it would be more "obvious" later that we really
always intended to use the head page but it is unnecessary.

> > @@ -1032,7 +1032,7 @@ static void *__ac_put_obj(struct kmem_cache *cachep, struct array_cache *ac,
> >  {
> >         if (unlikely(pfmemalloc_active)) {
> >                 /* Some pfmemalloc slabs exist, check if this is one */
> > -               struct page *page = virt_to_page(objp);
> > +               struct page *page = virt_to_head_page(objp);
> >                 if (PageSlabPfmemalloc(page))
> >                         set_obj_pfmemalloc(&objp);
> >         }
> > --
> > 1.7.9.2
> >
> 
> If we always use head page, following suggestion is more good to me.
> How about you?
> 
> diff --git a/mm/slab.c b/mm/slab.c
> index f8b0d53..ce70989 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
> @@ -1032,7 +1032,7 @@ static void *__ac_put_obj(struct kmem_cache
> *cachep, struct array_cache *ac,
>  {
>         if (unlikely(pfmemalloc_active)) {
>                 /* Some pfmemalloc slabs exist, check if this is one */
> -               struct page *page = virt_to_page(objp);
> +               struct page *page = virt_to_head_page(objp);
>                 if (PageSlabPfmemalloc(page))
>                         set_obj_pfmemalloc(&objp);
>         }

ok.

> @@ -1921,10 +1921,9 @@ static void *kmem_getpages(struct kmem_cache
> *cachep, gfp_t flags, int nodeid)
>                         NR_SLAB_UNRECLAIMABLE, nr_pages);
>         for (i = 0; i < nr_pages; i++) {
>                 __SetPageSlab(page + i);
> -
> -               if (page->pfmemalloc)
> -                       SetPageSlabPfmemalloc(page + i);
>         }
> +       if (page->pfmemalloc)
> +               SetPageSlabPfmemalloc(page);
> 
>         if (kmemcheck_enabled && !(cachep->flags & SLAB_NOTRACK)) {
>                 kmemcheck_alloc_shadow(page, cachep->gfporder, flags, nodeid);

ok.

> @@ -1943,26 +1942,26 @@ static void *kmem_getpages(struct kmem_cache
> *cachep, gfp_t flags, int nodeid)
>   */
>  static void kmem_freepages(struct kmem_cache *cachep, void *addr)
>  {
> -       unsigned long i = (1 << cachep->gfporder);
> +       int nr_pages = (1 << cachep->gfporder);
> +       int i;
>         struct page *page = virt_to_page(addr);
> -       const unsigned long nr_freed = i;
> 
>         kmemcheck_free_shadow(page, cachep->gfporder);
> 
>         if (cachep->flags & SLAB_RECLAIM_ACCOUNT)
>                 sub_zone_page_state(page_zone(page),
> -                               NR_SLAB_RECLAIMABLE, nr_freed);
> +                               NR_SLAB_RECLAIMABLE, nr_pages);
>         else
>                 sub_zone_page_state(page_zone(page),
> -                               NR_SLAB_UNRECLAIMABLE, nr_freed);
> -       while (i--) {
> -               BUG_ON(!PageSlab(page));
> -               __ClearPageSlabPfmemalloc(page);
> -               __ClearPageSlab(page);
> -               page++;
> +                               NR_SLAB_UNRECLAIMABLE, nr_pages);
> +       for (i = 0; i < nr_pages; i++) {
> +               BUG_ON(!PageSlab(page + i));
> +               __ClearPageSlab(page + i);
>         }
> +       __ClearPageSlabPfmemalloc(page);
> +
>         if (current->reclaim_state)
> -               current->reclaim_state->reclaimed_slab += nr_freed;
> +               current->reclaim_state->reclaimed_slab += nr_pages;
>         free_pages((unsigned long)addr, cachep->gfporder);
>  }

This churns code a lot more than is necessary. How about this as a
replacement patch?

---8<---
From: Joonsoo Kim <js1304@gmail.com>
Subject: [PATCH] slab: do ClearSlabPfmemalloc() for all pages of slab

Right now, we call ClearSlabPfmemalloc() for first page of slab when we
clear SlabPfmemalloc flag. This is fine for most swap-over-network use
cases as it is expected that order-0 pages are in use. Unfortunately it
is possible that that __ac_put_obj() checks SlabPfmemalloc on a tail page
and while this is harmless, it is sloppy. This patch ensures that the head
page is always used.

[mgorman@suse.de: Easier implementation, changelog cleanup]
Signed-off-by: Joonsoo Kim <js1304@gmail.com>
Signed-off-by: Mel Gorman <mgorman@suse.de>
---
 mm/slab.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 811af03..590d52a 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1032,7 +1032,7 @@ static void *__ac_put_obj(struct kmem_cache *cachep, struct array_cache *ac,
 {
 	if (unlikely(pfmemalloc_active)) {
 		/* Some pfmemalloc slabs exist, check if this is one */
-		struct page *page = virt_to_page(objp);
+		struct page *page = virt_to_head_page(objp);
 		if (PageSlabPfmemalloc(page))
 			set_obj_pfmemalloc(&objp);
 	}
@@ -1919,12 +1919,10 @@ static void *kmem_getpages(struct kmem_cache *cachep, gfp_t flags, int nodeid)
 	else
 		add_zone_page_state(page_zone(page),
 			NR_SLAB_UNRECLAIMABLE, nr_pages);
-	for (i = 0; i < nr_pages; i++) {
+	for (i = 0; i < nr_pages; i++)
 		__SetPageSlab(page + i);
-
-		if (page->pfmemalloc)
-			SetPageSlabPfmemalloc(page + i);
-	}
+	if (page->pfmemalloc)
+		SetPageSlabPfmemalloc(page);
 
 	if (kmemcheck_enabled && !(cachep->flags & SLAB_NOTRACK)) {
 		kmemcheck_alloc_shadow(page, cachep->gfporder, flags, nodeid);
@@ -1955,9 +1953,9 @@ static void kmem_freepages(struct kmem_cache *cachep, void *addr)
 	else
 		sub_zone_page_state(page_zone(page),
 				NR_SLAB_UNRECLAIMABLE, nr_freed);
+	__ClearPageSlabPfmemalloc(page);
 	while (i--) {
 		BUG_ON(!PageSlab(page));
-		__ClearPageSlabPfmemalloc(page);
 		__ClearPageSlab(page);
 		page++;
 	}

  reply	other threads:[~2012-09-07 12:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-04 17:24 [PATCH 0/4] Small fixes for swap-over-network Mel Gorman
2012-09-04 17:24 ` [PATCH 1/4] slab: do ClearSlabPfmemalloc() for all pages of slab Mel Gorman
2012-09-06 17:57   ` JoonSoo Kim
2012-09-06 18:05     ` JoonSoo Kim
2012-09-07 12:55       ` Mel Gorman [this message]
2012-09-07 21:10         ` JoonSoo Kim
2012-09-04 17:24 ` [PATCH 2/4] slab: fix starting index for finding another object Mel Gorman
2012-09-04 17:24 ` [PATCH 3/4] slub: consider pfmemalloc_match() in get_partial_node() Mel Gorman
2012-09-04 17:24 ` [PATCH 4/4] Squelch compiler warning in sk_rmem_schedule() Mel Gorman

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=20120907125519.GB11266@suse.de \
    --to=mgorman@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=chuck.lever@oracle.com \
    --cc=cl@linux.com \
    --cc=davem@davemloft.net \
    --cc=js1304@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=netdev@vger.kernel.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    /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).