Skip to contentSkip to conversation

Machine Learning (ML) library in Linux kernel

RFC PATCH In review Viacheslav Dubeyko 5 participants 14 messages Feb 6 – Feb 10

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

cover Machine Learning (ML) library in Linux kernel

Hello,

This patchset introduces initial vision of Machine Learning (ML) library in Linux kernel. It is an effort to define the ML library API and to elaborate the way of running ML models in Linux kernel.

Linux kernel is a huge code base with enormous number of subsystems and possible configuration options. Complexity and changing nature of modern workloads result in complexity of elaborating an efficient configuration and state of running Linux kernel.

Machine Learning (ML) is approach/area of learning from data, finding patterns, and making predictions without implementing algorithms by developers. The number of areas of ML applications is growing with every day. Generally speaking, ML can introduce a self-evolving and self-learning capability in Linux kernel. There are already research works and industry efforts to employ ML approaches for configuration and optimization the Linux kernel. However, introduction of ML approaches in Linux kernel is not so simple and straightforward way. There are multiple problems and unanswered questions on this road. First of all, any ML model requires the floating-point operations (FPU) for running. But there is no direct use of FPUs in kernel space. Also, ML model requires training phase that can be a reason of significant performance degradation of Linux kernel. Even inference phase could be problematic from the performance point of view on kernel side. The using of ML approaches in Linux kernel is inevitable step. But, how can we use ML approaches in Linux kernel? Which infrastructure do we need to adopt ML models in Linux kernel?

What is the goal of using ML models in Linux kernel? The main goal is to employ ML models for elaboration of a logic of particular Linux kernel subsystem based on processing data or/and an efficient subsystem configuration based on internal state of subsystem. As a result, it needs:
(1) collect data for training, (2) execute ML model training phase,
(3) test trained ML model, (4) use ML model for executing the inference phase. The ML model inference can be used for recommendation of Linux kernel subsystem configuration or/and for injecting a synthesized subsystem logic into kernel space (for example, eBPF logic).

How ML infrastructure can be designed in Linux kernel? It needs to introduce in Linux kernel a special ML library that can implement a generalized interface of interaction between ML model’s thread in user-space and kernel subsystem. Likewise interface requires to have the means:
(1) create/initialize/destroy ML model proxy in kernel subsystem,
(2) start/stop ML model proxy, (3) get/preprocess/publish data sets from kernel space, (4) receive/preprocess/apply ML model recommendation(s) from user-space, (5) execute synthesized logic/recommendations in kernel-space,
(6) estimate efficiency of synthesized logic/recommendations,
(7) execute error back-propagation with the goal of correction ML model on user-space side.

The create and initialize logic can be executed by kernel subsystem during module load or Linux kernel start (oppositely, module unload or kernel shutdown will execute destroy of ML model proxy logic). ML model thread in user-space will be capable to re-initialize and to execute the start/stop logic of ML model proxy on kernel side. First of all, ML model needs to be trained by data from kernel space. The data can be requested by ML model from user-space or data can be published by ML model proxy from kernel-space. The sysfs interface can be used to orchestrate this interaction. As a result, ML model in user-space should be capable to extract data set(s) from kernel space through sysfs, FUSE or character device. Extracted data can be stored in persistent storage and, finally, ML model can be trained in user-space by accessing these data.

The continuous learning model can be adopted during training phase. It implies that kernel subsystem can receive ML model recommendations even during training phase. ML model proxy on kernel side can estimate the current kernel subsystem state, tries to apply the ML model recommendations, and estimate the efficiency of applied recommendations. Generally speaking, ML model proxy on kernel side can consider several modes of interaction with ML model recommendations: (1) emergency mode,
(2) learning mode, (3) collaboration mode, (4) recommendation mode. The emergency mode is the mode when kernel subsystem is in critical state and it is required to work as efficient as possible without capability of involving the ML model recommendations (for example, ML model recommendations are completely inadequate or load is very high). The learning mode implies that kernel subsystem can try to apply the ML model recommendations for some operations with the goal of estimation the maturity of ML model. Also, ML model proxy can degrade the mode to learning state if ML model recommendations becomes inefficient. The collaboration mode has the goal of using ML recommendations in 50% of operations with the goal of achieving mature state of ML model. And, finally, ML model proxy can convert kernel subsystem in recommendation mode if ML model is mature enough and efficiency of applying the ML recommendations is higher than using human-made algorithms. The back-propagation approach can be used to correct the ML model by means of sharing feedback of efficiency estimation from kernel to user-space side.

[REFERENCES]
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
[2] https://www.youtube.com/watch?v=E7q0SKeniXU
[3] https://github.com/kernel-ml-lib/ml-lib
[4] https://github.com/kernel-ml-lib/ml-lib-linux

Viacheslav Dubeyko (4):
ml-lib: Introduce Machine Learning (ML) library declarations
ml-lib: Implement PoC of Machine Learning (ML) library functionality
ml-lib: Implement simple testing character device driver
ml-lib: Implement simple user-space testing application

 include/linux/ml-lib/ml_lib.h                 | 425 ++++++++++
 lib/Kconfig                                   |   6 +
 lib/Makefile                                  |   2 +
 lib/ml-lib/Kconfig                            |  18 +
 lib/ml-lib/Makefile                           |   7 +
 lib/ml-lib/ml_lib_main.c                      | 758 ++++++++++++++++++
 lib/ml-lib/sysfs.c                            | 187 +++++
 lib/ml-lib/sysfs.h                            |  17 +
 lib/ml-lib/test_driver/Kconfig                |  22 +
 lib/ml-lib/test_driver/Makefile               |   5 +
 lib/ml-lib/test_driver/README.md              | 233 ++++++
 lib/ml-lib/test_driver/ml_lib_char_dev.c      | 530 ++++++++++++
 .../test_application/ml_lib_char_dev_ioctl.h  |  21 +
 .../test_application/test_ml_lib_char_dev.c   | 206 +++++
 14 files changed, 2437 insertions(+)
 create mode 100644 include/linux/ml-lib/ml_lib.h
 create mode 100644 lib/ml-lib/Kconfig
 create mode 100644 lib/ml-lib/Makefile
 create mode 100644 lib/ml-lib/ml_lib_main.c
 create mode 100644 lib/ml-lib/sysfs.c
 create mode 100644 lib/ml-lib/sysfs.h
 create mode 100644 lib/ml-lib/test_driver/Kconfig
 create mode 100644 lib/ml-lib/test_driver/Makefile
 create mode 100644 lib/ml-lib/test_driver/README.md
 create mode 100644 lib/ml-lib/test_driver/ml_lib_char_dev.c
 create mode 100644 lib/ml-lib/test_driver/test_application/ml_lib_char_dev_ioctl.h
 create mode 100644 lib/ml-lib/test_driver/test_application/test_ml_lib_char_dev.c
