Skip to contentSkip to conversation

mm: Swap checksum

PATCH Superseded Cesar Eduardo Barros 6 participants 25 messages May 22, 2010 – May 26, 2010

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover mm: Swap checksum

Add support for checksumming the swap pages written to disk, using the same checksum as btrfs (crc32c). Since the contents of the swap do not matter after a shutdown, the checksum is kept in memory only.

Note that this code does not checksum the software suspend image.

Cesar Eduardo Barros (3):
mm/swapfile.c: better messages for swap_info_get kernel/power/swap.c: do not use end_swap_bio_read
mm: Swap checksum

 include/linux/swap.h |   31 +++++++-
 kernel/power/swap.c  |   21 +++++-
 mm/Kconfig           |   22 +++++
 mm/Makefile          |    1 +
 mm/page_io.c         |   92 ++++++++++++++++++--
 mm/swapcsum.c        |   94 +++++++++++++++++++++
 mm/swapfile.c        |  186 ++++++++++++++++++++++++++++++++++++++++--
 7 files changed, 429 insertions(+), 18 deletions(-)
 create mode 100644 mm/swapcsum.c
Signature · 9 lines
Cesar Eduardo Barros
[email protected]
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 1/3 mm/swapfile.c: better messages for swap_info_get

swap_info_get() is used for more than swap_free().

Use "swap_info_get:" instead of "swap_free:" in the error messages.

---
 mm/swapfile.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
mm/swapfile.c +4 -4
index 6cd0a8f..af7d499 100644
@@ -522,16 +522,16 @@ static struct swap_info_struct *swap_info_get(swp_entry_t entry)
 	return p;
 
 bad_free:
-	printk(KERN_ERR "swap_free: %s%08lx\n", Unused_offset, entry.val);
+	printk(KERN_ERR "swap_info_get: %s%08lx\n", Unused_offset, entry.val);
 	goto out;
 bad_offset:
-	printk(KERN_ERR "swap_free: %s%08lx\n", Bad_offset, entry.val);
+	printk(KERN_ERR "swap_info_get: %s%08lx\n", Bad_offset, entry.val);
 	goto out;
 bad_device:
-	printk(KERN_ERR "swap_free: %s%08lx\n", Unused_file, entry.val);
+	printk(KERN_ERR "swap_info_get: %s%08lx\n", Unused_file, entry.val);
 	goto out;
 bad_nofile:
-	printk(KERN_ERR "swap_free: %s%08lx\n", Bad_file, entry.val);
+	printk(KERN_ERR "swap_info_get: %s%08lx\n", Bad_file, entry.val);
 out:
 	return NULL;
 }
Signature · 7 lines
1.6.6.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

Re: [PATCH 1/3] mm/swapfile.c: better messages for swap_info_get

From: Cesar Eduardo Barros <[email protected]>
Date: Sat, May 22, 2010 at 03:08:49PM -0300

Quoted 14 lines

swap_info_get() is used for more than swap_free().

Use "swap_info_get:" instead of "swap_free:" in the error messages.

---
 mm/swapfile.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
mm/swapfile.c +0 -0
index 6cd0a8f..af7d499 100644

mm/swapfile.c static struct swap_info_struct *swap_info_get(swp_entry_t entry) · line 525

Quoted 5 lines
mm/swapfile.c +1 -1
@@ -522,16 +522,16 @@ static struct swap_info_struct *swap_info_get(swp_entry_t entry)
 	return p;
 
 bad_free:
-	printk(KERN_ERR "swap_free: %s%08lx\n", Unused_offset, entry.val);
+	printk(KERN_ERR "swap_info_get: %s%08lx\n", Unused_offset, entry.val);

Why not let the compiler do it for ya:

	printk(KERN_ERR "%s: %s%08lx\n", __func__, Unused_offset, entry.val);

?... etc.

Signature · 8 lines
Regards/Gruss,
    Boris.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

Re: [PATCH 1/3] mm/swapfile.c: better messages for swap_info_get

Em 22-05-2010 15:13, Borislav Petkov escreveu:

Quoted 9 lines

mm/swapfile.c static struct swap_info_struct *swap_info_get(swp_entry_t entry) · line 525

Quoted 6 lines
mm/swapfile.c +1 -1
@@ -522,16 +522,16 @@ static struct swap_info_struct *swap_info_get(swp_entry_t entry)
  	return p;
 
  bad_free:
-	printk(KERN_ERR "swap_free: %s%08lx\n", Unused_offset, entry.val);
+	printk(KERN_ERR "swap_info_get: %s%08lx\n", Unused_offset, entry.val);

Why not let the compiler do it for ya:

Quoted 3 lines
	printk(KERN_ERR "%s: %s%08lx\n", __func__, Unused_offset, entry.val);

?... etc.

See the third patch. This function becomes swap_info_get_unlocked(), and swap_info_get() becomes a small wrapper around it. Yet, I still want to keep printing swap_info_get: in the error message (whether it is locked or not makes no difference from the point of view of the error messsage).

Signature · 9 lines
Cesar Eduardo Barros
[email protected]
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw

PATCH 2/3 kernel/power/swap.c: do not use end_swap_bio_read

In reply to Cesar Eduardo Barros

The swap checksum patches will change end_swap_bio_read to also verify the page's checksum. This is not compatible with its use at submit() from kernel/power/swap.c.

Make kernel/power/swap.c use a private copy of end_swap_bio_read, and modify it to not say "Read-error" if the error was on a write.

---
 include/linux/swap.h |    1 -
 kernel/power/swap.c  |   21 ++++++++++++++++++++-
 mm/page_io.c         |    2 +-
 3 files changed, 21 insertions(+), 3 deletions(-)
include/linux/swap.h +0 -1
index 1f59d93..86a0d64 100644
@@ -291,7 +291,6 @@ extern void swap_unplug_io_fn(struct backing_dev_info *, struct page *);
 /* linux/mm/page_io.c */
 extern int swap_readpage(struct page *);
 extern int swap_writepage(struct page *page, struct writeback_control *wbc);
-extern void end_swap_bio_read(struct bio *bio, int err);
 
 /* linux/mm/swap_state.c */
 extern struct address_space swapper_space;
kernel/power/swap.c +20 -1
index 66824d7..7305a3f 100644
@@ -147,6 +147,25 @@ int swsusp_swap_in_use(void)
 static unsigned short root_swap = 0xffff;
 static struct block_device *resume_bdev;
 
