sbrk

Undefined reference to _sbrk

▼魔方 西西 提交于 2019-12-02 20:52:53
I am having a problem with _sbrk. In a link phase of compilation i use below comand to link my objects and i get undefined reference to _sbrk. arm-none-eabi-ld -static -T linkerscript.ld -o exe timer_example.o /home/ziga/projects/cs_lite/arm-none-eabi/lib/libc.a /home/ziga/projects/cs_lite/lib/gcc/arm-none-eabi/4.5.1/libgcc.a I am compiling for arm926ej-s and in ARM mode so i think i have chosen the right multilib (libc.a and libgcc.a) which is located in folder home/ziga/projects/cs_lite/arm-none-eabi/lib/. I have been searching internet for _sbrk function and it is some sort of a memory

What is the aligment requirements for sys_brk

空扰寡人 提交于 2019-12-02 02:10:39
I'm using sys_brk syscall to dynamically allocate memory in the heap. I noticed that when acquiring the current break location I usually get value similar to this: mov rax, 0x0C mov rdi, 0x00 syscall results in rax 0x401000 The value usually 512 bytes aligned. So I would like to ask is there some alignment requirements on the break value? Or we can misalign it the way we want? The kernel does track the break with byte granularity. But don't use it directly for small allocations if you care at all about performance. There was some discussion in comments about the kernel rounding the break to a

How do I free memory obtained by sbrk()?

半世苍凉 提交于 2019-11-30 17:28:49
I have a custom allocator function which uses sbrk() to obtain memory. How do I release this memory when it's no longer needed? Is there a function equivalent to free() for malloc() ? or do I have to use brk() to set the end of the data segment ? You need to use brk or sbrk again to shrink. In the end the only way you have to modify the amount of memory(apart from mmap like syscalls), is to increase or decrease the heap, so you move it up with sbrk or brk and you move it down with brk or sbrk with a negative increment. Don't use brk and sbrk . It's pretty much impossible to know which library

Does malloc() use brk() or mmap()?

末鹿安然 提交于 2019-11-30 08:32:53
c code: // program break mechanism // TLPI exercise 7-1 #include <stdio.h> #include <stdlib.h> void program_break_test() { printf("%10p\n", sbrk(0)); char *bl = malloc(1024 * 1024); printf("%x\n", sbrk(0)); free(bl); printf("%x\n", sbrk(0)); } int main(int argc, char **argv) { program_break_test(); return 0; } When compiling following code: printf("%10p\n", sbrk(0)); I get warning tip: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int’ Question 1: Why is that? And after I malloc(1024 * 1024) , it seems the program break didn't change. Here is the output: 9b12000

Does malloc() use brk() or mmap()?

久未见 提交于 2019-11-29 11:40:09
问题 c code: // program break mechanism // TLPI exercise 7-1 #include <stdio.h> #include <stdlib.h> void program_break_test() { printf("%10p\n", sbrk(0)); char *bl = malloc(1024 * 1024); printf("%x\n", sbrk(0)); free(bl); printf("%x\n", sbrk(0)); } int main(int argc, char **argv) { program_break_test(); return 0; } When compiling following code: printf("%10p\n", sbrk(0)); I get warning tip: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int’ Question 1: Why is that? And

How to return memory from process to the OS

北战南征 提交于 2019-11-29 02:30:52
I have an issue with memory management in various operating systems. My program is a server that does some processing that could take a few GB of memory. After that, it releases most of the memory while it waits for a few hours until another request arrives. On AIX and Solaris, I observe the following behavior, When I free memory, the memory is not returned back to the operating system. The amount of virtual memory used by a process always increases - never decreases. The same is true for the physical memory, up to its limit. Thus it appears that we use all this memory in sleep mode as well.

How does sbrk() work in C++?

丶灬走出姿态 提交于 2019-11-28 21:59:06
Where can I read about sbrk() in some detail? How does it exactly work? In what situations would I want to use sbrk() instead of the cumbersome malloc() and new() ? btw, what is the expansion for sbrk() ? Have a look at the specification for brk/sbrk . The call basically asks the OS to allocate some more memory for the application by incrementing the previous "break value" by a certain amount. This amount (the first parameter) is the amount of extra memory your application then gets. Most rudimentary malloc implementations build upon the sbrk system call to get blocks of memory that they split

How are sbrk/brk implemented in Linux?

前提是你 提交于 2019-11-28 04:44:52
I was thinking about how the Linux kernel implements system calls and I was wondering if someone could give me a high level view of how sbrk/brk work? I've reviewed the kernel code, but there is just so much of it and I don't understand it. I was hoping for a summary from someone? In a very high level view, the Linux kernel tracks the memory visible to a process as several "memory areas" ( struct vm_area_struct ). There is also a structure which represents (again in a very high level view) a process' whole address space ( struct mm_struct ). Each process (except some kernel threads) has

Why does calling sbrk(0) twice give a different value?

谁说胖子不能爱 提交于 2019-11-28 00:55:22
I'm trying to understand the sbrk() function. From what I know: sbrk(0) returns the current address of the break and doesn't increment it. sbrk(size) increments the address of the break by size bytes and returns the previous address of the break. So I created something to test it: #include <unistd.h> #include <stdio.h> int main(void) { printf("sbrk(0) = %p\n", sbrk(0)); // should return value x printf("sbrk(0) = %p\n", sbrk(0)); // should return value x printf("sbrk(5) = %p\n", sbrk(5)); // should return value x printf("sbrk(0) = %p\n", sbrk(0)); // should return value x + 5 } So I'm expecting

How to return memory from process to the OS

孤街醉人 提交于 2019-11-27 16:48:37
问题 I have an issue with memory management in various operating systems. My program is a server that does some processing that could take a few GB of memory. After that, it releases most of the memory while it waits for a few hours until another request arrives. On AIX and Solaris, I observe the following behavior, When I free memory, the memory is not returned back to the operating system. The amount of virtual memory used by a process always increases - never decreases. The same is true for the