Signature · 1 line
2.34.1
#1 lore raw

RFC PATCH 1/4 ml-lib: Introduce Machine Learning (ML) library declarations

Any kernel subsystem can be extended by one or several ML model(s). ML model is represented by struct ml_lib_model that contains:
(1) ML model mode, (2) ML model state, (3) pointer on parent kernel subsystem, (4) parent kernel subsystem state, (5) ML model options,
(6) current dataset, (7) ML model specialized operations,
(8) dataset specialized operations.

Any kernel subsystem can be in several modes that define how this subsystem interacts with ML model in user-space:
(1) EMERGENCY_MODE - ignore ML model and run default algorithm(s),
(2) LEARNING_MODE - ML model is learning and any recommendations requires of checking and errors back-propagation,
(3) COLLABORATION_MODE - ML model has good prediction but still requires correction by default algorithm(s),
(4) RECOMMENDATION_MODE - ML model is capable to substitute the default algorithm(s).

ML model can be: (1) created, (2) initialized, (3) started,
(4) running, (5) stopped, (6) shutted down.

The API of ML model includes:
(1) ml_model_create() - create ML model and initialize generic field
(2) ml_model_init() - execute specialized logic of ML model initialization
(3) ml_model_re_init() - execute specialized logic of ML model re-init
(4) ml_model_start() - start ML model activity
(5) ml_model_stop() - stop ML model activity
(6) ml_model_destroy() - destroy ML model and free all allocated memory
(7) get_system_state() - get current state of parent kernel subsystem
(8) ml_model_get_dataset() - prepare dataset for extraction by user-space agent
(9) ml_model_discard_dataset() - discard/obsolete dataset by user-space agent
(10) ml_model_preprocess_data() - preprocess data of current dataset
(11) ml_model_publish_data() - notify user-space agent about new dataset
(12) ml_model_preprocess_recommendation() - preprocess ML model recommendations
(13) estimate_system_state() - estimate parent kernel subsystem mode
(14) apply_ml_model_recommendation() - apply ML model recommendations
(15) execute_ml_model_operation() - execute logic following ML model mode
(16) estimate_ml_model_efficiency() - estimate ML model efficiency
(17) ml_model_error_backpropagation() - execute error backpropagation
(18) correct_system_state() - correct parent kernel subsystem mode

---
 include/linux/ml-lib/ml_lib.h | 425 ++++++++++++++++++++++++++++++++++
 1 file changed, 425 insertions(+)
 create mode 100644 include/linux/ml-lib/ml_lib.h