+static void end_swap_bio(struct bio *bio, int err)
+{
+	const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
+	struct page *page = bio->bi_io_vec[0].bv_page;
+
+	if (!uptodate) {
+		SetPageError(page);
+		ClearPageUptodate(page);
+		printk(KERN_ALERT "%s-error on swap-device (%u:%u:%Lu)\n",
+				bio->bi_rw & BIO_RW ? "Write" : "Read",
+				imajor(bio->bi_bdev->bd_inode),
+				iminor(bio->bi_bdev->bd_inode),
+				(unsigned long long)bio->bi_sector);
+	} else {
+		SetPageUptodate(page);
+	}
+	unlock_page(page);
+	bio_put(bio);
+}
 /**
  *	submit - submit BIO request.
  *	@rw:	READ or WRITE.
@@ -167,7 +186,7 @@ static int submit(int rw, pgoff_t page_off, struct page *page,
 	bio = bio_alloc(__GFP_WAIT | __GFP_HIGH, 1);
 	bio->bi_sector = page_off * (PAGE_SIZE >> 9);
 	bio->bi_bdev = resume_bdev;
-	bio->bi_end_io = end_swap_bio_read;
+	bio->bi_end_io = end_swap_bio;
 
 	if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
 		printk(KERN_ERR "PM: Adding page to bio failed at %ld\n",
mm/page_io.c +1 -1
index 31a3b96..0e2d4e8 100644
@@ -66,7 +66,7 @@ static void end_swap_bio_write(struct bio *bio, int err)
 	bio_put(bio);
 }
 
-void end_swap_bio_read(struct bio *bio, int err)
+static void end_swap_bio_read(struct bio *bio, int err)
 {
 	const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
 	struct page *page = bio->bi_io_vec[0].bv_page;
Signature · 7 lines
1.6.6.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw

PATCH 3/3 mm: Swap checksum

In reply to Cesar Eduardo Barros

Add support for checksumming the swap pages written to disk, using the same checksum as btrfs (crc32c). Since the contents of the swap do not matter after a shutdown, the checksum is kept in memory only.

Note that this code does not checksum the software suspend image.

---
 include/linux/swap.h |   30 +++++++++
 mm/Kconfig           |   22 ++++++
 mm/Makefile          |    1 +
 mm/page_io.c         |   90 +++++++++++++++++++++++---
 mm/swapcsum.c        |   94 ++++++++++++++++++++++++++
 mm/swapfile.c        |  178 +++++++++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 404 insertions(+), 11 deletions(-)
 create mode 100644 mm/swapcsum.c
include/linux/swap.h +30 -0
index 86a0d64..92b24d4 100644
@@ -15,6 +15,9 @@
 struct notifier_block;
 
 struct bio;
+struct bio_vec;
+
+struct workqueue_struct;
 
 #define SWAP_FLAG_PREFER	0x8000	/* set if swap priority specified */
 #define SWAP_FLAG_PRIO_MASK	0x7fff
@@ -180,6 +183,10 @@ struct swap_info_struct {
 	struct swap_extent *curr_swap_extent;
 	struct swap_extent first_swap_extent;
 	struct block_device *bdev;	/* swap device or bdev of swap file */
+#ifdef CONFIG_SWAP_CHECKSUM
+	unsigned short *csum_count;	/* usage count of a csum page */
+	u32 **csum;			/* vmalloc'ed array of swap csums */
+#endif
 	struct file *swap_file;		/* seldom referenced */
 	unsigned int old_block_size;	/* seldom referenced */
 };
@@ -369,6 +376,29 @@ static inline void mem_cgroup_uncharge_swap(swp_entry_t ent)
 }
 #endif
 
+#ifdef CONFIG_SWAP_CHECKSUM
+/* linux/mm/swapfile.c */
+extern int swap_csum_set(swp_entry_t entry, u32 crc);
+extern int swap_csum_get(swp_entry_t entry, u32 *crc);
+
+/* linux/mm/swapcsum.c */
+extern bool noswapcsum __read_mostly;
+extern bool swap_csum_verify(struct page *page);
+extern struct workqueue_struct *swapcsum_workqueue;
+#else
+#define noswapcsum true
+#endif
+
+/* linux/mm/swapcsum.c */
+extern int _swap_csum_write(struct page *page);
+
+static inline int swap_csum_write(struct page *page)
+{
+	if (noswapcsum)
+		return 0;
+	return _swap_csum_write(page);
+}
+
 #else /* CONFIG_SWAP */
 
 #define nr_swap_pages				0L
mm/Kconfig +22 -0
index 9c61158..890faf4 100644
@@ -287,3 +287,25 @@ config NOMMU_INITIAL_TRIM_EXCESS
 	  of 1 says that all excess pages should be trimmed.
 
 	  See Documentation/nommu-mmap.txt for more information.
+
+config SWAP_CHECKSUM
+	bool "Swap checksum"
+	depends on SWAP && EXPERIMENTAL
+	select LIBCRC32C
+	default n
+	help
+	  This option enables checksumming of swap pages when saved to disk.
+
+	  Use the kernel command line options "swapcsum" to enable and
+	  "noswapcsum" to disable. The default value is configurable.
+
+	  Note that this option does not checksum the software suspend image.
+
+config SWAP_CHECKSUM_DEFAULT
+	bool "Enable swap checksum by default"
+	depends on SWAP_CHECKSUM
+	default y
+	help
+	  You can use the kernel command line options "swapcsum" to enable and
+	  "noswapcsum" to disable swap checksumming. This option controls the
+	  default value.
mm/Makefile +1 -0
index 6c2a73a..677bc43 100644
@@ -17,6 +17,7 @@ obj-y += init-mm.o
 
 obj-$(CONFIG_BOUNCE)	+= bounce.o
 obj-$(CONFIG_SWAP)	+= page_io.o swap_state.o swapfile.o thrash.o
+obj-$(CONFIG_SWAP_CHECKSUM)	+= swapcsum.o
 obj-$(CONFIG_HAS_DMA)	+= dmapool.o
 obj-$(CONFIG_HUGETLBFS)	+= hugetlb.o
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
mm/page_io.c +81 -9

138 lines not on this page · raw message

mm/swapcsum.c new file +94 -0

94 lines not on this page · raw message

mm/swapfile.c +176 -2

252 lines not on this page · raw message

Signature · 7 lines
1.6.6.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
Quoted 12 lines · Cesar Eduardo Barros

Add support for checksumming the swap pages written to disk, using the same checksum as btrfs (crc32c). Since the contents of the swap do not matter after a shutdown, the checksum is kept in memory only.

