diff -u -3 -p -u -r1.1.1.5 sched.h
--- linux-2.4.x/include/linux/sched.h	28 Feb 2003 22:45:13 -0000	1.1.1.5
+++ linux-2.4.x/include/linux/sched.h	21 May 2003 13:03:56 -0000
@@ -260,8 +260,8 @@ extern int mmlist_nr;
 
 struct mm_rblock_struct {
 	int size;
-	int refcount;
-	void * kblock;
+	int refcount; /* Shouldn't this be an atomic_t? */
+	char kblock[0]; /* Allocated block follows */
 };
 
 struct mm_tblock_struct {
diff -u -3 -p -r1.1.1.5 mmap.c
--- linux-2.4.x/mmnommu/mmap.c	28 Feb 2003 22:45:17 -0000	1.1.1.5
+++ linux-2.4.x/mmnommu/mmap.c	21 May 2003 13:44:37 -0000
 #ifdef DEBUG
 static void show_process_blocks(void)
 {
-	struct mm_tblock_struct * tblock, *tmp;
+	struct mm_tblock_struct *tblock;
 	
 	printk("Process blocks %d:", current->pid);
-	
-	tmp = &current->mm->tblock;
-	while (tmp) {
-		printk(" %p: %p", tmp, tmp->rblock);
-		if (tmp->rblock)
-			printk(" (%d @%p #%d)", ksize(tmp->rblock->kblock), tmp->rblock->kblock, tmp->rblock->refcount);
-		if (tmp->next)
+
+	for (tblock = &current->mm->tblock; tblock; tblock = tblock->next) {
+		printk(" %p: %p", tblock, tblock->rblock);
+		if (tblock->rblock)
+			printk(" (%d @%p #%d)", ksize(tblock->rblock), tblock->rblock->kblock, tblock->rblock->refcount);
+		if (tblock->next)
 			printk(" ->");
 		else
 			printk(".");
-		tmp = tmp->next;
 	}
 	printk("\n");
 }
@@ -1275,7 +1273,6 @@ unsigned long do_mmap_pgoff(
 	unsigned long flags,
 	unsigned long pgoff)
 {
-	void * result;
 #if 0
 	struct mm_struct * mm = current->mm;
 #endif
@@ -1403,7 +1400,7 @@ unsigned long do_mmap_pgoff(
 	}
 
 	tblock->rblock = (struct mm_rblock_struct *)
-			kmalloc(sizeof(struct mm_rblock_struct), GFP_KERNEL);
+			kmalloc(sizeof(struct mm_rblock_struct) + len, GFP_KERNEL);
 
 	if (!tblock->rblock) {
 		printk("Allocation of rblock for %lu byte allocation from process %d failed\n", len, current->pid);
@@ -1413,64 +1410,48 @@ unsigned long do_mmap_pgoff(
 		return -ENOMEM;
 	}
 
-	
-	result = kmalloc(len, GFP_KERNEL);
-	if (!result) {
-		printk("Allocation of length %lu from process %d failed\n", len,
-				current->pid);
-		show_buffers();
-		show_free_areas();
-		kfree(tblock->rblock);
-		kfree(tblock);
-		return -ENOMEM;
-	}
-
 	tblock->rblock->refcount = 1;
-	tblock->rblock->kblock = result;
 	tblock->rblock->size = len;
-	
-	realalloc += ksize(result);
-	askedalloc += len;
 
 #ifdef WARN_ON_SLACK	
-	if ((len+WARN_ON_SLACK) <= ksize(result))
-		printk("Allocation of %lu bytes from process %d has %lu bytes of slack\n", len, current->pid, ksize(result)-len);
+	if ((len + sizeof(struct mm_rblock_struct) + WARN_ON_SLACK) <= ksize(tblock->rblock))
+		printk("Allocation of %lu bytes from process %d has %lu bytes of slack\n",
+			len, current->pid, ksize(tblock->rblock) - len - sizeof(struct mm_rblock_struct));
 #endif
-	
+
 	if (file) {
 		int error;
 		mm_segment_t old_fs = get_fs();
 		set_fs(KERNEL_DS);
-		error = file->f_op->read(file, (char *) result, len, &file->f_pos);
+		error = file->f_op->read(file, (char *)tblock->rblock->kblock, len, &file->f_pos);
 		set_fs(old_fs);
 		if (error < 0) {
-			kfree(result);
 			kfree(tblock->rblock);
 			kfree(tblock);
 			return error;
 		}
-		if (error<len)
-			memset(result+error, '\0', len-error);
+		if (error < len)
+			memset(tblock->rblock->kblock + error, '\0', len - error);
 	} else {
-		memset(result, '\0', len);
+		memset(tblock->rblock->kblock, '\0', len);
 	}
+ 
+	realalloc += ksize(tblock->rblock);
+	askedalloc += sizeof(struct mm_rblock_struct) + len;
 
-        
 	realalloc += ksize(tblock);
 	askedalloc += sizeof(struct mm_tblock_struct);
 
-	realalloc += ksize(tblock->rblock);
-	askedalloc += sizeof(struct mm_rblock_struct);
-
+	/* Add this new tblock to list head in mm_struct */
 	tblock->next = current->mm->tblock.next;
 	current->mm->tblock.next = tblock;
 
 #ifdef DEBUG
 	printk("do_mmap:\n");
 	show_process_blocks();
-#endif	  
+#endif
 
-	return (unsigned long)result;
+	return (unsigned long)tblock->rblock->kblock;
 }
 
 int do_munmap(struct mm_struct * mm, unsigned long addr, size_t len)
@@ -1489,27 +1470,18 @@ int do_munmap(struct mm_struct * mm, uns
 #endif
 
 	tmp = &mm->tblock; /* dummy head */
-	while ((tblock=tmp->next) && tblock->rblock &&
-			tblock->rblock->kblock != (void*)addr) 
+	while ((tblock=tmp->next) && (tblock->rblock->kblock != (void*)addr)) 
 		tmp = tblock;
-		
+
 	if (!tblock) {
 		printk("munmap of non-mmaped memory by process %d (%s): %p\n",
 				current->pid, current->comm, (void*)addr);
 		return -EINVAL;
 	}
-	if (tblock->rblock) {
-		if (!--tblock->rblock->refcount) {
-			if (tblock->rblock->kblock) {
-				realalloc -= ksize(tblock->rblock->kblock);
-				askedalloc -= tblock->rblock->size;
-				kfree(tblock->rblock->kblock);
-			}
-			
-			realalloc -= ksize(tblock->rblock);
-			askedalloc -= sizeof(struct mm_rblock_struct);
-			kfree(tblock->rblock);
-		}
+	if (!--tblock->rblock->refcount) {
+		realalloc -= ksize(tblock->rblock);
+		askedalloc -= sizeof(struct mm_rblock_struct) + tblock->rblock->size;
+		kfree(tblock->rblock);
 	}
 	tmp->next = tblock->next;
 	realalloc -= ksize(tblock);
@@ -1538,13 +1510,8 @@ void exit_mmap(struct mm_struct * mm)
 	while((tmp = mm->tblock.next)) {
 		if (tmp->rblock) {
 			if (!--tmp->rblock->refcount) {
-				if (tmp->rblock->kblock) {
-					realalloc -= ksize(tmp->rblock->kblock);
-					askedalloc -= tmp->rblock->size;
-					kfree(tmp->rblock->kblock);
-				}
 				realalloc -= ksize(tmp->rblock);
-				askedalloc -= sizeof(struct mm_rblock_struct);
+				askedalloc -= sizeof(struct mm_rblock_struct) + tmp->rblock->size;
 				kfree(tmp->rblock);
 			}
 			tmp->rblock = 0;