include/linux/ml-lib/ml_lib.h new file +425 -0
new file mode 100644
index 000000000000..001e781e0bf1
@@ -0,0 +1,425 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Machine Learning (ML) library
+ *
+ * Copyright (C) 2025-2026 Viacheslav Dubeyko <[email protected]>
+ */
+
+#ifndef _LINUX_ML_LIB_H
+#define _LINUX_ML_LIB_H
+
+/*
+ * Any kernel subsystem can be in several modes
+ * that define how this subsystem interacts with
+ * ML model in user-space:
+ * (1) EMERGENCY_MODE - ignore ML model and run default algorithm(s).
+ * (2) LEARNING_MODE - ML model is learning and any recommendations
+ *                     requires of checking and errors back-propagation.
+ * (3) COLLABORATION_MODE - ML model has good prediction but still
+ *                          requires correction by default algorithm(s).
+ * (4) RECOMMENDATION_MODE - ML model is capable to substitute
+ *                           the default algorithm(s).
+ */
+enum ml_lib_system_mode {
+	ML_LIB_UNKNOWN_MODE,
+	ML_LIB_EMERGENCY_MODE,
+	ML_LIB_LEARNING_MODE,
+	ML_LIB_COLLABORATION_MODE,
+	ML_LIB_RECOMMENDATION_MODE,
+	ML_LIB_MODE_MAX
+};
+
+enum {
+	ML_LIB_UNKNOWN_MODEL_STATE,
+	ML_LIB_MODEL_CREATED,
+	ML_LIB_MODEL_INITIALIZED,
+	ML_LIB_MODEL_STARTED,
+	ML_LIB_MODEL_RUNNING,
+	ML_LIB_MODEL_STOPPED,
+	ML_LIB_MODEL_SHUTTING_DOWN,
+	ML_LIB_MODEL_STATE_MAX
+};
+
+struct ml_lib_model;
+
+#define ML_LIB_SLEEP_TIMEOUT_DEFAULT	(10)
+
+/*
+ * struct ml_lib_model_options - ML model global options
+ * @sleep_timeout: main thread's sleep timeout
+ *
+ * These options define behavior of ML model.
+ * The options can be defined during init() or re-init() call.
+ */
+struct ml_lib_model_options {
+	u32 sleep_timeout;
+};
+
+/*
+ * struct ml_lib_model_run_config - ML model run config
+ * @sleep_timeout: main thread's sleep timeout
+ *
+ * The run config is used for correction of ML model options
+ * by means of start/stop methods pair.
+ */
+struct ml_lib_model_run_config {
+	u32 sleep_timeout;
+};
+
+/*
+ * struct ml_lib_subsystem - kernel subsystem object
+ * @type: object type
+ * @size: number of bytes in allocated object
+ * @private: private data of subsystem
+ */
+struct ml_lib_subsystem {
+	atomic_t type;
+	size_t size;
+
+	void *private;
+};
+
+enum {
+	ML_LIB_UNKNOWN_SUBSYSTEM_TYPE,
+	ML_LIB_GENERIC_SUBSYSTEM,
+	ML_LIB_SPECIALIZED_SUBSYSTEM,
+	ML_LIB_SUBSYSTEM_TYPE_MAX
+};
+
+/*
+ * struct ml_lib_subsystem_state - shared kernel subsystem state
+ * @state: object state
+ * @size: number of bytes in allocated object
+ */
+struct ml_lib_subsystem_state {
+	atomic_t state;
+	size_t size;
+};
+
+enum {
+	ML_LIB_UNKNOWN_SUBSYSTEM_STATE,
+	ML_LIB_SUBSYSTEM_CREATED,
+	ML_LIB_SUBSYSTEM_INITIALIZED,
+	ML_LIB_SUBSYSTEM_STARTED,
+	ML_LIB_SUBSYSTEM_RUNNING,
+	ML_LIB_SUBSYSTEM_SHUTTING_DOWN,
+	ML_LIB_SUBSYSTEM_STOPPED,
+	ML_LIB_SUBSYSTEM_STATE_MAX
+};
+
+struct ml_lib_subsystem_state_operations {
+	void *(*allocate)(size_t size, gfp_t gfp);
+	void (*free)(struct ml_lib_subsystem_state *state);
+	int (*init)(struct ml_lib_subsystem_state *state);
+	int (*destroy)(struct ml_lib_subsystem_state *state);
+	int (*check_state)(struct ml_lib_subsystem_state *state);
+	struct ml_lib_subsystem_state *
+	    (*snapshot_state)(struct ml_lib_subsystem *object);
+	int (*estimate_system_state)(struct ml_lib_model *ml_model);
+	int (*correct_system_state)(struct ml_lib_model *ml_model);
+};
+
+/*
+ * struct ml_lib_dataset - exported subsystem's dataset
+ * @type: object type
+ * @state: object state
+ * @allocated_size: number of bytes in allocated object
+ * @portion_offset: portion offset in the data stream
+ * @portion_size: extracted portion size
+ */
+struct ml_lib_dataset {
+	atomic_t type;
+	atomic_t state;
+	size_t allocated_size;
+
+	u64 portion_offset;
+	u32 portion_size;
+};
+
+enum {
+	ML_LIB_UNKNOWN_DATASET_TYPE,
+	ML_LIB_EMPTY_DATASET,
+	ML_LIB_VALUE_DATASET,
+	ML_LIB_STRUCTURE_DATASET,
+	ML_LIB_MEMORY_STREAM_DATASET,
+	ML_LIB_DATASET_TYPE_MAX
+};
+
+enum {
+	ML_LIB_UNKNOWN_DATASET_STATE,
+	ML_LIB_DATASET_ALLOCATED,
+	ML_LIB_DATASET_CLEAN,
+	ML_LIB_DATASET_EXTRACTED_PARTIALLY,
+	ML_LIB_DATASET_EXTRACTED_COMPLETELY,
+	ML_LIB_DATASET_OBSOLETE,
+	ML_LIB_DATASET_EXTRACTION_FAILURE,
+	ML_LIB_DATASET_CORRUPTED,
+	ML_LIB_DATASET_STATE_MAX
+};
+
+struct ml_lib_dataset_operations {
+	void *(*allocate)(size_t size, gfp_t gfp);
+	void (*free)(struct ml_lib_dataset *dataset);
+	int (*init)(struct ml_lib_dataset *dataset);
+	int (*destroy)(struct ml_lib_dataset *dataset);
+	int (*extract)(struct ml_lib_model *ml_model,
+			struct ml_lib_dataset *dataset);
+	int (*preprocess_data)(struct ml_lib_model *ml_model,
+				struct ml_lib_dataset *dataset);
+	int (*publish_data)(struct ml_lib_model *ml_model,
+			    struct ml_lib_dataset *dataset);
+};
+
+/*
+ * struct ml_lib_request_config - dataset operation configuration
+ * @type: object type
+ * @state: object state
+ * @size: number of bytes in allocated object
+ */
+struct ml_lib_request_config {
+	atomic_t type;
+	atomic_t state;
+	size_t size;
+};
+
+enum {
+	ML_LIB_UNKNOWN_REQUEST_CONFIG_TYPE,
+	ML_LIB_EMPTY_REQUEST_CONFIG,
+	ML_LIB_REQUEST_CONFIG_TYPE_MAX
+};
+
+enum {
+	ML_LIB_UNKNOWN_REQUEST_CONFIG_STATE,
+	ML_LIB_REQUEST_CONFIG_ALLOCATED,
+	ML_LIB_REQUEST_CONFIG_INITIALIZED,
+	ML_LIB_REQUEST_CONFIG_STATE_MAX
+};
+
+struct ml_lib_request_config_operations {
+	void *(*allocate)(size_t size, gfp_t gfp);
+	void (*free)(struct ml_lib_request_config *config);
+	int (*init)(struct ml_lib_request_config *config);
+	int (*destroy)(struct ml_lib_request_config *config);
+};
+
+struct ml_lib_user_space_request {
+};
+
+struct ml_lib_user_space_request_operations {
+	int (*operation)(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_request *request);
+};
+
+struct ml_lib_user_space_notification {
+};
+
+struct ml_lib_user_space_notification_operations {
+	int (*operation)(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_notification *notify);
+};
+
+struct ml_lib_user_space_recommendation {
+};
+
+struct ml_lib_user_space_recommendation_operations {
+	int (*operation)(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_recommendation *hint);
+};
+
+struct ml_lib_backpropagation_feedback {
+};
+
+struct ml_lib_backpropagation_operations {
+	int (*operation)(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_recommendation *hint);
+};
+
+/*
+ * struct ml_lib_model_operations - ML model operations
+ * @create: specialized method of ML model creation
+ * @init: specialized method of ML model initialization
+ * @re_init: specialized method of ML model re-initialization
+ * @start: specialized method of ML model start
+ * @stop: specialized method of ML model stop
+ * @destroy: specialized method of ML model destroy
+ * @get_system_state: specialized method of getting subsystem state
+ * @get_dataset: specialized method of getting a dataset
+ * @preprocess_data: specialized method of data preprocessing
+ * @publish_data: specialized method of sharing data with user-space
+ * @preprocess_recommendation: specialized method of preprocess recomendations
+ * @estimate_system_state: specialized method of system state estimation
+ * @apply_recommendation: specialized method of recommendations applying
+ * @execute_operation: specialized method of operation execution
+ * @estimate_efficiency: specialized method of operation efficiency estimation
+ * @error_backpropagation: specialized method of error backpropagation
+ * @correct_system_state: specialized method of subsystem state correction
+ */
+struct ml_lib_model_operations {
+	int (*create)(struct ml_lib_model *ml_model);
+	int (*init)(struct ml_lib_model *ml_model,
+		    struct ml_lib_model_options *options);
+	int (*re_init)(struct ml_lib_model *ml_model,
+			struct ml_lib_model_options *options);
+	int (*start)(struct ml_lib_model *ml_model,
+		     struct ml_lib_model_run_config *config);
+	int (*stop)(struct ml_lib_model *ml_model);
+	void (*destroy)(struct ml_lib_model *ml_model);
+	struct ml_lib_subsystem_state *
+		(*get_system_state)(struct ml_lib_model *ml_model);
+	int (*get_dataset)(struct ml_lib_model *ml_model,
+			   struct ml_lib_dataset *dataset);
+	int (*preprocess_data)(struct ml_lib_model *ml_model,
+				struct ml_lib_dataset *dataset);
+	int (*publish_data)(struct ml_lib_model *ml_model,
+			    struct ml_lib_dataset *dataset,
+			    struct ml_lib_user_space_notification *notify);
+	int (*preprocess_recommendation)(struct ml_lib_model *ml_model,
+			    struct ml_lib_user_space_recommendation *hint);
+	int (*estimate_system_state)(struct ml_lib_model *ml_model);
+	int (*apply_recommendation)(struct ml_lib_model *ml_model,
+			    struct ml_lib_user_space_recommendation *hint);
+	int (*execute_operation)(struct ml_lib_model *ml_model,
+			    struct ml_lib_user_space_recommendation *hint,
+			    struct ml_lib_user_space_request *request);
+	int (*estimate_efficiency)(struct ml_lib_model *ml_model,
+			    struct ml_lib_user_space_recommendation *hint,
+			    struct ml_lib_user_space_request *request);
+	int (*error_backpropagation)(struct ml_lib_model *ml_model,
+			    struct ml_lib_backpropagation_feedback *feedback,
+			    struct ml_lib_user_space_notification *notify);
+	int (*correct_system_state)(struct ml_lib_model *ml_model);
+};
+
+/*
+ * struct ml_lib_model - ML model declaration
+ * @mode: ML model mode (enum ml_lib_system_mode)
+ * @state: ML model state
+ * @subsystem_name: name of susbsystem
+ * @model_name: name of the ML model
+ * @parent: parent kernel subsystem
+ * @parent_state: parent kernel subsystem's state
+ * @options: ML model options
+ * @model_ops: ML model specialized operations
+ * @system_state_ops: subsystem state specialized operations
+ * @dataset_ops: dataset specialized operations
+ * @request_config_ops: specialized dataset configuration operations
+ * @kobj: /sys/<subsystem>/<ml_model>/ ML model object
+ * @kobj_unregister: completion state for <ml_model> kernel object
+ */
+struct ml_lib_model {
+	atomic_t mode;
+	atomic_t state;
+	const char *subsystem_name;
+	const char *model_name;
+
+	struct ml_lib_subsystem *parent;
+
+	spinlock_t parent_state_lock;
+	struct ml_lib_subsystem_state * __rcu parent_state;
+
+	spinlock_t options_lock;
+	struct ml_lib_model_options * __rcu options;
+
+	spinlock_t dataset_lock;
+	struct ml_lib_dataset * __rcu dataset;
+
+	struct ml_lib_model_operations *model_ops;
+	struct ml_lib_subsystem_state_operations *system_state_ops;
+	struct ml_lib_dataset_operations *dataset_ops;
+	struct ml_lib_request_config_operations *request_config_ops;
+
+	/* /sys/<subsystem>/<ml_model>/ */
+	struct kobject kobj;
+	struct completion kobj_unregister;
+};
+
+/* ML library API */
+
+void *allocate_ml_model(size_t size, gfp_t gfp);
+void free_ml_model(struct ml_lib_model *ml_model);
+void *allocate_subsystem_object(size_t size, gfp_t gfp);
+void free_subsystem_object(struct ml_lib_subsystem *object);
+void *allocate_ml_model_options(size_t size, gfp_t gfp);
+void free_ml_model_options(struct ml_lib_model_options *options);
+void *allocate_subsystem_state(size_t size, gfp_t gfp);
+void free_subsystem_state(struct ml_lib_subsystem_state *state);
+void *allocate_dataset(size_t size, gfp_t gfp);
+void free_dataset(struct ml_lib_dataset *dataset);
+void *allocate_request_config(size_t size, gfp_t gfp);
+void free_request_config(struct ml_lib_request_config *config);
+
+int ml_model_create(struct ml_lib_model *ml_model,
+		    const char *subsystem_name,
+		    const char *model_name,
+		    struct kobject *subsystem_kobj);
+int ml_model_init(struct ml_lib_model *ml_model,
+		  struct ml_lib_model_options *options);
+int ml_model_re_init(struct ml_lib_model *ml_model,
+		     struct ml_lib_model_options *options);
+int ml_model_start(struct ml_lib_model *ml_model,
+		   struct ml_lib_model_run_config *config);
+int ml_model_stop(struct ml_lib_model *ml_model);
+void ml_model_destroy(struct ml_lib_model *ml_model);
+struct ml_lib_subsystem_state *get_system_state(struct ml_lib_model *ml_model);
+int ml_model_get_dataset(struct ml_lib_model *ml_model,
+			 struct ml_lib_request_config *config,
+			 struct ml_lib_user_space_request *request);
+int ml_model_discard_dataset(struct ml_lib_model *ml_model);
+int ml_model_preprocess_data(struct ml_lib_model *ml_model,
+			     struct ml_lib_dataset *dataset);
+int ml_model_publish_data(struct ml_lib_model *ml_model,
+			  struct ml_lib_dataset *dataset,
+			  struct ml_lib_user_space_notification *notify);
+int ml_model_preprocess_recommendation(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_recommendation *hint);
+int estimate_system_state(struct ml_lib_model *ml_model);
+int apply_ml_model_recommendation(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_recommendation *hint);
+int execute_ml_model_operation(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_recommendation *hint,
+			 struct ml_lib_user_space_request *request);
+int estimate_ml_model_efficiency(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_recommendation *hint,
+			 struct ml_lib_user_space_request *request);
+int ml_model_error_backpropagation(struct ml_lib_model *ml_model,
+			    struct ml_lib_backpropagation_feedback *feedback,
+			    struct ml_lib_user_space_notification *notify);
+int correct_system_state(struct ml_lib_model *ml_model);
+
+/* Generic implementation of ML model's methods */
+
+int generic_create_ml_model(struct ml_lib_model *ml_model);
+int generic_init_ml_model(struct ml_lib_model *ml_model,
+			  struct ml_lib_model_options *options);
+int generic_re_init_ml_model(struct ml_lib_model *ml_model,
+			     struct ml_lib_model_options *options);
+int generic_start_ml_model(struct ml_lib_model *ml_model,
+			   struct ml_lib_model_run_config *config);
+int generic_stop_ml_model(struct ml_lib_model *ml_model);
+void generic_destroy_ml_model(struct ml_lib_model *ml_model);
+struct ml_lib_subsystem_state *
+generic_get_system_state(struct ml_lib_model *ml_model);
+int generic_get_dataset(struct ml_lib_model *ml_model,
+			struct ml_lib_dataset *dataset);
+int generic_preprocess_data(struct ml_lib_model *ml_model,
+			    struct ml_lib_dataset *dataset);
+int generic_publish_data(struct ml_lib_model *ml_model,
+			 struct ml_lib_dataset *dataset,
+			 struct ml_lib_user_space_notification *notify);
+int generic_preprocess_recommendation(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_recommendation *hint);
+int generic_estimate_system_state(struct ml_lib_model *ml_model);
+int generic_apply_recommendation(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_recommendation *hint);
+int generic_execute_operation(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_recommendation *hint,
+			 struct ml_lib_user_space_request *request);
+int generic_estimate_efficiency(struct ml_lib_model *ml_model,
+			 struct ml_lib_user_space_recommendation *hint,
+			 struct ml_lib_user_space_request *request);
+int generic_error_backpropagation(struct ml_lib_model *ml_model,
+			    struct ml_lib_backpropagation_feedback *feedback,
+			    struct ml_lib_user_space_notification *notify);
+int generic_correct_system_state(struct ml_lib_model *ml_model);
+
+#endif /* _LINUX_ML_LIB_H */
Signature · 1 line
2.34.1
#2 lore raw

