Skip to content

swap on flash support

Richard Purdie linux-mtd lkml 1 version NAK

Status from this message: NAK, Even though we can use it. it's out of Spec. It's reason I don't add

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest9 patches 6 repliesNAK

Patches in v1

#Subject and filesSizeRepliesApplied
1/9swap: Have swap_free() mark pages with errors as badinclude/linux/swap.h kernel/power/swsusp.c mm/memory.c +4 more+26 -180 replies
2/9swap: Add try_to_unuse_page_entry()include/linux/rmap.h include/linux/swap.h mm/rmap.c +1 more+63 -10 replies
3/9swap: Catch pages with errors and mark as badmm/page_io.c mm/vmscan.c+9 -30 replies
4/9swap: Simplify shmem_unuse() usage [optional]mm/shmem.c mm/swapfile.c+7 -282 replies
5/9mtd: Allow dynamic major/minor number for mtd block devicesdrivers/mtd/mtd_blkdevs.c+4 -10 replies
6/9mtd: Add a 'block unused' ioctl call to provide hints to block driversblock/ioctl.c include/linux/fs.h include/linux/swap.h +1 more+15 -21 reply
7/9mtd: Fix number of free oob spaces in onenand driverdrivers/mtd/onenand/onenand_base.c+3 -31 reply
8/9mtd: Allow mtd block device drivers to have a custom ioctl functiondrivers/mtd/mtd_blkdevs.c include/linux/mtd/blktrans.h+16 -32 replies
9/9mtd: Add swaponflash block driverdrivers/mtd/Kconfig drivers/mtd/Makefile drivers/mtd/mtdswap.c+1195 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/9] swap on flash support

The following patch series adds a device driver which allows an mtd flash device to be used as a swap device. Since flash needs wear levelling, a normal block device can't be used directly.

In order to work efficiently, some changes to other parts of Linux are needed. Most of these changes are hopefully useful in their own right.

The better handling of swap write failure patches have been seen before. There were no real problems identified last time these were posted and they haven't changed since then, I'm just posting them in context now. The resulting patches are not particularly invasive and I hopefully these could be considered for merging.

The most controversial part of the series is probably the mark unused ioctl. Whilst frowned upon, I used an ioctl as it seemed the only way to get a message from the swap layer to the block driver. I'm open to suggestions for a better way to do this. Knowing which blocks it can reuse is extremely useful to the swaponflash driver and makes it much more efficient.

Its possible to think of races where a block is marked as used but a write is still in the bio queue and ends up containing data when it could really be empty. The false positive of a block being marked empty when its not shouldn't (and mustn't) happen though. The ioctl should be thought of as a hint to the block device rather than an absolute.

The swaponflash driver itself has several features to try and extend the lifetime of any flash chip being used as swap. There is some detail at the top of the file but in summary, it creates a block device (mtdswapX) which already contains the swap header and can then be directly used by swapon. Devices appearing as swap must be explicitly referenced on the commandline or as a module parameter.

A simple map is then used to keep track of blocks in use by the kernel and the placement of these blocks on flash is determined by the driver. These blocks can be moved around for wear levelling as needed, transparent to the kernel's swap layer. If we run out of space (too many bad blocks), we return a write error to the kernel which is why bad swap handling needs improvement. I've tested the pathological case where all swap goes bad and the swap device size tends to zero and the kernel survives!

One simplification it takes advantage of is that no state need be stored over a reboot and it assumes it can start wear levelling from scratch since it would have tried to keep wear level before in any previous runs.

Richard