Commit Graph

34 Commits

Author SHA1 Message Date
Nitin Gupta 3c8bb7aab9 staging: Allow sharing xvmalloc for zram and zcache
Both zram and zcache use xvmalloc allocator. If xvmalloc
is compiled separately for both of them, we will get linker
error if they are both selected as "built-in". We can also
get linker error regarding missing xvmalloc symbols if zram
is not built.

So, we now compile xvmalloc separately and export its symbols
which are then used by both of zram and zcache.

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Acked-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-23 14:02:56 -08:00
Jerome Marchand 6642a67c55 Staging: zram: initialize device on first read
Currently the device is initialized when first write is done to the
device. Any read attempt before the first write would fail, including
"hidden" read the user may not know about (as for example if he tries
to write a partial block).

This patch initializes the device on first request, whether read or
write.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-18 13:26:12 -08:00
Greg Kroah-Hartman 80ae3fa5d6 Merge 2.6.38-rc5 into staging-next
This is to resolve a merge conflict with:
	drivers/staging/zram/zram_drv.c
as pointed out by Stephen Rothwell

Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Robert Jennings <rcj@linux.vnet.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-18 12:11:27 -08:00
Nitin Gupta 5414e557fc staging: zram: fix data corruption issue
In zram_read() and zram_write() we were not incrementing the
index number and thus were reading/writing values from/to
incorrect sectors on zram disk, resulting in data corruption.

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-09 11:39:51 -08:00
Robert Jennings 939b3f0b14 zram/xvmalloc: combine duplicate block delete code
This patch eliminates duplicate code.  The remove_block_head function
is a special case of remove_block which can be contained in remove_block
without confusion.

The portion of code in remove_block_head which was noted as "DEBUG ONLY"
is now mandatory.  Doing this provides consistent management of the double
linked list of blocks under a freelist and makes this consolidation
of delete block code safe.  The first and last blocks will have NULL
pointers in their previous and next page pointers respectively.

Additionally, any time a block is removed from a free list the next and
previous pointers will be set to NULL to avoid misuse outside xvmalloc.

Signed-off-by: Robert Jennings <rcj@linux.vnet.ibm.com>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Acked-by: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-04 13:29:12 -08:00
Robert Jennings 2787f959d6 zram: Return zero'd pages on new reads
Currently zram will do nothing to the page in the bvec when that page
has not been previously written.  This allows random data to leak to
user space.  That can be seen by doing the following:

 ## Load the module and create a 256Mb zram device called /dev/zram0
 # modprobe zram
 # echo $((256*1024*1024)) > /sys/class/block/zram0/disksize

 ## Initialize the device by writing zero to the first block
 # dd if=/dev/zero of=/dev/zram0 bs=512 count=1

 ## Read ~256Mb of memory into a file and hope for something interesting
 # dd if=/dev/zram0 of=file

This patch will treat an unwritten page as a zero-filled page.  If a
page is read before a write has occurred the data returned is all 0's.

Signed-off-by: Robert Jennings <rcj@linux.vnet.ibm.com>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-04 13:29:12 -08:00
Robert Jennings 3770096585 zram/xvmalloc: Close 32byte hole on 64bit CPUs
By swapping the total_pages statistic with the lock we close a
hole in the structure for 64-bit CPUs.

Signed-off-by: Robert Jennings <rcj@linux.vnet.ibm.com>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-04 13:29:11 -08:00
Robert Jennings b1f5b81ebe zram/xvmalloc: create CONFIG_ZRAM_DEBUG for debug code
Add a debug config flag to enable debug printk output and future
debug code.

Signed-off-by: Robert Jennings <rcj@linux.vnet.ibm.com>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-04 13:29:11 -08:00
Robert Jennings e3f201b541 zram/xvmalloc: free bit block insertion optimization
This change is in a conditional block which is entered only when there is
an existing data block on the freelist where the insert has taken place.

The new block is pushed onto the freelist stack and this conditional block
is updating links in the prior stack head to point to the new stack head.
After this conditional block the first-/second-level indices are updated
to indicate that there is a free block at this location.

This patch adds an immediate return from the conditional block to avoid
setting bits again to indicate a free block on this freelist. The bits
would already be set because there was an existing free block on this
freelist.

