Skip to content

Commit 054c636

Browse files
committed
fsnotify: Move ->free_mark callback to fsnotify_ops
Pointer to ->free_mark callback unnecessarily occupies one long in each fsnotify_mark although they are the same for all marks from one notification group. Move the callback pointer to fsnotify_ops. Reviewed-by: Miklos Szeredi <mszeredi@redhat.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 7b12932 commit 054c636

12 files changed

Lines changed: 41 additions & 35 deletions

File tree

‎fs/notify/dnotify/dnotify.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static void dnotify_free_mark(struct fsnotify_mark *fsn_mark)
135135

136136
static struct fsnotify_ops dnotify_fsnotify_ops = {
137137
.handle_event = dnotify_handle_event,
138+
.free_mark = dnotify_free_mark,
138139
};
139140

140141
/*
@@ -305,7 +306,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
305306

306307
/* set up the new_fsn_mark and new_dn_mark */
307308
new_fsn_mark = &new_dn_mark->fsn_mark;
308-
fsnotify_init_mark(new_fsn_mark, dnotify_group, dnotify_free_mark);
309+
fsnotify_init_mark(new_fsn_mark, dnotify_group);
309310
new_fsn_mark->mask = mask;
310311
new_dn_mark->dn = NULL;
311312

‎fs/notify/fanotify/fanotify.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,14 @@ static void fanotify_free_event(struct fsnotify_event *fsn_event)
262262
kmem_cache_free(fanotify_event_cachep, event);
263263
}
264264

265+
static void fanotify_free_mark(struct fsnotify_mark *fsn_mark)
266+
{
267+
kmem_cache_free(fanotify_mark_cache, fsn_mark);
268+
}
269+
265270
const struct fsnotify_ops fanotify_fsnotify_ops = {
266271
.handle_event = fanotify_handle_event,
267272
.free_group_priv = fanotify_free_group_priv,
268273
.free_event = fanotify_free_event,
274+
.free_mark = fanotify_free_mark,
269275
};

‎fs/notify/fanotify/fanotify.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <linux/path.h>
33
#include <linux/slab.h>
44

5+
extern struct kmem_cache *fanotify_mark_cache;
56
extern struct kmem_cache *fanotify_event_cachep;
67
extern struct kmem_cache *fanotify_perm_event_cachep;
78

‎fs/notify/fanotify/fanotify_user.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
extern const struct fsnotify_ops fanotify_fsnotify_ops;
4343

44-
static struct kmem_cache *fanotify_mark_cache __read_mostly;
44+
struct kmem_cache *fanotify_mark_cache __read_mostly;
4545
struct kmem_cache *fanotify_event_cachep __read_mostly;
4646
struct kmem_cache *fanotify_perm_event_cachep __read_mostly;
4747

@@ -445,11 +445,6 @@ static const struct file_operations fanotify_fops = {
445445
.llseek = noop_llseek,
446446
};
447447

448-
static void fanotify_free_mark(struct fsnotify_mark *fsn_mark)
449-
{
450-
kmem_cache_free(fanotify_mark_cache, fsn_mark);
451-
}
452-
453448
static int fanotify_find_path(int dfd, const char __user *filename,
454449
struct path *path, unsigned int flags)
455450
{
@@ -628,7 +623,7 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
628623
if (!mark)
629624
return ERR_PTR(-ENOMEM);
630625

631-
fsnotify_init_mark(mark, group, fanotify_free_mark);
626+
fsnotify_init_mark(mark, group);
632627
ret = fsnotify_add_mark_locked(mark, inode, mnt, 0);
633628
if (ret) {
634629
fsnotify_put_mark(mark);

‎fs/notify/inotify/inotify.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern int inotify_handle_event(struct fsnotify_group *group,
3131
struct fsnotify_iter_info *iter_info);
3232

3333
extern const struct fsnotify_ops inotify_fsnotify_ops;
34+
extern struct kmem_cache *inotify_inode_mark_cachep;
3435

3536
#ifdef CONFIG_INOTIFY_USER
3637
static inline void dec_inotify_instances(struct ucounts *ucounts)

‎fs/notify/inotify/inotify_fsnotify.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,20 @@ static void inotify_free_event(struct fsnotify_event *fsn_event)
176176
kfree(INOTIFY_E(fsn_event));
177177
}
178178

179+
/* ding dong the mark is dead */
180+
static void inotify_free_mark(struct fsnotify_mark *fsn_mark)
181+
{
182+
struct inotify_inode_mark *i_mark;
183+
184+
i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);
185+
186+
kmem_cache_free(inotify_inode_mark_cachep, i_mark);
187+
}
188+
179189
const struct fsnotify_ops inotify_fsnotify_ops = {
180190
.handle_event = inotify_handle_event,
181191
.free_group_priv = inotify_free_group_priv,
182192
.free_event = inotify_free_event,
183193
.freeing_mark = inotify_freeing_mark,
194+
.free_mark = inotify_free_mark,
184195
};

‎fs/notify/inotify/inotify_user.c‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
/* configurable via /proc/sys/fs/inotify/ */
4848
static int inotify_max_queued_events __read_mostly;
4949

