Skip to content

Commit

Permalink
Update kmem to latest macOS
Browse files Browse the repository at this point in the history
Fix the memory pressure thread to set the pressure
variable, as well as relax them on timeout (no pressure)

Update abdos.c to actually allocate abd from the expected
cache, so reaping works.

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Oct 31, 2023
1 parent c2e9403 commit 538d466
Show file tree
Hide file tree
Showing 12 changed files with 1,216 additions and 624 deletions.
5 changes: 5 additions & 0 deletions include/os/windows/spl/sys/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@

#endif

// cdefs.h
#ifndef __DECONST
#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
#endif

extern void _Noreturn panic(const char *fmt, ...);


Expand Down
4 changes: 2 additions & 2 deletions include/os/windows/spl/sys/kmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extern uint64_t physmem;

void *zfs_kmem_alloc(size_t size, int kmflags);
void *zfs_kmem_zalloc(size_t size, int kmflags);
void zfs_kmem_free(void *buf, size_t size);
void zfs_kmem_free(const void *buf, size_t size);

void spl_kmem_init(uint64_t);
void spl_kmem_thread_init();
Expand Down Expand Up @@ -128,7 +128,7 @@ kmem_cache_t *kmem_cache_create(char *name, size_t bufsize, size_t align,
void *_private, struct vmem *vmp, int cflags);
void kmem_cache_destroy(kmem_cache_t *cache);
void *kmem_cache_alloc(kmem_cache_t *cache, int flags);
void kmem_cache_free(kmem_cache_t *cache, void *buf);
void kmem_cache_free(kmem_cache_t *cache, const void *buf);
void kmem_cache_free_to_slab(kmem_cache_t *cache, void *buf);
void kmem_cache_reap_now(kmem_cache_t *cache);
void kmem_depot_ws_zero(kmem_cache_t *cache);
Expand Down
3 changes: 2 additions & 1 deletion include/os/windows/spl/sys/kmem_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ struct kmem_cache {
uint64_t cache_bufmax; /* max buffers ever */
uint64_t cache_bufslab; /* buffers free in slab layer */
uint64_t cache_reap; /* cache reaps */
kmutex_t cache_reap_lock; /* one reap at a time */
uint64_t cache_rescale; /* hash table rescales */
uint64_t cache_lookup_depth; /* hash lookup depth */
uint64_t cache_depot_contention; /* mutex contention count */
Expand Down Expand Up @@ -464,7 +465,7 @@ typedef struct kmem_log_header {
kmutex_t lh_lock;
char *lh_base;
uint32_t *lh_free;
uint32_t lh_chunksize;
size_t lh_chunksize;
uint32_t lh_nchunks;
uint32_t lh_head;
uint32_t lh_tail;
Expand Down
3 changes: 2 additions & 1 deletion include/os/windows/spl/sys/seg_kmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern "C" {
extern uint64_t segkmem_total_allocated;

extern vmem_t *abd_arena;
extern vmem_t *abd_subpage_arena;

/*
* segkmem page vnodes
Expand All @@ -54,7 +55,7 @@ extern vmem_t *abd_arena;
#endif /* __sparc */

void *segkmem_alloc(vmem_t *, size_t, int);
extern void segkmem_free(vmem_t *, void *, size_t);
extern void segkmem_free(vmem_t *, const void *, size_t);
extern void kernelheap_init(void);
extern void kernelheap_fini(void);
extern void *segkmem_zio_alloc(vmem_t *, size_t, int);
Expand Down
6 changes: 3 additions & 3 deletions include/os/windows/spl/sys/vmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct vmem;

typedef struct vmem vmem_t;
typedef void *(vmem_alloc_t)(vmem_t *, size_t, int);
typedef void (vmem_free_t)(vmem_t *, void *, size_t);
typedef void (vmem_free_t)(vmem_t *, const void *, size_t);

/*
* Alternate import style; the requested size is passed in a pointer,
Expand All @@ -151,8 +151,8 @@ extern void vmem_destroy(vmem_t *);
extern void *vmem_alloc_impl(vmem_t *, size_t, int);
extern void *vmem_xalloc(vmem_t *, size_t, size_t, size_t, size_t,
void *, void *, int);
extern void vmem_free_impl(vmem_t *, void *, size_t);
extern void vmem_xfree(vmem_t *, void *, size_t);
extern void vmem_free_impl(vmem_t *, const void *, size_t);
extern void vmem_xfree(vmem_t *, const void *, size_t);
extern void *vmem_add(vmem_t *, void *, size_t, int);
extern int vmem_contains(vmem_t *, void *, size_t);
extern void vmem_walk(vmem_t *, int, void (*)(void *, void *, size_t),
Expand Down
2 changes: 2 additions & 0 deletions include/os/windows/spl/sys/vmem_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ typedef struct vmem_kstat {
kstat_named_t vk_parent_free; /* called the source free function */
kstat_named_t vk_threads_waiting; /* threads in cv_wait in vmem */
kstat_named_t vk_excess; /* count of retained excess imports */
kstat_named_t vk_lowest_stack; /* least remaining stack seen */
kstat_named_t vk_async_stack_calls; /* times allocated off-thread */
} vmem_kstat_t;

struct vmem {
Expand Down
Loading

0 comments on commit 538d466

Please sign in to comment.