modify_ldt always allocates a 64 kB vmalloc block, regardless of how many ldt entries are actually needed. All apps linked to libpthread now use the ldt to access thread-local variables, and an 8192 entry ldt is both a waste of memory and of the vmalloc area. The attached patch: * dynamically allocs and reallocs the ldt, starting with a 512 entry (4 kB) ldt allocated with kmalloc. * returns all 5 entries of the default ldt if modify_ldt(2,,) is called. * moves copy_segments into init_new_context, and adds error handling. * deletes copy_segments on i386. * removes the call to copy_segments from kernel/fork.c. No other platform uses it. * reuses cpu_vm_valid for the LDT reload: there is no need to maintain 2 cpu bitmasks, one set_bit removed from every thread switch. Tested on i386 SMP, both with libpthread apps and a small test app. -- Manfred