Skip to contentSkip to conversation

mm/slub: Factor out some common code.

PATCH In review George Spelvin 4 participants 10 messages Mar 16, 2011 – Mar 17, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 5/8 mm/slub: Factor out some common code.

For sysfs files that map a boolean to a flags bit.

---
 mm/slub.c |   93 ++++++++++++++++++++++++++++--------------------------------
 1 files changed, 43 insertions(+), 50 deletions(-)
mm/slub.c +43 -50
index e15aa7f..856246f 100644
@@ -3982,38 +3982,61 @@ static ssize_t objects_partial_show(struct kmem_cache *s, char *buf)
 }
 SLAB_ATTR_RO(objects_partial);
 
+static ssize_t flag_show(struct kmem_cache *s, char *buf, unsigned flag)
+{
+	return sprintf(buf, "%d\n", !!(s->flags & flag));
+}
+
+static ssize_t flag_store(struct kmem_cache *s,
+				const char *buf, size_t length, unsigned flag)
+{
+	s->flags &= ~flag;
+	if (buf[0] == '1')
+		s->flags |= flag;
+	return length;
+}
+
+/* Like above, but changes allocation size; so only allowed on empty slab */
+static ssize_t flag_store_sizechange(struct kmem_cache *s,
+				const char *buf, size_t length, unsigned flag)
+{
+	if (any_slab_objects(s))
+		return -EBUSY;
+
+	flag_store(s, buf, length, flag);
+	calculate_sizes(s, -1);
+	return length;
+}
+
 static ssize_t reclaim_account_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_RECLAIM_ACCOUNT));
+	return flag_show(s, buf, SLAB_RECLAIM_ACCOUNT);
 }
 
 static ssize_t reclaim_account_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	s->flags &= ~SLAB_RECLAIM_ACCOUNT;
-	if (buf[0] == '1')
-		s->flags |= SLAB_RECLAIM_ACCOUNT;
-	return length;
+	return flag_store(s, buf, length, SLAB_RECLAIM_ACCOUNT);
 }
 SLAB_ATTR(reclaim_account);
 
 static ssize_t hwcache_align_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_HWCACHE_ALIGN));
+	return flag_show(s, buf, SLAB_HWCACHE_ALIGN);
 }
 SLAB_ATTR_RO(hwcache_align);
 
 #ifdef CONFIG_ZONE_DMA
 static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_CACHE_DMA));
+	return flag_show(s, buf, SLAB_CACHE_DMA);
 }
 SLAB_ATTR_RO(cache_dma);
 #endif
 
 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
+	return flag_show(s, buf, SLAB_DESTROY_BY_RCU);
 }
 SLAB_ATTR_RO(destroy_by_rcu);
 
@@ -4032,88 +4055,61 @@ SLAB_ATTR_RO(total_objects);
 
 static ssize_t sanity_checks_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_DEBUG_FREE));
+	return flag_show(s, buf, SLAB_DEBUG_FREE);
 }
 
 static ssize_t sanity_checks_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	s->flags &= ~SLAB_DEBUG_FREE;
-	if (buf[0] == '1')
-		s->flags |= SLAB_DEBUG_FREE;
-	return length;
+	return flag_store(s, buf, length, SLAB_DEBUG_FREE);
 }
 SLAB_ATTR(sanity_checks);
 
 static ssize_t trace_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_TRACE));
+	return flag_show(s, buf, SLAB_TRACE);
 }
 
 static ssize_t trace_store(struct kmem_cache *s, const char *buf,
 							size_t length)
 {
-	s->flags &= ~SLAB_TRACE;
-	if (buf[0] == '1')
-		s->flags |= SLAB_TRACE;
-	return length;
+	return flag_store(s, buf, length, SLAB_TRACE);
 }
 SLAB_ATTR(trace);
 
 static ssize_t red_zone_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_RED_ZONE));
+	return flag_show(s, buf, SLAB_RED_ZONE);
 }
 
 static ssize_t red_zone_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	if (any_slab_objects(s))
-		return -EBUSY;
-
-	s->flags &= ~SLAB_RED_ZONE;
-	if (buf[0] == '1')
-		s->flags |= SLAB_RED_ZONE;
-	calculate_sizes(s, -1);
-	return length;
+	return flag_store_sizechange(s, buf, length, SLAB_RED_ZONE);
 }
 SLAB_ATTR(red_zone);
 
 static ssize_t poison_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_POISON));