Note that this code does not checksum the software suspend image.

  #define SWAP_FLAG_PREFER	0x8000	/* set if swap priority specified */
  #define SWAP_FLAG_PRIO_MASK	0x7fff

include/linux/swap.h struct swap_info_struct { · line 192

Quoted 10 lines
include/linux/swap.h +4 -0
@@ -180,6 +183,10 @@ struct swap_info_struct {
  	struct swap_extent *curr_swap_extent;
  	struct swap_extent first_swap_extent;
  	struct block_device *bdev;	/* swap device or bdev of swap file */
+#ifdef CONFIG_SWAP_CHECKSUM
+	unsigned short *csum_count;	/* usage count of a csum page */
+	u32 **csum;			/* vmalloc'ed array of swap csums */
+#endif
  	struct file *swap_file;		/* seldom referenced */
  	unsigned int old_block_size;	/* seldom referenced */
  };

On 64-bit, we may be able to store the checksum in the pte, if the swap device is small enough.

If we take the trouble to touch the page, we may as well compare it against zero, and if so drop it instead of swapping it out.

Signature · 7 lines
error compiling committee.c: too many arguments to function

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw

Em 23-05-2010 12:19, Avi Kivity escreveu:

Quoted 2 lines

On 64-bit, we may be able to store the checksum in the pte, if the swap device is small enough.

Which pte? Correct me if I am wrong, but I do not think all pages written to the swap have exactly one pte pointing to them. And I have not looked at the shmem.c code yet, but does it even use ptes?

It might be possible (find all ptes and write the 32-bit checksum to them, do something else for shmem, have two different code paths for small/large swapfiles), but I do not know if the memory savings are worth the extra complexity (especially the need for two separate code paths).

Quoted 2 lines

If we take the trouble to touch the page, we may as well compare it against zero, and if so drop it instead of swapping it out.

The problem with this is that the page is touched deep inside the crc32c code, which might even be using hardware instructions (crc32c-intel). So we would need to read it two times to compare against zero.

One possibility could be to compare the full page against zero only if its crc is a specific value (the crc32c of a page full of zeros). This would not be too slow (we would be wasting time only when we have a very high probability of saving much more time), and not need to touch the crc32c code at all. I would only have to look at how this messes up the state tracking (i.e. how to make it track the fact that, instead of getting written out, this is now a zeroed page). Other than that, it seems a good idea.

Signature · 9 lines
Cesar Eduardo Barros
[email protected]
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#8 lore raw
Quoted 5 lines · Cesar Eduardo Barros

Em 23-05-2010 12:19, Avi Kivity escreveu:

Quoted 2 lines

On 64-bit, we may be able to store the checksum in the pte, if the swap device is small enough.

Which pte?

All of them.

Quoted 1 line

Correct me if I am wrong, but I do not think all pages written to the swap have exactly one pte pointing to them. And I have not looked at the shmem.c code yet, but does it even use ptes?

Well, the ptes need the swap address written into them, so they are already found and updated somehow. All that's needed is to update the value written to also include the checksum.

Quoted 1 line

It might be possible (find all ptes and write the 32-bit checksum to them, do something else for shmem, have two different code paths for small/large swapfiles), but I do not know if the memory savings are worth the extra complexity (especially the need for two separate code paths).

Certainly not at first, but later it may be worthwhile.

Quoted 5 lines
Quoted 3 lines

If we take the trouble to touch the page, we may as well compare it against zero, and if so drop it instead of swapping it out.

The problem with this is that the page is touched deep inside the crc32c code, which might even be using hardware instructions (crc32c-intel). So we would need to read it two times to compare against zero.

The second read is very cheap since the page is already in cache. Also, we fail early when any word is nonzero, so usually the compare exits quickly.

Quoted 2 lines

One possibility could be to compare the full page against zero only if its crc is a specific value (the crc32c of a page full of zeros). This would not be too slow (we would be wasting time only when we have a very high probability of saving much more time), and not need to touch the crc32c code at all. I would only have to look at how this messes up the state tracking (i.e. how to make it track the fact that, instead of getting written out, this is now a zeroed page).

Instead of returning a swap pte to be written to the page tables, return a zeroed pte.

Quoted 2 lines

Other than that, it seems a good idea.

Signature · 7 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw
Quoted 29 lines · Avi Kivity
Quoted 5 lines · Cesar Eduardo Barros

Em 23-05-2010 12:19, Avi Kivity escreveu:

Quoted 2 lines

On 64-bit, we may be able to store the checksum in the pte, if the swap device is small enough.

Which pte?

All of them.

Quoted 3 lines

Correct me if I am wrong, but I do not think all pages written to the swap have exactly one pte pointing to them. And I have not looked at the shmem.c code yet, but does it even use ptes?

Well, the ptes need the swap address written into them, so they are already found and updated somehow. All that's needed is to update the value written to also include the checksum.

Quoted 5 lines

It might be possible (find all ptes and write the 32-bit checksum to them, do something else for shmem, have two different code paths for small/large swapfiles), but I do not know if the memory savings are worth the extra complexity (especially the need for two separate code paths).

Certainly not at first, but later it may be worthwhile.

Quoted 4 lines
Quoted 3 lines

If we take the trouble to touch the page, we may as well compare it against zero, and if so drop it instead of swapping it out.

Quoted 8 lines
Quoted 4 lines

The problem with this is that the page is touched deep inside the crc32c code, which might even be using hardware instructions (crc32c-intel). So we would need to read it two times to compare against zero.

The second read is very cheap since the page is already in cache. Also, we fail early when any word is nonzero, so usually the compare exits quickly.

For a page being written back from pagecache to disk, or for a page being swapped out, the contents are likely cache cold and likely not to be used in future either. Therefore a crc routine for that would do well to minimise cache pollution.

Quoted 11 lines
Quoted 8 lines

One possibility could be to compare the full page against zero only if its crc is a specific value (the crc32c of a page full of zeros). This would not be too slow (we would be wasting time only when we have a very high probability of saving much more time), and not need to touch the crc32c code at all. I would only have to look at how this messes up the state tracking (i.e. how to make it track the fact that, instead of getting written out, this is now a zeroed page).

Instead of returning a swap pte to be written to the page tables, return a zeroed pte.

A pte_none pte, to be precise.

I wonder, though. If we no longer trust block devices to give the correct data back, should we provide a meta block device to do error detection? No production filesystem on Linux has checksums (well, ext4 has a few). Of the ones that add checksumming, I'd say most will not do data checksumming (and for direct IO it is not done).

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw
Quoted 4 lines · Nick Piggin

I wonder, though. If we no longer trust block devices to give the correct data back, should we provide a meta block device to do error detection?

Some block devices do provide space for end-to-end checksums. For the ones that don't, I see no efficient way of adding it (either we turn one access into two, or we have a non-power-of-two block size).

Quoted 4 lines

No production filesystem on Linux has checksums (well, ext4 has a few). Of the ones that add checksumming, I'd say most will not do data checksumming (and for direct IO it is not done).

I believe btrfs checksums direct IO. Unfortunately it has some way to go before it can be used in production.

Signature · 7 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#11 lore raw
In reply to Avi Kivity

Em 24-05-2010 03:41, Avi Kivity escreveu:

Quoted 11 lines · Cesar Eduardo Barros
Quoted 7 lines

One possibility could be to compare the full page against zero only if its crc is a specific value (the crc32c of a page full of zeros). This would not be too slow (we would be wasting time only when we have a very high probability of saving much more time), and not need to touch the crc32c code at all. I would only have to look at how this messes up the state tracking (i.e. how to make it track the fact that, instead of getting written out, this is now a zeroed page).

Instead of returning a swap pte to be written to the page tables, return a zeroed pte.

Unfortunately, at this point in the code (swap_writepage) it is not a matter of simply returning a zeroed pte; it would have to go looking for the page tables.

If I am understanding things correctly, in some situations even looking for them via the struct page I have and its rmap stuff is not enough; you could have a pte still pointing to the swap instead of pointing to the page (which when faulted would go via the swap cache to get the page).

For instance, if the page was shared between several processes, got swapped out, swapped in but accessed only by some of the processes, and in the process of being swapped out again.

Signature · 9 lines
Cesar Eduardo Barros
[email protected]
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#12 lore raw
In reply to Cesar Eduardo Barros
Quoted 5 lines · Cesar Eduardo Barros

Add support for checksumming the swap pages written to disk, using the same checksum as btrfs (crc32c). Since the contents of the swap do not matter after a shutdown, the checksum is kept in memory only.

Note that this code does not checksum the software suspend image.

We have been used swap pages without checksum.

First of all, Could you explain why you need checksum on swap pages? Do you see any problem which swap pages are broken?

I could miss your claim at old disucussion thread in LKML.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw

Em 23-05-2010 11:03, Minchan Kim escreveu:

Quoted 10 lines · Cesar Eduardo Barros
Quoted 5 lines

Add support for checksumming the swap pages written to disk, using the same checksum as btrfs (crc32c). Since the contents of the swap do not matter after a shutdown, the checksum is kept in memory only.

Note that this code does not checksum the software suspend image.

We have been used swap pages without checksum.

First of all, Could you explain why you need checksum on swap pages? Do you see any problem which swap pages are broken?

The same reason we need checksums in the filesystem.

If you use btrfs as your root filesystem, you are protected by checksums from damage in the filesystem, but not in the swap partition (which is often in the same disk, and thus as vulnerable as the filesystem). It is better to get a checksum error when swapping in than having a silently corrupted page.

If you add checksums to the swap, the only piece missing (besides the partition table and bootloader, and the first one is solved by GPT, which also has a checksum) is checksumming the software suspend image. But it has a differente read/write path and different requirements (to start with, the checksums must be written to the disk too, while for the swap they can stay in memory only).

Signature · 9 lines
Cesar Eduardo Barros
[email protected]
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#14 lore raw

Hi, Cesar.
I am not sure Cesar is first name. :)

