Home

kobject

A kobject is the fundamental building block of the Linux kernel's object model used for representing kernel objects in sysfs. It is a lightweight, reference-counted container that participates in a hierarchical tree under the /sys pseudo-filesystem. Each kobject carries a name and may have a parent; it is associated with a kset (a group of related objects) and a kobj_type that describes its attributes and behavior.

The kobject hierarchy reflects kernel subsystems and devices. The parent pointer forms the tree; kset groups

Lifetime management is based on reference counting. Users can increase or decrease the reference count via

Attributes and sysfs integration are achieved by declaring attributes with kobj_attribute structures and grouping them into

Usage-wise, kobjects are widely used by drivers and kernel subsystems to expose information and controls. A

organize
related
objects;
kobj_type
describes
the
object's
attribute
set
and
lifecycle
hooks.
When
a
kobject
is
added
to
the
sysfs
tree,
corresponding
directories
are
created
and
files
representing
the
object's
attributes
are
created
from
the
defined
kobj_attributes
and
attribute
groups.
kobject_get
and
kobject_put.
When
the
last
reference
is
released,
a
release
callback
is
invoked,
allowing
the
subsystem
to
free
resources
and
remove
any
associated
sysfs
entries.
attribute
groups.
The
sysfs
interface
exposes
these
attributes
as
files,
enabling
runtime
inspection
and
control
without
requiring
a
reboot
or
recompilation.
driver
typically
creates
a
kobject
for
a
device
or
subsystem,
binds
it
into
the
appropriate
part
of
the
hierarchy,
and
defines
attributes
that
appear
under
the
/sys
hierarchy,
facilitating
user-space
interaction
and
debugging.