summaryrefslogtreecommitdiff
path: root/drivers/staging/ramzswap/ramzswap_drv.c
AgeCommit message (Collapse)AuthorFilesLines
2010-06-18Staging: Rename ramzswap files to zramNitin Gupta1-805/+0
Related changes: - Modify revelant Kconfig and Makefile accordingly. - Change include filenames in code. - Remove dependency on CONFIG_SWAP in Kconfig as zram usage is no longer limited to swap disks. Signed-off-by: Nitin Gupta <ngupta@vflare.org> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-06-18Staging: ramzswap: Support generic I/O requestsNitin Gupta1-179/+147
Currently, ramzwap devices (/dev/ramzswapX) can only be used as swap disks since it was hard-coded to consider only the first request in bio vector. Now, we iterate over all the segments in an incoming bio which allows us to handle all kinds of I/O requests. ramzswap devices can still handle PAGE_SIZE aligned and multiple of PAGE_SIZE sized I/O requests only. To ensure that we get always get such requests only, we set following request_queue attributes to PAGE_SIZE: - physical_block_size - logical_block_size - io_min - io_opt Note: physical and logical block sizes were already set equal to PAGE_SIZE and that seems to be sufficient to get PAGE_SIZE aligned I/O. Since we are no longer limited to handling swap requests only, the next few patches rename ramzswap to zram. So, the devices will then be called /dev/zram{0, 1, 2, ...} Usage/Examples: 1) Use as /tmp storage - mkfs.ext4 /dev/zram0 - mount /dev/zram0 /tmp 2) Use as swap: - mkswap /dev/zram0 - swapon /dev/zram0 -p 10 # give highest priority to zram0 Performance: - I/O benchamark done with 'dd' command. Details can be found here: http://code.google.com/p/compcache/wiki/zramperf Summary: - Maximum read speed (approx): - ram disk: 1200 MB/sec - zram disk: 600 MB/sec - Maximum write speed (approx): - ram disk: 500 MB/sec - zram disk: 160 MB/sec Issues: - Double caching: We can potentially waste memory by having two copies of a page -- one in page cache (uncompress) and second in the device memory (compressed). However, during reclaim, clean page cache pages are quickly freed, so this does not seem to be a big problem. - Stale data: Not all filesystems support issuing 'discard' requests to underlying block devices. So, if such filesystems are used over zram devices, we can accumulate lot of stale data in memory. Even for filesystems to do support discard (example, ext4), we need to see how effective it is. - Scalability: There is only one (per-device) de/compression buffer stats. This can lead to significant contention, especially when used for generic (non-swap) purposes. Signed-off-by: Nitin Gupta <ngupta@vflare.org> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-05-18Staging: ramzswap: Handler for swap slot free callbackNitin Gupta1-9/+13
Install handler for swap_slot_free_notify callback which is called when a swap slot is no longer used. This handler immediately frees memory allocated corresponding to the given swap slot. Signed-off-by: Nitin Gupta <ngupta@vflare.org> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Acked-by: Nigel Cunningham <nigel@tuxonice.net> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Reviewed-by: Minchan Kim <minchan.kim@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-05-14Staging: ramzswap: Remove backing swap supportNitin Gupta1-627/+18
Currently, each ramzswap device can be assigned a separate 'backing swap' file/partition. The ramzswap driver forwards swap I/O requests to this backing swap whenever an incompressible page is found. This feature adds nearly 700 lines of code and it also duplicates much of the swapon() functionality (for example, finding swap extents and so on). Removing this code makes the driver much simpler and should help its transition from staging to stable drivers area (drivers/block/). Similar functionality may be implemented if we can implement migrating pages across swap devices but the details have not yet been worked out. Support for _partitions_ as backing swap could be retained as it requires a few lines of code only. This part can be re-introduced later if above swap migration method turns out to be infeasible. More cleanups and code comments will be added soon. Signed-off-by: Nitin Gupta <ngupta@vflare.org> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-03-30include cleanup: Update gfp.h and slab.h includes to prepare for breaking ↵Tejun Heo1-0/+1
implicit slab.h inclusion from percpu.h percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-03Staging: ramzswap: Update copyright noticeNitin Gupta1-1/+1
Update copyright notice. Signed-off-by: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-03-03Staging: ramzswap: Handle case for invalid backing swapNitin Gupta1-5/+11
Currently, we crash (issue BUG_ON) if backing swap disk size is zero. This can happen is user specified an extended partition or simply a bad disk as backing swap. A crash is really an unpleasant surprise to user for such trivial problems. Now, we check for this condition and simply fail device initialization if this is the case. Additional cleanups: * use static for all functions * remove extra newline between functions * memset backing_swap_name to NULL on device reset Signed-off-by: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-03-03Staging: ramzswap: Remove redundant check for zero pageNitin Gupta1-10/+5
ramzswap_free_page() already handles the case for zero filled pages. So, remove redundant logic for the same in ramzswap_write(). Signed-off-by: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-03-03Staging: ramzswap: Return proper error code on device create failureNitin Gupta1-16/+28
Currently, we return 0 if create_device() fails and 1 otherwise. Now, proper error code is returned from create_device() and the same is propagated as module error code from ramzswap_init(). Also added some cleanups for ramzswap_init(), improving function structure. Signed-off-by: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-03-03Staging: ramzswap: Set block size to PAGE_SIZENitin Gupta1-0/+4
ramzswap block size needs to be set equal to PAGE_SIZE to avoid receiving any unaligned block I/O requests (happens due to readahead logic during swapon). These unaligned accesses produce unnecessary I/O errors, scaring users. Signed-off-by: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-03-03Staging: ramzswap: Flush block device before resetNitin Gupta1-3/+8
Make sure we flush block device before freeing all metadata during reset ioctl. Signed-off-by: Nitin Gupta <ngupta@vflar.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-03-03Staging: ramzswap: Use lock for 64-bit statsNitin Gupta1-28/+30
64-bit stats corruption was observed when ramzswap was used on SMP systems. To prevent this, use separate spinlock to protect these stats. Also, replace stat_*() with rzs_stat*() to avoid possible conflict with core kernel code. Eventually, these will be converted to per-cpu counters if this driver finds use on large scale systems and this locking is found to affect scalability. Signed-off-by: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-03-03Staging: ramzswap: Free memory when create_device is failedMinchan Kim1-8/+13
If create_device is failed, it can't free gendisk and request_queue of preceding devices. It cause memory leak. This patch fixes it. Signed-off-by: Minchan Kim <minchan.kim@gmail.com> Acked-by: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-03-03Staging: ramzswap: Minor spelling fixesC yp1-2/+2
Also removed an extra semicolon. Signed-off-by: Cyp <cyp561@gmail.com> Cc: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-03-03Staging: ramzswap: remove unused #include <linux/version.h>Huang Weiyi1-1/+0
Remove unused #include <linux/version.h>('s) in drivers/staging/ramzswap/ramzswap_drv.c Signed-off-by: Huang Weiyi <weiyi.huang@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-23Staging: ramzswap: remove ARM specific d-cache hackNitin Gupta1-25/+3
Remove d-cache hack in ramzswap driver that was needed to workaround a bug in ARM version of update_mmu_cache() which caused stale data in d-cache to be transferred to userspace. This bug was fixed by git commit: 787b2faadc4356b6c2c71feb42fb944fece9a12f This also brings down one entry in TODO file. Signed-off-by: Nitin Gupta <ngupta@vflare.org> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-11Staging: virtual block device driver (ramzswap)Nitin Gupta1-0/+1435
Creates RAM based block devices (/dev/ramzswapX) which can be used (only) as swap disks. Pages swapped to these are compressed and stored in memory itself. The module is called ramzswap.ko. It depends on: - xvmalloc memory allocator (compiled with this driver) - lzo_compress.ko - lzo_decompress.ko See ramzswap.txt for usage details. Signed-off-by: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>