lkml.org 
[lkml]   [2002]   [Nov]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] fork.c bits for uClinux
mmuless ports don't need dup_mmap nor allocation of a pgd.

I tried to avoid ifdef-mess as far as possible, and to archive that
I created small wrappers for pgd allocation/freeing and move taking
of the mmap semaphore into dup_mmap from the only caller. The end
result is just one additiona ifdef.


--- 1.83/kernel/fork.c Tue Nov 5 23:27:16 2002
+++ edited/kernel/fork.c Thu Nov 14 00:53:05 2002
@@ -205,12 +205,14 @@
return tsk;
}

+#ifdef CONFIG_MMU
static inline int dup_mmap(struct mm_struct * mm)
{
struct vm_area_struct * mpnt, *tmp, **pprev;
int retval;
unsigned long charge = 0;

+ down_write(&mm->mmap_sem);
flush_cache_mm(current->mm);
mm->locked_vm = 0;
mm->mmap = NULL;
@@ -287,11 +289,29 @@

out:
flush_tlb_mm(current->mm);
+ up_write(&mm->mmap_sem);
return retval;
fail_nomem:
vm_unacct_memory(charge);
goto out;
}
+static inline int mm_alloc_pgd(struct mm_struct * mm)
+{
+ mm->pgd = pgd_alloc(mm);
+ if (unlikely(!mm->pgd))
+ return -ENOMEM;
+ return 0;
+}
+
+static inline void mm_free_pgd(struct mm_struct * mm)
+{
+ pgd_free(mm->pgd);
+}
+#else
+#define dup_mmap(mm) (0)
+#define mm_alloc_pgd(mm) (0)
+#define mm_free_pgd(mm)
+#endif /* CONFIG_MMU */

spinlock_t mmlist_lock __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
int mmlist_nr;
@@ -314,8 +334,7 @@
mm->default_kioctx = (struct kioctx)INIT_KIOCTX(mm->default_kioctx, *mm);
mm->free_area_cache = TASK_UNMAPPED_BASE;

- mm->pgd = pgd_alloc(mm);
- if (mm->pgd)
+ if (likely(!mm_alloc_pgd(mm)))
return mm;
free_mm(mm);
return NULL;
@@ -344,8 +363,8 @@
*/
inline void __mmdrop(struct mm_struct *mm)
{
- if (mm == &init_mm) BUG();
- pgd_free(mm->pgd);
+ BUG_ON(mm == &init_mm);
+ mm_free_pgd(mm);
destroy_context(mm);
free_mm(mm);
}
@@ -444,10 +463,7 @@
if (init_new_context(tsk,mm))
goto free_pt;

- down_write(&oldmm->mmap_sem);
retval = dup_mmap(mm);
- up_write(&oldmm->mmap_sem);
-
if (retval)
goto free_pt;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 13:31    [W:0.028 / U:0.720 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site