Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase the size of uvm memory allocation #11

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kernel-open/common/inc/nv-linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ static inline void *nv_vmalloc(unsigned long size)
static inline void nv_vfree(void *ptr, NvU64 size)
{
NV_MEMDBG_REMOVE(ptr, size);
vfree(ptr);
vfree(ptr, size);
}

static inline void *nv_ioremap(NvU64 phys, NvU64 size)
Expand Down
4 changes: 2 additions & 2 deletions kernel-open/common/inc/nv-nanos.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ typedef struct nvidia_event
#define vmalloc(size) kmalloc(size, 0)
#define vzalloc(size) kzalloc(size, 0)
#define ksize(p) objcache_from_object(u64_from_pointer(p), PAGESIZE_2M)->pagesize
#define is_vmalloc_addr(p) false
#define vfree kfree
#define is_vmalloc_addr(p) (objcache_from_object(u64_from_pointer(p), PAGESIZE_2M) == INVALID_ADDRESS)
#define vfree NV_KFREE

static inline void *kmalloc(unsigned long size, int flags)
{
Expand Down
2 changes: 1 addition & 1 deletion kernel-open/nvidia-modeset/nvidia-modeset-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void nvkms_free(void *ptr, size_t size)
if (size <= KMALLOC_LIMIT) {
kfree(ptr);
} else {
vfree(ptr);
vfree(ptr, size);
}
}

Expand Down
2 changes: 1 addition & 1 deletion kernel-open/nvidia-uvm/nv-kthread-q-selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static int _multithreaded_q_kthread_function(void *args)

done:
if (q_items)
vfree(q_items);
vfree(q_items, alloc_size);

while (!kthread_should_stop())
schedule();
Expand Down
15 changes: 9 additions & 6 deletions kernel-open/nvidia-uvm/uvm_kvmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ static void *alloc_internal(size_t size, bool zero_memory)
// Make sure that (sizeof(hdr) + size) is what it should be
BUILD_BUG_ON(sizeof(uvm_vmalloc_hdr_t) != offsetof(uvm_vmalloc_hdr_t *, ptr));

assert(size <= (1 << 16));
if (size <= UVM_KMALLOC_THRESHOLD) {
if (zero_memory)
return kzalloc(size, NV_UVM_GFP_FLAGS);
Expand Down Expand Up @@ -298,16 +297,20 @@ void *__uvm_kvmalloc_zero(size_t size, const char *file, int line, const char *f

void uvm_kvfree(void *p)
{
uvm_vmalloc_hdr_t *hdr = NULL;

if (!p)
return;

if (uvm_leak_checker)
alloc_tracking_remove(p);

if (is_vmalloc_addr(p))
vfree(get_hdr(p));
else
if (is_vmalloc_addr(p)){
hdr = get_hdr(p);
vfree(hdr, hdr->alloc_size);
} else {
kfree(p);
}
}

// Handle reallocs of kmalloc-based allocations
Expand Down Expand Up @@ -335,7 +338,7 @@ static void *realloc_from_vmalloc(void *p, size_t new_size)
void *new_p;

if (new_size == 0) {
vfree(old_hdr);
vfree(old_hdr, old_hdr->alloc_size);
return ZERO_SIZE_PTR; // What krealloc returns for this case
}

Expand All @@ -349,7 +352,7 @@ static void *realloc_from_vmalloc(void *p, size_t new_size)
return NULL;

memcpy(new_p, p, min(new_size, old_hdr->alloc_size));
vfree(old_hdr);
vfree(old_hdr, old_hdr->alloc_size);
return new_p;
}

Expand Down
7 changes: 6 additions & 1 deletion kernel-open/nvidia-uvm/uvm_kvmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
#include "uvm_nanos.h"
#include "uvm_test_ioctl.h"

#ifndef _CONFIG_H_
#include <config.h>
#define _CONFIG_H_
#endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary, the config.h header is included internally by other Nanos header files.

// kmalloc is faster than vmalloc because it doesn't have to remap kernel
// virtual memory, but for that same reason it requires physically-contiguous
// memory. It also supports a native krealloc function which is missing in
Expand All @@ -41,7 +46,7 @@
//
// This is in the header so callers can use it to inform their allocation sizes
// if they wish.
#define UVM_KMALLOC_THRESHOLD infinity
#define UVM_KMALLOC_THRESHOLD (1 << MAX_MCACHE_ORDER)

NV_STATUS uvm_kvmalloc_init(void);
void uvm_kvmalloc_exit(void);
Expand Down
2 changes: 1 addition & 1 deletion kernel-open/nvidia/linux_nvswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ _nvswitch_os_free

if (is_vmalloc_addr(ptr))
{
vfree(ptr);
vfree(ptr, -1ull);
Copy link
Author

@0x5459 0x5459 Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@francescolavra I don't know how to call vfree here. Please guide me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I export the uvm_vmalloc_hdr_t structure for reference in kernel-open/nvidia/linux_nvswitch.c?

}
else
{
Expand Down