Skip to contentSkip to conversation

modify_ldt returning ENOMEM on highmem

DISCUSSION Manfred Spraul 3 participants 3 messages Dec 17, 2001 – Dec 18, 2001

Subsystems (3)
lore
Share & tools
lore
#0 lore raw
Quoted 5 lines

Do you have an NTFS disk mounted? I had a similar problem which was "fixed" by not having an NTFS vol mounted. Apparently the ntfs code makes a lot of calls to vmalloc which leads to badness.

Both modify_ldt and NTFS make lots of calls to vmalloc.

AFAICS this limits the number of concurrently running processes that are linked to libpthread to less than 2000 on highmem machines, regardless of the actual free memory.

Could you try the attached patch?
It should permit you to keep the NTFS vol mounted - libpthread doesn't need a 64 kB LDT. That should reduce the pressure on the vmalloc area.

The patch applies to both 2.4.16 and 2.5.1

--
Manfred

// $Header$
// Kernel Version:

//  VERSION = 2
//  PATCHLEVEL = 5
//  SUBLEVEL = 1
//  EXTRAVERSION =
arch/i386/kernel/process.c +5 -47
@@ -465,23 +465,6 @@
 }
 
 /*
- * No need to lock the MM as we are the last user
- */
-void release_segments(struct mm_struct *mm)
-{
-	void * ldt = mm->context.segments;
-
-	/*
-	 * free the LDT
-	 */
-	if (ldt) {
-		mm->context.segments = NULL;
-		clear_LDT();
-		vfree(ldt);
-	}
-}
-
-/*
  * Create a kernel thread
  */
 int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
@@ -533,40 +516,15 @@
 void release_thread(struct task_struct *dead_task)
 {
 	if (dead_task->mm) {
-		void * ldt = dead_task->mm->context.segments;
-
 		// temporary debugging check
-		if (ldt) {
-			printk("WARNING: dead process %8s still has LDT? <%p>\n",
-					dead_task->comm, ldt);
+		if (dead_task->mm->context.size) {
+			printk("WARNING: dead process %8s still has LDT? <%p/%d>\n",
+					dead_task->comm,
+					dead_task->mm->context.ldt,
+					dead_task->mm->context.size);
 			BUG();
 		}
 	}
-}
-
-/*
- * we do not have to muck with descriptors here, that is
- * done in switch_mm() as needed.
- */
-void copy_segments(struct task_struct *p, struct mm_struct *new_mm)
-{
-	struct mm_struct * old_mm;
-	void *old_ldt, *ldt;
-
-	ldt = NULL;
-	old_mm = current->mm;
-	if (old_mm && (old_ldt = old_mm->context.segments) != NULL) {
-		/*
-		 * Completely new LDT, we initialize it from the parent:
-		 */
-		ldt = vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE);
-		if (!ldt)
-			printk(KERN_WARNING "ldt allocation failed\n");
-		else
-			memcpy(ldt, old_ldt, LDT_ENTRIES*LDT_ENTRY_SIZE);
-	}
-	new_mm->context.segments = ldt;
-	new_mm->context.cpuvalid = ~0UL;	/* valid on all CPU's - they can't have stale data */
 }
 
 /*
arch/i386/kernel/ldt.c +119 -29

194 lines not on this page · raw message

include/asm-i386/mmu.h +5 -2
@@ -4,10 +4,13 @@
 /*
  * The i386 doesn't have a mmu context, but
  * we put the segment information here.
+ *
+ * cpu_vm_mask is used to optimize ldt flushing.
  */
 typedef struct { 
-	void *segments;
-	unsigned long cpuvalid;
+	int size;
+	struct semaphore sem;
+	void *	ldt;
 } mm_context_t;
 
 #endif
include/asm-i386/desc.h +4 -4
@@ -79,13 +79,13 @@
 /*
  * load one particular LDT into the current CPU
  */
-static inline void load_LDT (struct mm_struct *mm)
+static inline void load_LDT (mm_context_t *pc)
 {
 	int cpu = smp_processor_id();
-	void *segments = mm->context.segments;
-	int count = LDT_ENTRIES;
+	void *segments = pc->ldt;
+	int count = pc->size;
 
-	if (!segments) {
+	if (!count) {
 		segments = &default_ldt[0];
 		count = 5;
 	}
include/asm-i386/mmu_context.h +8 -9
@@ -10,7 +10,7 @@
  * possibly do the LDT unload here?
  */
 #define destroy_context(mm)		do { } while(0)
-#define init_new_context(tsk,mm)	0
+int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
 
 #ifdef CONFIG_SMP
 
@@ -30,19 +30,19 @@
 	if (prev != next) {
 		/* stop flush ipis for the previous mm */
 		clear_bit(cpu, &prev->cpu_vm_mask);
-		/*
-		 * Re-load LDT if necessary
-		 */
-		if (prev->context.segments != next->context.segments)
-			load_LDT(next);
 #ifdef CONFIG_SMP
 		cpu_tlbstate[cpu].state = TLBSTATE_OK;
 		cpu_tlbstate[cpu].active_mm = next;
 #endif
 		set_bit(cpu, &next->cpu_vm_mask);
-		set_bit(cpu, &next->context.cpuvalid);
+
 		/* Re-load page tables */
 		asm volatile("movl %0,%%cr3": :"r" (__pa(next->pgd)));
+		/* load_LDT, if either the previous or next thread
+		 * has a non-default LDT.
+		 */
+		if (next->context.size+prev->context.size)
+			load_LDT(&next->context);
 	}
 #ifdef CONFIG_SMP
 	else {
@@ -54,9 +54,8 @@
 			 * tlb flush IPI delivery. We must flush our tlb.
 			 */
 			local_flush_tlb();
+			load_LDT(&next->context);
 		}
-		if (!test_and_set_bit(cpu, &next->context.cpuvalid))
-			load_LDT(next);
 	}
 #endif
 }