+	return flag_show(s, buf, SLAB_POISON);
 }
 
 static ssize_t poison_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	if (any_slab_objects(s))
-		return -EBUSY;
-
-	s->flags &= ~SLAB_POISON;
-	if (buf[0] == '1')
-		s->flags |= SLAB_POISON;
-	calculate_sizes(s, -1);
-	return length;
+	return flag_store_sizechange(s, buf, length, SLAB_POISON);
 }
 SLAB_ATTR(poison);
 
 static ssize_t store_user_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_STORE_USER));
+	return flag_show(s, buf, SLAB_STORE_USER);
 }
 
 static ssize_t store_user_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	if (any_slab_objects(s))
-		return -EBUSY;
-
-	s->flags &= ~SLAB_STORE_USER;
-	if (buf[0] == '1')
-		s->flags |= SLAB_STORE_USER;
-	calculate_sizes(s, -1);
-	return length;
+	return flag_store_sizechange(s, buf, length, SLAB_STORE_USER);
 }
 SLAB_ATTR(store_user);
 
@@ -4156,16 +4152,13 @@ SLAB_ATTR_RO(free_calls);
 #ifdef CONFIG_FAILSLAB
 static ssize_t failslab_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_FAILSLAB));
+	return flag_show(s, buf, SLAB_FAILSLAB);
 }
 
 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
 							size_t length)
 {
-	s->flags &= ~SLAB_FAILSLAB;
-	if (buf[0] == '1')
-		s->flags |= SLAB_FAILSLAB;
-	return length;
+	return flag_store(s, buf, length, SLAB_FAILSLAB);
 }
 SLAB_ATTR(failslab);
 #endif
Signature · 8 lines
1.7.4.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 1 line · George Spelvin

For sysfs files that map a boolean to a flags bit.

This one's actually pretty nice. You should really try to put all the uncontroversial bits of a series first.

Quoted 196 lines
---
 mm/slub.c |   93 ++++++++++++++++++++++++++++--------------------------------
 1 files changed, 43 insertions(+), 50 deletions(-)
mm/slub.c +43 -50
index e15aa7f..856246f 100644
@@ -3982,38 +3982,61 @@ static ssize_t objects_partial_show(struct kmem_cache *s, char *buf)
 }
 SLAB_ATTR_RO(objects_partial);
 
+static ssize_t flag_show(struct kmem_cache *s, char *buf, unsigned flag)
+{
+	return sprintf(buf, "%d\n", !!(s->flags & flag));
+}
+
+static ssize_t flag_store(struct kmem_cache *s,
+				const char *buf, size_t length, unsigned flag)
+{
+	s->flags &= ~flag;
+	if (buf[0] == '1')
+		s->flags |= flag;
+	return length;
+}
+
+/* Like above, but changes allocation size; so only allowed on empty slab */
+static ssize_t flag_store_sizechange(struct kmem_cache *s,
+				const char *buf, size_t length, unsigned flag)
+{
+	if (any_slab_objects(s))
+		return -EBUSY;
+
+	flag_store(s, buf, length, flag);
+	calculate_sizes(s, -1);
+	return length;
+}
+
 static ssize_t reclaim_account_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_RECLAIM_ACCOUNT));
+	return flag_show(s, buf, SLAB_RECLAIM_ACCOUNT);
 }
 
 static ssize_t reclaim_account_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	s->flags &= ~SLAB_RECLAIM_ACCOUNT;
-	if (buf[0] == '1')
-		s->flags |= SLAB_RECLAIM_ACCOUNT;
-	return length;
+	return flag_store(s, buf, length, SLAB_RECLAIM_ACCOUNT);
 }
 SLAB_ATTR(reclaim_account);
 
 static ssize_t hwcache_align_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_HWCACHE_ALIGN));
+	return flag_show(s, buf, SLAB_HWCACHE_ALIGN);
 }
 SLAB_ATTR_RO(hwcache_align);
 
 #ifdef CONFIG_ZONE_DMA
 static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_CACHE_DMA));
+	return flag_show(s, buf, SLAB_CACHE_DMA);
 }
 SLAB_ATTR_RO(cache_dma);
 #endif
 
 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
+	return flag_show(s, buf, SLAB_DESTROY_BY_RCU);
 }
 SLAB_ATTR_RO(destroy_by_rcu);
 
@@ -4032,88 +4055,61 @@ SLAB_ATTR_RO(total_objects);
 
 static ssize_t sanity_checks_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_DEBUG_FREE));
