Skip to content

Commit 6cfb9c7

Browse files
authored
Merge pull request #33 from DataCoreSoftware/zfs_total_memory_limit
zfs_total_memory_limit registry change
2 parents 438dac8 + 8231bf6 commit 6cfb9c7

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

ZFSin/driver.c

+24-7
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING pRe
6363

6464
/* Setup print buffer, since we print from SPL */
6565
initDbgCircularBuffer();
66-
66+
6767
spl_start();
6868

6969
kstat_osx_init(pRegistryPath);
@@ -147,6 +147,8 @@ void spl_update_version(HANDLE h, PUNICODE_STRING pRegistryPath)
147147
}
148148
}
149149

150+
extern boolean_t spl_minimal_physmem_p_logic(void);
151+
extern uint64_t total_memory;
150152
int spl_check_assign_types(kstat_named_t *kold, PKEY_VALUE_FULL_INFORMATION regBuffer)
151153
{
152154

@@ -162,12 +164,27 @@ int spl_check_assign_types(kstat_named_t *kold, PKEY_VALUE_FULL_INFORMATION regB
162164
return 0;
163165
}
164166
uint64_t newvalue = *(uint64_t *)((uint8_t *)regBuffer + regBuffer->DataOffset);
165-
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "%s: kstat '%s': 0x%llx -> 0x%llx\n", __func__,
166-
kold->name,
167-
kold->value.ui64,
168-
newvalue
169-
));
170-
kold->value.ui64 = newvalue;
167+
if (strcmp(kold->name, "zfs_total_memory_limit") == 0) {
168+
if (newvalue >= 2ULL * 1024ULL * 1024ULL * 1024ULL && newvalue < total_memory) {
169+
dprintf("%s:%d: total_memory 0x%llx -> %llx\n", __func__, __LINE__, total_memory, MIN(newvalue, total_memory));
170+
total_memory = MIN(newvalue, total_memory);
171+
physmem = total_memory / PAGE_SIZE;
172+
spl_minimal_physmem_p_logic();
173+
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "%s: kstat '%s': 0x%llx -> 0x%llx\n", __func__,
174+
kold->name,
175+
kold->value.ui64,
176+
newvalue));
177+
kold->value.ui64 = newvalue;
178+
} else {
179+
dprintf("%s:%d: Invalid value 0x%llx for %s, value should be >=0x%llx and <=0x%llx\n", __func__, __LINE__, newvalue, kold->name, (2ULL * 1024ULL * 1024ULL * 1024ULL), total_memory);
180+
}
181+
} else {
182+
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "%s: kstat '%s': 0x%llx -> 0x%llx\n", __func__,
183+
kold->name,
184+
kold->value.ui64,
185+
newvalue));
186+
kold->value.ui64 = newvalue;
187+
}
171188
return 1;
172189
}
173190

ZFSin/spl/module/spl/spl-kmem.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3358,7 +3358,7 @@ kmem_cache_stat(kmem_cache_t *cp, char *name)
33583358

33593359
// TRUE if we have more than a critical minimum of memory
33603360
// used in arc_memory_throttle; if FALSE, we throttle
3361-
static inline boolean_t
3361+
boolean_t
33623362
spl_minimal_physmem_p_logic()
33633363
{
33643364
// Are we using more than ZFS has?

ZFSin/zfs/include/sys/kstat_windows.h

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ typedef struct osx_kstat {
154154
kstat_named_t zfs_vdev_initialize_value;
155155
kstat_named_t zfs_autoimport_disable;
156156
kstat_named_t metaslab_unload_delay;
157+
kstat_named_t zfs_total_memory_limit;
157158
} osx_kstat_t;
158159

159160

ZFSin/zfs/module/zfs/zfs_kstat_windows.c

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ osx_kstat_t osx_kstat = {
184184
{ "zfs_vdev_initialize_value", KSTAT_DATA_UINT64 },
185185
{ "zfs_autoimport_disable", KSTAT_DATA_UINT64 },
186186
{ "metaslab_unload_delay", KSTAT_DATA_UINT64 },
187+
{ "zfs_total_memory_limit", KSTAT_DATA_UINT64 },
187188
};
188189

189190

0 commit comments

Comments
 (0)