How to temporarily stop synchronizing of dirty data with disk, instead just keeping it in memory.
Clarification: I want to sync it later.
If you want to prevent disk writes as much as possible, you can do this with Laptop Mode. One of the features of laptop mode is to allow a disk to spin down and to prevent the kernel from writing to it until memory gets full or until a timeout occurs (or until the disk needs to spin up in order to read data from it). See also the Arch Wiki. You'll presumably want to enable only disk spindown and not other features, and set
LM_SECONDS_BEFORE_SYNC to a large value in the configuration.
There's also noflushd, which does this specific job (and is a lot easier to configure than Laptop Mode since it doesn't do anything else). I've used it happily in the past, but it's been unmaintained for a while so I don't know if it still works on modern systems.
Note that preventing disk writes isn't a defense against writing, it's a power saving (and noise reduction) measure. It's difficult to control exactly what might cause the disk to spin up, for example some data that needs to be read because it got wiped from the cache, and at that point the disk will be written to.
If the reason you want to prevent disk writes is that you don't want the disk content to be modified under any circumstances, you need different tools. You can do that at the filesystem level with a union mount. Mount the disk read-only, create a directory on a
tmpfs filesystem, and create a union mount of the two where the tmpfs directory is the read-write branch. See Mount a filesystem read-only, and redirect writes to RAM? for several examples of union mount software on Linux. This is how live installations of Linux with a persistence option work: the live installation is read-only, but the persistent data partition is union-mounted on top of it.
You can also achieve a similar effect at the block device level, though I can't think of a compelling reason to prefer this solution. See GNU/Linux: overlay block device / stackable block device Alternatively, if the disk data is on an LVM volume or on a ZFS filesystem, you can make a snapshot to keep a copy of the data at a point in time while continuing to write to a logically separate device.
sounds like a job for eatmydata ( http://www.makelinux.net/man/1/E/eatmydata )
in debian, try something like
apt-get install eatmydata;
printf "\nLD_PRELOAD=libeatmydata.so" >> /etc/ld.so.preload