Quoted 15 lines · Cesar Eduardo Barros

Em 23-05-2010 11:03, Minchan Kim escreveu:

Quoted 7 lines · Cesar Eduardo Barros
Quoted 5 lines

Add support for checksumming the swap pages written to disk, using the same checksum as btrfs (crc32c). Since the contents of the swap do not matter after a shutdown, the checksum is kept in memory only.

Quoted 6 lines
Quoted 1 line

Note that this code does not checksum the software suspend image.

We have been used swap pages without checksum.

First of all, Could you explain why you need checksum on swap pages? Do you see any problem which swap pages are broken?

Quoted 6 lines

The same reason we need checksums in the filesystem.

If you use btrfs as your root filesystem, you are protected by checksums from damage in the filesystem, but not in the swap partition (which is often in the same disk, and thus as vulnerable as the filesystem). It is better to get a checksum error when swapping in than having a silently corrupted page.

Do you mean "vulnerable" is other file system or block I/O operation invades swap partition and breaks data of swap?

If it is, I think it's the problem of them. so we have to fix it before merged into mainline. But I admit human being always take a mistake so that we can miss it at review time. In such case, it would be very hard bug when swap pages are broken. I haven't hear about such problem until now but it might be useful if the problem happens. (Maybe they can't notice that due to hard bug to find)

But I have a concern about breaking memory which includes crc by dangling pointer. In this case, swap block is correct but it would emit crc error.

Do you have an idea making sure memory includes crc is correct?

Before review code, let's discuss we really need this and it's useful.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#15 lore raw

Em 23-05-2010 21:09, Minchan Kim escreveu:

Quoted 2 lines

Hi, Cesar.
I am not sure Cesar is first name. :)

Yes, it is.

Quoted 9 lines · Cesar Eduardo Barros
Quoted 8 lines

Em 23-05-2010 11:03, Minchan Kim escreveu:

Quoted 4 lines

We have been used swap pages without checksum.

First of all, Could you explain why you need checksum on swap pages? Do you see any problem which swap pages are broken?

The same reason we need checksums in the filesystem.

Quoted 7 lines
Quoted 4 lines

If you use btrfs as your root filesystem, you are protected by checksums from damage in the filesystem, but not in the swap partition (which is often in the same disk, and thus as vulnerable as the filesystem). It is better to get a checksum error when swapping in than having a silently corrupted page.

Do you mean "vulnerable" is other file system or block I/O operation invades swap partition and breaks data of swap?

Vulnerable in that the same kind of hardware problems which can silently damage filesystem data in the disk can damage swap pages in the disk.

This is the reason both btrfs and zfs checksum all their data and metadata. However, the swap partition is still vulnerable (using a swap file is not a solution, since the swap code bypasses the filesystem). And silent data corruption in the swap partition could be even worse than in the filesystem - while a program might not trust a file it is reading to not be corrupted, almost all programs will trust their *memory* to not be corrupted.

The internal ECC of the disk will not save you - a quick Google search found an instance of someone with silent data corruption caused by a faulty *power supply*.[1]

