Re: [REPOST PATCH 2/4] slab: introduce helper functions to get/set free object

2013-09-06 Thread Christoph Lameter
On Fri, 6 Sep 2013, Joonsoo Kim wrote:

> In the following patches, to get/set free objects from the freelist
> is changed so that simple casting doesn't work for it. Therefore,
> introduce helper functions.

Acked-by: Christoph Lameter 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [REPOST PATCH 2/4] slab: introduce helper functions to get/set free object

2013-09-06 Thread Christoph Lameter
On Fri, 6 Sep 2013, Joonsoo Kim wrote:

 In the following patches, to get/set free objects from the freelist
 is changed so that simple casting doesn't work for it. Therefore,
 introduce helper functions.

Acked-by: Christoph Lameter c...@linux.com
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[REPOST PATCH 2/4] slab: introduce helper functions to get/set free object

2013-09-05 Thread Joonsoo Kim
In the following patches, to get/set free objects from the freelist
is changed so that simple casting doesn't work for it. Therefore,
introduce helper functions.

Signed-off-by: Joonsoo Kim 

diff --git a/mm/slab.c b/mm/slab.c
index 9d4bad5..a0e49bb 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2545,9 +2545,15 @@ static struct freelist *alloc_slabmgmt(struct kmem_cache 
*cachep,
return freelist;
 }
 
-static inline unsigned int *slab_freelist(struct page *page)
+static inline unsigned int get_free_obj(struct page *page, unsigned int idx)
 {
-   return (unsigned int *)(page->freelist);
+   return ((unsigned int *)page->freelist)[idx];
+}
+
+static inline void set_free_obj(struct page *page,
+   unsigned int idx, unsigned int val)
+{
+   ((unsigned int *)(page->freelist))[idx] = val;
 }
 
 static void cache_init_objs(struct kmem_cache *cachep,
@@ -2592,7 +2598,7 @@ static void cache_init_objs(struct kmem_cache *cachep,
if (cachep->ctor)
cachep->ctor(objp);
 #endif
-   slab_freelist(page)[i] = i;
+   set_free_obj(page, i, i);
}
 }
 
