]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
STABLE12-linux-alloc-avoid-potential-recursion-freeing-memory-and-schedule-when-vmall...
authorDavid Howells <bartbanter@hotmail.com>
Sun, 20 Jan 2002 08:41:28 +0000 (08:41 +0000)
committerDerrick Brashear <shadow@dementia.org>
Sun, 20 Jan 2002 08:41:28 +0000 (08:41 +0000)
"The first is to change the gfp_mask passed to kmalloc(). Using GFP_KERNEL,
  it is possible that the VM will call back to the filesystem to free up
  memory to satisfy the kmalloc request. GFP_NOFS will prevent this possible
  recursion. I believe GFP_NOFS first appeared in the 2.4.6 kernel.

  The second change involves the call to schedule() when vmalloc() fails. This
  can also cause a hang. The schedule() call could be replaced with:

  set_current_state(TASK_INTERRUPTIBLE);
  schedule_timeout(HZ);"

src/afs/LINUX/osi_alloc.c

index 9169ed624d4a7c723f5adeb4538923c399b3c035..580e899610bee9df643b0e2286d94d02c7549adf 100644 (file)
@@ -87,7 +87,13 @@ static void *linux_alloc(unsigned int asize)
 
     /*  if we can use kmalloc use it to allocate the required memory. */
     if (asize <  MAX_KMALLOC_SIZE) {
-        new = (void *)(unsigned long)kmalloc(asize, GFP_KERNEL);
+        new = (void *)(unsigned long)kmalloc(asize, 
+#ifdef GFP_NOFS
+                                            GFP_NOFS
+#else
+                                            GFP_KERNEL
+#endif
+                                            );
         if (new) /* piggy back alloc type */
             (unsigned long)new |= KM_TYPE;
     }
@@ -97,7 +103,8 @@ static void *linux_alloc(unsigned int asize)
             if (--max_wait <=0) {
                break;
             }
-           schedule();
+           set_current_state(TASK_INTERRUPTIBLE);
+           schedule_timeout(HZ);
         }
        if (new) /* piggy back alloc type */
            (unsigned long)new |= VM_TYPE;