50-
static struct kmem_cache *inotify_inode_mark_cachep __read_mostly;
50+
struct kmem_cache *inotify_inode_mark_cachep __read_mostly;
5151

5252
#ifdef CONFIG_SYSCTL
5353

@@ -483,16 +483,6 @@ void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,
483483
dec_inotify_watches(group->inotify_data.ucounts);
484484
}
485485

486-
/* ding dong the mark is dead */
487-
static void inotify_free_mark(struct fsnotify_mark *fsn_mark)
488-
{
489-
struct inotify_inode_mark *i_mark;
490-
491-
i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);
492-
493-
kmem_cache_free(inotify_inode_mark_cachep, i_mark);
494-
}
495-
496486
static int inotify_update_existing_watch(struct fsnotify_group *group,
497487
struct inode *inode,
498488
u32 arg)
@@ -558,7 +548,7 @@ static int inotify_new_watch(struct fsnotify_group *group,
558548
if (unlikely(!tmp_i_mark))
559549
return -ENOMEM;
560550

561-
fsnotify_init_mark(&tmp_i_mark->fsn_mark, group, inotify_free_mark);
551+
fsnotify_init_mark(&tmp_i_mark->fsn_mark, group);
562552
tmp_i_mark->fsn_mark.mask = mask;
563553
tmp_i_mark->wd = -1;
564554

‎fs/notify/mark.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,12 @@ static struct inode *fsnotify_detach_connector_from_object(
195195

196196
static void fsnotify_final_mark_destroy(struct fsnotify_mark *mark)
197197
{
198-
if (mark->group)
199-
fsnotify_put_group(mark->group);
200-
mark->free_mark(mark);
198+
struct fsnotify_group *group = mark->group;
199+
200+
if (WARN_ON_ONCE(!group))
201+
return;
202+
group->ops->free_mark(mark);
203+
fsnotify_put_group(group);
201204
}
202205

203206
void fsnotify_put_mark(struct fsnotify_mark *mark)
@@ -732,13 +735,11 @@ void fsnotify_destroy_marks(struct fsnotify_mark_connector __rcu **connp)
732735
* Nothing fancy, just initialize lists and locks and counters.
733736
*/
734737
void fsnotify_init_mark(struct fsnotify_mark *mark,
735-
struct fsnotify_group *group,
736-
void (*free_mark)(struct fsnotify_mark *mark))
738+
struct fsnotify_group *group)
737739
{
738740
memset(mark, 0, sizeof(*mark));
739741
spin_lock_init(&mark->lock);
740742
atomic_set(&mark->refcnt, 1);
741-
mark->free_mark = free_mark;
742743
fsnotify_get_group(group);
743744
mark->group = group;
744745
}

‎include/linux/fsnotify_backend.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ struct fsnotify_ops {
104104
void (*free_group_priv)(struct fsnotify_group *group);
105105
void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
106106
void (*free_event)(struct fsnotify_event *event);
107+
/* called on final put+free to free memory */
108+
void (*free_mark)(struct fsnotify_mark *mark);
107109
};
108110

109111
/*
@@ -261,7 +263,6 @@ struct fsnotify_mark {
261263
#define FSNOTIFY_MARK_FLAG_ALIVE 0x02
262264
#define FSNOTIFY_MARK_FLAG_ATTACHED 0x04
263265
unsigned int flags; /* flags [mark->lock] */
264-
void (*free_mark)(struct fsnotify_mark *mark); /* called on final put+free */
265266
};
266267

267268
#ifdef CONFIG_FSNOTIFY
@@ -341,8 +342,7 @@ extern struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group
341342
/* Calculate mask of events for a list of marks */
342343
extern void fsnotify_recalc_mask(struct fsnotify_mark_connector *conn);
343344
extern void fsnotify_init_mark(struct fsnotify_mark *mark,
344-
struct fsnotify_group *group,
345-
void (*free_mark)(struct fsnotify_mark *mark));
345+
struct fsnotify_group *group);
346346
/* Find mark belonging to given group in the list of marks */
347347
extern struct fsnotify_mark *fsnotify_find_mark(
348348
struct fsnotify_mark_connector __rcu **connp,

‎kernel/audit_fsnotify.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ struct audit_fsnotify_mark *audit_alloc_mark(struct audit_krule *krule, char *pa
103103
goto out;
104104
}
105105

106-
fsnotify_init_mark(&audit_mark->mark, audit_fsnotify_group,
107-
audit_fsnotify_free_mark);
106+
fsnotify_init_mark(&audit_mark->mark, audit_fsnotify_group);
108107
audit_mark->mark.mask = AUDIT_FS_EVENTS;
109108
audit_mark->path = pathname;
110109
audit_update_mark(audit_mark, dentry->d_inode);
@@ -203,6 +202,7 @@ static int audit_mark_handle_event(struct fsnotify_group *group,
203202

204203
static const struct fsnotify_ops audit_mark_fsnotify_ops = {
205204
.handle_event = audit_mark_handle_event,
205+
.free_mark = audit_fsnotify_free_mark,
206206
};
207207

208208
static int __init audit_fsnotify_init(void)

0 commit comments

Comments
 (0)