+	return flag_show(s, buf, SLAB_DEBUG_FREE);
 }
 
 static ssize_t sanity_checks_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	s->flags &= ~SLAB_DEBUG_FREE;
-	if (buf[0] == '1')
-		s->flags |= SLAB_DEBUG_FREE;
-	return length;
+	return flag_store(s, buf, length, SLAB_DEBUG_FREE);
 }
 SLAB_ATTR(sanity_checks);
 
 static ssize_t trace_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_TRACE));
+	return flag_show(s, buf, SLAB_TRACE);
 }
 
 static ssize_t trace_store(struct kmem_cache *s, const char *buf,
 							size_t length)
 {
-	s->flags &= ~SLAB_TRACE;
-	if (buf[0] == '1')
-		s->flags |= SLAB_TRACE;
-	return length;
+	return flag_store(s, buf, length, SLAB_TRACE);
 }
 SLAB_ATTR(trace);
 
 static ssize_t red_zone_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_RED_ZONE));
+	return flag_show(s, buf, SLAB_RED_ZONE);
 }
 
 static ssize_t red_zone_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	if (any_slab_objects(s))
-		return -EBUSY;
-
-	s->flags &= ~SLAB_RED_ZONE;
-	if (buf[0] == '1')
-		s->flags |= SLAB_RED_ZONE;
-	calculate_sizes(s, -1);
-	return length;
+	return flag_store_sizechange(s, buf, length, SLAB_RED_ZONE);
 }
 SLAB_ATTR(red_zone);
 
 static ssize_t poison_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_POISON));
+	return flag_show(s, buf, SLAB_POISON);
 }
 
 static ssize_t poison_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	if (any_slab_objects(s))
-		return -EBUSY;
-
-	s->flags &= ~SLAB_POISON;
-	if (buf[0] == '1')
-		s->flags |= SLAB_POISON;
-	calculate_sizes(s, -1);
-	return length;
+	return flag_store_sizechange(s, buf, length, SLAB_POISON);
 }
 SLAB_ATTR(poison);
 
 static ssize_t store_user_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_STORE_USER));
+	return flag_show(s, buf, SLAB_STORE_USER);
 }
 
 static ssize_t store_user_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	if (any_slab_objects(s))
-		return -EBUSY;
-
-	s->flags &= ~SLAB_STORE_USER;
-	if (buf[0] == '1')
-		s->flags |= SLAB_STORE_USER;
-	calculate_sizes(s, -1);
-	return length;
+	return flag_store_sizechange(s, buf, length, SLAB_STORE_USER);
 }
 SLAB_ATTR(store_user);
 
@@ -4156,16 +4152,13 @@ SLAB_ATTR_RO(free_calls);
 #ifdef CONFIG_FAILSLAB
 static ssize_t failslab_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", !!(s->flags & SLAB_FAILSLAB));
+	return flag_show(s, buf, SLAB_FAILSLAB);
 }
 
 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
 							size_t length)
 {
-	s->flags &= ~SLAB_FAILSLAB;
-	if (buf[0] == '1')
-		s->flags |= SLAB_FAILSLAB;
-	return length;
+	return flag_store(s, buf, length, SLAB_FAILSLAB);
 }
 SLAB_ATTR(failslab);
 #endif
Signature · 9 lines
Mathematics is the supreme nostalgia of our time.


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
In reply to George Spelvin
Quoted 1 line · George Spelvin

For sysfs files that map a boolean to a flags bit.

Looks good to me. I'll cc Christoph and David too.

Quoted 199 lines

---
 mm/slub.c |   93 ++++++++++++++++++++++++++++--------------------------------

 1 files changed, 43 insertions(+), 50 deletions(-)
mm/slub.c +43 -51
index e15aa7f..856246f 100644
@@ -3982,38 +3982,61 @@ static ssize_t objects_partial_show(struct kmem_cache *s, char *buf)
  }
  SLAB_ATTR_RO(objects_partial);
 