Signed-off-by: Robert Jennings <rcj@linux.vnet.ibm.com>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-04 13:29:11 -08:00
Robert Jennings 7b19b8d45b zram: Prevent overflow in logical block size
On a 64K page kernel, the value PAGE_SIZE passed to
blk_queue_logical_block_size would overflow the logical block size
argument (resulting in setting it to 0).

This patch sets the logical block size to 4096, using a new
ZRAM_LOGICAL_BLOCK_SIZE constant.

Signed-off-by: Robert Jennings <rcj@linux.vnet.ibm.com>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-04 13:29:11 -08:00
Robert Jennings f3bc232c2e zram/vmalloc: Correct tunings to enable use with 64K pages
xvmalloc will not currently function with 64K pages.  Newly allocated
pages will be inserted at an offset beyond the end of the first-level
index.  This tuning is needed to properly size the allocator for 64K
pages.

The default 3 byte shift results in a second level list size which can not
be indexed using the 64 bits of the flbitmap in the xv_pool structure.
The shift must increase to 4 bytes between second level list entries to
fit the size of the first level bitmap.

Here are a few statistics for structure sizes on 32- and 64-bit CPUs
with 4KB and 64KB page sizes.

bits_per_long              32        64        64
page_size               4,096     4,096    65,535
xv_align                    4         8         8
fl_delta                    3         3         4
num_free_lists            508       508     4,094
xv_pool size            4,144b    8,216b   66,040b
per object overhead        32        64        64
zram struct 0.5GB disk    512KB    1024KB      64KB

This patch maintains the current tunings for 4K pages, adds an optimal
sizing for 64K pages and adds a safe tuning for any other page sizes.

Signed-off-by: Robert Jennings <rcj@linux.vnet.ibm.com>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-02-04 13:29:10 -08:00
Nitin Gupta 7d7854b4da Staging: zram: simplify zram_make_request
zram_read() and zram_write() always return zero, so make them return
void to simplify the code.

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Acked-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-01-25 18:15:24 +08:00
Justin P. Mattock c4586c1685 staging:zram:xvmalloc.c Fix a typo.
Not exactly sure if this is a typo or not, due to my search
results comming up with not that many hits. Either its dereferenceable
or dereferencable from the two I choose the later. if it's wrong let me know
and I'll resend.

Signed-off-by: Justin P. Mattock <justinmattock@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-01-20 16:08:23 -08:00
Jerome Marchand 1aa326640d Staging: zram: make zram_read return a bio error if the device is not initialized
Make zram_read() return a bio error if the device is not initialized
instead of pretending nothing happened.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Acked-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-01-20 16:07:00 -08:00
Jerome Marchand f2da98739d Staging: zram: round up the disk size provided by user
Currently disksize_store() round down the disk size provided by user.
This is probably not what one would expect, so round up instead.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Acked-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-01-20 16:06:18 -08:00
Jerome Marchand 2b15287346 Staging: zram: make ZRAM depends on SYSFS
We can not configure zram device without sysfs anyway, so make zram
depends on it.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Acked-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-01-20 16:06:18 -08:00
Linus Torvalds 949f6711b8 Merge branch 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
* 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6: (510 commits)
  staging: speakup: fix failure handling
  staging: usbip: remove double giveback of URB
  Staging: batman-adv: Remove batman-adv from staging
  Staging: hv: Use only one txf buffer per channel and kmalloc/GFP_KERNEL on initialize
  staging: hv: remove unneeded osd_schedule_callback
  staging: hv: convert channel_mgmt.c to not call osd_schedule_callback
  staging: hv: convert vmbus_on_msg_dpc to not call osd_schedule_callback
  staging: brcm80211: Fix WL_<type> logging macros
  Staging: IIO: DDS: AD9833 / AD9834 driver
  Staging: IIO: dds.h convenience macros
  Staging: IIO: Direct digital synthesis abi documentation
  staging: brcm80211: Convert ETHER_TYPE_802_1X to ETH_P_PAE
  staging: brcm80211: Remove unused ETHER_TYPE_<foo> #defines
  staging: brcm80211: Remove ETHER_HDR_LEN, use ETH_HLEN
  staging: brcm80211: Convert ETHER_ADDR_LEN to ETH_ALEN
  staging: brcm80211: Convert ETHER_IS<FOO> to is_<foo>_ether_addr
  staging: brcm80211: Remove unused ether_<foo> #defines and struct
  staging: brcm80211: Convert ETHER_IS_MULTI to is_multicast_ether_addr
  staging: brcm80211: Remove unused #defines ETHER_<foo>_LOCALADDR
  Staging: comedi: Fix checkpatch.pl issues in file s526.c
  ...