Re: [RFC PATCH v1 1/4] ml-lib: Introduce Machine Learning (ML) library declarations

Quoted 19 lines · Viacheslav Dubeyko

+ * @kobj: /sys/<subsystem>/<ml_model>/ ML model object
+ * @kobj_unregister: completion state for <ml_model> kernel object
+ */

include/linux/ml-lib/ml_lib.h new file +16 -0
+struct ml_lib_model {
+	atomic_t mode;
+	atomic_t state;
+	const char *subsystem_name;
+	const char *model_name;
+
+	struct ml_lib_subsystem *parent;
+
+	spinlock_t parent_state_lock;
+	struct ml_lib_subsystem_state * __rcu parent_state;
+
+	spinlock_t options_lock;
+	struct ml_lib_model_options * __rcu options;
+
+	spinlock_t dataset_lock;
+	struct ml_lib_dataset * __rcu dataset;

include/linux/ml-lib/ml_lib.h line 334

Quoted 10 lines
include/linux/ml-lib/ml_lib.h new file +10 -0
+
+	struct ml_lib_model_operations *model_ops;
+	struct ml_lib_subsystem_state_operations *system_state_ops;
+	struct ml_lib_dataset_operations *dataset_ops;
+	struct ml_lib_request_config_operations *request_config_ops;
+
+	/* /sys/<subsystem>/<ml_model>/ */
+	struct kobject kobj;
+	struct completion kobj_unregister;
+};

