reduce fragmentation: patch for 2.1.108 fs/namei.c

Bill Hawes (whawes@star.net)
Wed, 15 Jul 1998 11:20:16 -0400


This is a multi-part message in MIME format.
--------------3A0091237FF3C863F74F973C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

With the recent concern for memory fragmentation I thought it would be
helpful to reexamine the places where memory is allocated without a
means of freeing it.

One of these is in the fs/namei.c "quicklist" for getname; pages are
allocated and cached without even an upper bound on the count. Since the
getname quicklist is just a performance optimization and the pages in it
are unused, it's trivial to free them, so I think it makes sense to
release the whole list when the system starts swapping.

The attached patch adds a free_misc_mem() routine that (for now) just
releases the getname quicklist. (There may be some other allocations
that can be freed as well.)

The patch has performed well with about 10 min of testing :-)

Regards,
Bill
--------------3A0091237FF3C863F74F973C
Content-Type: text/plain; charset=us-ascii; name="fs_namei108-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="fs_namei108-patch"

--- linux-2.1.108/fs/namei.c.old Fri Jul 3 10:32:32 1998
+++ linux-2.1.108/fs/namei.c Wed Jul 15 10:50:58 1998
@@ -91,9 +91,13 @@
spinlock_t getname_quicklock = SPIN_LOCK_UNLOCKED;

/* Tuning: increase locality by reusing same pages again...
- * if getname_quicklist becomes too long on low memory machines, either a limit
- * should be added or after a number of cycles some pages should
- * be released again ...
+ * If getname_quicklist becomes too long on low memory machines,
+ * either a limit should be added or after a number of cycles
+ * some pages should be released again ...
+ *
+ * N.B. Has anybody benchmarked this to see if it really increases
+ * performance? Maybe we don't need it -- gfp() may be fast enough.
+ *
*/
static inline char * get_page(void)
{
@@ -132,6 +136,24 @@
*/
}

+/*
+ * Reclaim the pages in the getname quicklist, and any
+ * other memory left lying around.
+ */
+void free_misc_mem(void)
+{
+ if (getname_quickcount) {
+ char * page;
+ spin_lock(&getname_quicklock);
+ while ((page = getname_quicklist) != NULL) {
+ getname_quicklist = *(char**)page;
+ free_page((unsigned long) page);
+ }
+ getname_quickcount = 0;
+ spin_unlock(&getname_quicklock);
+ }
+}
+
/* In order to reduce some races, while at the same time doing additional
* checking and hopefully speeding things up, we copy filenames to the
* kernel data space before using them..
--- linux-2.1.108/mm/vmscan.c.old Fri Jul 3 10:32:34 1998
+++ linux-2.1.108/mm/vmscan.c Wed Jul 15 10:53:55 1998
@@ -453,6 +462,9 @@
/* Always trim SLAB caches when memory gets low. */
kmem_cache_reap(gfp_mask);

+ /* Free any other loose memory as well. */
+ free_misc_mem();
+
/* We try harder if we are waiting .. */
stop = 3;
if (gfp_mask & __GFP_WAIT)

--------------3A0091237FF3C863F74F973C--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html