And if it is silent corruption, without the checksums you will not notice it - it will just be dismissed as "oh, Firefox just crashed again" or similar (the same as bit flips on RAM without ECC).

Quoted 7 lines

If it is, I think it's the problem of them. so we have to fix it before merged into mainline. But I admit human being always take a mistake so that we can miss it at review time. In such case, it would be very hard bug when swap pages are broken. I haven't hear about such problem until now but it might be useful if the problem happens. (Maybe they can't notice that due to hard bug to find)

Quoted 5 lines

But I have a concern about breaking memory which includes crc by dangling pointer. In this case, swap block is correct but it would emit crc error.

Do you have an idea making sure memory includes crc is correct?

The swap checksum only protects the page against being silently corrupted while on the disk and at least to some degree on the I/O path between the memory and the disk. It does not protect against broken kernel-mode code writing to the wrong address, nor against broken hardware (or hardware misconfigured by broken drivers) doing DMA to wrong addresses. It also does not protect against hardware errors in the RAM itself (you have ECC memory for that).

That is, the code assumes the memory containing the checksums will not be corrupted, because if it is, you have worse problems (and the CRC error here would be a *good* thing, since it would make you notice something is not quite right).

[1] http://blogs.sun.com/elowe/entry/zfs_saves_the_day_ta

Signature · 3 lines
Cesar Eduardo Barros
[email protected]
[email protected]
#16 lore raw
Quoted 40 lines · Cesar Eduardo Barros

Em 23-05-2010 21:09, Minchan Kim escreveu:

Quoted 3 lines

Hi, Cesar.
I am not sure Cesar is first name. :)

Yes, it is.

Quoted 20 lines
Quoted 10 lines · Cesar Eduardo Barros

Em 23-05-2010 11:03, Minchan Kim escreveu:

Quoted 5 lines

We have been used swap pages without checksum.

First of all, Could you explain why you need checksum on swap pages? Do you see any problem which swap pages are broken?

The same reason we need checksums in the filesystem.

Quoted 7 lines

If you use btrfs as your root filesystem, you are protected by checksums from damage in the filesystem, but not in the swap partition (which is often
in the same disk, and thus as vulnerable as the filesystem). It is better to
get a checksum error when swapping in than having a silently corrupted page.

Quoted 2 lines

Do you mean "vulnerable" is other file system or block I/O operation invades swap partition and breaks data of swap?

Vulnerable in that the same kind of hardware problems which can silently damage filesystem data in the disk can damage swap pages in the disk.

This is the reason both btrfs and zfs checksum all their data and metadata. However, the swap partition is still vulnerable (using a swap file is not a solution, since the swap code bypasses the filesystem). And silent data corruption in the swap partition could be even worse than in the filesystem
- while a program might not trust a file it is reading to not be corrupted, almost all programs will trust their *memory* to not be corrupted.

Quoted 7 lines

The internal ECC of the disk will not save you - a quick Google search found an instance of someone with silent data corruption caused by a faulty *power supply*.[1]

And if it is silent corruption, without the checksums you will not notice it
- it will just be dismissed as "oh, Firefox just crashed again" or similar (the same as bit flips on RAM without ECC).

Thanks for kind explanation.

When I read your comment, suddenly some thought occurred to me. If we can't believe ECC of the disk, why do we separate error detection logic between file system and swap disk?

I mean it make sense that put crc detection into block layer? It can make sure any block I/O.

And what's BER of disk?
Is it usual to meet the problem?

In normal desktop, some app killed are not critical. If the application is critical, maybe app have to logic fault handling. Firefox has session restore feature and Office program has temporal save feature.

On the other hand, in server, does it designed well to use swap disk until we meet bit error of disk?

My feel is that it seem to be rather overkill.

Quoted 22 lines
Quoted 8 lines

