linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] mm/slab: clean up and constify sysfs attributes
@ 2026-02-23 21:37 Thomas Weißschuh
  2026-02-23 21:37 ` [PATCH 1/2] mm/slab: create sysfs attribute through default_groups Thomas Weißschuh
  2026-02-23 21:37 ` [PATCH 2/2] mm/slab: constify sysfs attributes Thomas Weißschuh
  0 siblings, 2 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-02-23 21:37 UTC (permalink / raw)
  To: Vlastimil Babka, Andrew Morton, Christoph Lameter,
	David Rientjes, Roman Gushchin, Harry Yoo
  Cc: linux-mm, linux-kernel, Thomas Weißschuh

Some small cleanups to the slab sysfs attributes.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (2):
      mm/slab: create sysfs attribute through default_groups
      mm/slab: constify sysfs attributes

 mm/slub.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260223-sysfs-const-slub-3bd764c37b6b

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] mm/slab: create sysfs attribute through default_groups
  2026-02-23 21:37 [PATCH 0/2] mm/slab: clean up and constify sysfs attributes Thomas Weißschuh
@ 2026-02-23 21:37 ` Thomas Weißschuh
  2026-02-24  7:49   ` Harry Yoo
  2026-02-23 21:37 ` [PATCH 2/2] mm/slab: constify sysfs attributes Thomas Weißschuh
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Weißschuh @ 2026-02-23 21:37 UTC (permalink / raw)
  To: Vlastimil Babka, Andrew Morton, Christoph Lameter,
	David Rientjes, Roman Gushchin, Harry Yoo
  Cc: linux-mm, linux-kernel, Thomas Weißschuh

The driver core can automatically create custom type attributes.
This makes the code and error-handling shorter.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 mm/slub.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 862642c165ed..a48ea23b1728 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -9317,9 +9317,7 @@ static struct attribute *slab_attrs[] = {
 	NULL
 };
 
-static const struct attribute_group slab_attr_group = {
-	.attrs = slab_attrs,
-};
+ATTRIBUTE_GROUPS(slab);
 
 static ssize_t slab_attr_show(struct kobject *kobj,
 				struct attribute *attr,
@@ -9366,6 +9364,7 @@ static const struct sysfs_ops slab_sysfs_ops = {
 static const struct kobj_type slab_ktype = {
 	.sysfs_ops = &slab_sysfs_ops,
 	.release = kmem_cache_release,
+	.default_groups = slab_groups,
 };
 
 static struct kset *slab_kset;
@@ -9453,10 +9452,6 @@ static int sysfs_slab_add(struct kmem_cache *s)
 	if (err)
 		goto out;
 
-	err = sysfs_create_group(&s->kobj, &slab_attr_group);
-	if (err)
-		goto out_del_kobj;
-
 	if (!unmergeable) {
 		/* Setup first alias */
 		sysfs_slab_alias(s, s->name);
@@ -9465,9 +9460,6 @@ static int sysfs_slab_add(struct kmem_cache *s)
 	if (!unmergeable)
 		kfree(name);
 	return err;
-out_del_kobj:
-	kobject_del(&s->kobj);
-	goto out;
 }
 
 void sysfs_slab_unlink(struct kmem_cache *s)

-- 
2.53.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mm/slab: constify sysfs attributes
  2026-02-23 21:37 [PATCH 0/2] mm/slab: clean up and constify sysfs attributes Thomas Weißschuh
  2026-02-23 21:37 ` [PATCH 1/2] mm/slab: create sysfs attribute through default_groups Thomas Weißschuh
@ 2026-02-23 21:37 ` Thomas Weißschuh
  2026-02-24  7:52   ` Harry Yoo
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Weißschuh @ 2026-02-23 21:37 UTC (permalink / raw)
  To: Vlastimil Babka, Andrew Morton, Christoph Lameter,
	David Rientjes, Roman Gushchin, Harry Yoo
  Cc: linux-mm, linux-kernel, Thomas Weißschuh

These attributes are never modified, make them read-only.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 mm/slub.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index a48ea23b1728..73051cf77353 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -8833,7 +8833,7 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
 	return len;
 }
 