Fix up trivial conflict in drivers/video/udlfb.c
2011-01-10 16:04:53 -08:00
Nitin Gupta e983dc2428 Revert "Staging: zram: work around oops due to startup ordering snafu"
This reverts commit 7e24cce38a because it
was never appropriate for mainline.

Do not check for init flag before starting I/O - zram module is unusable
without this fix.

The oops mentioned in the reverted commit message was actually a problem
only with the zram version as present in project's own repository where
we allocate struct zram_stats_cpu upon device initialization.  OTOH, In
mainline/staging version of zram, we allocate struct stats upfront, so
this oops cannot happen in mainline version.

Checking for init_done flag in zram_make_request() results in a *no-op*
for any I/O operation since we simply always return success.  This flag
is actually set when the first write occurs on a zram disk which
triggers its initialization.

Bug report: https://bugzilla.kernel.org/show_bug.cgi?id=25722

Reported-by: Dennis Jansen <dennis.jansen@web.de>
Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Cc: Anton Blanchard <anton@samba.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-12-30 12:07:22 -08:00
Peter Huewe be3e5b3246 staging/zram: Fix sparse warning 'Using plain integer as NULL pointer'
This patch fixes the warning generated by sparse: "Using plain integer
as NULL pointer" by replacing the offending 0s with NULL.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-12-08 14:31:02 -08:00
Greg Kroah-Hartman ea3398a1ae Staging: Merge 2.6.37-rc5 into staging-next
This was done to handle a number of conflicts in the batman-adv
and winbond drivers properly.  It also now allows us to fix up the sysfs
attributes properly that were not in the .37 release due to them being
only in this tree at the time.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-12-07 10:47:56 -08:00
Greg Kroah-Hartman a3d1310701 Staging: zram: fix up my fixup for some sysfs attribute permissions
They should be writable by root, not readable.
Doh, stupid me with the wrong flags.

Reported-by: Jonathan Cameron <jic23@cam.ac.uk>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-11-18 11:27:19 -08:00
Greg Kroah-Hartman 0281b490dd Staging: zram: fix up some sysfs attribute permissions
They should not be writable by any user

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-11-16 11:22:43 -08:00
Joe Perches 5b84cc7810 staging: Use vzalloc
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-11-09 16:34:01 -08:00
Greg Kroah-Hartman e4c5bf8e3d Merge 'staging-next' to Linus's tree
This merges the staging-next tree to Linus's tree and resolves
some conflicts that were present due to changes in other trees that were
affected by files here.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-10-28 09:44:56 -07:00
Tracey Dent 597716d9e2 Staging: zram: Makefile: replace the use of <module>-objs with <module>-y
Changed <module>-objs to <module>-y in Makefile.

Signed-off-by: Tracey Dent <tdent48227@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-10-08 07:23:41 -07:00
Anton Blanchard 7e24cce38a Staging: zram: work around oops due to startup ordering snafu
I'm getting an oops when running mkfs on zram:

NIP [d0000000030e0340] .zram_inc_stat+0x58/0x84 [zram]
[c00000006d58f720] [d0000000030e091c] .zram_make_request+0xa8/0x6a0 [zram]
[c00000006d58f840] [c00000000035795c] .generic_make_request+0x390/0x434
[c00000006d58f950] [c000000000357b14] .submit_bio+0x114/0x140
[c00000006d58fa20] [c000000000361778] .blkdev_issue_discard+0x1ac/0x250
[c00000006d58fb10] [c000000000361f68] .blkdev_ioctl+0x358/0x7fc
[c00000006d58fbd0] [c0000000001c1c1c] .block_ioctl+0x6c/0x90
[c00000006d58fc70] [c0000000001984c4] .do_vfs_ioctl+0x660/0x6d4
[c00000006d58fd70] [c0000000001985a0] .SyS_ioctl+0x68/0xb0

