Memory Leak Fix

Mark Hemment (markhe@sco.COM)
Mon, 2 Jun 1997 14:37:44 +0100 (BST)


This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.

---559023410-5758-865258664=:20596
Content-Type: TEXT/PLAIN; charset=US-ASCII

Hi David/All,

Please find attached a diff against the slab allocator for 2.1.42

This contains the changes for the "Debugging Slab", which was on my
homepage, but with the debugging disabled.

Most importantly, it contains a fix for the memory leak.

This occured when a slab contained only one object (ie. the object is
_large_). __kmem_cache_free() use to check for a fully free slab,
and then for a first-free from a fully active slab (this is to maintain
the partial ordering of slabs with a cache).

kmem_cache_full_free() makes the assumption that 'c_freep' refers to
the slab being moved, or to a slab which appears earlier in the ordering.
Unfortunately, this is not true for single object slabs, as 'c_freep' can
refer to a later slab (or even the cache head). If the slab does _not_
need to be moved (to maintain the ordering), it does not update 'c_freep'
- which caused the leak.

The fix is to change the testing order in __kmem_cache_free(), so that the
test for 'first-object-free' is made before the 'fully-free' test.

Regards,

markhe

----------------------------------------------------
Mark Hemment UNIX/C Sotware Engineer (contractor)
"Success has many fathers. Failure is a b**tard"
----------------------------------------------------

---559023410-5758-865258664=:20596
Content-Type: APPLICATION/octet-stream; name="slab.patch.gz"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.SCO.3.94.970602143744.20596B@tyne.london.sco.com>
Content-Description: slab.patch.gz

H4sICCTDkjMAA3NsYWIubWVtb3J5LmxlYWsucGF0Y2gApVj9UxppEv6Z/BWt
W2vAAQNGQeVIhSiXuGc0paZSe3VVU8PwArPOBzcfsu6u//s93e/MMANI2Iup
CvB+dj/d/XT322g0KHKt4YF90GxWPgc+/ZL4RIfUent21DlrNal1etp5ZRhG
umx5Tfvs7bFe8/49NTrt03qbDP7o0Pv3r6hSmYWOHz9Ud3+O/hmEtuNPKHL+
UDQPwhFZrjPxPeXH1KCfo//4u3UaJ75t+l6dfMtTtS5OeH5Fr4yKbdlTNWu8
s80g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