+static ssize_t flag_show(struct kmem_cache *s, char *buf, unsigned flag)
+{
+       return sprintf(buf, "%d\n", !!(s->flags & flag));
+}
+
+static ssize_t flag_store(struct kmem_cache *s,
+                               const char *buf, size_t length, unsigned flag)
+{
+       s->flags &= ~flag;
+       if (buf[0] == '1')
+               s->flags |= flag;
+       return length;
+}
+
+/* Like above, but changes allocation size; so only allowed on empty slab */
+static ssize_t flag_store_sizechange(struct kmem_cache *s,
+                               const char *buf, size_t length, unsigned flag)
+{
+       if (any_slab_objects(s))
+               return -EBUSY;
+
+       flag_store(s, buf, length, flag);
+       calculate_sizes(s, -1);
+       return length;
+}
+
  static ssize_t reclaim_account_show(struct kmem_cache *s, char *buf)
  {
-       return sprintf(buf, "%d\n", !!(s->flags & SLAB_RECLAIM_ACCOUNT));
+       return flag_show(s, buf, SLAB_RECLAIM_ACCOUNT);
  }
 
  static ssize_t reclaim_account_store(struct kmem_cache *s,
                                const char *buf, size_t length)
  {
-       s->flags &= ~SLAB_RECLAIM_ACCOUNT;
-       if (buf[0] == '1')
-               s->flags |= SLAB_RECLAIM_ACCOUNT;
-       return length;
+       return flag_store(s, buf, length, SLAB_RECLAIM_ACCOUNT);
  }
  SLAB_ATTR(reclaim_account);
 
  static ssize_t hwcache_align_show(struct kmem_cache *s, char *buf)
  {
-       return sprintf(buf, "%d\n", !!(s->flags & SLAB_HWCACHE_ALIGN));
+       return flag_show(s, buf, SLAB_HWCACHE_ALIGN);
  }
  SLAB_ATTR_RO(hwcache_align);
 
  #ifdef CONFIG_ZONE_DMA
  static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
  {
-       return sprintf(buf, "%d\n", !!(s->flags & SLAB_CACHE_DMA));
+       return flag_show(s, buf, SLAB_CACHE_DMA);
  }
  SLAB_ATTR_RO(cache_dma);
  #endif
 
  static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
  {
-       return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
+       return flag_show(s, buf, SLAB_DESTROY_BY_RCU);
  }
  SLAB_ATTR_RO(destroy_by_rcu);
 
@@ -4032,88 +4055,61 @@ SLAB_ATTR_RO(total_objects);
 
  static ssize_t sanity_checks_show(struct kmem_cache *s, char *buf)
  {
-       return sprintf(buf, "%d\n", !!(s->flags & SLAB_DEBUG_FREE));
+       return flag_show(s, buf, SLAB_DEBUG_FREE);
  }
 
  static ssize_t sanity_checks_store(struct kmem_cache *s,
                                const char *buf, size_t length)
  {
-       s->flags &= ~SLAB_DEBUG_FREE;
-       if (buf[0] == '1')
-               s->flags |= SLAB_DEBUG_FREE;
-       return length;
+       return flag_store(s, buf, length, SLAB_DEBUG_FREE);
  }
  SLAB_ATTR(sanity_checks);
 
  static ssize_t trace_show(struct kmem_cache *s, char *buf)
  {
-       return sprintf(buf, "%d\n", !!(s->flags & SLAB_TRACE));
+       return flag_show(s, buf, SLAB_TRACE);
  }
 
  static ssize_t trace_store(struct kmem_cache *s, const char *buf,
                                                        size_t length)
  {
-       s->flags &= ~SLAB_TRACE;
-       if (buf[0] == '1')
-               s->flags |= SLAB_TRACE;
-       return length;
+       return flag_store(s, buf, length, SLAB_TRACE);
  }
  SLAB_ATTR(trace);
 
  static ssize_t red_zone_show(struct kmem_cache *s, char *buf)
  {
-       return sprintf(buf, "%d\n", !!(s->flags & SLAB_RED_ZONE));
+       return flag_show(s, buf, SLAB_RED_ZONE);
  }
 
  static ssize_t red_zone_store(struct kmem_cache *s,
                                const char *buf, size_t length)
  {
-       if (any_slab_objects(s))
-               return -EBUSY;
-
-       s->flags &= ~SLAB_RED_ZONE;
-       if (buf[0] == '1')
-               s->flags |= SLAB_RED_ZONE;
-       calculate_sizes(s, -1);
-       return length;
+       return flag_store_sizechange(s, buf, length, SLAB_RED_ZONE);
  }
  SLAB_ATTR(red_zone);
 
  static ssize_t poison_show(struct kmem_cache *s, char *buf)
  {
-       return sprintf(buf, "%d\n", !!(s->flags & SLAB_POISON));
+       return flag_show(s, buf, SLAB_POISON);
  }
 
  static ssize_t poison_store(struct kmem_cache *s,
                                const char *buf, size_t length)
  {
-       if (any_slab_objects(s))
-               return -EBUSY;
-
-       s->flags &= ~SLAB_POISON;
-       if (buf[0] == '1')
-               s->flags |= SLAB_POISON;
-       calculate_sizes(s, -1);
-       return length;
+       return flag_store_sizechange(s, buf, length, SLAB_POISON);
  }
  SLAB_ATTR(poison);
 
  static ssize_t store_user_show(struct kmem_cache *s, char *buf)
  {
-       return sprintf(buf, "%d\n", !!(s->flags & SLAB_STORE_USER));
+       return flag_show(s, buf, SLAB_STORE_USER);
  }
 
  static ssize_t store_user_store(struct kmem_cache *s,
                                const char *buf, size_t length)
  {
-       if (any_slab_objects(s))
-               return -EBUSY;
-
-       s->flags &= ~SLAB_STORE_USER;
-       if (buf[0] == '1')
-               s->flags |= SLAB_STORE_USER;
-       calculate_sizes(s, -1);
-       return length;
+       return flag_store_sizechange(s, buf, length, SLAB_STORE_USER);
  }
  SLAB_ATTR(store_user);
 
