From: Matthew Dobson <colpatch@us.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: andrea@suse.de, Sridhar Samudrala <sri@us.ibm.com>,
pavel@suse.cz, Andrew Morton <akpm@osdl.org>,
Linux Memory Management <linux-mm@kvack.org>
Subject: [RFC][PATCH 3/6] Slab Prep: get/return_object
Date: Tue, 13 Dec 2005 23:56:33 -0800 [thread overview]
Message-ID: <439FD031.1040608@us.ibm.com> (raw)
In-Reply-To: <439FCECA.3060909@us.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 235 bytes --]
Create 2 helper functions in mm/slab.c: get_object() and return_object().
These functions reduce some existing duplicated code in the slab allocator
and will be used when adding Critical Page Pool support to the slab allocator.
-Matt
[-- Attachment #2: slab_prep-get_return_object.patch --]
[-- Type: text/x-patch, Size: 3912 bytes --]
Create two helper functions: get_object_from_slab() & return_object_to_slab().
Use these two helper function to replace duplicated code in mm/slab.c
These functions will also be reused by a later patch in this series.
Signed-off-by: Matthew Dobson <colpatch@us.ibm.com>
Index: linux-2.6.15-rc5+critical_pool/mm/slab.c
===================================================================
--- linux-2.6.15-rc5+critical_pool.orig/mm/slab.c 2005-12-13 15:56:55.459287208 -0800
+++ linux-2.6.15-rc5+critical_pool/mm/slab.c 2005-12-13 16:05:21.308386456 -0800
@@ -2140,6 +2140,42 @@ static void kmem_flagcheck(kmem_cache_t
}
}
+static void *get_object(kmem_cache_t *cachep, struct slab *slabp, int nodeid)
+{
+ void *objp = slabp->s_mem + (slabp->free * cachep->objsize);
+ kmem_bufctl_t next;
+
+ slabp->inuse++;
+ next = slab_bufctl(slabp)[slabp->free];
+#if DEBUG
+ slab_bufctl(slabp)[slabp->free] = BUFCTL_FREE;
+ WARN_ON(slabp->nodeid != nodeid);
+#endif
+ slabp->free = next;
+
+ return objp;
+}
+
+static void return_object(kmem_cache_t *cachep, struct slab *slabp, void *objp,
+ int nodeid)
+{
+ unsigned int objnr = (objp - slabp->s_mem) / cachep->objsize;
+
+#if DEBUG
+ /* Verify that the slab belongs to the intended node */
+ WARN_ON(slabp->nodeid != nodeid);
+
+ if (slab_bufctl(slabp)[objnr] != BUFCTL_FREE) {
+ printk(KERN_ERR "slab: double free detected in cache "
+ "'%s', objp %p\n", cachep->name, objp);
+ BUG();
+ }
+#endif
+ slab_bufctl(slabp)[objnr] = slabp->free;
+ slabp->free = objnr;
+ slabp->inuse--;
+}
+
static void set_slab_attr(kmem_cache_t *cachep, struct slab *slabp, void *objp)
{
int i;
@@ -2418,22 +2454,12 @@ retry:
check_slabp(cachep, slabp);
check_spinlock_acquired(cachep);
while (slabp->inuse < cachep->num && batchcount--) {
- kmem_bufctl_t next;
STATS_INC_ALLOCED(cachep);
STATS_INC_ACTIVE(cachep);
STATS_SET_HIGH(cachep);
- /* get obj pointer */
- ac->entry[ac->avail++] = slabp->s_mem +
- slabp->free*cachep->objsize;
-
- slabp->inuse++;
- next = slab_bufctl(slabp)[slabp->free];
-#if DEBUG
- slab_bufctl(slabp)[slabp->free] = BUFCTL_FREE;
- WARN_ON(numa_node_id() != slabp->nodeid);
-#endif
- slabp->free = next;
+ ac->entry[ac->avail++] = get_object(cachep, slabp,
+ numa_node_id());
}
check_slabp(cachep, slabp);
@@ -2565,7 +2591,6 @@ static void *__cache_alloc_node(kmem_cac
struct slab *slabp;
struct kmem_list3 *l3;
void *obj;
- kmem_bufctl_t next;
int x;
l3 = cachep->nodelists[nodeid];
@@ -2591,14 +2616,7 @@ retry:
BUG_ON(slabp->inuse == cachep->num);
- /* get obj pointer */
- obj = slabp->s_mem + slabp->free*cachep->objsize;
- slabp->inuse++;
- next = slab_bufctl(slabp)[slabp->free];
-#if DEBUG
- slab_bufctl(slabp)[slabp->free] = BUFCTL_FREE;
-#endif
- slabp->free = next;
+ obj = get_object(cachep, slabp, nodeid);
check_slabp(cachep, slabp);
l3->free_objects--;
/* move slabp to correct slabp list: */
@@ -2637,29 +2655,14 @@ static void free_block(kmem_cache_t *cac
for (i = 0; i < nr_objects; i++) {
void *objp = objpp[i];
struct slab *slabp;
- unsigned int objnr;
slabp = page_get_slab(virt_to_page(objp));
l3 = cachep->nodelists[node];
list_del(&slabp->list);
- objnr = (objp - slabp->s_mem) / cachep->objsize;
check_spinlock_acquired_node(cachep, node);
check_slabp(cachep, slabp);
-
-#if DEBUG
- /* Verify that the slab belongs to the intended node */
- WARN_ON(slabp->nodeid != node);
-
- if (slab_bufctl(slabp)[objnr] != BUFCTL_FREE) {
- printk(KERN_ERR "slab: double free detected in cache "
- "'%s', objp %p\n", cachep->name, objp);
- BUG();
- }
-#endif
- slab_bufctl(slabp)[objnr] = slabp->free;
- slabp->free = objnr;
+ return_object(cachep, slabp, objp, node);
STATS_DEC_ACTIVE(cachep);
- slabp->inuse--;
l3->free_objects++;
check_slabp(cachep, slabp);
next prev parent reply other threads:[~2005-12-14 7:56 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-14 7:50 [RFC][PATCH 0/6] Critical Page Pool Matthew Dobson
2005-12-14 7:52 ` [RFC][PATCH 1/6] Create " Matthew Dobson
2005-12-14 10:48 ` Andrea Arcangeli
2005-12-14 13:30 ` Rik van Riel
2005-12-14 16:26 ` Matthew Dobson
2005-12-15 3:29 ` Matt Mackall
2005-12-14 7:54 ` [RFC][PATCH 2/6] in_emergency Trigger Matthew Dobson
2005-12-14 7:56 ` Matthew Dobson [this message]
2005-12-14 8:19 ` [RFC][PATCH 3/6] Slab Prep: get/return_object Pekka Enberg
2005-12-14 16:26 ` Matthew Dobson
2005-12-14 7:58 ` [RFC][PATCH 4/6] Slab Prep: slab_destruct() Matthew Dobson
2005-12-14 8:37 ` Pekka Enberg
2005-12-14 16:30 ` Matthew Dobson
2005-12-14 7:59 ` [RFC][PATCH 5/6] Slab Prep: Move cache_grow() Matthew Dobson
2005-12-14 8:02 ` [RFC][PATCH 6/6] Critical Page Pool: Slab Support Matthew Dobson
2005-12-14 10:08 ` [RFC][PATCH 0/6] Critical Page Pool Pavel Machek
2005-12-14 12:01 ` Andrea Arcangeli
2005-12-14 13:03 ` Alan Cox
2005-12-14 16:37 ` Matthew Dobson
2005-12-14 19:17 ` Alan Cox
2005-12-15 16:27 ` Pavel Machek
2005-12-14 16:03 ` Matthew Dobson
2005-12-14 15:55 ` Matthew Dobson
2005-12-15 16:26 ` Pavel Machek
2005-12-15 21:51 ` Matthew Dobson
2005-12-16 5:02 ` Sridhar Samudrala
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=439FD031.1040608@us.ibm.com \
--to=colpatch@us.ibm.com \
--cc=akpm@osdl.org \
--cc=andrea@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pavel@suse.cz \
--cc=sri@us.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).