perf(storage): opt-in skip of Steam's space reservation on the second library

Steam reserves every file's full size before downloading. On a portable SD card
the app reaches through Android's FUSE layer, fallocate is rejected and the
reservation can take tens of minutes for a large game, with nothing downloaded.

A new experimental setting (Steam > storage, off by default) makes the session
preload answer plain fallocate/posix_fallocate requests on the selected library
with success and leave the file untouched, so Steam goes straight to the
download. Hole punching and other fallocate modes still pass through, as does
every other device. A full card shows up as a disk write error during the
download instead of up front. Storage diagnostics behave as before and log the
skipped calls.
This commit is contained in:
The412Banner committed 2026-10-06 15:35:35 -04:00
1 parent 1e877fa602
commit 40461caf4a
7 files changed
+83 -18

No files matched your search

@@ -327,6 +327,7 @@ class MainActivity : ComponentActivity() {
private var renderer by mutableStateOf("vulkan")
private var gameStorage by mutableStateOf("")
private var storageDiagnostics by mutableStateOf(false)
private var skipPreallocation by mutableStateOf(false)
private var storageOptions by mutableStateOf<List<Pair<String, String>>>(emptyList())
private val pickGameStorage = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
if (r.resultCode == RESULT_OK) InAppFilePicker.pickedPath(r.data)?.let { path -> setGameStorage(path, GameStorage.labelFor(this, path)) }
@@ -1154,6 +1155,7 @@ class MainActivity : ComponentActivity() {
gameStorage = if (mode == SessionService.MODE_STEAM) gameStorage else null,
storageOptions = storageOptions,
storageDiagnostics = mode == SessionService.MODE_STEAM && storageDiagnostics,
skipPreallocation = mode == SessionService.MODE_STEAM && skipPreallocation,
fexPreset = if (mode == SessionService.MODE_STEAM) fexPreset else null,
forceSsbs = forceSsbs,
syncBackend = if (mode == SessionService.MODE_STEAM) SessionPrefs.syncBackendOf(fastSync, fsyncFirst, syncFallback) else null,
@@ -1227,6 +1229,10 @@ class MainActivity : ComponentActivity() {
SessionPrefs.setStorageDiagnosticsEnabled(this, on)
storageDiagnostics = on
},
onSkipPreallocation = { on ->
SessionPrefs.setSkipLibraryPreallocation(this, on)
skipPreallocation = on
},
onFexPreset = { id -> SessionPrefs.setFexPreset(this, id); fexPreset = id },
onForceSsbs = { on -> SessionPrefs.setForceSsbs(this, on); forceSsbs = on },
onSyncBackend = { id ->
@@ -1378,6 +1384,7 @@ class MainActivity : ComponentActivity() {
renderer = SessionPrefs.desktopRenderer(this)
gameStorage = SessionPrefs.gameStorage(this)
storageDiagnostics = SessionPrefs.storageDiagnosticsEnabled(this)
skipPreallocation = SessionPrefs.skipLibraryPreallocation(this)
settingsMode = mode
// The page opens at once, on what was last read; the slow part (driver files, a walk of the
// added-games folders, the storage volumes) lands while it animates in.
@@ -177,6 +177,7 @@ object DeviceReport {
SessionPrefs.GAME_STORAGE_OFF -> "internal only"
else -> g
})
k("Skip space reservation", SessionPrefs.skipLibraryPreallocation(context))
h("Android process limits")
k("Phantom proc monitor", PhantomProcessLimit.reportValue(PhantomProcessLimit.read(context)))
@@ -467,6 +467,14 @@ object SessionPrefs {
prefs(context).edit().putBoolean("storageDiagnostics", on).apply()
}
/** Experimental: Steam's space reservation on the second library reports success untouched. */
fun skipLibraryPreallocation(context: Context): Boolean =
prefs(context).getBoolean("skipLibraryPreallocation", false)
fun setSkipLibraryPreallocation(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("skipLibraryPreallocation", on).apply()
}
// ── Per-mode display ────────────────────────────────────────────────────────────────────
/**
@@ -826,6 +826,20 @@ class SessionService : Service() {
} else {
Log.i(TAG, "game storage: internal only")
}
// guest already has the session command at this point. These go with the `env -i`
// assignments so they reach the Steam process instead of becoming script args.
val storageEnv = ArrayList<String>()
val skipLibrary = storageDiagnosticLibrary
if (SessionState.mode == MODE_STEAM && skipLibrary != null && SessionPrefs.skipLibraryPreallocation(this)) {
val device = runCatching { android.system.Os.stat(skipLibrary.absolutePath).st_dev }.getOrNull()
if (device != null) {
storageEnv.add("BL_STORAGE_DEVICE=$device")
storageEnv.add("BL_STORAGE_PREALLOCATE_SKIP=1")
Log.i(TAG, "game storage: Steam's space reservation on the second library is skipped")
} else {
Log.w(TAG, "game storage: library could not be identified; space reservation not skipped")
}
}
if (SessionState.mode == MODE_STEAM && SessionPrefs.storageDiagnosticsEnabled(this)) {
val target = storageDiagnosticLibrary ?: File(LinuxRuntime.rootDir(this), "root/.local/share/Steam")
val device = StorageDiagnostics.writeSnapshot(
@@ -836,16 +850,18 @@ class SessionService : Service() {
} ?: false,
)
if (device != null) {
// guest already has the session command at this point. Put these with the `env -i`
// assignments so they reach the Steam process instead of becoming script args.
val envAt = guest.indexOf(LinuxRuntime.SESSION_SCRIPT).takeIf { it >= 0 } ?: guest.size
guest.add(envAt, "BL_STORAGE_DIAGNOSTICS=1")
guest.add(envAt + 1, "BL_STORAGE_DEVICE=$device")
guest.add(envAt + 2, "BL_STORAGE_LOG=${File(sessionDir, "storage.log").absolutePath}")
// Both observe the same library, so a device the skip already set is the same one.
if (storageEnv.none { it.startsWith("BL_STORAGE_DEVICE=") }) storageEnv.add("BL_STORAGE_DEVICE=$device")
storageEnv.add("BL_STORAGE_DIAGNOSTICS=1")
storageEnv.add("BL_STORAGE_LOG=${File(sessionDir, "storage.log").absolutePath}")
} else {
Log.w(TAG, "storage diagnostics: selected library could not be identified; metadata snapshot only")
}
}
if (storageEnv.isNotEmpty()) {
val envAt = guest.indexOf(LinuxRuntime.SESSION_SCRIPT).takeIf { it >= 0 } ?: guest.size
guest.addAll(envAt, storageEnv)
}
// The user's own games folder (the Steam cog's "Added games"), bound at a fixed place so
// the shortcuts the app writes point somewhere whatever storage the folder is on.
for (root in com.droiddeck.launcher.frontend.AddedGames.roots(this)) {
@@ -69,6 +69,8 @@ class ModeSettings(
val storageOptions: List<Pair<String, String>> = emptyList(),
/** Steam only: record allocation and sampled storage timings in the next session's Share logs. */
val storageDiagnostics: Boolean = false,
/** Steam only: report Steam's space reservation on the second library as done (experimental). */
val skipPreallocation: Boolean = false,
val fexPreset: String? = null,
/** Steam only: Force SSBS for Proton games (SessionPrefs.forceSsbs). */
val forceSsbs: Boolean = false,
@@ -130,6 +132,7 @@ class ModeSettingsActions(
val onGameStorage: (path: String, label: String) -> Unit = { _, _ -> },
val onPickGameStorageFolder: () -> Unit = {},
val onStorageDiagnostics: (Boolean) -> Unit = {},
val onSkipPreallocation: (Boolean) -> Unit = {},
val onFexPreset: (String) -> Unit = {},
val onForceSsbs: (Boolean) -> Unit = {},
val onSyncBackend: (String) -> Unit = {},
@@ -505,6 +508,11 @@ fun ModeSettingsPage(s: ModeSettings, a: ModeSettingsActions) {
stringResource(R.string.mode_storage_diagnostics_hint), s.storageDiagnostics,
onChange = a.onStorageDiagnostics,
)
ToggleRow(
host, "skipPreallocation", stringResource(R.string.mode_skip_preallocation),
stringResource(R.string.mode_skip_preallocation_hint), s.skipPreallocation,
onChange = a.onSkipPreallocation,
)
}
if (!steam && tab == ModeSettingsTab.DISPLAY && s.renderer != null) SettingsGroup(stringResource(R.string.mode_renderer)) {
ChoiceRow(
+2
View File
@@ -358,6 +358,8 @@
<string name="mode_second_library">Second library</string>
<string name="mode_storage_note">Games that stream assets from SD or shared storage may stutter.</string>
<string name="mode_storage_diagnostics">Storage diagnostics</string>
<string name="mode_skip_preallocation">Skip space reservation (experimental)</string>
<string name="mode_skip_preallocation_hint">Steam starts downloading to the game storage folder straight away instead of reserving every file\'s space first, which can take many minutes on an SD card. If the card fills up, the download stops with a disk write error. Applies next session.</string>
<string name="mode_storage_diagnostics_hint">Record allocation results and sampled storage timings in Share logs. May slow installs while enabled. Applies next session.</string>
<string name="mode_choose_folder">Choose a folder…</string>
<string name="mode_renderer">Renderer</string>