[Codefragments-commits] bryce commits r6 - trunk/fragment-slab
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Nov 15 07:10:17 CST 2005
Author: bryce
Date: 2005-11-15 07:10:16 -0600 (Tue, 15 Nov 2005)
New Revision: 6
Modified:
trunk/fragment-slab/fragment.c
Log:
Tidyup
Modified: trunk/fragment-slab/fragment.c
===================================================================
--- trunk/fragment-slab/fragment.c 2005-11-14 17:13:03 UTC (rev 5)
+++ trunk/fragment-slab/fragment.c 2005-11-15 13:10:16 UTC (rev 6)
@@ -24,7 +24,7 @@
#define PROCFS_MAX_SIZE 1024
-// This structure hold information about the /proc file */
+// This structure holds information about the /proc file */
struct proc_dir_entry *module_procfile;
@@ -169,7 +169,7 @@
int x = 0;
int loop = 0;
int diff = 0;
- int *ptr=NULL;
+ int *ptr = NULL;
struct node *tmp = NULL;
// how many items are there in the list?
@@ -205,27 +205,29 @@
("%s: WHOA! kmalloc failed. no memory left?"
" bailing out having only created %d elements\n",
MODULE_NAME, (loop + x));
- goto interleave; // abandon loop, we've all the memory
+
+ // abandon loop, we've all the memory
// we can handle so before 'dying' we should
// try freeing up holes rather than skipping through and
// trying malloc again in the next bit of code
+
+ goto interleave;
}
// track what number this node is
tmp->idx = loop + x;
// Finally we get to do the one line of code we actually
- // truely care about... Note, PAGE_SIZE is defined in linux/a.out.h
+ // truely care about...
ptr = &(tmp->chunksize);
tmp->page = malloc_slab_slice (131072, ptr);
-// tmp->page =
-// kmalloc (32, GFP_KERNEL | __GFP_NORETRY | __GFP_NORECLAIM);
- if (debug) {
- printk ("tmp->page = %p\n", tmp->page);
- printk ("tmp->chunksize = %d\n", tmp->chunksize);
- printk ("tmp->chunksize = %d\n", tmp->chunksize);
- }
+ if (debug)
+ {
+ printk ("tmp->page = %p\n", tmp->page);
+ printk ("tmp->chunksize = %d\n", tmp->chunksize);
+ printk ("tmp->chunksize = %d\n", tmp->chunksize);
+ }
if ((tmp->page) == NULL)
{
@@ -263,12 +265,12 @@
if (tmp->location % ((tmp->chunksize) * 2) == 0)
{
list_del (pos);
- kfree (tmp->page);
+ kfree (tmp->page); // This is a pointer to a kmalloced area
kfree (tmp);
- if (debug)
+ if (debug)
printk
("%s: deleted element %d in list from holding a %d byte page of memory at %p\n",
- MODULE_NAME, x, tmp->chunksize, tmp->page);
+ MODULE_NAME, x, tmp->chunksize, tmp->page);
}
}
if (debug)
@@ -285,7 +287,7 @@
{
tmp = list_entry (pos, struct node, list);
list_del (pos);
- kfree (tmp->page);
+ kfree (tmp->page); // This is a pointer to a kmalloced area
kfree (tmp);
diff--;
if (diff == 0)
@@ -309,10 +311,10 @@
{
char *tmp = NULL;
- // Stride down from 'chunk' by power of 2, trying to wedge in a malloc
- // aggressively try to hammer in the big slices as much as possible
+ // Stride down from 'chunk' by power of 2, trying to wedge in a malloc.
+ // Aggressively try to hammer in the big slices as much as possible
- while (chunk >= 32) // don't try anything below 32
+ while (chunk >= 32) // don't try anything below 32 bytes
{
// malloc some space for the struct
// to prevent this from invoking the oom killer we add two
@@ -323,21 +325,24 @@
GFP_KERNEL | __GFP_NORETRY | __GFP_NORECLAIM |
__GFP_NOWARN);
+ // make a note of how big this chunk request was
+ *chunksize = chunk;
+
if (tmp == NULL) // if we cant get a malloc, try at 1/2 the size
{
chunk = (chunk >> 1); // 131072 -> 65536 -> ... -> 128 -> 64 -> 32
+ if (chunk > 32)
+ *chunksize = 0;
}
else
{
break; // we got what we wanted, lets barge out of the while loop
}
}
+
if (debug)
printk ("Chunk size = %d\n", chunk);
- // make a note of how big this chunk was
- *chunksize = chunk;
-
return (tmp);
}
More information about the Codefragments-commits
mailing list