Since disksize no longer starts as 0 it looks like we can call
zram_make_request before the device has been initialised. The patch below
fixes the immediate problem but this would go away if we move the
initialisation function elsewhere (as suggested in another thread).

Signed-off-by: Anton Blanchard <anton@samba.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-10-05 11:44:29 -07:00
Shahar Havivi 273ad8dcef Staging: zram: free device memory when init fails
Signed-off-by: Shahar Havivi <shaharh@redhat.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-09-03 17:37:15 -07:00
Nitin Gupta 9b9913d80b Staging: zram: Update zram documentation
Update zram documentation to reflect transition form
ioctl to sysfs interface.

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-08-31 15:36:36 -07:00
Nitin Gupta 484875adbc Staging: zram: Remove need for explicit device initialization
Currently, the user has to explicitly write a positive value to
initstate sysfs node before the device can be used. This event
triggers allocation of per-device metadata like memory pool,
table array and so on.

We do not pre-initialize all zram devices since the 'table' array,
mapping disk blocks to compressed chunks, takes considerable amount
of memory (8 bytes per page). So, pre-initializing all devices will
be quite wasteful if only few or none of the devices are actually
used.

This explicit device initialization from user is an odd requirement and
can be easily avoided. We now initialize the device when first write is
done to the device.

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-08-31 15:36:36 -07:00
Nitin Gupta 33863c21e6 Staging: zram: Replace ioctls with sysfs interface
Creates per-device sysfs nodes in /sys/block/zram<id>/
Currently following stats are exported:
 - disksize
 - num_reads
 - num_writes
 - invalid_io
 - zero_pages
 - orig_data_size
 - compr_data_size
 - mem_used_total

By default, disksize is set to 0. So, to start using
a zram device, fist write a disksize value and then
initialize device by writing any positive value to
initstate. For example:

        # initialize /dev/zram0 with 50MB disksize
        echo 50*1024*1024 | bc > /sys/block/zram0/disksize
        echo 1 > /sys/block/zram0/initstate

When done using a disk, issue reset to free its memory
by writing any positive value to reset node:

        echo 1 > /sys/block/zram0/reset

This change also obviates the need for 'rzscontrol' utility.

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Acked-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-08-31 15:33:54 -07:00
Randy Dunlap 8946a08648 Staging: zram: fix build errors, depends on BLOCK
Fix 49 zram build errors in one swoop.  Examples:

drivers/staging/zram/zram_drv.c:225: error: dereferencing pointer to incomplete type
drivers/staging/zram/zram_drv.c:226: error: implicit declaration of function 'bio_for_each_segment'
drivers/staging/zram/zram_drv.c:226: error: expected ';' before '{' token
drivers/staging/zram/zram_drv.c:281: error: implicit declaration of function 'bio_endio'
drivers/staging/zram/zram_drv.c:285: error: implicit declaration of function 'bio_io_error'
drivers/staging/zram/zram_drv.c:545: error: implicit declaration of function 'set_capacity'
drivers/staging/zram/zram_drv.c:548: error: implicit declaration of function 'queue_flag_set_unlocked'
drivers/staging/zram/zram_drv.c:548: error: 'QUEUE_FLAG_NONROT' undeclared (first use in this function)
drivers/staging/zram/zram_drv.c:548: error: dereferencing pointer to incomplete type

Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-06-24 14:15:07 -07:00
Nitin Gupta 00ac9ba01d Staging: zram: Rename ramzswap to zram in documentation
Related changes:
 - Included example to show usage as generic
(non-swap) disk with ext4 filesystem.
 - Renamed rzscontrol to zramconfig to match
with new device naming.

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-18 12:50:30 -07:00
Nitin Gupta f1e3cfff4d Staging: zram: Rename ramzswap to zram in code
Automated renames in code:
 - rzs* -> zram*
 - RZS* -> ZRAM*
 - ramzswap* -> zram*

Manual changes:
 - Edited comments/messages mentioning "swap"

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-18 12:49:48 -07:00
Nitin Gupta 16a4bfb9e9 Staging: Rename ramzswap files to zram
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-18 12:46:42 -07:00