kernel/fork.c +0 -5
@@ -340,11 +340,6 @@
 	if (retval)
 		goto free_pt;
 
-	/*
-	 * child gets a private LDT (if there was an LDT in the parent)
-	 */
-	copy_segments(tsk, mm);
-
 	if (init_new_context(tsk,mm))
 		goto free_pt;
 
include/asm-i386/processor.h +1 -2
@@ -431,8 +431,7 @@
  */
 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
 
-/* Copy and release all segment info associated with a VM */
-extern void copy_segments(struct task_struct *p, struct mm_struct * mm);
+/* Release all segment info associated with a VM */
 extern void release_segments(struct mm_struct * mm);
 
 /*
#1 lore raw

Manfred Spraul wrote:

|   > Do you have an NTFS disk mounted? I had a similar problem which was
|   > "fixed" by not having an NTFS vol mounted. Apparently the ntfs code
|   > makes a lot of calls to vmalloc which leads to badness.
|   > 
|   Both modify_ldt and NTFS make lots of calls to vmalloc.
|   
|   AFAICS this limits the number of concurrently running processes that are
|   linked to libpthread to less than 2000 on highmem machines, regardless
|   of the actual free memory.
|   
|   Could you try the attached patch?
|   It should permit you to keep the NTFS vol mounted - libpthread doesn't
|   need a 64 kB LDT. That should reduce the pressure on the vmalloc area.
|   
|   The patch applies to both 2.4.16 and 2.5.1

Tried your patch against 2.4.16.

After running updatedb with all my vols mounted (including ntfs) I was able to start up all applications without trouble, so your patch was good in that regard. However, ntfs isn't happy. A whole lotta this is in my syslog:

Dec 17 22:36:55 orf kernel: NTFS: ntfs_getdir_unsorted(): Read failed. Returning error code -95.
Dec 17 22:36:55 orf last message repeated 5 times
Dec 17 22:36:55 orf kernel: NTFS: ntfs_insert_run: ntfs_vmalloc(new_size = 0x1000) failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_process_runs: ntfs_insert_run failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_getdir_unsorted(): Read failed. Returning error code -95.
Dec 17 22:36:55 orf kernel: NTFS: ntfs_insert_run: ntfs_vmalloc(new_size = 0x1000) failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_process_runs: ntfs_insert_run failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_getdir_unsorted(): Read failed. Returning error code -95.
Dec 17 22:36:55 orf kernel: NTFS: ntfs_insert_run: ntfs_vmalloc(new_size = 0x1000) failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_process_runs: ntfs_insert_run failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_insert_run: ntfs_vmalloc(new_size = 0x1000) failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_process_runs: ntfs_insert_run failed

Leigh Orf

#2 lore raw
Quoted 17 lines · Leigh Orf

Manfred Spraul wrote:

|  > Do you have an NTFS disk mounted? I had a similar problem which was
|   > "fixed" by not having an NTFS vol mounted. Apparently the ntfs code
|   > makes a lot of calls to vmalloc which leads to badness.
|   >
|   Both modify_ldt and NTFS make lots of calls to vmalloc.
|
|   AFAICS this limits the number of concurrently running processes that are
|   linked to libpthread to less than 2000 on highmem machines, regardless
|   of the actual free memory.
|
|   Could you try the attached patch?
|   It should permit you to keep the NTFS vol mounted - libpthread doesn't
|   need a 64 kB LDT. That should reduce the pressure on the vmalloc area.
|
|   The patch applies to both 2.4.16 and 2.5.1
Quoted 6 lines

Tried your patch against 2.4.16.

After running updatedb with all my vols mounted (including ntfs) I was able to start up all applications without trouble, so your patch was good in that regard. However, ntfs isn't happy. A whole lotta this is in my syslog:

Hi,

I am going on holiday for two weeks from tomorrow but when I get back I will backport the new allocator from ntfs tng to the old ntfs driver. This only uses vmalloc if necessary so will decrease the number of vmalloc()s dramatically and hopefully this will make your kernel happier.

I will CC: patch to you so you can see if all your problems go away or if it is not sufficient.

Best regards,

Anton

Quoted 20 lines
Dec 17 22:36:55 orf kernel: NTFS: ntfs_getdir_unsorted(): Read failed. Returning error code -95.
Dec 17 22:36:55 orf last message repeated 5 times
Dec 17 22:36:55 orf kernel: NTFS: ntfs_insert_run: ntfs_vmalloc(new_size = 0x1000) failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_process_runs: ntfs_insert_run failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_getdir_unsorted(): Read failed. Returning error code -95.
Dec 17 22:36:55 orf kernel: NTFS: ntfs_insert_run: ntfs_vmalloc(new_size = 0x1000) failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_process_runs: ntfs_insert_run failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_getdir_unsorted(): Read failed. Returning error code -95.
Dec 17 22:36:55 orf kernel: NTFS: ntfs_insert_run: ntfs_vmalloc(new_size = 0x1000) failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_process_runs: ntfs_insert_run failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_insert_run: ntfs_vmalloc(new_size = 0x1000) failed
Dec 17 22:36:55 orf kernel: NTFS: ntfs_process_runs: ntfs_insert_run failed

Leigh Orf

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 5 lines
  "I've not lost my mind. It's backed up on tape somewhere." - Unknown
-- 
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Linux NTFS Maintainer / WWW: http://linux-ntfs.sf.net/
ICQ: 8561279 / WWW: http://www-stu.christs.cam.ac.uk/~aia21/