Do NOT abuse sysfs for something like this. Please make your own filesystem or char device or something else, but this is not what sysfs is for at all, sorry.

greg k-h

#3 lore raw

RE: [RFC PATCH v1 1/4] ml-lib: Introduce Machine Learning (ML) library declarations

Quoted 26 lines · Greg KH
Quoted 25 lines · Viacheslav Dubeyko

+ * @kobj: /sys/<subsystem>/<ml_model>/ ML model object
+ * @kobj_unregister: completion state for <ml_model> kernel object
+ */

include/linux/ml-lib/ml_lib.h new file +22 -0
+struct ml_lib_model {
+	atomic_t mode;
+	atomic_t state;
+	const char *subsystem_name;
+	const char *model_name;
+
+	struct ml_lib_subsystem *parent;
+
+	spinlock_t parent_state_lock;
+	struct ml_lib_subsystem_state * __rcu parent_state;
+
+	spinlock_t options_lock;
+	struct ml_lib_model_options * __rcu options;
+
+	spinlock_t dataset_lock;
+	struct ml_lib_dataset * __rcu dataset;
+
+	struct ml_lib_model_operations *model_ops;
+	struct ml_lib_subsystem_state_operations *system_state_ops;
+	struct ml_lib_dataset_operations *dataset_ops;
+	struct ml_lib_request_config_operations *request_config_ops;
+
Quoted 9 lines

include/linux/ml-lib/ml_lib.h line 334

Quoted 4 lines
include/linux/ml-lib/ml_lib.h new file +4 -0
+	/* /sys/<subsystem>/<ml_model>/ */
+	struct kobject kobj;
+	struct completion kobj_unregister;
+};

Do NOT abuse sysfs for something like this. Please make your own filesystem or char device or something else, but this is not what sysfs is for at all, sorry.

Currently, sysfs entry is used for sending commands (start, stop, prepare_dataset, discard_dataset) from user-space on the kernel-space side. And the intention of using sysfs entries is the export information about kernel subsystem and exchanging by commands and notifications between user-space and kernel-space sides. Do you mean that it is wrong using of sysfs? Have I misunderstood your point?

Thanks,
Slava.

#4 lore raw

Re: [RFC PATCH v1 1/4] ml-lib: Introduce Machine Learning (ML) library declarations

Quoted 37 lines · Viacheslav Dubeyko
Quoted 26 lines · Greg KH
Quoted 25 lines · Viacheslav Dubeyko

+ * @kobj: /sys/<subsystem>/<ml_model>/ ML model object
+ * @kobj_unregister: completion state for <ml_model> kernel object
+ */

include/linux/ml-lib/ml_lib.h new file +22 -0
+struct ml_lib_model {
+	atomic_t mode;
+	atomic_t state;
+	const char *subsystem_name;
+	const char *model_name;
+
+	struct ml_lib_subsystem *parent;
+
+	spinlock_t parent_state_lock;
+	struct ml_lib_subsystem_state * __rcu parent_state;
+
+	spinlock_t options_lock;
+	struct ml_lib_model_options * __rcu options;
+
+	spinlock_t dataset_lock;
+	struct ml_lib_dataset * __rcu dataset;
+
+	struct ml_lib_model_operations *model_ops;
+	struct ml_lib_subsystem_state_operations *system_state_ops;
+	struct ml_lib_dataset_operations *dataset_ops;
+	struct ml_lib_request_config_operations *request_config_ops;
+
Quoted 9 lines

include/linux/ml-lib/ml_lib.h line 334

Quoted 4 lines
include/linux/ml-lib/ml_lib.h new file +4 -0
+	/* /sys/<subsystem>/<ml_model>/ */
+	struct kobject kobj;
+	struct completion kobj_unregister;
+};

Do NOT abuse sysfs for something like this. Please make your own filesystem or char device or something else, but this is not what sysfs is for at all, sorry.

Quoted 6 lines

Currently, sysfs entry is used for sending commands (start, stop, prepare_dataset, discard_dataset) from user-space on the kernel-space side. And the intention of using sysfs entries is the export information about kernel subsystem and exchanging by commands and notifications between user-space and kernel-space sides. Do you mean that it is wrong using of sysfs? Have I misunderstood your point?

Yes, this is NOT the correct use of sysfs, do NOT use it for an api like this at all. Use the correct ones instead.

thanks,

greg k-h

#5 lore raw

RE: [RFC PATCH v1 1/4] ml-lib: Introduce Machine Learning (ML) library declarations

Quoted 45 lines · On Tue, 2026-02-10 at 06:20 +0100, [email protected] wrote:
Quoted 37 lines · Viacheslav Dubeyko
Quoted 26 lines · Greg KH
Quoted 25 lines · Viacheslav Dubeyko

