kernel-2.4 delays during core dumping.
Subsystems (2)
With the 2.4 kernel, large core dumps tie up some /proc/<pid> read handlers for extended periods of time. I have looked at the code and see it is caused the core dump handler holding a down_write copy of mm->mmap_sem. This makes sense. I also know that a rewrite for 2.4 is unreasonable and have verified by both inspection and empirically that the problem does not exist in 2.6.
That said, the problem does still exist in 2.4. I have coded up a work around for 2.4. I will attach for illustration a diff that stands little chance of applying cleanly against the bitkeeper source. The gist of the patch is have the core dump code predetermine the information that will be needed later by the proc read handlers. When the proc read handler runs, if it cannot acquire the semaphore, it checks an new flag in the mm and uses the other information instead if the flag indicates the information is available.
I realize that some information will be a snapshot in time which is no longer 100% correct. That seems to be less of a concern to the interested parties than not having their system appear to be locked up for extremely long periods of time.
Am I on the right track with this? I don't know if this is of interest to others. If so, please let me know.
Thanks,
Robin Holt
[holt@attica work]$ p_rdiff -u p_list
===========================================================================linux/linux/fs/binfmt_elf.c
===========================================================================
linux/fs/binfmt_elf.c Thu Dec 11 16:59:40 2003 renamed from usr/tmp/TmpDir.24518-0/linux/linux/fs/binfmt_elf.c_1.42 Thu Dec 11 16:59:53 2003 +111 -0
@@ -15,6 +15,7 @@ #include <linux/stat.h> #include <linux/sched.h> #include <linux/mm.h> +#include <linux/hugetlb.h> #include <linux/mman.h> #include <linux/a.out.h> #include <linux/errno.h>
@@ -1082,8 +1083,106 @@ *(struct pt_regs *)&prstatus.pr_reg = *regs; #endif + /* Temporary kludge to prevent core dumps from tying up /proc */ + { + struct mm_struct *mm = current->mm; + char *cmdline, *environ; + + cmdline = kmalloc(PAGE_SIZE,GFP_KERNEL); + environ = kmalloc(PAGE_SIZE,GFP_KERNEL); + + if (cmdline != NULL) { + int res = 0; + int len = mm->arg_end - mm->arg_start; + if (len > PAGE_SIZE) + len = PAGE_SIZE; + res = access_process_vm(current, mm->arg_start, cmdline, len, 0); + // If the nul at the end of args has been overwritten, then + // assume application is using setproctitle(3). + if ( res > 0 && cmdline[res-1] != '\0' ) + { + len = strnlen( cmdline, res ); + if ( len < res ) + { + res = len; + } + else + { + len = mm->env_end - mm->env_start; + if (len > PAGE_SIZE - res) + len = PAGE_SIZE - res; + res += access_process_vm(current, mm->env_start, + cmdline+res, len, 0); + } + } + } + + if (environ != NULL) { + int len = mm->env_end - mm->env_start; + if (len > PAGE_SIZE) + len = PAGE_SIZE; + (void) access_process_vm(current, mm->env_start, environ, len, 0); + } + spin_lock(&mm->environ_lock); + mm->cmdline = cmdline; + mm->environ = environ; + spin_unlock(&mm->environ_lock); + } + /* now stop all vm operations */ down_write(¤t->mm->mmap_sem); + + { /* Temporary kludge to prevent core dumps from tying up /proc */ + struct vm_area_struct *vma; + unsigned long area_size; + struct mm_struct *mm = current->mm; + + mm->vsize = 0; + + mm->resident = mm->rss; + mm->share = mm->trs = mm->drs = 0; + mm->data = mm->stack = mm->exec = mm->lib = 0; + + vma = mm->mmap; + while (vma) { + area_size = vma->vm_end - vma->vm_start; + + mm->vsize += area_size; + + if (!vma->vm_file) { + mm->data += area_size; + if (vma->vm_flags & VM_GROWSDOWN) + mm->stack += area_size; + } else if (!vma->vm_flags & VM_WRITE) { + if (vma->vm_flags & VM_EXEC) { + mm->exec += area_size; + if (!vma->vm_flags & VM_EXECUTABLE) + mm->lib += area_size; + } + } + if (is_vm_hugetlb_page(vma)) { + if (!(vma->vm_flags & VM_DONTCOPY)) + mm->share += area_size; + continue; + } + if (vma->vm_flags & VM_SHARED || vma->vm_next_share) + mm->share += area_size; + if (vma->vm_flags & VM_EXECUTABLE) { + mm->trs += area_size; /* text */ + if ((mm->exe_mnt == NULL) && (vma->vm_file)) { + mm->exe_mnt = mntget(vma->vm_file->f_vfsmnt); + mm->exe_dentry = dget(vma->vm_file->f_dentry); + } + } else + mm->drs += area_size; + + vma = vma->vm_next; + } + mm->eip = KSTK_EIP(current); + mm->esp = KSTK_ESP(current); + atomic_inc(&mm->vsize_valid); + } /* end kludge */ + segs = current->mm->map_count; #ifdef DEBUG
@@ -1279,6 +1378,18 @@ end_coredump: set_fs(fs); + spin_lock(¤t->mm->environ_lock); + if (current->mm->cmdline != NULL) { + kfree(current->mm->cmdline); + current->mm->cmdline = NULL; + } + if (current->mm->environ != NULL) { + kfree(current->mm->environ); + current->mm->environ = NULL; + } + spin_unlock(¤t->mm->environ_lock); + atomic_dec(¤t->mm->vsize_valid); + current->mm->exe_mnt = NULL; up_write(¤t->mm->mmap_sem); return has_dumped; }
===========================================================================linux/linux/fs/proc/array.c
===========================================================================
linux/fs/proc/array.c Thu Dec 11 16:08:19 2003 renamed from usr/tmp/TmpDir.24518-0/linux/linux/fs/proc/array.c_1.38 Thu Dec 11 16:59:53 2003 +71 -41
150 lines not on this page · raw message
===========================================================================linux/linux/fs/proc/base.c
===========================================================================
linux/fs/proc/base.c Thu Dec 11 16:08:19 2003 renamed from usr/tmp/TmpDir.24518-0/linux/linux/fs/proc/base.c_1.32 Thu Dec 11 16:59:53 2003 +62 -35
125 lines not on this page · raw message
===========================================================================linux/linux/include/linux/sched.h
===========================================================================
linux/include/linux/sched.h Wed Dec 10 09:39:32 2003 renamed from usr/tmp/TmpDir.24518-0/linux/linux/include/linux/sched.h_1.79 Thu Dec 11 16:59:53 2003 +14 -0
@@ -223,6 +223,15 @@ atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */ int map_count; /* number of VMAs */ struct rw_semaphore mmap_sem; + atomic_t vsize_valid; /* following 5 are valid */ + unsigned long vsize, eip, esp; + unsigned long resident, share, trs, drs; + unsigned long data, stack, exec, lib; + struct vfsmount *exe_mnt; + struct dentry *exe_dentry; + spinlock_t environ_lock; /* protect environ and cmdline */ + char *environ; + char *cmdline; spinlock_t page_table_lock; /* Protects task page tables and mm->rss */ struct list_head mmlist; /* List of all active mm's. These are globally strung
@@ -257,6 +266,11 @@ mm_users: ATOMIC_INIT(2), \ mm_count: ATOMIC_INIT(1), \ mmap_sem: __RWSEM_INITIALIZER(name.mmap_sem), \ + vsize_valid: ATOMIC_INIT(0), \ + environ_lock: SPIN_LOCK_UNLOCKED, \ + exe_mnt: NULL, \ + environ: NULL, \ + cmdline: NULL, \ page_table_lock: SPIN_LOCK_UNLOCKED, \ mmlist: LIST_HEAD_INIT(name.mmlist), \ }