linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jongseok Kim <ks77sj@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Vitaly Wool <vitalywool@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Jongseok Kim <ks77sj@gmail.com>
Subject: [PATCH] z3fold: fix wrong handling of headless pages
Date: Fri,  6 Jul 2018 14:10:46 +0900	[thread overview]
Message-ID: <1530853846-30215-1-git-send-email-ks77sj@gmail.com> (raw)

During the processing of headless pages in z3fold_reclaim_page(),
there was a problem that the zhdr pointed to another page
or a page was already released in z3fold_free(). So, the wrong page
is encoded in headless, or test_bit does not work properly
in z3fold_reclaim_page(). This patch fixed these problems.

Signed-off-by: Jongseok Kim <ks77sj@gmail.com>
---
 mm/z3fold.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index 4b366d1..201a8ac 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -746,6 +746,9 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
 	}
 
 	if (bud == HEADLESS) {
+		if (test_bit(UNDER_RECLAIM, &page->private))
+			return;
+
 		spin_lock(&pool->lock);
 		list_del(&page->lru);
 		spin_unlock(&pool->lock);
@@ -836,20 +839,20 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
 		}
 		list_for_each_prev(pos, &pool->lru) {
 			page = list_entry(pos, struct page, lru);
+			zhdr = page_address(page);
 			if (test_bit(PAGE_HEADLESS, &page->private))
 				/* candidate found */
 				break;
 
-			zhdr = page_address(page);
 			if (!z3fold_page_trylock(zhdr))
 				continue; /* can't evict at this point */
 			kref_get(&zhdr->refcount);
 			list_del_init(&zhdr->buddy);
 			zhdr->cpu = -1;
-			set_bit(UNDER_RECLAIM, &page->private);
 			break;
 		}
 
+		set_bit(UNDER_RECLAIM, &page->private);
 		list_del_init(&page->lru);
 		spin_unlock(&pool->lock);
 
@@ -898,6 +901,7 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
 		if (test_bit(PAGE_HEADLESS, &page->private)) {
 			if (ret == 0) {
 				free_z3fold_page(page);
+				atomic64_dec(&pool->pages_nr);
 				return 0;
 			}
 			spin_lock(&pool->lock);
-- 
2.7.4

             reply	other threads:[~2018-07-06  5:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-06  5:10 Jongseok Kim [this message]
2018-11-06  7:48 ` [PATCH] z3fold: fix wrong handling of headless pages Vitaly Wool
2018-11-08 12:26   ` 김종석
2018-11-08 12:34   ` 김종석
2018-11-08 12:57     ` Vitaly Wool
2018-11-08 13:45       ` Jongseok Kim
2018-11-08 22:23         ` Andrew Morton
2018-11-08 22:33           ` Vitaly Wool

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=1530853846-30215-1-git-send-email-ks77sj@gmail.com \
    --to=ks77sj@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vitalywool@gmail.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).