+ * @kobj: /sys/<subsystem>/<ml_model>/ ML model object
+ * @kobj_unregister: completion state for <ml_model> kernel object
+ */

include/linux/ml-lib/ml_lib.h new file +22 -0
+struct ml_lib_model {
+	atomic_t mode;
+	atomic_t state;
+	const char *subsystem_name;
+	const char *model_name;
+
+	struct ml_lib_subsystem *parent;
+
+	spinlock_t parent_state_lock;
+	struct ml_lib_subsystem_state * __rcu parent_state;
+
+	spinlock_t options_lock;
+	struct ml_lib_model_options * __rcu options;
+
+	spinlock_t dataset_lock;
+	struct ml_lib_dataset * __rcu dataset;
+
+	struct ml_lib_model_operations *model_ops;
+	struct ml_lib_subsystem_state_operations *system_state_ops;
+	struct ml_lib_dataset_operations *dataset_ops;
+	struct ml_lib_request_config_operations *request_config_ops;
+
Quoted 9 lines

include/linux/ml-lib/ml_lib.h line 334

Quoted 4 lines
include/linux/ml-lib/ml_lib.h new file +4 -0
+	/* /sys/<subsystem>/<ml_model>/ */
+	struct kobject kobj;
+	struct completion kobj_unregister;
+};

Do NOT abuse sysfs for something like this. Please make your own filesystem or char device or something else, but this is not what sysfs is for at all, sorry.

Quoted 6 lines

Currently, sysfs entry is used for sending commands (start, stop, prepare_dataset, discard_dataset) from user-space on the kernel-space side. And the intention of using sysfs entries is the export information about kernel subsystem and exchanging by commands and notifications between user-space and kernel-space sides. Do you mean that it is wrong using of sysfs? Have I misunderstood your point?

Quoted 4 lines

Yes, this is NOT the correct use of sysfs, do NOT use it for an api like this at all. Use the correct ones instead.

So, to summarize your recommendations:
(1) Do not use sysfs;
(2) Do not use character device but misc device instead;
(3) Implement specialized file system;
(4) eBPF?

Would you like to share any other recommendations?

Thanks,
Slava.

#6 lore raw

RFC PATCH 2/4 ml-lib: Implement PoC of Machine Learning (ML) library functionality

In reply to Viacheslav Dubeyko

ML model can be represented by process/thread running in user-space. Particular kernel subsystem needs to implement ML model proxy on kernel-space side. The process of loading kernel subsystem creates and intializes the ML model proxy, create sysfs entries, and character device, for example. The sysfs entries and character device create the mechanism of interaction and collaboration of kernel subsystem and ML model in user-space.

The simplest model of collaboration could include such steps:
(1) user-space process/thread (ML model) sends START command

    to kernel subsystem through sysfs control entry;

(2) user-space process/thread (ML model) requests to prepare a dataset by means of PREPARE_DATASET command through sysfs control entry;
(3) user-space process/thread (ML model) extracts the dataset

    by means of reading data from character device;

(4) dataset can be marked as obsolete after extraction by means of DISCARD_DATASET command through sysfs control entry and new dataset can be requested and extracted;
(5) extracted data can be used as training data by ML model

    on user-space side;

(6) ML model can execute the inference after some number of training cycles and to elaborate some recommendations or optimized logic for kernel subsystem;
(7) ML model's recommendations can be written into character device, for example, by user-space process/thread and kernel subsystem can use this recommendations for optimization or changing the logic;
(8) based on kernel subsystem's mode, recommendations can be completely ignored, partially applied, tested, or used instead of default configuration/logic;
(9) every time efficiency of applied recommendations or

    logic needs to be estimated;

(10) if ML model recommendations degrade efficiency of kernel subsystem, then error backpropagation needs to be used for ML model correction on user-space side.

---
 lib/Kconfig              |   6 +
 lib/Makefile             |   2 +
 lib/ml-lib/Kconfig       |  18 +
 lib/ml-lib/Makefile      |   7 +
 lib/ml-lib/ml_lib_main.c | 758 +++++++++++++++++++++++++++++++++++++++
 lib/ml-lib/sysfs.c       | 187 ++++++++++
 lib/ml-lib/sysfs.h       |  17 +
 7 files changed, 995 insertions(+)
 create mode 100644 lib/ml-lib/Kconfig
 create mode 100644 lib/ml-lib/Makefile
 create mode 100644 lib/ml-lib/ml_lib_main.c
 create mode 100644 lib/ml-lib/sysfs.c
 create mode 100644 lib/ml-lib/sysfs.h
lib/Kconfig +6 -0
index 2923924bea78..2d56977c0638 100644
@@ -604,6 +604,12 @@ config LWQ_TEST
 	help
           Run boot-time test of light-weight queuing.
 
+#
+# Machine Learning (ML) library configuration
+#
+
+source "lib/ml-lib/Kconfig"
+
 endmenu
 
 config GENERIC_IOREMAP
lib/Makefile +2 -0
index aaf677cf4527..154e7fd220ab 100644
@@ -332,3 +332,5 @@ obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o
 obj-$(CONFIG_FIRMWARE_TABLE) += fw_table.o
 
 subdir-$(CONFIG_FORTIFY_SOURCE) += test_fortify
+
+obj-$(CONFIG_ML_LIB) += ml-lib/
lib/ml-lib/Kconfig new file +18 -0
new file mode 100644
index 000000000000..d2f2ea40a833
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+#
+# Machine Learning (ML) library configuration
+#
+
+config ML_LIB
+	tristate "ML library support"
+	help
+	  Machine Learning (ML) library has goal to provide
+	  the interaction and communication of ML models in
+	  user-space with kernel subsystems. It implements
+	  the basic code primitives that builds the way of
+	  ML models integration into Linux kernel functionality.
+
+	  If unsure, say N.
+
+source "lib/ml-lib/test_driver/Kconfig"
lib/ml-lib/Makefile new file +7 -0
new file mode 100644
index 000000000000..b1103ab3e1c8
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_ML_LIB) += ml_lib.o
+
+ml_lib-y := sysfs.o ml_lib_main.o
+
+obj-$(CONFIG_ML_LIB_TEST_DRIVER) += test_driver/
lib/ml-lib/ml_lib_main.c new file +758 -0

758 lines not on this page · raw message

lib/ml-lib/sysfs.c new file +187 -0

187 lines not on this page · raw message