-#define to_slab_attr(n) container_of(n, struct slab_attribute, attr)
+#define to_slab_attr(n) container_of_const(n, struct slab_attribute, attr)
 #define to_slab(n) container_of(n, struct kmem_cache, kobj)
 
 struct slab_attribute {
@@ -8843,10 +8843,10 @@ struct slab_attribute {
 };
 
 #define SLAB_ATTR_RO(_name) \
-	static struct slab_attribute _name##_attr = __ATTR_RO_MODE(_name, 0400)
+	static const struct slab_attribute _name##_attr = __ATTR_RO_MODE(_name, 0400)
 
 #define SLAB_ATTR(_name) \
-	static struct slab_attribute _name##_attr = __ATTR_RW_MODE(_name, 0600)
+	static const struct slab_attribute _name##_attr = __ATTR_RW_MODE(_name, 0600)
 
 static ssize_t slab_size_show(struct kmem_cache *s, char *buf)
 {
@@ -9240,7 +9240,7 @@ static ssize_t skip_kfence_store(struct kmem_cache *s,
 SLAB_ATTR(skip_kfence);
 #endif
 
-static struct attribute *slab_attrs[] = {
+static const struct attribute *const slab_attrs[] = {
 	&slab_size_attr.attr,
 	&object_size_attr.attr,
 	&objs_per_slab_attr.attr,
@@ -9323,7 +9323,7 @@ static ssize_t slab_attr_show(struct kobject *kobj,
 				struct attribute *attr,
 				char *buf)
 {
-	struct slab_attribute *attribute;
+	const struct slab_attribute *attribute;
 	struct kmem_cache *s;
 
 	attribute = to_slab_attr(attr);
@@ -9339,7 +9339,7 @@ static ssize_t slab_attr_store(struct kobject *kobj,
 				struct attribute *attr,
 				const char *buf, size_t len)
 {
-	struct slab_attribute *attribute;
+	const struct slab_attribute *attribute;
 	struct kmem_cache *s;
 
 	attribute = to_slab_attr(attr);

-- 
2.53.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mm/slab: create sysfs attribute through default_groups
  2026-02-23 21:37 ` [PATCH 1/2] mm/slab: create sysfs attribute through default_groups Thomas Weißschuh
@ 2026-02-24  7:49   ` Harry Yoo
  0 siblings, 0 replies; 5+ messages in thread
From: Harry Yoo @ 2026-02-24  7:49 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Vlastimil Babka, Andrew Morton, Christoph Lameter,
	David Rientjes, Roman Gushchin, linux-mm, linux-kernel

On Mon, Feb 23, 2026 at 10:37:43PM +0100, Thomas Weißschuh wrote:
> The driver core can automatically create custom type attributes.
> This makes the code and error-handling shorter.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---

Looks good to me,
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>

-- 
Cheers,
Harry / Hyeonggon


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mm/slab: constify sysfs attributes
  2026-02-23 21:37 ` [PATCH 2/2] mm/slab: constify sysfs attributes Thomas Weißschuh
@ 2026-02-24  7:52   ` Harry Yoo
  0 siblings, 0 replies; 5+ messages in thread
From: Harry Yoo @ 2026-02-24  7:52 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Vlastimil Babka, Andrew Morton, Christoph Lameter,
	David Rientjes, Roman Gushchin, linux-mm, linux-kernel

On Mon, Feb 23, 2026 at 10:37:44PM +0100, Thomas Weißschuh wrote:
> These attributes are never modified, make them read-only.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---

Looks good to me,
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>

-- 
Cheers,
Harry / Hyeonggon


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-24  7:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-23 21:37 [PATCH 0/2] mm/slab: clean up and constify sysfs attributes Thomas Weißschuh
2026-02-23 21:37 ` [PATCH 1/2] mm/slab: create sysfs attribute through default_groups Thomas Weißschuh
2026-02-24  7:49   ` Harry Yoo
2026-02-23 21:37 ` [PATCH 2/2] mm/slab: constify sysfs attributes Thomas Weißschuh
2026-02-24  7:52   ` Harry Yoo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox