I'm working in a c program(I can rewrite in java easily) and I thought if I use swap to increase ram it could run smoothly. But I don't know how to call the swap file/partition. Could I do it on c or java? And can I ask if the user, on the installation, if he wants to create a swap file?
-
3What? It's part of the OS virtual memory subsystem. It's 'already on'. It's transparent to user code. – ThingyWotsit Apr 03 '17 at 15:00
-
1@ThingyWotsit yes, but it's only turned on if the system RAM is full, I was wondering if there's a way to turn it on by default – Strule Apr 03 '17 at 15:02
-
In Java, you simply pass an argument to increase memory allocated to the JVM: http://stackoverflow.com/questions/1565388/increase-heap-size-in-java – Jacob G. Apr 03 '17 at 15:02
-
3Java doesn't allow you to manipulate memory that way. You can specify how much you allocate to the JVM; the rest is handled by the JVM and the operating system. – duffymo Apr 03 '17 at 15:03
-
2If every program could change system settings that easily, everything will break very quickly. This is the OS domain, it decides what to allocate to a user-mode program. – Eugene Sh. Apr 03 '17 at 15:18
1 Answers
But I don't know how to call the swap file/partition. Could I do it on c or java?
Inasmuch as C and Java programs can execute external system commands and can make system calls (via JNI, in the Java case), you could, in principle, do this. This sort of thing surely requires privilege, however, so it generally cannot be done on the authority of ordinary users.
And can I ask if the user, on the installation, if he wants to create a swap file?
In principle, yes, you could do that. Where the program is being installed by a system administrator, you might even be able to rely on having sufficient privilege to act on a positive response.
But you shouldn't. This is the domain and responsibility of the system administrator, and no sysadmin I know would welcome a program's installer trying -- or even offering -- to muck with the system's virtual memory configuration. Furthermore, it is questionable whether your installer could count on successfully following through on such an offer if it were accepted, for you need sufficient unallocated disk space to create a swap partition, and sufficient free, possibly contiguous, disk space for a swap file.
Instead, document your program's minimum and ideal memory requirements. You could consider checking at install time whether the system satisfies those requirements, but your responsibility as software provider ends there, and this is not an area where it would be appropriate or welcome for you to go beyond your responsibility.

- 160,171
- 8
- 81
- 157