If it is, I think it's the problem of them. so we have to fix it before merged into mainline. But I admit human being always take a mistake so that we can miss it at review time. In such case, it would be very hard bug when swap pages are broken. I haven't hear about such problem until now but it might be useful if the problem happens. (Maybe they can't notice that due to hard bug to find)

Quoted 5 lines

But I have a concern about breaking memory which includes crc by dangling pointer. In this case, swap block is correct but it would emit crc error.

Do you have an idea making sure memory includes crc is correct?

The swap checksum only protects the page against being silently corrupted while on the disk and at least to some degree on the I/O path between the memory and the disk. It does not protect against broken kernel-mode code writing to the wrong address, nor against broken hardware (or hardware misconfigured by broken drivers) doing DMA to wrong addresses. It also does not protect against hardware errors in the RAM itself (you have ECC memory for that).

Quoted 5 lines

That is, the code assumes the memory containing the checksums will not be corrupted, because if it is, you have worse problems (and the CRC error here would be a *good* thing, since it would make you notice something is not quite right).

Which is high between BER of RAM and disk?
It's a just question. :)

Quoted 8 lines

[1] http://blogs.sun.com/elowe/entry/zfs_saves_the_day_ta

--
Cesar Eduardo Barros
[email protected]
[email protected]

Signature · 2 lines
Kind regards,
Minchan Kim
#17 lore raw

Em 23-05-2010 23:05, Minchan Kim escreveu:

Quoted 9 lines · Cesar Eduardo Barros
Quoted 7 lines

The internal ECC of the disk will not save you - a quick Google search found an instance of someone with silent data corruption caused by a faulty *power supply*.[1]

And if it is silent corruption, without the checksums you will not notice it
- it will just be dismissed as "oh, Firefox just crashed again" or similar (the same as bit flips on RAM without ECC).

Quoted 6 lines

When I read your comment, suddenly some thought occurred to me. If we can't believe ECC of the disk, why do we separate error detection logic between file system and swap disk?

I mean it make sense that put crc detection into block layer? It can make sure any block I/O.

There are differences as to where the checksum will be stored.

For the filesystem (and for the software suspend image), you have to store the checksums in the disk itself, and the correct place (and ordering requirements) depends on the filesystem. Also, most filesystems do not currently have on-disk checksums.

For the swap, it is much simpler; the checksums can be stored in memory (since they do not matter after a reboot; the swap contents are simply discarded). This also gives better performance, since the checksums do not have to be separately written, and more flexibility, since the kernel can use whatever kind of checksum it wants and can store the checksum in whatever data structure it choses, without worrying about compatibility.

And, in fact, there is a CRC code in the block layer; it is CONFIG_BLK_DEV_INTEGRITY. However, it is not a generic solution; it needs some extra prerequisites (like a disk low-level formatted with sectors with >512 bytes).

Quoted 2 lines

And what's BER of disk?
Is it usual to meet the problem?

It is unusual enough that most people who meet it will not notice.

And the filesystem developers (who understand about these things more than me) seem to be trending towards adding checksums to their filesystems. The point of this patch is to meet the same level of safety as btrfs (thus the choice of crc32c, which is what btrfs uses).

Quoted 4 lines

In normal desktop, some app killed are not critical. If the application is critical, maybe app have to logic fault handling. Firefox has session restore feature and Office program has temporal save feature.

In fact, crashing is the "best" outcome here. The worst outcome is your application silently corrupting the data you then save to disk.

Quoted 2 lines

On the other hand, in server, does it designed well to use swap disk until we meet bit error of disk?

Servers are the ones which would benefit the most, as their RAM is usually very reliable (they tend to use ECC memory). Their disk subsystems, however, are also more reliable.

Desktop systems (especially "no-name" brand ones) do not gain as much, since their RAM is usually unprotected; however, they are also the ones which have better chance of having low-quality power supplies, uncommon storage media (USB flash drives as the root disk is an example), and problematic I/O subsystems.

Quoted 1 line

My feel is that it seem to be rather overkill.

Yes, it is a bit overkill, except when you are using software suspend. While the software suspend image is not protected by this patch (I am already thinking of a separate patch to add checksums to it), the swapped out pages are (software suspend uses both a memory image saved to the swap partition and the normal swapped out pages).

But you do not have to use it if you think it is overkill - I even added a kernel parameter to easily disable it.

Quoted 8 lines
Quoted 8 lines

The swap checksum only protects the page against being silently corrupted while on the disk and at least to some degree on the I/O path between the memory and the disk. It does not protect against broken kernel-mode code writing to the wrong address, nor against broken hardware (or hardware misconfigured by broken drivers) doing DMA to wrong addresses. It also does not protect against hardware errors in the RAM itself (you have ECC memory for that).

Quoted 8 lines
Quoted 5 lines

That is, the code assumes the memory containing the checksums will not be corrupted, because if it is, you have worse problems (and the CRC error here would be a *good* thing, since it would make you notice something is not quite right).

Which is high between BER of RAM and disk?
It's a just question. :)

I have no idea.

However, we can do nothing in software against RAM errors; it would kill performance too much. Against disk errors, however, we can do a lot (software RAID-1 is just one of the simplest examples).

Signature · 9 lines
Cesar Eduardo Barros
[email protected]
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#18 lore raw

Hi, Cesar.

Quoted 38 lines · Cesar Eduardo Barros

Em 23-05-2010 23:05, Minchan Kim escreveu:

Quoted 16 lines
Quoted 7 lines · Cesar Eduardo Barros

The internal ECC of the disk will not save you - a quick Google search found
an instance of someone with silent data corruption caused by a faulty *power
supply*.[1]

Quoted 5 lines

And if it is silent corruption, without the checksums you will not notice it
- it will just be dismissed as "oh, Firefox just crashed again" or similar
(the same as bit flips on RAM without ECC).

Quoted 6 lines

When I read your comment, suddenly some thought occurred to me. If we can't believe ECC of the disk, why do we separate error detection logic between file system and swap disk?

I mean it make sense that put crc detection into block layer? It can make sure any block I/O.

There are differences as to where the checksum will be stored.

For the filesystem (and for the software suspend image), you have to store the checksums in the disk itself, and the correct place (and ordering requirements) depends on the filesystem. Also, most filesystems do not currently have on-disk checksums.

For the swap, it is much simpler; the checksums can be stored in memory (since they do not matter after a reboot; the swap contents are simply discarded). This also gives better performance, since the checksums do not have to be separately written, and more flexibility, since the kernel can use whatever kind of checksum it wants and can store the checksum in whatever data structure it choses, without worrying about compatibility.

Quoted 4 lines

And, in fact, there is a CRC code in the block layer; it is CONFIG_BLK_DEV_INTEGRITY. However, it is not a generic solution; it needs some extra prerequisites (like a disk low-level formatted with sectors with

Quoted 1 line

512 bytes).

Thanks for good information.

You mean BLK_DEV_INTEGRITY has a dependency with block device driver? If you want to support checksum into suspend, At last, should we put the checksum on disk?

I mean could we extend BLK_DEV_INTEGRITY by more generic solution? As you said, in case of swap, we don't need to put checksum on disk.

If swap case, let it put the one on memory. If non-swap case, let it put checksum on disk,
I am not sure it's possible.

When we have a unreliable disk, your point is that let's solve it with (btrfs + swap) which both supports checksum. And my point is that let's solve it with (any file system + swap) which is put on block layer which supports checksum.

I am not a expert of block layer. so whatever i says might be nonsense. And any mm guys don't oppose this idea until now(except Nick). Could we regard it as ack of others?

If others don't oppose the idea, I will be not against, either.

Thanks, Cesar.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#19 lore raw

Em 25-05-2010 20:52, Minchan Kim escreveu:

Quoted 12 lines · Cesar Eduardo Barros
Quoted 4 lines

And, in fact, there is a CRC code in the block layer; it is CONFIG_BLK_DEV_INTEGRITY. However, it is not a generic solution; it needs some extra prerequisites (like a disk low-level formatted with sectors with

Quoted 1 line

512 bytes).

You mean BLK_DEV_INTEGRITY has a dependency with block device driver? If you want to support checksum into suspend, At last, should we put the checksum on disk?

I mean could we extend BLK_DEV_INTEGRITY by more generic solution? As you said, in case of swap, we don't need to put checksum on disk.

CONFIG_BLK_DEV_INTEGRITY writes the checksum to the same sector as the data. However, for that to be possible, the sector size is increased on the disk itself, from 512 bytes to 520 bytes (and not all disks can do that). It is not a generic solution. It also, as far as I can see, does nothing against the disk simply failing to write and later returning stale data, since the stale checksum would match the stale data.

See the LWN article [1] and the presentations [2] for more detail.

For suspend, the swap checksum pages would be saved together with the rest of the memory (they are in the memory, after all), and the suspend snapshot would have its own separate checksum (written directly to the disk after the image).

Quoted 8 lines

If swap case, let it put the one on memory. If non-swap case, let it put checksum on disk,
I am not sure it's possible.

When we have a unreliable disk, your point is that let's solve it with (btrfs + swap) which both supports checksum. And my point is that let's solve it with (any file system + swap) which is put on block layer which supports checksum.

A generic "checksumming block device" would be less efficient.

For the swap case, it cannot exploit the fact that its state tracking is within the swapfile code. Avi Kivity's idea of storing the checksum in otherwise wasted bits of the pte is an example of how this could be exploited in the future. In fact, the reason I did it on the swap layer (instead of interposing something in the block layer) was precisely to make it easier to enhance the state tracking in the future (and also because it felt the most natural layer to do it).

It would also complicate adding checksums to the software suspend snapshot. While normally you do not want to write the swap checksums to the disk, you do want to write them when saving the memory snapshot - which is written to the same block device. However, the checksums for the rest of the swap pages are already being saved as part of the memory snapshot (since the checksums were in the memory).

For the generic ("any file system") case, it is worse, since you actually have to write the checksum to the disk, and unlike in the software suspend case you cannot simply write them all in one pass at the end. In the worst case, you would have to write twice for each sector/page - once for the data, and once for the checksums (CONFIG_BLK_DEV_INTEGRITY completely avoids this issue since with it the checksum is together with the data in the same sector). Not to mention fun things like write amplification.

A filesystem with data checksums can write the checksum as part of its normal metadata updates (which it already has to do anyway).

A generic "checksumming block device" could be a way of "updating" a filesystem without checksums (or with only metadata checksums) to have them. However, I believe it would be more productive to add them directly to the filesystem itself. Even more since the only way I can see of doing it efficiently in a generic block layer is by using lots of filesystem-style tricks (things like a log-structured list of CRC values, dividing the device in "block groups" to keep the checksum close to the data, and so on).

[1] Block layer: integrity checking and lots of partitions

    http://lwn.net/Articles/290141/

[2] http://oss.oracle.com/projects/data-integrity/documentation/

Signature · 9 lines
Cesar Eduardo Barros
[email protected]
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#20 lore raw
Quoted 11 lines · Cesar Eduardo Barros

Em 25-05-2010 20:52, Minchan Kim escreveu:

Quoted 10 lines · Cesar Eduardo Barros
Quoted 4 lines

And, in fact, there is a CRC code in the block layer; it is CONFIG_BLK_DEV_INTEGRITY. However, it is not a generic solution; it needs some extra prerequisites (like a disk low-level formatted with sectors with

Quoted 1 line

512 bytes).

You mean BLK_DEV_INTEGRITY has a dependency with block device driver? If you want to support checksum into suspend, At last, should we put the checksum on disk?

Quoted 7 lines
Quoted 2 lines

I mean could we extend BLK_DEV_INTEGRITY by more generic solution? As you said, in case of swap, we don't need to put checksum on disk.

CONFIG_BLK_DEV_INTEGRITY writes the checksum to the same sector as the data. However, for that to be possible, the sector size is increased on the disk itself, from 512 bytes to 520 bytes (and not all disks can do that). It is not a generic solution. It also, as

It means if disk don't support 520 byte sector, CONFIG_BLK_DEV_INTEGRITY can't work? That means CONFIG_BLK_DEV_INTEGRITY depends on block device?

Quoted 3 lines

far as I can see, does nothing against the disk simply failing to write and later returning stale data, since the stale checksum would match the stale data.

Sorry. I can't understand your point.
Who makes stale data? If any layer makes data as stale, integrity is up to the layer. Maybe I am missing your point.
Could you explain more detail?

Quoted 2 lines

See the LWN article [1] and the presentations [2] for more detail.

Thanks for good information.

Quoted 17 lines

For suspend, the swap checksum pages would be saved together with the rest of the memory (they are in the memory, after all), and the suspend snapshot would have its own separate checksum (written directly to the disk after the image).

Quoted 8 lines

If swap case, let it put the one on memory. If non-swap case, let it put checksum on disk,
I am not sure it's possible.

When we have a unreliable disk, your point is that let's solve it with (btrfs + swap) which both supports checksum. And my point is that let's solve it with (any file system + swap) which is put on block layer which supports checksum.

A generic "checksumming block device" would be less efficient.

Quoted 8 lines

For the swap case, it cannot exploit the fact that its state tracking is within the swapfile code. Avi Kivity's idea of storing the checksum in otherwise wasted bits of the pte is an example of how this could be exploited in the future. In fact, the reason I did it on the swap layer (instead of interposing something in the block layer) was precisely to make it easier to enhance the state tracking in the future (and also because it felt the most natural layer to do it).

Hmm. I don't know what is the state you mentioned in future. But As view of design, I tend to agree.

Quoted 31 lines

It would also complicate adding checksums to the software suspend snapshot. While normally you do not want to write the swap checksums to the disk, you do want to write them when saving the memory snapshot - which is written to the same block device. However, the checksums for the rest of the swap pages are already being saved as part of the memory snapshot (since the checksums were in the memory).

For the generic ("any file system") case, it is worse, since you actually have to write the checksum to the disk, and unlike in the software suspend case you cannot simply write them all in one pass at the end. In the worst case, you would have to write twice for each sector/page - once for the data, and once for the checksums (CONFIG_BLK_DEV_INTEGRITY completely avoids this issue since with it the checksum is together with the data in the same sector). Not to mention fun things like write amplification.

A filesystem with data checksums can write the checksum as part of its normal metadata updates (which it already has to do anyway).

A generic "checksumming block device" could be a way of "updating" a filesystem without checksums (or with only metadata checksums) to have them. However, I believe it would be more productive to add them directly to the filesystem itself. Even more since the only way I can see of doing it efficiently in a generic block layer is by using lots of filesystem-style tricks (things like a log-structured list of CRC values, dividing the device in "block groups" to keep the checksum close to the data, and so on).

Quoted 3 lines

[1] Block layer: integrity checking and lots of partitions

    http://lwn.net/Articles/290141/

[2] http://oss.oracle.com/projects/data-integrity/documentation/

Thanks for good explanation.

I agree we don't have any method to detect disk error about swap pages. I am not sure we _really_ need it and who want it in practice(now even many of file systems don't support checksum) but it's optional feature. so if there is anyone want it, he just use it by enable.

