Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7d358c2 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "mm: swap: Add randomization check for swapon/off calls"

parents 3d6fd426 9ac5f3cf
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -3800,6 +3800,17 @@
				(that will set all pages holding image data
				during restoration read-only).

	noswap_randomize
			Kernel uses random disk offsets to help with wear-levelling
			of SSD devices, while saving the hibernation snapshot image to
			disk. Use this parameter to disable this feature for SSD
			devices in scenarios when, such randomization is addressed at
			the firmware level and hibenration image is not re-generated
			frequently.
			(Useful for improving hibernation resume time as snapshot pages
			are available in disk serially and can be read in bigger chunks
			without seeking)

	retain_initrd	[RAM] Keep initrd memory after extraction

	rfkill.default_state=
+1 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ struct hd_struct {
#define GENHD_FL_NATIVE_CAPACITY		128
#define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE	256
#define GENHD_FL_NO_PART_SCAN			512
#define GENHD_FL_NO_RANDOMIZE			1024

enum {
	DISK_EVENT_MEDIA_CHANGE			= 1 << 0, /* media changed */
+12 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
 */
static bool clean_pages_on_read;
static bool clean_pages_on_decompress;
static bool noswap_randomize;

/*
 *	The swap map is a data structure used for keeping track of each page
@@ -1533,6 +1534,9 @@ int swsusp_check(void)
					    FMODE_READ, NULL);
	if (!IS_ERR(hib_resume_bdev)) {
		set_blocksize(hib_resume_bdev, PAGE_SIZE);
		if (noswap_randomize)
			hib_resume_bdev->bd_disk->flags |=
					GENHD_FL_NO_RANDOMIZE;
		clear_page(swsusp_header);
		error = hib_submit_io(REQ_OP_READ, 0,
					swsusp_resume_block,
@@ -1620,3 +1624,11 @@ static int swsusp_header_init(void)
}

core_initcall(swsusp_header_init);

static int __init noswap_randomize_setup(char *str)
{
	noswap_randomize = true;
	return 1;
}

__setup("noswap_randomize", noswap_randomize_setup);
+4 −2
Original line number Diff line number Diff line
@@ -2645,7 +2645,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
	if (p->flags & SWP_CONTINUED)
		free_swap_count_continuations(p);

	if (!p->bdev || !blk_queue_nonrot(bdev_get_queue(p->bdev)))
	if (!p->bdev || (p->bdev->bd_disk->flags & GENHD_FL_NO_RANDOMIZE) ||
			!blk_queue_nonrot(bdev_get_queue(p->bdev)))
		atomic_dec(&nr_rotate_swap);

	mutex_lock(&swapon_mutex);
@@ -3220,7 +3221,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
	if (bdi_cap_synchronous_io(inode_to_bdi(inode)))
		p->flags |= SWP_SYNCHRONOUS_IO;

	if (p->bdev && blk_queue_nonrot(bdev_get_queue(p->bdev))) {
	if (p->bdev && !(p->bdev->bd_disk->flags & GENHD_FL_NO_RANDOMIZE) &&
				blk_queue_nonrot(bdev_get_queue(p->bdev))) {
		int cpu;
		unsigned long ci, nr_cluster;