lib/ml-lib/sysfs.h new file +17 -0
new file mode 100644
index 000000000000..6bd3ab64a1c0
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Machine Learning (ML) library
+ *
+ * Copyright (C) 2025-2026 Viacheslav Dubeyko <[email protected]>
+ */
+
+#ifndef _LINUX_ML_LIB_SYSFS_H
+#define _LINUX_ML_LIB_SYSFS_H
+
+#include <linux/sysfs.h>
+
+int ml_model_create_sysfs_group(struct ml_lib_model *ml_model,
+				struct kobject *subsystem_kobj);
+void ml_model_delete_sysfs_group(struct ml_lib_model *ml_model);
+
+#endif /* _LINUX_ML_LIB_SYSFS_H */
Signature · 1 line
2.34.1
#7 lore raw

RFC PATCH 3/4 ml-lib: Implement simple testing character device driver

In reply to Viacheslav Dubeyko

Implement simple testing character device driver

---
 lib/ml-lib/test_driver/Kconfig           |  22 +
 lib/ml-lib/test_driver/Makefile          |   5 +
 lib/ml-lib/test_driver/README.md         | 233 ++++++++++
 lib/ml-lib/test_driver/ml_lib_char_dev.c | 530 +++++++++++++++++++++++
 4 files changed, 790 insertions(+)
 create mode 100644 lib/ml-lib/test_driver/Kconfig
 create mode 100644 lib/ml-lib/test_driver/Makefile
 create mode 100644 lib/ml-lib/test_driver/README.md
 create mode 100644 lib/ml-lib/test_driver/ml_lib_char_dev.c
lib/ml-lib/test_driver/Kconfig new file +22 -0
new file mode 100644
index 000000000000..183fc1de57a8
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config ML_LIB_TEST_DRIVER
+	tristate "ML library testing character device driver"
+	depends on ML_LIB
+	default n
+	help
+	  This is a ML library testing character device driver for
+	  testing generic ML library functionality. It provides:
+
+	  - Basic read/write operations
+	  - IOCTL interface for device control
+	  - Sysfs attributes for runtime information
+	  - Procfs entry for debugging
+
+	  The driver creates a /dev/mllibdev device node that can be
+	  used to read and write data to a kernel buffer.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mllibdev.
lib/ml-lib/test_driver/Makefile new file +5 -0
new file mode 100644
index 000000000000..6444bcf8985b
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_ML_LIB_TEST_DRIVER) += ml_lib_test_dev.o
+
+ml_lib_test_dev-y := ml_lib_char_dev.o
lib/ml-lib/test_driver/README.md new file +233 -0

233 lines not on this page · raw message

lib/ml-lib/test_driver/ml_lib_char_dev.c new file +530 -0

530 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw

Re: [RFC PATCH v1 3/4] ml-lib: Implement simple testing character device driver

Quoted 3 lines · Viacheslav Dubeyko

Implement simple testing character device driver

It's hard to tell if this is just an early april-fools joke or not, but if it's not:

Quoted 7 lines
lib/ml-lib/test_driver/README.md new file +7 -0
+### Character Device Operations
+- **Open/Close**: Device can be opened and closed multiple times
+- **Read**: Read data from a kernel buffer
+- **Write**: Write data to a kernel buffer (1KB capacity)
+- **Seek**: Support for lseek() operations
+
+### IOCTL Commands

lib/ml-lib/test_driver/README.md line 27

Quoted 10 lines
lib/ml-lib/test_driver/README.md new file +10 -0
+- `ML_LIB_TEST_DEV_IOCRESET`: Clear the device buffer
+- `ML_LIB_TEST_DEV_IOCGETSIZE`: Get current data size
+- `ML_LIB_TEST_DEV_IOCSETSIZE`: Set data size
+
+### Sysfs Attributes
+Located at `/sys/class/ml_lib_test/mllibdev`:
+- `buffer_size`: Maximum buffer capacity (read-only)
+- `data_size`: Current amount of data in buffer (read-only)
+- `access_count`: Number of times device has been opened (read-only)
+- `stats`: Comprehensive statistics (opens, reads, writes)

Again, this is not an acceptable use of sysfs.

lib/ml-lib/test_driver/ml_lib_char_dev.c line 357

Quoted 2 lines
lib/ml-lib/test_driver/ml_lib_char_dev.c new file +2 -0
+	/* Allocate device number */
+	ret = alloc_chrdev_region(&dev_number, 0, 1, DEVICE_NAME);

Don't burn a cdev for this, please use the misc device api.

good luck!

greg k-h

#9 lore raw

RE: [RFC PATCH v1 3/4] ml-lib: Implement simple testing character device driver

Quoted 19 lines · Greg KH
Quoted 3 lines · Viacheslav Dubeyko

Implement simple testing character device driver

It's hard to tell if this is just an early april-fools joke or not, but if it's not:

Quoted 11 lines
lib/ml-lib/test_driver/README.md new file +11 -0
+### Character Device Operations
+- **Open/Close**: Device can be opened and closed multiple times
+- **Read**: Read data from a kernel buffer
+- **Write**: Write data to a kernel buffer (1KB capacity)
+- **Seek**: Support for lseek() operations
+
+### IOCTL Commands
+- `ML_LIB_TEST_DEV_IOCRESET`: Clear the device buffer
+- `ML_LIB_TEST_DEV_IOCGETSIZE`: Get current data size
+- `ML_LIB_TEST_DEV_IOCSETSIZE`: Set data size
+
Quoted 8 lines

lib/ml-lib/test_driver/README.md line 27

Quoted 6 lines
lib/ml-lib/test_driver/README.md new file +6 -0
+### Sysfs Attributes
+Located at `/sys/class/ml_lib_test/mllibdev`:
+- `buffer_size`: Maximum buffer capacity (read-only)
+- `data_size`: Current amount of data in buffer (read-only)
+- `access_count`: Number of times device has been opened (read-only)
+- `stats`: Comprehensive statistics (opens, reads, writes)

Again, this is not an acceptable use of sysfs.

Maybe, I am missing your point. Are you assuming that I am going to share huge pieces of data by means of sysfs? If so, then I am not going to use sysfs for it.

Quoted 6 lines

lib/ml-lib/test_driver/ml_lib_char_dev.c line 357

Quoted 3 lines
lib/ml-lib/test_driver/ml_lib_char_dev.c new file +2 -0
+	/* Allocate device number */
+	ret = alloc_chrdev_region(&dev_number, 0, 1, DEVICE_NAME);

Don't burn a cdev for this, please use the misc device api.

It is not real-life driver. It is only testing driver with the goal to check/test the ML library infrastructure and to show the potential way of using the ML library.

As the next step, I am planning to use the ML library for two potential real- life use-case: (1) GC subsystem of LFS file system, (2) ML-based DAMON approach.

So, this driver is only testing engine of implementing and testing the vision of ML library.

Thanks,
Slava.

#10 lore raw

