diff options
author | Christoph Lameter <clameter@sgi.com> | 2007-05-17 01:10:50 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-17 08:23:03 -0400 |
commit | c59def9f222d44bb7e2f0a559f2906191a0862d7 (patch) | |
tree | 51bc0c12906b13887c6e53d1e06b48b411443129 /mm/slab.c | |
parent | afc0cedbe9138e3e8b38bfa1e4dfd01a2c537d62 (diff) |
Slab allocators: Drop support for destructors
There is no user of destructors left. There is no reason why we should keep
checking for destructors calls in the slab allocators.
The RFC for this patch was discussed at
http://marc.info/?l=linux-kernel&m=117882364330705&w=2
Destructors were mainly used for list management which required them to take a
spinlock. Taking a spinlock in a destructor is a bit risky since the slab
allocators may run the destructors anytime they decide a slab is no longer
needed.
Patch drops destructor support. Any attempt to use a destructor will BUG().
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
Acked-by: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/slab.c')
-rw-r--r-- | mm/slab.c | 27 |
1 files changed, 2 insertions, 25 deletions
@@ -409,9 +409,6 @@ struct kmem_cache { | |||
409 | /* constructor func */ | 409 | /* constructor func */ |
410 | void (*ctor) (void *, struct kmem_cache *, unsigned long); | 410 | void (*ctor) (void *, struct kmem_cache *, unsigned long); |
411 | 411 | ||
412 | /* de-constructor func */ | ||
413 | void (*dtor) (void *, struct kmem_cache *, unsigned long); | ||
414 | |||
415 | /* 5) cache creation/removal */ | 412 | /* 5) cache creation/removal */ |
416 | const char *name; | 413 | const char *name; |
417 | struct list_head next; | 414 | struct list_head next; |
@@ -1911,20 +1908,11 @@ static void slab_destroy_objs(struct kmem_cache *cachep, struct slab *slabp) | |||
1911 | slab_error(cachep, "end of a freed object " | 1908 | slab_error(cachep, "end of a freed object " |
1912 | "was overwritten"); | 1909 | "was overwritten"); |
1913 | } | 1910 | } |
1914 | if (cachep->dtor && !(cachep->flags & SLAB_POISON)) | ||
1915 | (cachep->dtor) (objp + obj_offset(cachep), cachep, 0); | ||
1916 | } | 1911 | } |
1917 | } | 1912 | } |
1918 | #else | 1913 | #else |
1919 | static void slab_destroy_objs(struct kmem_cache *cachep, struct slab *slabp) | 1914 | static void slab_destroy_objs(struct kmem_cache *cachep, struct slab *slabp) |
1920 | { | 1915 | { |
1921 | if (cachep->dtor) { | ||
1922 | int i; | ||
1923 | for (i = 0; i < cachep->num; i++) { | ||
1924 | void *objp = index_to_obj(cachep, slabp, i); | ||
1925 | (cachep->dtor) (objp, cachep, 0); | ||
1926 | } | ||
1927 | } | ||
1928 | } | 1916 | } |
1929 | #endif | 1917 | #endif |
1930 | 1918 | ||
@@ -2124,7 +2112,7 @@ static int setup_cpu_cache(struct kmem_cache *cachep) | |||
2124 | * @align: The required alignment for the objects. | 2112 | * @align: The required alignment for the objects. |
2125 | * @flags: SLAB flags | 2113 | * @flags: SLAB flags |
2126 | * @ctor: A constructor for the objects. | 2114 | * @ctor: A constructor for the objects. |
2127 | * @dtor: A destructor for the objects. | 2115 | * @dtor: A destructor for the objects (not implemented anymore). |
2128 | * | 2116 | * |
2129 | * Returns a ptr to the cache on success, NULL on failure. | 2117 | * Returns a ptr to the cache on success, NULL on failure. |
2130 | * Cannot be called within a int, but can be interrupted. | 2118 | * Cannot be called within a int, but can be interrupted. |
@@ -2159,7 +2147,7 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
2159 | * Sanity checks... these are all serious usage bugs. | 2147 | * Sanity checks... these are all serious usage bugs. |
2160 | */ | 2148 | */ |
2161 | if (!name || in_interrupt() || (size < BYTES_PER_WORD) || | 2149 | if (!name || in_interrupt() || (size < BYTES_PER_WORD) || |
2162 | (size > (1 << MAX_OBJ_ORDER) * PAGE_SIZE) || (dtor && !ctor)) { | 2150 | (size > (1 << MAX_OBJ_ORDER) * PAGE_SIZE) || dtor) { |
2163 | printk(KERN_ERR "%s: Early error in slab %s\n", __FUNCTION__, | 2151 | printk(KERN_ERR "%s: Early error in slab %s\n", __FUNCTION__, |
2164 | name); | 2152 | name); |
2165 | BUG(); | 2153 | BUG(); |
@@ -2213,9 +2201,6 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
2213 | if (flags & SLAB_DESTROY_BY_RCU) | 2201 | if (flags & SLAB_DESTROY_BY_RCU) |
2214 | BUG_ON(flags & SLAB_POISON); | 2202 | BUG_ON(flags & SLAB_POISON); |
2215 | #endif | 2203 | #endif |
2216 | if (flags & SLAB_DESTROY_BY_RCU) | ||
2217 | BUG_ON(dtor); | ||
2218 | |||
2219 | /* | 2204 | /* |
2220 | * Always checks flags, a caller might be expecting debug support which | 2205 | * Always checks flags, a caller might be expecting debug support which |
2221 | * isn't available. | 2206 | * isn't available. |
@@ -2370,7 +2355,6 @@ kmem_cache_create (const char *name, size_t size, size_t align, | |||
2370 | BUG_ON(!cachep->slabp_cache); | 2355 | BUG_ON(!cachep->slabp_cache); |
2371 | } | 2356 | } |
2372 | cachep->ctor = ctor; | 2357 | cachep->ctor = ctor; |
2373 | cachep->dtor = dtor; | ||
2374 | cachep->name = name; | 2358 | cachep->name = name; |
2375 | 2359 | ||
2376 | if (setup_cpu_cache(cachep)) { | 2360 | if (setup_cpu_cache(cachep)) { |
@@ -2835,7 +2819,6 @@ failed: | |||
2835 | * Perform extra freeing checks: | 2819 | * Perform extra freeing checks: |
2836 | * - detect bad pointers. | 2820 | * - detect bad pointers. |
2837 | * - POISON/RED_ZONE checking | 2821 | * - POISON/RED_ZONE checking |
2838 | * - destructor calls, for caches with POISON+dtor | ||
2839 | */ | 2822 | */ |
2840 | static void kfree_debugcheck(const void *objp) | 2823 | static void kfree_debugcheck(const void *objp) |
2841 | { | 2824 | { |
@@ -2894,12 +2877,6 @@ static void *cache_free_debugcheck(struct kmem_cache *cachep, void *objp, | |||
2894 | BUG_ON(objnr >= cachep->num); | 2877 | BUG_ON(objnr >= cachep->num); |
2895 | BUG_ON(objp != index_to_obj(cachep, slabp, objnr)); | 2878 | BUG_ON(objp != index_to_obj(cachep, slabp, objnr)); |
2896 | 2879 | ||
2897 | if (cachep->flags & SLAB_POISON && cachep->dtor) { | ||
2898 | /* we want to cache poison the object, | ||
2899 | * call the destruction callback | ||
2900 | */ | ||
2901 | cachep->dtor(objp + obj_offset(cachep), cachep, 0); | ||
2902 | } | ||
2903 | #ifdef CONFIG_DEBUG_SLAB_LEAK | 2880 | #ifdef CONFIG_DEBUG_SLAB_LEAK |
2904 | slab_bufctl(slabp)[objnr] = BUFCTL_FREE; | 2881 | slab_bufctl(slabp)[objnr] = BUFCTL_FREE; |
2905 | #endif | 2882 | #endif |