mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Minchan Kim <minchan@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: [RFC][PATCH] zram: try harder to store user data on compression error
Date: Thu, 18 May 2017 11:17:14 +0900	[thread overview]
Message-ID: <20170518021714.3229-1-sergey.senozhatsky@gmail.com> (raw)

__zram_bvec_write() overwrites the existing compressed object only when
it successfully compresses a new one. When zram_compress() fails, we
propagate the error, but never touch the old object, so we keep the old
data for that particular page and all reads that could hit that index
later will read stale data. This can cause problems. By example,

- Overwriting a file

     over-write block 1 aaa->xxx OK
     over-write block 2 bbb->yyy OK
     over-write block 3 ccc->zzz error << the block still has 'ccc' data.

- Now, reading the file

     read block 1 xxx OK
     read block 2 yyy OK
     read block 3 ccc OK   << we should not return OK here. Because
                              "xxxyyyccc" is not correct file.

As a solution, when we fail to compress a new page (S/W or H/W compressor
error, depending on particular setup) try to store the page uncompressed
(PAGE_SIZE-ed zs_pool object). This, at least, lets us to return valid
and correct data:
     read block 1  xxx - OK, compressed
     read block 2  yyy - OK, compressed
     read block 3  zzz - OK, uncompressed (because compressing back-end
                                           returned an error)

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
 drivers/block/zram/zram_drv.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 372602c7da49..ba3e36bbb619 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -723,10 +723,12 @@ static int zram_compress(struct zram *zram, struct zcomp_strm **zstrm,
 	kunmap_atomic(src);
 
 	if (unlikely(ret)) {
+		/*
+		 * We failed to compress the page, try to store it
+		 * uncompressed (if there is enough memory).
+		 */
 		pr_err("Compression failed! err=%d\n", ret);
-		if (entry)
-			zram_entry_free(zram, entry);
-		return ret;
+		comp_len = PAGE_SIZE;
 	}
 
 	if (unlikely(comp_len > max_zpage_size))
-- 
2.13.0

                 reply	other threads:[~2017-05-18  2:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20170518021714.3229-1-sergey.senozhatsky@gmail.com \
    --to=sergey.senozhatsky.work@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=sergey.senozhatsky@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

all inboxes | Powered by JetHome®