Re: [RFC PATCH v1 3/4] ml-lib: Implement simple testing character device driver

Quoted 29 lines · Viacheslav Dubeyko
Quoted 19 lines · Greg KH
Quoted 3 lines · Viacheslav Dubeyko

Implement simple testing character device driver

It's hard to tell if this is just an early april-fools joke or not, but if it's not:

Quoted 11 lines
lib/ml-lib/test_driver/README.md new file +11 -0
+### Character Device Operations
+- **Open/Close**: Device can be opened and closed multiple times
+- **Read**: Read data from a kernel buffer
+- **Write**: Write data to a kernel buffer (1KB capacity)
+- **Seek**: Support for lseek() operations
+
+### IOCTL Commands
+- `ML_LIB_TEST_DEV_IOCRESET`: Clear the device buffer
+- `ML_LIB_TEST_DEV_IOCGETSIZE`: Get current data size
+- `ML_LIB_TEST_DEV_IOCSETSIZE`: Set data size
+
Quoted 8 lines

lib/ml-lib/test_driver/README.md line 27

Quoted 6 lines
lib/ml-lib/test_driver/README.md new file +6 -0
+### Sysfs Attributes
+Located at `/sys/class/ml_lib_test/mllibdev`:
+- `buffer_size`: Maximum buffer capacity (read-only)
+- `data_size`: Current amount of data in buffer (read-only)
+- `access_count`: Number of times device has been opened (read-only)
+- `stats`: Comprehensive statistics (opens, reads, writes)

Again, this is not an acceptable use of sysfs.

Quoted 3 lines

Maybe, I am missing your point. Are you assuming that I am going to share huge pieces of data by means of sysfs? If so, then I am not going to use sysfs for it.

Please do not use sysfs for this at all.

Quoted 10 lines
Quoted 5 lines

lib/ml-lib/test_driver/ml_lib_char_dev.c line 357

Quoted 2 lines
lib/ml-lib/test_driver/ml_lib_char_dev.c new file +2 -0
+	/* Allocate device number */
+	ret = alloc_chrdev_region(&dev_number, 0, 1, DEVICE_NAME);

Don't burn a cdev for this, please use the misc device api.

It is not real-life driver. It is only testing driver with the goal to check/test the ML library infrastructure and to show the potential way of using the ML library.

Quoted 5 lines

As the next step, I am planning to use the ML library for two potential real- life use-case: (1) GC subsystem of LFS file system, (2) ML-based DAMON approach.

So, this driver is only testing engine of implementing and testing the vision of ML library.

We don't take code that uses apis incorrectly. Please do not use a cdev for this type of "testing" driver, that is the incorrect thing to do and actually makes your code more complex than it needs to.

good luck!

greg k-h

#11 lore raw

RFC PATCH 4/4 ml-lib: Implement simple user-space testing application

In reply to Viacheslav Dubeyko

Implement simple user-space testing application

---
 .../test_application/ml_lib_char_dev_ioctl.h  |  21 ++
 .../test_application/test_ml_lib_char_dev.c   | 206 ++++++++++++++++++
 2 files changed, 227 insertions(+)
 create mode 100644 lib/ml-lib/test_driver/test_application/ml_lib_char_dev_ioctl.h
 create mode 100644 lib/ml-lib/test_driver/test_application/test_ml_lib_char_dev.c
lib/ml-lib/test_driver/test_application/ml_lib_char_dev_ioctl.h new file +21 -0
new file mode 100644
index 000000000000..7ea74e840fda
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Machine Learning (ML) library
+ *
+ * Userspace API for ml_lib_dev testing driver
+ *
+ * Copyright (C) 2025-2026 Viacheslav Dubeyko <[email protected]>
+ */
+
+#ifndef _ML_LIB_TEST_DEV_IOCTL_H
+#define _ML_LIB_TEST_DEV_IOCTL_H
+
+#include <linux/ioctl.h>
+
+/* IOCTL commands */
+#define ML_LIB_TEST_DEV_IOC_MAGIC   'M'
+#define ML_LIB_TEST_DEV_IOCRESET    _IO(ML_LIB_TEST_DEV_IOC_MAGIC, 0)
+#define ML_LIB_TEST_DEV_IOCGETSIZE  _IOR(ML_LIB_TEST_DEV_IOC_MAGIC, 1, int)
+#define ML_LIB_TEST_DEV_IOCSETSIZE  _IOW(ML_LIB_TEST_DEV_IOC_MAGIC, 2, int)
+
+#endif /* _ML_LIB_TEST_DEV_IOCTL_H */
lib/ml-lib/test_driver/test_application/test_ml_lib_char_dev.c new file +206 -0

206 lines not on this page · raw message

Signature · 1 line
2.34.1
#12 lore raw
In reply to Viacheslav Dubeyko
Quoted 3 lines · Viacheslav Dubeyko

This patchset introduces initial vision of Machine Learning (ML) library in Linux kernel. It is an effort to define the ML library API and to elaborate the way of running ML models in Linux kernel.

I went looking for the documentation files ... but then I've always been known as an optimist. That would be a nice thing to fill in.

Perhaps more important, though, would be a real user for this facility. You must certainly have one in mind, can we see it to get a sense for how this library is meant to be used?

Thanks,

jon

#13 lore raw
Quoted 8 lines · Jonathan Corbet
Quoted 3 lines · Viacheslav Dubeyko

This patchset introduces initial vision of Machine Learning (ML) library in Linux kernel. It is an effort to define the ML library API and to elaborate the way of running ML models in Linux kernel.

I went looking for the documentation files ... but then I've always been known as an optimist. That would be a nice thing to fill in.

Yeah, I can see your pain. :) I totally agree that documentation is necessary. This patchset is only the first small step to share and discuss with the community. I am sharing the initial vision of the idea and API with the hope to have the review and discussion. If the API vision makes sense and it looks good, then it makes sense to prepare documentation. I am planning to have the documentation after checking the whole infrastructure with a real-life use- case(s).

Quoted 4 lines

Perhaps more important, though, would be a real user for this facility. You must certainly have one in mind, can we see it to get a sense for how this library is meant to be used?

I believe there are multiple potential real-life use-cases. Currently, I have implemented very simple testing driver that generates random numbers and, potentially, some ML model can be trained on this "mess". :) But it's not very interesting example. As a next step, I am considering to use this ML library infrastructure for: (1) GC subsystem in LFS file systems (NILFS2, F2FS, SSDFS),
(2) ML-based DAMON extension with the goal to check the whole idea for real-life use-cases.

So, let me make the next step and we will be able to discuss this ML library for real-life use-cases. But the main approach is the collaboration of kernel subsystem and ML model running in user-space.

Thanks,
Slava.