@@ -2611,7 +2617,7 @@ static void *slab_get_obj(struct kmem_cache *cachep, 
struct page *page,
 {
void *objp;
 
-   objp = index_to_obj(cachep, page, slab_freelist(page)[page->active]);
+   objp = index_to_obj(cachep, page, get_free_obj(page, page->active));
page->active++;
 #if DEBUG
WARN_ON(page_to_nid(virt_to_page(objp)) != nodeid);
@@ -2632,7 +2638,7 @@ static void slab_put_obj(struct kmem_cache *cachep, 
struct page *page,
 
/* Verify double free bug */
for (i = page->active; i < cachep->num; i++) {
-   if (slab_freelist(page)[i] == objnr) {
+   if (get_free_obj(page, i) == objnr) {
printk(KERN_ERR "slab: double free detected in cache "
"'%s', objp %p\n", cachep->name, objp);
BUG();
@@ -2640,7 +2646,7 @@ static void slab_put_obj(struct kmem_cache *cachep, 
struct page *page,
}
 #endif
page->active--;
-   slab_freelist(page)[page->active] = objnr;
+   set_free_obj(page, page->active, objnr);
 }
 
 /*
@@ -4214,7 +4220,7 @@ static void handle_slab(unsigned long *n, struct 
kmem_cache *c,
 
for (j = page->active; j < c->num; j++) {
/* Skip freed item */
-   if (slab_freelist(page)[j] == i) {
+   if (get_free_obj(page, j) == i) {
active = false;
break;
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[REPOST PATCH 2/4] slab: introduce helper functions to get/set free object

2013-09-05 Thread Joonsoo Kim
In the following patches, to get/set free objects from the freelist
is changed so that simple casting doesn't work for it. Therefore,
introduce helper functions.

Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/mm/slab.c b/mm/slab.c
index 9d4bad5..a0e49bb 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2545,9 +2545,15 @@ static struct freelist *alloc_slabmgmt(struct kmem_cache 
*cachep,
return freelist;
 }
 
-static inline unsigned int *slab_freelist(struct page *page)
+static inline unsigned int get_free_obj(struct page *page, unsigned int idx)
 {
-   return (unsigned int *)(page-freelist);
+   return ((unsigned int *)page-freelist)[idx];
+}
+
+static inline void set_free_obj(struct page *page,
+   unsigned int idx, unsigned int val)
+{
+   ((unsigned int *)(page-freelist))[idx] = val;
 }
 
 static void cache_init_objs(struct kmem_cache *cachep,
@@ -2592,7 +2598,7 @@ static void cache_init_objs(struct kmem_cache *cachep,
if (cachep-ctor)
cachep-ctor(objp);
 #endif
-   slab_freelist(page)[i] = i;
+   set_free_obj(page, i, i);
}
 }
 
@@ -2611,7 +2617,7 @@ static void *slab_get_obj(struct kmem_cache *cachep, 
struct page *page,
 {
void *objp;
 
-   objp = index_to_obj(cachep, page, slab_freelist(page)[page-active]);
+   objp = index_to_obj(cachep, page, get_free_obj(page, page-active));
page-active++;
 #if DEBUG
WARN_ON(page_to_nid(virt_to_page(objp)) != nodeid);
@@ -2632,7 +2638,7 @@ static void slab_put_obj(struct kmem_cache *cachep, 
struct page *page,
 
/* Verify double free bug */
for (i = page-active; i  cachep-num; i++) {
-   if (slab_freelist(page)[i] == objnr) {
+   if (get_free_obj(page, i) == objnr) {
printk(KERN_ERR slab: double free detected in cache 
'%s', objp %p\n, cachep-name, objp);
BUG();
@@ -2640,7 +2646,7 @@ static void slab_put_obj(struct kmem_cache *cachep, 
struct page *page,
}
 #endif
page-active--;
-   slab_freelist(page)[page-active] = objnr;
+   set_free_obj(page, page-active, objnr);
 }
 
 /*
@@ -4214,7 +4220,7 @@ static void handle_slab(unsigned long *n, struct 
kmem_cache *c,
 
for (j = page-active; j  c-num; j++) {
/* Skip freed item */
-   if (slab_freelist(page)[j] == i) {
+   if (get_free_obj(page, j) == i) {
active = false;
break;
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/4] slab: introduce helper functions to get/set free object

2013-09-02 Thread Joonsoo Kim
In the following patches, to get/set free objects from the freelist
is changed so that simple casting doesn't work for it. Therefore,
introduce helper functions.

Signed-off-by: Joonsoo Kim 

diff --git a/mm/slab.c b/mm/slab.c
index 9d4bad5..a0e49bb 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2545,9 +2545,15 @@ static struct freelist *alloc_slabmgmt(struct kmem_cache 
*cachep,
return freelist;
 }
 
-static inline unsigned int *slab_freelist(struct page *page)
+static inline unsigned int get_free_obj(struct page *page, unsigned int idx)
 {
-   return (unsigned int *)(page->freelist);
+   return ((unsigned int *)page->freelist)[idx];
+}
+
+static inline void set_free_obj(struct page *page,
+   unsigned int idx, unsigned int val)
+{
+   ((unsigned int *)(page->freelist))[idx] = val;
 }
 
 static void cache_init_objs(struct kmem_cache *cachep,
@@ -2592,7 +2598,7 @@ static void cache_init_objs(struct kmem_cache *cachep,
if (cachep->ctor)
cachep->ctor(objp);
 #endif
-   slab_freelist(page)[i] = i;
+   set_free_obj(page, i, i);
}
 }
 
@@ -2611,7 +2617,7 @@ static void *slab_get_obj(struct kmem_cache *cachep, 
struct page *page,
 {
void *objp;
 
-   objp = index_to_obj(cachep, page, slab_freelist(page)[page->active]);
+   objp = index_to_obj(cachep, page, get_free_obj(page, page->active));
page->active++;
 #if DEBUG
WARN_ON(page_to_nid(virt_to_page(objp)) != nodeid);
@@ -2632,7 +2638,7 @@ static void slab_put_obj(struct kmem_cache *cachep, 
struct page *page,
 
/* Verify double free bug */
for (i = page->active; i < cachep->num; i++) {
-   if (slab_freelist(page)[i] == objnr) {
+   if (get_free_obj(page, i) == objnr) {
printk(KERN_ERR "slab: double free detected in cache "
"'%s', objp %p\n", cachep->name, objp);
BUG();
@@ -2640,7 +2646,7 @@ static void slab_put_obj(struct kmem_cache *cachep, 
struct page *page,
}
 #endif
page->active--;
-   slab_freelist(page)[page->active] = objnr;
+   set_free_obj(page, page->active, objnr);
 }
 
 /*
@@ -4214,7 +4220,7 @@ static void handle_slab(unsigned long *n, struct 
kmem_cache *c,
 
for (j = page->active; j < c->num; j++) {
/* Skip freed item */
-   if (slab_freelist(page)[j] == i) {
+   if (get_free_obj(page, j) == i) {
active = false;
break;
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/4] slab: introduce helper functions to get/set free object

2013-09-02 Thread Joonsoo Kim
In the following patches, to get/set free objects from the freelist
is changed so that simple casting doesn't work for it. Therefore,
introduce helper functions.

Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/mm/slab.c b/mm/slab.c
index 9d4bad5..a0e49bb 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2545,9 +2545,15 @@ static struct freelist *alloc_slabmgmt(struct kmem_cache 
*cachep,
return freelist;
 }
 
-static inline unsigned int *slab_freelist(struct page *page)
+static inline unsigned int get_free_obj(struct page *page, unsigned int idx)
 {
-   return (unsigned int *)(page-freelist);
+   return ((unsigned int *)page-freelist)[idx];
+}
+
+static inline void set_free_obj(struct page *page,
+   unsigned int idx, unsigned int val)
+{
+   ((unsigned int *)(page-freelist))[idx] = val;
 }
 
 static void cache_init_objs(struct kmem_cache *cachep,
@@ -2592,7 +2598,7 @@ static void cache_init_objs(struct kmem_cache *cachep,
if (cachep-ctor)
cachep-ctor(objp);
 #endif
-   slab_freelist(page)[i] = i;
+   set_free_obj(page, i, i);
}
 }
 
@@ -2611,7 +2617,7 @@ static void *slab_get_obj(struct kmem_cache *cachep, 
struct page *page,
 {
void *objp;
 
-   objp = index_to_obj(cachep, page, slab_freelist(page)[page-active]);
+   objp = index_to_obj(cachep, page, get_free_obj(page, page-active));
page-active++;
 #if DEBUG
WARN_ON(page_to_nid(virt_to_page(objp)) != nodeid);
@@ -2632,7 +2638,7 @@ static void slab_put_obj(struct kmem_cache *cachep, 
struct page *page,
 
/* Verify double free bug */
for (i = page-active; i  cachep-num; i++) {
-   if (slab_freelist(page)[i] == objnr) {
+   if (get_free_obj(page, i) == objnr) {
printk(KERN_ERR slab: double free detected in cache 
'%s', objp %p\n, cachep-name, objp);
BUG();
@@ -2640,7 +2646,7 @@ static void slab_put_obj(struct kmem_cache *cachep, 
struct page *page,
}
 #endif
page-active--;
-   slab_freelist(page)[page-active] = objnr;
+   set_free_obj(page, page-active, objnr);
 }
 
 /*
@@ -4214,7 +4220,7 @@ static void handle_slab(unsigned long *n, struct 
kmem_cache *c,
 
for (j = page-active; j  c-num; j++) {
/* Skip freed item */
-   if (slab_freelist(page)[j] == i) {
+   if (get_free_obj(page, j) == i) {
active = false;
break;
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/