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 mulyadi.sant...@gmail.com wrote: On Thu, Nov 22, 2012 at 10:12 AM, horse_rivers horse_riv...@126.com 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 rpj...@crashcourse.ca 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 mulyadi.sant...@gmail.com wrote: Hi.. :) On Tue, Aug 14, 2012 at 9:14 AM, 王哲 wangzhe5...@gmail.com 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: Macro explanation
On Sat, Mar 10, 2012 at 12:10 AM, Manohar Vanga manohar.va...@gmail.com 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 kernel.vi...@gmail.com 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
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: #includestdio.h #includeunistd.h #includesys/types.h #includestdlib.h 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