Yes. I am not against this patch any more.
I hope when you send this patch, please, write down things discussed with me in description.

1. Why do we need it?(ie, who can use it useful?)
2. Why is CONFIG_BLK_DEV_INTEGRITY's extension bad design?

And

3. Please, Cc Jens Axboe <[email protected]>, Hugh Dickins <[email protected]>

Thanks for good reply on my long bore question.

Quoted 5 lines
Signature · 4 lines
-- 
Cesar Eduardo Barros
[email protected]
[email protected]
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#21 lore raw
Quoted 9 lines · Minchan Kim
Quoted 3 lines · Cesar Eduardo Barros

far as I can see, does nothing against the disk simply failing to write and later returning stale data, since the stale checksum would match the stale data.

Sorry. I can't understand your point.
Who makes stale data? If any layer makes data as stale, integrity is up to the layer. Maybe I am missing your point.
Could you explain more detail?

I'm pretty sure that what Cesar meant was that the following could happen:

1) Write block 11983 on the disk, checksum 34FE9B72.
(... time passes.. maybe weeks)
2) Attempt to write block 11983 on disk with checksum AE9F3581. The write fails due to a power failure or something.
(... more time passes...)
3) Read block 11983, get back data with checksum 34FE9B72. Checksum matches, and there's no indication that the write in (2) ever failed. The program proceeds thinking it's just read back the most recently written data, when in fact it's just read an older version of that block. Problems can ensue if the data just read is now out of sync with *other* blocks of data - instant data corruption.