@@ -4156,16 +4152,13 @@ SLAB_ATTR_RO(free_calls);
  #ifdef CONFIG_FAILSLAB
  static ssize_t failslab_show(struct kmem_cache *s, char *buf)
  {
-       return sprintf(buf, "%d\n", !!(s->flags & SLAB_FAILSLAB));
+       return flag_show(s, buf, SLAB_FAILSLAB);
  }
 
  static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
                                                        size_t length)
  {
-       s->flags &= ~SLAB_FAILSLAB;
-       if (buf[0] == '1')
-               s->flags |= SLAB_FAILSLAB;
-       return length;
+       return flag_store(s, buf, length, SLAB_FAILSLAB);
  }
  SLAB_ATTR(failslab);
  #endif
--

1.7.4.1

Quoted 7 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

reviewer Acked-by on v1 5/8
#3 lore raw
In reply to George Spelvin
Quoted 1 line · George Spelvin

For sysfs files that map a boolean to a flags bit.

Where's your signed-off-by?

Quoted 28 lines
---
 mm/slub.c |   93 ++++++++++++++++++++++++++++--------------------------------
 1 files changed, 43 insertions(+), 50 deletions(-)
mm/slub.c +16 -0
index e15aa7f..856246f 100644
@@ -3982,38 +3982,61 @@ static ssize_t objects_partial_show(struct kmem_cache *s, char *buf)
 }
 SLAB_ATTR_RO(objects_partial);
 
+static ssize_t flag_show(struct kmem_cache *s, char *buf, unsigned flag)
+{
+	return sprintf(buf, "%d\n", !!(s->flags & flag));
+}
+
+static ssize_t flag_store(struct kmem_cache *s,
+				const char *buf, size_t length, unsigned flag)
+{
+	s->flags &= ~flag;
+	if (buf[0] == '1')
+		s->flags |= flag;
+	return length;
+}
+
+/* Like above, but changes allocation size; so only allowed on empty slab */
+static ssize_t flag_store_sizechange(struct kmem_cache *s,

mm/slub.c static ssize_t objects_partial_show(struct kmem_cache *s, char *buf) · line 4010

Quoted 10 lines
mm/slub.c +10 -0
+				const char *buf, size_t length, unsigned flag)
+{
+	if (any_slab_objects(s))
+		return -EBUSY;
+
+	flag_store(s, buf, length, flag);
+	calculate_sizes(s, -1);
+	return length;
+}
+

Nice cleanup.

"flag" should be unsigned long in all of these functions: the constants are declared with UL suffixes in slab.h.

After that's fixed,

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 1 line

Where's your signed-off-by?

