linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Minchan Kim <minchan@kernel.org>
To: Dan Streetman <ddstreet@ieee.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Linux-MM <linux-mm@kvack.org>, Hugh Dickins <hughd@google.com>,
	Shaohua Li <shli@kernel.org>,
	Jerome Marchand <jmarchan@redhat.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Nitin Gupta <ngupta@vflare.org>,
	Luigi Semenzato <semenzato@google.com>,
	juno.choi@lge.com
Subject: Re: [PATCH v1 2/5] mm: add full variable in swap_info_struct
Date: Wed, 24 Sep 2014 16:57:42 +0900	[thread overview]
Message-ID: <20140924075742.GB3181@bbox> (raw)
In-Reply-To: <CALZtONCgteaZwvS-oipcs3zK--AfDMSM0bEcFkEemmg_DvZF=A@mail.gmail.com>

On Tue, Sep 23, 2014 at 10:53:05PM -0400, Dan Streetman wrote:
> On Sun, Sep 21, 2014 at 8:03 PM, Minchan Kim <minchan@kernel.org> wrote:
> > Now, swap leans on !p->highest_bit to indicate a swap is full.
> > It works well for normal swap because every slot on swap device
> > is used up when the swap is full but in case of zram, swap sees
> > still many empty slot although backed device(ie, zram) is full
> > since zram's limit is over so that it could make trouble when
> > swap use highest_bit to select new slot via free_cluster.
> >
> > This patch introduces full varaiable in swap_info_struct
> > to solve the problem.
> >
> > Suggested-by: Dan Streetman <ddstreet@ieee.org>
> > Signed-off-by: Minchan Kim <minchan@kernel.org>
> > ---
> >  include/linux/swap.h |  1 +
> >  mm/swapfile.c        | 33 +++++++++++++++++++--------------
> >  2 files changed, 20 insertions(+), 14 deletions(-)
> >
> > diff --git a/include/linux/swap.h b/include/linux/swap.h
> > index ea4f926e6b9b..a3c11c051495 100644
> > --- a/include/linux/swap.h
> > +++ b/include/linux/swap.h
> > @@ -224,6 +224,7 @@ struct swap_info_struct {
> >         struct swap_cluster_info free_cluster_tail; /* free cluster list tail */
> >         unsigned int lowest_bit;        /* index of first free in swap_map */
> >         unsigned int highest_bit;       /* index of last free in swap_map */
> > +       bool    full;                   /* whether swap is full or not */
> >         unsigned int pages;             /* total of usable pages of swap */
> >         unsigned int inuse_pages;       /* number of those currently in use */
> >         unsigned int cluster_next;      /* likely index for next allocation */
> > diff --git a/mm/swapfile.c b/mm/swapfile.c
> > index c07f7f4912e9..209112cf8b83 100644
> > --- a/mm/swapfile.c
> > +++ b/mm/swapfile.c
> > @@ -558,7 +558,7 @@ checks:
> >         }
> >         if (!(si->flags & SWP_WRITEOK))
> >                 goto no_page;
> > -       if (!si->highest_bit)
> > +       if (si->full)
> >                 goto no_page;
> >         if (offset > si->highest_bit)
> >                 scan_base = offset = si->lowest_bit;
> > @@ -589,6 +589,7 @@ checks:
> >                 spin_lock(&swap_avail_lock);
> >                 plist_del(&si->avail_list, &swap_avail_head);
> >                 spin_unlock(&swap_avail_lock);
> > +               si->full = true;
> >         }
> >         si->swap_map[offset] = usage;
> >         inc_cluster_info_page(si, si->cluster_info, offset);
> > @@ -653,14 +654,14 @@ start_over:
> >                 plist_requeue(&si->avail_list, &swap_avail_head);
> >                 spin_unlock(&swap_avail_lock);
> >                 spin_lock(&si->lock);
> > -               if (!si->highest_bit || !(si->flags & SWP_WRITEOK)) {
> > +               if (si->full || !(si->flags & SWP_WRITEOK)) {
> >                         spin_lock(&swap_avail_lock);
> >                         if (plist_node_empty(&si->avail_list)) {
> >                                 spin_unlock(&si->lock);
> >                                 goto nextsi;
> >                         }
> > -                       WARN(!si->highest_bit,
> > -                            "swap_info %d in list but !highest_bit\n",
> > +                       WARN(si->full,
> > +                            "swap_info %d in list but swap is full\n",
> >                              si->type);
> >                         WARN(!(si->flags & SWP_WRITEOK),
> >                              "swap_info %d in list but !SWP_WRITEOK\n",
> > @@ -796,21 +797,25 @@ static unsigned char swap_entry_free(struct swap_info_struct *p,
> >
> >         /* free if no reference */
> >         if (!usage) {
> > +               bool was_full;
> > +
> >                 dec_cluster_info_page(p, p->cluster_info, offset);
> >                 if (offset < p->lowest_bit)
> >                         p->lowest_bit = offset;
> > -               if (offset > p->highest_bit) {
> > -                       bool was_full = !p->highest_bit;
> > +               if (offset > p->highest_bit)
> >                         p->highest_bit = offset;
> > -                       if (was_full && (p->flags & SWP_WRITEOK)) {
> > -                               spin_lock(&swap_avail_lock);
> > -                               WARN_ON(!plist_node_empty(&p->avail_list));
> > -                               if (plist_node_empty(&p->avail_list))
> > -                                       plist_add(&p->avail_list,
> > -                                                 &swap_avail_head);
> > -                               spin_unlock(&swap_avail_lock);
> > -                       }
> > +               was_full = p->full;
> > +
> > +               if (was_full && (p->flags & SWP_WRITEOK)) {
> 
> was_full was only needed because highest_bit was reset to offset right
> before checking for fullness, so now that ->full is used instead of
> !highest_bit, was_full isn't needed anymore, you can just check
> p->full.

Okay.

-- 
Kind regards,
Minchan Kim

--
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:[~2014-09-24  7:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-22  0:03 [PATCH v1 0/5] stop anon reclaim when zram is full Minchan Kim
2014-09-22  0:03 ` [PATCH v1 1/5] zram: generalize swap_slot_free_notify Minchan Kim
2014-09-22 20:41   ` Andrew Morton
2014-09-23  4:45     ` Minchan Kim
2014-09-22  0:03 ` [PATCH v1 2/5] mm: add full variable in swap_info_struct Minchan Kim
2014-09-22 20:45   ` Andrew Morton
2014-09-23  4:45     ` Minchan Kim
2014-09-24  2:53   ` Dan Streetman
2014-09-24  7:57     ` Minchan Kim [this message]
2014-09-22  0:03 ` [PATCH v1 3/5] mm: VM can be aware of zram fullness Minchan Kim
2014-09-24 14:12   ` Dan Streetman
2014-09-25  1:06     ` Minchan Kim
2014-09-25  1:31       ` Dan Streetman
2014-09-22  0:03 ` [PATCH v1 4/5] zram: add swap full hint Minchan Kim
2014-09-22 21:11   ` Andrew Morton
2014-09-23  4:56     ` Minchan Kim
2014-09-23 21:17       ` Andrew Morton
2014-09-24  7:57         ` Minchan Kim
2014-09-24 15:10         ` Jerome Marchand
2014-09-25  1:07           ` Minchan Kim
2014-09-24 14:01   ` Dan Streetman
2014-09-25  1:02     ` Minchan Kim
2014-09-25 15:52       ` Dan Streetman
2014-10-06 23:36         ` Minchan Kim
2014-10-06 23:46           ` Minchan Kim
2014-10-08 18:29             ` Dan Streetman
2014-09-22  0:03 ` [PATCH v1 5/5] zram: add fullness knob to control swap full Minchan Kim
2014-09-22 21:17   ` Andrew Morton
2014-09-23  4:57     ` Minchan Kim
2014-12-02  3:04 ` [PATCH v1 0/5] stop anon reclaim when zram is full Minchan Kim

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=20140924075742.GB3181@bbox \
    --to=minchan@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ddstreet@ieee.org \
    --cc=hughd@google.com \
    --cc=jmarchan@redhat.com \
    --cc=juno.choi@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ngupta@vflare.org \
    --cc=semenzato@google.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=shli@kernel.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).