From: Minchan Kim <minchan@kernel.org>
To: Tino Lehnig <tino.lehnig@contabo.de>
Cc: ngupta@vflare.org, linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: Zram writeback feature unstable with heavy swap utilization - BUG: Bad page state in process...
Date: Sat, 28 Jul 2018 07:58:50 +0900 [thread overview]
Message-ID: <20180727225850.GC229060@rodete-desktop-imager.corp.google.com> (raw)
In-Reply-To: <54eddd07-9fe5-0a83-0d2f-556726f64516@contabo.de>
[-- Attachment #1: Type: text/plain, Size: 475 bytes --]
On Fri, Jul 27, 2018 at 02:13:57PM +0200, Tino Lehnig wrote:
> On 07/27/2018 02:05 PM, Minchan Kim wrote:
> > And bad page is always with writeback enable?
> >
> > writeback enable means "echo "some dev" > /sys/block/zram0/backing_dev,
> > not just enable CONFIG_ZRAM_WRITEBACK.
>
> Yes, the bug only appears when backing_dev is set.
Thanks for the clarifiation.
I made a mistake on previous patch.
Could you test this patches?
>
> --
> Kind regards,
>
> Tino Lehnig
[-- Attachment #2: 0001-zram-remove-BD_CAP_SYNCHRONOUS_IO-with-writeback-fea.patch --]
[-- Type: text/x-diff, Size: 1706 bytes --]
From 77a5fc378dfae733af5a0f0c7ef901668d8c9778 Mon Sep 17 00:00:00 2001
From: Minchan Kim <minchan@kernel.org>
Date: Fri, 27 Jul 2018 15:15:33 +0900
Subject: [PATCH 1/2] zram: remove BD_CAP_SYNCHRONOUS_IO with writeback feature
If zram supports writeback feature, it's no more syncrhonous
device beause we need asynchronous IO opeation.
Do not pretend to be syncrhonous IO device. It makes system
very sluggish as waiting IO completion from upper layer.
Furthermore, it makes user-after-free problem because swap
think the opearion is done when the IO functions returns so
it could free page by will but in fact, IO is asynchrnous
so driver could access the freed page afterward.
(I will make description more clear at the formal patch).
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
drivers/block/zram/zram_drv.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 7436b2d27fa3..0b6eda1bd77a 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -298,7 +298,8 @@ static void reset_bdev(struct zram *zram)
zram->backing_dev = NULL;
zram->old_block_size = 0;
zram->bdev = NULL;
-
+ zram->disk->queue->backing_dev_info->capabilities |=
+ BDI_CAP_SYNCHRONOUS_IO;
kvfree(zram->bitmap);
zram->bitmap = NULL;
}
@@ -400,6 +401,8 @@ static ssize_t backing_dev_store(struct device *dev,
zram->backing_dev = backing_dev;
zram->bitmap = bitmap;
zram->nr_pages = nr_pages;
+ zram->disk->queue->backing_dev_info->capabilities &=
+ ~BDI_CAP_SYNCHRONOUS_IO;
up_write(&zram->init_lock);
pr_info("setup backing device %s\n", file_name);
--
2.18.0.345.g5c9ce644c3-goog
[-- Attachment #3: 0002-swap-free-allocated-page-if-swap_read-fails.patch --]
[-- Type: text/x-diff, Size: 949 bytes --]
From 7c263ac8b9557c60c631c239cc7b863ed762098f Mon Sep 17 00:00:00 2001
From: Minchan Kim <minchan@kernel.org>
Date: Fri, 27 Jul 2018 17:17:01 +0900
Subject: [PATCH 2/2] swap: free allocated page if swap_read fails
swap_readpage could fails by -ENOMEM. In this case, we should free
allocated page instantly and bail out. There is no reason to retry.
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
mm/memory.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/memory.c b/mm/memory.c
index 7206a634270b..8a5e304ffd91 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2943,7 +2943,8 @@ int do_swap_page(struct vm_fault *vmf)
__SetPageSwapBacked(page);
set_page_private(page, entry.val);
lru_cache_add_anon(page);
- swap_readpage(page, true);
+ if (swap_readpage(page, true))
+ goto out_page;
}
} else {
page = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE,
--
2.18.0.345.g5c9ce644c3-goog
next prev parent reply other threads:[~2018-07-27 22:58 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-23 12:29 Tino Lehnig
2018-07-24 1:03 ` Minchan Kim
2018-07-24 2:53 ` Sergey Senozhatsky
2018-07-24 6:47 ` Minchan Kim
2018-07-24 7:30 ` Tino Lehnig
2018-07-25 1:32 ` Minchan Kim
2018-07-25 1:55 ` Matthew Wilcox
2018-07-25 2:16 ` Minchan Kim
2018-07-25 2:35 ` Matthew Wilcox
2018-07-25 2:51 ` Minchan Kim
2018-07-25 2:55 ` Matthew Wilcox
2018-07-25 3:02 ` Minchan Kim
2018-07-25 2:51 ` Matthew Wilcox
2018-07-25 4:07 ` Sergey Senozhatsky
2018-07-25 13:21 ` Minchan Kim
2018-07-25 15:12 ` Tino Lehnig
2018-07-26 2:03 ` Minchan Kim
2018-07-26 6:10 ` Tino Lehnig
2018-07-26 6:21 ` Minchan Kim
2018-07-26 6:34 ` Tino Lehnig
2018-07-26 10:00 ` Tino Lehnig
2018-07-26 10:30 ` Minchan Kim
2018-07-26 12:35 ` Tino Lehnig
2018-07-27 9:14 ` Minchan Kim
2018-07-27 11:00 ` Tino Lehnig
2018-07-27 12:05 ` Minchan Kim
2018-07-27 12:13 ` Tino Lehnig
2018-07-27 22:58 ` Minchan Kim [this message]
2018-07-30 6:09 ` Tino Lehnig
2018-08-02 5:15 ` 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=20180727225850.GC229060@rodete-desktop-imager.corp.google.com \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ngupta@vflare.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=tino.lehnig@contabo.de \
/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
all inboxes | Powered by JetHome®