Somewhere under the pile of crap on my desk. :-)
(More to the point, waiting for me to think it's good enough to submit For Real.)

Quoted 4 lines

Nice cleanup.

"flag" should be unsigned long in all of these functions: the constants are declared with UL suffixes in slab.h.

Actually, I did that deliberately. Because there's a problem I keep wondering about, which repeats many many times in the kernel:

*Why* are they unsigned long? That's an awkward type: 32 bits on many architectures, so we can't portably assign more than 32 bits, and on platforms where it's 64 bits, the upper 32 are just wasting space. (And REX prefixes on x86-64.)

Wouldn't it be a better cleanup to convert the whole lot to unsigned or u32?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 6 lines · George Spelvin
Quoted 1 line

Where's your signed-off-by?

Somewhere under the pile of crap on my desk. :-)
(More to the point, waiting for me to think it's good enough to submit For Real.)

Patches that you would like to propose but don't think are ready for merge should have s/PATCH/RFC/ done on the subject line.

Quoted 8 lines
Quoted 4 lines

Nice cleanup.

"flag" should be unsigned long in all of these functions: the constants are declared with UL suffixes in slab.h.

Actually, I did that deliberately. Because there's a problem I keep wondering about, which repeats many many times in the kernel:

You deliberately created a helper function to take an unsigned int when the actuals being passed in are all unsigned long to trigger a discussion on why they are unsigned long?

Quoted 5 lines

*Why* are they unsigned long? That's an awkward type: 32 bits on many architectures, so we can't portably assign more than 32 bits, and on platforms where it's 64 bits, the upper 32 are just wasting space. (And REX prefixes on x86-64.)

unsigned long uses the native word size of the architecture which can generate more efficient code; we typically imply that flags have a limited size by including leading zeros in their definition for 32-bit compatibility:

#define SLAB_DEBUG_FREE         0x00000100UL    /* DEBUG: Perform (expensive) checks on free */
#define SLAB_RED_ZONE           0x00000400UL    /* DEBUG: Red zone objs in a cache */
#define SLAB_POISON             0x00000800UL    /* DEBUG: Poison objects */

...

#6 lore raw
Quoted 2 lines

Patches that you would like to propose but don't think are ready for merge should have s/PATCH/RFC/ done on the subject line.

You're right; I should have. I blame git-format-patch's defaults, but mea culpa. (Now I know about the --subject-prefix=RFC option!)

Quoted 3 lines

You deliberately created a helper function to take an unsigned int when the actuals being passed in are all unsigned long to trigger a discussion on why they are unsigned long?

Er, no, I'm not that Machiavellian.
I deliberately did it because it was obvious that the flags would always fit into an "unsigned", so I didn't need "unsigned long".

(Actually, I owe you an apology; when writing that e-mail, I remember thinking "I should go back and clarify that statement", but forgot before hitting send.)

Quoted 4 lines

unsigned long uses the native word size of the architecture which can generate more efficient code; we typically imply that flags have a limited size by including leading zeros in their definition for 32-bit compatibility:

Um, can you name a (64-bit) architecture on which 32-bit is more expensive than 64-bit? On x86-64, it's potentially cheaper, and even the infamous Alpha 21064 has no penalty for 32-bit accesses. SPARC, MIPS, PPC, Itanium, what else? I don't know about z/ARchitecture, but given the emphasis on backward compatibility in IBM's mainframes, it seems hard to imagine.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw

Hi George!

Quoted 2 lines · George Spelvin

Um, can you name a (64-bit) architecture on which 32-bit is more expensive than 64-bit?

I certainly don't but I'd still like to ask you to change it to 'unsigned long'. That's a Linux kernel idiom and we're not going to change the whole kernel.

Pekka

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
Quoted 3 lines

I certainly don't but I'd still like to ask you to change it to 'unsigned long'. That's a Linux kernel idiom and we're not going to change the whole kernel.

Damn, and I just prepared the following patch. Should I, instead, do

include/linux/slab_def.h +1 -1
@@ -62,5 +62,5 @@ struct kmem_cache {
 /* 3) touched by every alloc & free from the backend */
 
-	unsigned int flags;		/* constant flags */
+	unsigned long flags;		/* constant flags */
 	unsigned int num;		/* # of objs per slab */
 

... because the original slab code uses an unsigned int. To fix it the other way (for SLAB_ flags only) is a patch like this:

#9 lore raw
Quoted 15 lines · George Spelvin
Quoted 3 lines

I certainly don't but I'd still like to ask you to change it to 'unsigned long'. That's a Linux kernel idiom and we're not going to change the whole kernel.

Damn, and I just prepared the following patch.  Should I, instead, do

include/linux/slab_def.h +1 -1
@@ -62,5 +62,5 @@ struct kmem_cache {
  /* 3) touched by every alloc & free from the backend */
 
-       unsigned int flags;             /* constant flags */
+       unsigned long flags;            /* constant flags */

       unsigned int num;               /* # of objs per slab */

Quoted 1 line

... because the original slab code uses an unsigned int.

Looks good to me.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>