To be fair, we currently have the "read a stale block" problem after crashes already. The issue is that BLK_DEV_INTEGRITY can't provide a solution here, but most users will form a mental image that it *is* in fact giving them that guarantee. The resulting mismatch between reality and expectations cannot end well.

#22 lore raw
Quoted 13 lines · On Thu, May 27, 2010 at 6:28 AM, <[email protected]> wrote:
Quoted 9 lines · Minchan Kim
Quoted 3 lines · Cesar Eduardo Barros

far as I can see, does nothing against the disk simply failing to write and later returning stale data, since the stale checksum would match the stale data.

Sorry. I can't understand your point.
Who makes stale data? If any layer makes data as stale, integrity is up to the layer. Maybe I am missing your point.
Could you explain more detail?

I'm pretty sure that what Cesar meant was that the following could happen:

Quoted 11 lines

1) Write block 11983 on the disk, checksum 34FE9B72.
(... time passes.. maybe weeks)
2) Attempt to write block 11983 on disk with checksum AE9F3581. The write fails due to a power failure or something.
(... more time passes...)
3) Read block 11983, get back data with checksum 34FE9B72. Checksum matches, and there's no indication that the write in (2) ever failed. The program proceeds thinking it's just read back the most recently written data, when in fact it's just read an older version of that block. Problems can ensue if the data just read is now out of sync with *other* blocks of data - instant data corruption.

Oh, doesn't normal disk support atomicity of sector write?
I have been thought disk must support atomicity of sector write at least.

AFAIK, other device(ex, nand device by FTL) supports atomicity of sector write.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#23 lore raw

Em 26-05-2010 19:45, Minchan Kim escreveu:

Quoted 26 lines · On Thu, May 27, 2010 at 6:28 AM,<[email protected]> wrote:
Quoted 13 lines · Minchan Kim
Quoted 9 lines · Cesar Eduardo Barros
Quoted 3 lines

far as I can see, does nothing against the disk simply failing to write and later returning stale data, since the stale checksum would match the stale data.

Sorry. I can't understand your point.
Who makes stale data? If any layer makes data as stale, integrity is up to the layer. Maybe I am missing your point.
Could you explain more detail?

I'm pretty sure that what Cesar meant was that the following could happen:

Quoted 11 lines

1) Write block 11983 on the disk, checksum 34FE9B72.
(... time passes.. maybe weeks)
2) Attempt to write block 11983 on disk with checksum AE9F3581. The write fails due to a power failure or something.
(... more time passes...)
3) Read block 11983, get back data with checksum 34FE9B72. Checksum matches, and there's no indication that the write in (2) ever failed. The program proceeds thinking it's just read back the most recently written data, when in fact it's just read an older version of that block. Problems can ensue if the data just read is now out of sync with *other* blocks of data - instant data corruption.

Quoted 2 lines

Oh, doesn't normal disk support atomicity of sector write?
I have been thought disk must support atomicity of sector write at least.

It is called a "high fly write" (a write where the disk head was flying too high and the data did not get written at all). There are other causes than high fly writes for this, of course, but the symptom is the same: whatever you were trying to write was not written at all, and the old contents are still there.

The write is still atomic: it either did happen completely or did not happen at all (in this case, it did not happen at all). You *can* have a partial write (with a well-timed power loss, for instance), but the disk's own ECC will detect this as a corrupted sector and return an error on read.

Signature · 9 lines
Cesar Eduardo Barros
[email protected]
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#24 lore raw
Quoted 38 lines · Cesar Eduardo Barros

Em 26-05-2010 19:45, Minchan Kim escreveu:

Quoted 37 lines · On Thu, May 27, 2010 at 6:28 AM,<[email protected]>  wrote:
Quoted 34 lines · Minchan Kim
Quoted 7 lines · Cesar Eduardo Barros
Quoted 4 lines

far as I can see, does nothing against the disk simply failing to write and later returning stale data, since the stale checksum would match the stale data.

Quoted 5 lines

Sorry. I can't understand your point.
Who makes stale data? If any layer makes data as stale, integrity is up to
the layer. Maybe I am missing your point.
Could you explain more detail?

I'm pretty sure that what Cesar meant was that the following could happen:

1) Write block 11983 on the disk, checksum 34FE9B72.
(... time passes.. maybe weeks)
2) Attempt to write block 11983 on disk with checksum AE9F3581. The write fails
due to a power failure or something.
(... more time passes...)
3) Read block 11983, get back data with checksum 34FE9B72. Checksum matches,
and there's no indication that the write in (2) ever failed. The program proceeds thinking it's just read back the most recently written data, when in
fact it's just read an older version of that block. Problems can ensue if the
data just read is now out of sync with *other* blocks of data - instant data
corruption.

Quoted 8 lines
Quoted 2 lines

Oh, doesn't normal disk support atomicity of sector write?
I have been thought disk must support atomicity of sector write at least.

It is called a "high fly write" (a write where the disk head was flying too high and the data did not get written at all). There are other causes than high fly writes for this, of course, but the symptom is the same: whatever you were trying to write was not written at all, and the old contents are still there.

It means that disk return _success_ even though data isn't written at all on disk?

Quoted 5 lines

The write is still atomic: it either did happen completely or did not happen at all (in this case, it did not happen at all). You *can* have a partial write (with a well-timed power loss, for instance), but the disk's own ECC will detect this as a corrupted sector and return an error on read.

Yes. still disk support atomicity as I expect.
Thanks.

Quoted 6 lines

--
Cesar Eduardo Barros
[email protected]
[email protected]

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>