mm/damon/sysfs-schemes.c

Source file repositories/reference/linux-study-clean/mm/damon/sysfs-schemes.c

File Facts

System
Linux kernel
Corpus path
mm/damon/sysfs-schemes.c
Extension
.c
Size
81966 bytes
Lines
3155
Domain
Core OS
Bucket
Memory Management
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct damos_sysfs_probe {
	struct kobject kobj;
	unsigned char hits;
};

static struct damos_sysfs_probe *damos_sysfs_probe_alloc(unsigned char hits)
{
	struct damos_sysfs_probe *probe;

	probe = kzalloc_obj(*probe);
	if (!probe)
		return NULL;
	probe->hits = hits;
	return probe;
}

static ssize_t hits_show(struct kobject *kobj, struct kobj_attribute *attr,
		char *buf)
{
	struct damos_sysfs_probe *probe = container_of(kobj,
			struct damos_sysfs_probe, kobj);

	return sysfs_emit(buf, "%hhu\n", probe->hits);
}

static void damos_sysfs_probe_release(struct kobject *kobj)
{
	struct damos_sysfs_probe *probe = container_of(kobj,
			struct damos_sysfs_probe, kobj);

	kfree(probe);
}

static struct kobj_attribute damos_sysfs_probe_hits_attr =
		__ATTR_RO_MODE(hits, 0400);

static struct attribute *damos_sysfs_probe_attrs[] = {
	&damos_sysfs_probe_hits_attr.attr,
	NULL,
};
ATTRIBUTE_GROUPS(damos_sysfs_probe);

static const struct kobj_type damos_sysfs_probe_ktype = {
	.release = damos_sysfs_probe_release,
	.sysfs_ops = &kobj_sysfs_ops,
	.default_groups = damos_sysfs_probe_groups,
};

/*
 * probes directory
 */

struct damos_sysfs_probes {
	struct kobject kobj;
	struct damos_sysfs_probe **probes_arr;
	int nr;
};

static struct damos_sysfs_probes *damos_sysfs_probes_alloc(void)
{
	return kzalloc_obj(struct damos_sysfs_probes);
}

static void damos_sysfs_probes_rm_dirs(struct damos_sysfs_probes *probes)
{
	struct damos_sysfs_probe **probes_arr = probes->probes_arr;
	int i;

	for (i = 0; i < probes->nr; i++)
		kobject_put(&probes_arr[i]->kobj);
	probes->nr = 0;
	kfree(probes_arr);
	probes->probes_arr = NULL;
}

static int damos_sysfs_probes_add_dirs(struct damos_sysfs_probes *probes,
		struct damon_ctx *ctx, struct damon_region *region)
{
	struct damon_probe *probe;
	struct damos_sysfs_probe **probes_arr;
	int i = 0;

	damon_for_each_probe(probe, ctx)
		i++;

	if (!i)
		return 0;

	probes_arr = kmalloc_objs(*probes_arr, i);
	if (!probes_arr)

Annotation

Implementation Notes