Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144341543
D48747.id150544.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D48747.id150544.diff
View Options
diff --git a/sys/compat/linuxkpi/common/include/linux/shrinker.h b/sys/compat/linuxkpi/common/include/linux/shrinker.h
--- a/sys/compat/linuxkpi/common/include/linux/shrinker.h
+++ b/sys/compat/linuxkpi/common/include/linux/shrinker.h
@@ -27,6 +27,8 @@
#define _LINUXKPI_LINUX_SHRINKER_H_
#include <sys/queue.h>
+
+#include <linux/bitops.h>
#include <linux/gfp.h>
struct shrink_control {
@@ -39,6 +41,7 @@
unsigned long (*count_objects)(struct shrinker *, struct shrink_control *);
unsigned long (*scan_objects)(struct shrinker *, struct shrink_control *);
int seeks;
+ unsigned int flags;
void * private_data;
long batch;
TAILQ_ENTRY(shrinker) next;
@@ -48,10 +51,23 @@
#define DEFAULT_SEEKS 2
+#define SHRINKER_REGISTERED BIT(0)
+#define SHRINKER_ALLOCATED BIT(1)
+
+struct shrinker * linuxkpi_shrinker_alloc(
+ unsigned int flags, const char *fmt, ...);
int linuxkpi_register_shrinker(struct shrinker *s);
void linuxkpi_unregister_shrinker(struct shrinker *s);
+void linuxkpi_shrinker_free(struct shrinker *shrinker);
void linuxkpi_synchronize_shrinkers(void);
+#define shrinker_alloc(flags, fmt, ...) \
+ linuxkpi_shrinker_alloc(flags, fmt __VA_OPT__(,) __VA_ARGS__)
+#define shrinker_register(shrinker) \
+ linuxkpi_register_shrinker(shrinker)
+#define shrinker_free(shrinker) \
+ linuxkpi_shrinker_free(shrinker)
+
#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 60000
#define register_shrinker(s, ...) linuxkpi_register_shrinker(s)
#else
diff --git a/sys/compat/linuxkpi/common/src/linux_shrinker.c b/sys/compat/linuxkpi/common/src/linux_shrinker.c
--- a/sys/compat/linuxkpi/common/src/linux_shrinker.c
+++ b/sys/compat/linuxkpi/common/src/linux_shrinker.c
@@ -32,10 +32,26 @@
#include <linux/compat.h>
#include <linux/shrinker.h>
+#include <linux/slab.h>
TAILQ_HEAD(, shrinker) lkpi_shrinkers = TAILQ_HEAD_INITIALIZER(lkpi_shrinkers);
static struct sx sx_shrinker;
+struct shrinker *
+linuxkpi_shrinker_alloc(unsigned int flags, const char *fmt, ...)
+{
+ struct shrinker *shrinker;
+
+ shrinker = kzalloc(sizeof(*shrinker), GFP_KERNEL);
+ if (shrinker == NULL)
+ return (NULL);
+
+ shrinker->flags = flags | SHRINKER_ALLOCATED;
+ shrinker->seeks = DEFAULT_SEEKS;
+
+ return (shrinker);
+}
+
int
linuxkpi_register_shrinker(struct shrinker *s)
{
@@ -44,6 +60,7 @@
KASSERT(s->count_objects != NULL, ("NULL shrinker"));
KASSERT(s->scan_objects != NULL, ("NULL shrinker"));
sx_xlock(&sx_shrinker);
+ s->flags |= SHRINKER_REGISTERED;
TAILQ_INSERT_TAIL(&lkpi_shrinkers, s, next);
sx_xunlock(&sx_shrinker);
return (0);
@@ -55,9 +72,20 @@
sx_xlock(&sx_shrinker);
TAILQ_REMOVE(&lkpi_shrinkers, s, next);
+ s->flags &= ~SHRINKER_REGISTERED;
sx_xunlock(&sx_shrinker);
}
+void
+linuxkpi_shrinker_free(struct shrinker *shrinker)
+{
+
+ if (shrinker->flags & SHRINKER_REGISTERED)
+ unregister_shrinker(shrinker);
+
+ kfree(shrinker);
+}
+
void
linuxkpi_synchronize_shrinkers(void)
{
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 8, 10:47 PM (14 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28507376
Default Alt Text
D48747.id150544.diff (2 KB)
Attached To
Mode
D48747: linuxkpi: Add `shrinker_alloc()` and `shrinker_free()`
Attached
Detach File
Event Timeline
Log In to Comment