kernel: vm: reduce stack usage in swap_init_post_modules().

* avoid a struct copy in PartitionScorer.
* reduce stack usage in get_mount_point().

Change-Id: I60a3161ba39e9a50eaae972b7ff5b4a26d6292fa
This commit is contained in:
Jérôme Duval 2018-04-07 11:36:22 +02:00 committed by Rene Gollent
parent 1fb59be1d1
commit 03df8bfcf2

View File

@ -27,6 +27,7 @@
#include <FindDirectory.h> #include <FindDirectory.h>
#include <KernelExport.h> #include <KernelExport.h>
#include <NodeMonitor.h> #include <NodeMonitor.h>
#include <StackOrHeapArray.h>
#include <arch_config.h> #include <arch_config.h>
#include <boot_device.h> #include <boot_device.h>
@ -1238,7 +1239,7 @@ public:
private: private:
int32 fBestScore; int32 fBestScore;
VolumeInfo fVolumeInfo; VolumeInfo& fVolumeInfo;
}; };
@ -1248,14 +1249,24 @@ get_mount_point(KPartition* partition, KPath* mountPoint)
if (!mountPoint || !partition->ContainsFileSystem()) if (!mountPoint || !partition->ContainsFileSystem())
return B_BAD_VALUE; return B_BAD_VALUE;
int nameLength = 0;
const char* volumeName = partition->ContentName(); const char* volumeName = partition->ContentName();
if (!volumeName || strlen(volumeName) == 0) if (volumeName != NULL)
nameLength = strlen(volumeName);
if (nameLength == 0) {
volumeName = partition->Name(); volumeName = partition->Name();
if (!volumeName || strlen(volumeName) == 0) if (volumeName != NULL)
volumeName = "unnamed volume"; nameLength = strlen(volumeName);
if (nameLength == 0) {
volumeName = "unnamed volume";
nameLength = strlen(volumeName);
}
}
char basePath[B_PATH_NAME_LENGTH]; BStackOrHeapArray<char, 128> basePath(nameLength + 1);
int32 len = snprintf(basePath, sizeof(basePath), "/%s", volumeName); if (!basePath.IsValid())
return B_NO_MEMORY;
int32 len = snprintf(basePath, nameLength + 1, "/%s", volumeName);
for (int32 i = 1; i < len; i++) for (int32 i = 1; i < len; i++)
if (basePath[i] == '/') if (basePath[i] == '/')
basePath[i] = '-'; basePath[i] = '-';
@ -1267,7 +1278,7 @@ get_mount_point(KPartition* partition, KPath* mountPoint)
for (int i = 1; ; i++) { for (int i = 1; ; i++) {
if (stat(path, &dummy) != 0) if (stat(path, &dummy) != 0)
break; break;
snprintf(path, pathLen, "%s%d", basePath, i); snprintf(path, pathLen, "%s%d", (char*)basePath, i);
} }
mountPoint->UnlockBuffer(); mountPoint->UnlockBuffer();