Max open file limit
Hello, How many files a process can open at a time? Is it configurable? I found following in the kernel code: .. .max_fds= NR_OPEN_DEFAULT, .. .. #define NR_OPEN_DEFAULT BITS_PER_LONG .. .. #ifdef __KERNEL__ #define BITS_PER_LONG 32 .. But I can open more than 32 files in my user space program. Thank you, Vijay ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: what is the difference between kmalloc and vmalloc?
On Thu, Nov 22, 2012 at 9:39 AM, Mulyadi Santosa wrote: > On Thu, Nov 22, 2012 at 10:12 AM, horse_rivers wrote: >> thanks! > > kmalloc allocates memory from slab cache. It tends to be physically > contigous and you can get memory size smaller than page size. > > vmalloc, on the other hand, is when you need only virtually contigous > memory area. Example of such usage is for allocating memory to load > kernel module. Is it necessary that vmalloc always allocate virtually contiguous memory and not physically contiguous? Except large size memory allocation why one needs to use vmalloc? Can we say that use kmalloc and if it fails retry with kmalloc? regards Vijay > > -- > regards, > > Mulyadi Santosa > Freelance Linux trainer and consultant > > blog: the-hydra.blogspot.com > training: mulyaditraining.blogspot.com > > ___ > Kernelnewbies mailing list > Kernelnewbies@kernelnewbies.org > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: /proc/cpuinfo versus /proc/softirqs: how to properly count CPUs?
On Mon, Oct 22, 2012 at 7:30 PM, Robert P. J. Day wrote: > > poking around under /proc on my quad-core asus laptop and just > noticed that while /proc/cpuinfo (properly) lists my 8 processors, > /proc/softirqs instead lists 16, with the last 8 having values of all > zeroes (not surprisingly). with the middle columns snipped for > brevity, my /proc/softirqs shows: > > CPU0 CPU1 ... CPU13 CPU14 CPU15 > HI: 0 0 ... 0 0 0 >TIMER:1018887 45313 ... 0 0 0 > NET_TX: 1182 1813 ... 0 0 0 > NET_RX:991719 ... 0 0 0 >BLOCK: 44559 13 ... 0 0 0 > BLOCK_IOPOLL: 0 0 ... 0 0 0 > TASKLET: 41582419 ... 0 0 0 >SCHED: 76438 28658 ... 0 0 0 > HRTIMER:738709 ... 0 0 0 > RCU: 136797 82392 ... 0 0 0 > > with all of the zero values from CPU8-CPU15. so the obvious question > is -- why? why the difference in the way those two proc files count > the "number" of CPUs on my system? > > for /proc/cpuinfo, the logic is in arch/x86/kernel/cpu/proc.c, and > the way the seq_file is implemented: > > static void *c_start(struct seq_file *m, loff_t *pos) > { > *pos = cpumask_next(*pos - 1, cpu_online_mask); > if ((*pos) < nr_cpu_ids) > return &cpu_data(*pos); > return NULL; > } > > so that loop clearly iterates through the "online" CPUs, which would > appear to be the correct loop criteria. > > the code for softirqs, however, is in fs/proc/softirqs.c, and is > much simpler: > > static int show_softirqs(struct seq_file *p, void *v) > { > int i, j; > > seq_puts(p, ""); > for_each_possible_cpu(i) > seq_printf(p, "CPU%-8d", i); > seq_putc(p, '\n'); > > for (i = 0; i < NR_SOFTIRQS; i++) { > seq_printf(p, "%12s:", softirq_to_name[i]); > for_each_possible_cpu(j) > seq_printf(p, " %10u", kstat_softirqs_cpu(i, j)); > seq_putc(p, '\n'); > } > return 0; > } > > note that that code uses the macro "for_each_possible_cpu()" rather > than examining only *online* CPUs. in dmesg, i see the lines: > > [0.00] smpboot: Allowing 16 CPUs, 8 hotplug CPUs > [0.00] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:16 > nr_node_ids:1 > > and the code for all this counting is in arch/x86/kernel/smpboot.c, > which you can check out for yourself, but this brings me back to the > basic question -- why is the code for softirqs iterating through all > *possible* CPUs (in my case, apparently, 16), when i have only 8 > *online* CPUs? Sorry for jumping in but i have basic question here. What is the difference between *online* CPUs and *possible* CPUs? Thanks, VIjay > > rday > > -- > > > Robert P. J. Day Ottawa, Ontario, CANADA > http://crashcourse.ca > > Twitter: http://twitter.com/rpjday > LinkedIn: http://ca.linkedin.com/in/rpjday > > > > ___ > Kernelnewbies mailing list > Kernelnewbies@kernelnewbies.org > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: How to understand the macro __init?
Hi, On Tue, Aug 14, 2012 at 9:34 AM, Mulyadi Santosa wrote: > Hi.. :) > > On Tue, Aug 14, 2012 at 9:14 AM, 王哲 wrote: >> i use the __init for function print_k. >> in my opinion after the fisrt invoking the print_k in the hello_init. >> the memory of print_k will be freed,and the second invoking will >> not be executed.but the result of second invoking is executing . >> >> why? > > because you're still in module_init :) > > right after modul init stage is done, _init marked function is thrown away... Even if we call print_k() function inside hello_exit, it still works. At that point __init hello_init execution is over. How its still working? Regards, Vijay > > -- > regards, > > Mulyadi Santosa > Freelance Linux trainer and consultant > > blog: the-hydra.blogspot.com > training: mulyaditraining.blogspot.com > > ___ > Kernelnewbies mailing list > Kernelnewbies@kernelnewbies.org > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Kernel Memory
Thanks everyone. I think i got enough information for further study. Thanks, Vijay On Thu, Jun 21, 2012 at 7:10 PM, kishore sheik ahamed wrote: > Hey Vijay > > I am a newbie too. Just sharing what I could go through. > > It is said that Kernel or atleast a part of kernel needs to be non paged for > fast interrupt access etc as pinned memory > Wiki says > > Pinned/Locked/Fixed pages > > Operating systems have memory areas that are pinned (never swapped to > secondary storage). For example, interrupt mechanisms rely on an array of > pointers to their handlers, such as I/O completion and page fault. If the > pages containing these pointers or the code that they invoke were pageable, > interrupt-handling would become far more complex and time-consuming, > particularly in the case of page fault interrupts. Hence, some part of the > page table structures is not pageable. > > Some pages may be pinned for short periods of time, others may be pinned for > long periods of time, and still others may need to be permanently pinned. > For example: > > The paging supervisor code and drivers for secondary storage devices on > which pages reside must be permanently pinned, as otherwise paging wouldn't > even work because the necessary code wouldn't be available. > Timing-dependent components may be pinned to avoid variable paging delays. > Data buffers that are accessed directly by peripheral devices that use > direct memory access or I/O channels must reside in pinned pages while the > I/O operation is in progress because such devices and the buses to which > they are attached expect to find data buffers located at physical memory > addresses; regardless of whether the bus has a memory management unit for > I/O, transfers cannot be stopped if a page fault occurs and then restarted > when the page fault has been processed. > > There are other two discussion thread which say kernel is non-pageable and > now due to growing kernel Data structures it is allowed > > http://kerneltrap.org/node/6404 > > http://kerneltrap.org/node/8206 > > > Regards > > Kishore > > > > On Thu, Jun 21, 2012 at 5:57 PM, Vijay Chauhan > wrote: >> >> Hello, >> >> I am newbie. >> It has been said "kernel memory is not pageable" >> What does it mean? There is no concept of kernel virtual address? >> >> Any simple explanation will help me to udnerstand. >> >> Thanks, >> Vijay >> >> ___ >> Kernelnewbies mailing list >> Kernelnewbies@kernelnewbies.org >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > > ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Kernel Memory
Hello, I am newbie. It has been said "kernel memory is not pageable" What does it mean? There is no concept of kernel virtual address? Any simple explanation will help me to udnerstand. Thanks, Vijay ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Macro explanation
On Mon, Mar 12, 2012 at 10:19 AM, Manish Katiyar wrote: > On Sun, Mar 11, 2012 at 9:40 PM, Mandeep Sandhu > wrote: >> On Mon, Mar 12, 2012 at 1:03 AM, Vijay Chauhan >> wrote: >>> On Sat, Mar 10, 2012 at 12:10 AM, Manohar Vanga >>> wrote: >>>> Also, from the >>>> archives: http://www.mail-archive.com/kernelnewbies@nl.linux.org/msg12320.html >>> >>> Thank you for links which gives good explanation. >>> But I am not able to understand the part accessing a member through >>> NULL pointer like ((size_t) &((TYPE *)0)->MEMBER) >>> How it is handled? > > All you are doing is computing the address and not dereferencing it. > If you dereference it, yes it will panic. eg.. > > *(((size_t) &((TYPE *)0)->MEMBER)) will cause panic OK I got it. Thank you all for your help. Vijay > > -- > Thanks - > Manish ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Macro explanation
On Sat, Mar 10, 2012 at 12:10 AM, Manohar Vanga wrote: > Also, from the > archives: http://www.mail-archive.com/kernelnewbies@nl.linux.org/msg12320.html Thank you for links which gives good explanation. But I am not able to understand the part accessing a member through NULL pointer like ((size_t) &((TYPE *)0)->MEMBER) How it is handled? In C code if we access a member through NULL pointer like this will cause the code to crash. Am I missing something? > > On Fri, Mar 9, 2012 at 7:21 PM, Vijay Chauhan > wrote: >> >> Hi, >> >> I'm checking the container_of and offsetof macro >> >> #define container_of(ptr, type, member) ({ \ >> const typeof( ((type *)0)->member ) *__mptr = (ptr); >> (type *)( (char *)__mptr - offsetof(type,member) );}) >> >> #define offsetof(TYPE, MEMBER) \ >> ((size_t) &((TYPE *)0)->MEMBER) >> >> >> I did not understand the first line of both macro. Will it not create >> the NULL pointer dereference problem? I know it works and read some >> article but it did not explain this part, so can anyone explain why >> the NULL pointer error is not coming. Am I missing something? >> Any C language specification of such example. >> >> ___ >> Kernelnewbies mailing list >> Kernelnewbies@kernelnewbies.org >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > > > > > -- > /manohar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Macro explanation
Hi, I'm checking the container_of and offsetof macro #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); (type *)( (char *)__mptr - offsetof(type,member) );}) #define offsetof(TYPE, MEMBER) \ ((size_t) &((TYPE *)0)->MEMBER) I did not understand the first line of both macro. Will it not create the NULL pointer dereference problem? I know it works and read some article but it did not explain this part, so can anyone explain why the NULL pointer error is not coming. Am I missing something? Any C language specification of such example. ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: fork() and exec()
Thank you all for your help. Vijay. On Tue, Feb 7, 2012 at 9:10 PM, Bernd Petrovitsch wrote: > On Die, 2012-02-07 at 00:38 +0530, Vijay Chauhan wrote: >> Hi List, >> >> I am learning Linux and trying to understand exec and fork function. >> execl says that it overlays the running address space. What does it mean? >> >> I created the following program and used top command with >> intentionally wrong arguments: >> >> #include >> #include >> #include >> #include >> >> int main(){ >> int a = -1; >> if(fork()==0){ >> printf("Inside child\n"); >> printf("child pid=%d, parentid=%d\n", getpid(), getppid()); >> execl("/usr/bin/top", "/usr/bin/top", ">/dev/null" ,(char*)0 ); > > You get here only if the execl() as such fails. > >> scanf("inside child provide a %d", &a); > > You should check the return value here if you actually got a matching > parameter. > scanf() is actually a function to be avoided. > >> printf("Inside child a=%d\n", a); >> exit(1); >> } else { >> printf("Inside parent, going to wait\n"); >> printf("my pid=%d, parentid=%d\n", getpid(), getppid()); >> scanf("input parent %d\n", &a); > > You should check the return value here if you actually got a matching > parameter. > scanf() is actually a function to be avoided. > >> wait(NULL); > > You should check the return value here to know why "wait()" returns. > >> printf("Wait over\n"); >> printf("Inside parent a=%d\n", a); >> } >> return 0; >> } > > Bernd > -- > Bernd Petrovitsch Email : be...@petrovitsch.priv.at > LUGA : http://www.luga.at > ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
fork() and exec()
Hi List, I am learning Linux and trying to understand exec and fork function. execl says that it overlays the running address space. What does it mean? I created the following program and used top command with intentionally wrong arguments: #include #include #include #include int main(){ int a = -1; if(fork()==0){ printf("Inside child\n"); printf("child pid=%d, parentid=%d\n", getpid(), getppid()); execl("/usr/bin/top", "/usr/bin/top", ">/dev/null" ,(char*)0 ); scanf("inside child provide a %d", &a); printf("Inside child a=%d\n", a); exit(1); } else { printf("Inside parent, going to wait\n"); printf("my pid=%d, parentid=%d\n", getpid(), getppid()); scanf("input parent %d\n", &a); wait(NULL); printf("Wait over\n"); printf("Inside parent a=%d\n", a); } return 0; } When i run this program, it gives following output: [vijay@localhost]$ ./a.out Inside parent, going to wait Inside child child pid=2775, parentid=2774 my pid=2774, parentid=2681 top: unknown argument '>' usage: top -hv | -bcisSHM -d delay -n iterations [-u user | -U user] -p pid [,pid ...] 10 Wait over Inside parent a=-1 [vijay@localhost]$ Why the child scanf and printf not executed? In the parent program, i expected input parent should be printed. But it doesnt and just wait for some input. When i entered 10 it resumes but printing -1 as a value. Could anyone please help me to understand this behavior? or any good tutorial or book Thanks. Vijay ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: thread_info address calculation
> It's the same thing as you read: > THREAD size is 8kb so the operation looks like the following: > current_stack_pointer & ~(8191) == current_stack_pointet & 0xFE00 > (last 13 bits are 0) Ok. Got it. But how ANDing it with current stack pointer points to the address of thread_info structure. Suppose stack is growing from higher to lower memory address. Thanks, Vijay ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
thread_info address calculation
Hi list, I would like to know how the thread_info address is calculated? As per the LKD book: struct thread_info is stored on the kernel stack. On x86, current is calculated by masking out the 13 least-significant bits of the stack pointer to obtain the thread_info structure.This is done by the current_thread_info() function.The assembly is shown here: movl $-8192, %eax andl %esp, %eax This assumes that the stack size is 8KB. But in code i found that: /* how to get the thread information struct from C */ static inline struct thread_info *current_thread_info(void) { return (struct thread_info *) (current_stack_pointer & ~(THREAD_SIZE - 1)); } /* how to get the current stack pointer from C */ static inline unsigned long current_stack_pointer(void) { unsigned long sp; asm("mov sp,%0; ":"=r" (sp)); return sp; } Could anyone help me in explaining the current_stack_pointer and (current_stack_pointer & ~(THREAD_SIZE - 1)) calculation? This is not as mentioned in the book. If page size is 4KB and 2 page per process kernel stack is used then THREAD_Size will be 8KB. Thanks, Vijay ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Paging of Kernel Memory
Hi, i was going through the Linux Kernel Development book. It mention the following: "Additionally, kernel memory is not pageable.Therefore, every byte of memory you consume is one less byte of available physical memory." What is the meaning of 'Kernel memory is not pageable'? Anyone can give details would help me in understanding. Thanks, Vijay ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies