Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/mempolicy: prepare weighted interleave sysfs for memory hotplug

Previously, the weighted interleave sysfs structure was statically managed
during initialization. This prevented new nodes from being recognized
when memory hotplug events occurred, limiting the ability to update or
extend sysfs entries dynamically at runtime.

To address this, this patch refactors the sysfs infrastructure and
encapsulates it within a new structure, `sysfs_wi_group`, which holds both
the kobject and an array of node attribute pointers.

By allocating this group structure globally, the per-node sysfs attributes
can be managed beyond initialization time, enabling external modules to
insert or remove node entries in response to events such as memory hotplug
or node online/offline transitions.

Instead of allocating all per-node sysfs attributes at once, the
initialization path now uses the existing sysfs_wi_node_add() and
sysfs_wi_node_delete() helpers. This refactoring makes it possible to
modularly manage per-node sysfs entries and ensures the infrastructure is
ready for runtime extension.

Link: https://lkml.kernel.org/r/20250417072839.711-3-rakie.kim@sk.com
Signed-off-by: Rakie Kim <rakie.kim@sk.com>
Reviewed-by: Gregory Price <gourry@gourry.net>
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Honggyu Kim <honggyu.kim@sk.com>
Cc: "Huang, Ying" <ying.huang@linux.alibaba.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Yunjeong Mun <yunjeong.mun@sk.com>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Rakie Kim and committed by
Andrew Morton
cf8cecf2 bb52e89d

+31 -33
+31 -33
mm/mempolicy.c
··· 3427 3427 int nid; 3428 3428 }; 3429 3429 3430 + struct sysfs_wi_group { 3431 + struct kobject wi_kobj; 3432 + struct iw_node_attr *nattrs[]; 3433 + }; 3434 + 3435 + static struct sysfs_wi_group *wi_group; 3436 + 3430 3437 static ssize_t node_show(struct kobject *kobj, struct kobj_attribute *attr, 3431 3438 char *buf) 3432 3439 { ··· 3476 3469 return count; 3477 3470 } 3478 3471 3479 - static struct iw_node_attr **node_attrs; 3480 - 3481 - static void sysfs_wi_node_delete(struct iw_node_attr *node_attr, 3482 - struct kobject *parent) 3472 + static void sysfs_wi_node_delete(int nid) 3483 3473 { 3484 - if (!node_attr) 3474 + if (!wi_group->nattrs[nid]) 3485 3475 return; 3486 - sysfs_remove_file(parent, &node_attr->kobj_attr.attr); 3487 - kfree(node_attr->kobj_attr.attr.name); 3488 - kfree(node_attr); 3476 + 3477 + sysfs_remove_file(&wi_group->wi_kobj, 3478 + &wi_group->nattrs[nid]->kobj_attr.attr); 3479 + kfree(wi_group->nattrs[nid]->kobj_attr.attr.name); 3480 + kfree(wi_group->nattrs[nid]); 3489 3481 } 3490 3482 3491 - static void sysfs_wi_node_delete_all(struct kobject *wi_kobj) 3483 + static void sysfs_wi_node_delete_all(void) 3492 3484 { 3493 3485 int nid; 3494 3486 3495 3487 for (nid = 0; nid < nr_node_ids; nid++) 3496 - sysfs_wi_node_delete(node_attrs[nid], wi_kobj); 3488 + sysfs_wi_node_delete(nid); 3497 3489 } 3498 3490 3499 3491 static void iw_table_free(void) ··· 3509 3503 kfree(old); 3510 3504 } 3511 3505 3512 - static void wi_cleanup(struct kobject *wi_kobj) { 3513 - sysfs_wi_node_delete_all(wi_kobj); 3506 + static void wi_cleanup(void) { 3507 + sysfs_wi_node_delete_all(); 3514 3508 iw_table_free(); 3515 - kfree(node_attrs); 3516 3509 } 3517 3510 3518 3511 static void wi_kobj_release(struct kobject *wi_kobj) 3519 3512 { 3520 - kfree(wi_kobj); 3513 + kfree(wi_group); 3521 3514 } 3522 3515 3523 3516 static const struct kobj_type wi_ktype = { ··· 3524 3519 .release = wi_kobj_release, 3525 3520 }; 3526 3521 3527 - static int add_weight_node(int nid, struct kobject *wi_kobj) 3522 + static int sysfs_wi_node_add(int nid) 3528 3523 { 3529 3524 struct iw_node_attr *node_attr; 3530 3525 char *name; ··· 3546 3541 node_attr->kobj_attr.store = node_store; 3547 3542 node_attr->nid = nid; 3548 3543 3549 - if (sysfs_create_file(wi_kobj, &node_attr->kobj_attr.attr)) { 3544 + if (sysfs_create_file(&wi_group->wi_kobj, &node_attr->kobj_attr.attr)) { 3550 3545 kfree(node_attr->kobj_attr.attr.name); 3551 3546 kfree(node_attr); 3552 3547 pr_err("failed to add attribute to weighted_interleave\n"); 3553 3548 return -ENOMEM; 3554 3549 } 3555 3550 3556 - node_attrs[nid] = node_attr; 3551 + wi_group->nattrs[nid] = node_attr; 3557 3552 return 0; 3558 3553 } 3559 3554 3560 - static int add_weighted_interleave_group(struct kobject *root_kobj) 3555 + static int __init add_weighted_interleave_group(struct kobject *mempolicy_kobj) 3561 3556 { 3562 - struct kobject *wi_kobj; 3563 3557 int nid, err; 3564 3558 3565 - node_attrs = kcalloc(nr_node_ids, sizeof(struct iw_node_attr *), 3566 - GFP_KERNEL); 3567 - if (!node_attrs) 3559 + wi_group = kzalloc(struct_size(wi_group, nattrs, nr_node_ids), 3560 + GFP_KERNEL); 3561 + if (!wi_group) 3568 3562 return -ENOMEM; 3569 3563 3570 - wi_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL); 3571 - if (!wi_kobj) { 3572 - kfree(node_attrs); 3573 - return -ENOMEM; 3574 - } 3575 - 3576 - err = kobject_init_and_add(wi_kobj, &wi_ktype, root_kobj, 3564 + err = kobject_init_and_add(&wi_group->wi_kobj, &wi_ktype, mempolicy_kobj, 3577 3565 "weighted_interleave"); 3578 3566 if (err) 3579 3567 goto err_put_kobj; 3580 3568 3581 3569 for_each_node_state(nid, N_POSSIBLE) { 3582 - err = add_weight_node(nid, wi_kobj); 3570 + err = sysfs_wi_node_add(nid); 3583 3571 if (err) { 3584 3572 pr_err("failed to add sysfs [node%d]\n", nid); 3585 3573 goto err_cleanup_kobj; ··· 3582 3584 return 0; 3583 3585 3584 3586 err_cleanup_kobj: 3585 - wi_cleanup(wi_kobj); 3586 - kobject_del(wi_kobj); 3587 + wi_cleanup(); 3588 + kobject_del(&wi_group->wi_kobj); 3587 3589 err_put_kobj: 3588 - kobject_put(wi_kobj); 3590 + kobject_put(&wi_group->wi_kobj); 3589 3591 return err; 3590 3592 } 3591 3593