Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

struct filename: use names_cachep only for getname() and friends

Instances of struct filename come from names_cachep (via
__getname()). That is done by getname_flags() and getname_kernel()
and these two are the main callers of __getname(). However, there are
other callers that simply want to allocate PATH_MAX bytes for uses that
have nothing to do with struct filename.

We want saner allocation rules for long pathnames, so that struct
filename would *always* come from names_cachep, with the out-of-line
pathname getting kmalloc'ed. For that we need to be able to change the
size of objects allocated by getname_flags()/getname_kernel().

That requires the rest of __getname() users to stop using
names_cachep; we could explicitly switch all of those to kmalloc(),
but that would cause quite a bit of noise. So the plan is to switch
getname_...() to new helpers and turn __getname() into a wrapper for
kmalloc(). Remaining __getname() users could be converted to explicit
kmalloc() at leisure, hopefully along with figuring out what size do
they really want - PATH_MAX is an overkill for some of them, used out
of laziness ("we have a convenient helper that does 4K allocations and
that's large enough, let's use it").

As a side benefit, names_cachep is no longer used outside
of fs/namei.c, so we can move it there and be done with that.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro c3a3577c 8f2ac848

+33 -20
+1 -7
fs/dcache.c
··· 3290 3290 runtime_const_init(ptr, dentry_hashtable); 3291 3291 } 3292 3292 3293 - /* SLAB cache for __getname() consumers */ 3294 - struct kmem_cache *names_cachep __ro_after_init; 3295 - EXPORT_SYMBOL(names_cachep); 3296 - 3297 3293 void __init vfs_caches_init_early(void) 3298 3294 { 3299 3295 int i; ··· 3303 3307 3304 3308 void __init vfs_caches_init(void) 3305 3309 { 3306 - names_cachep = kmem_cache_create_usercopy("names_cache", PATH_MAX, 0, 3307 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, 0, PATH_MAX, NULL); 3308 - 3310 + filename_init(); 3309 3311 dcache_init(); 3310 3312 inode_init(); 3311 3313 files_init();
+2
fs/internal.h
··· 72 72 unsigned int lookup_flags); 73 73 int lookup_noperm_common(struct qstr *qname, struct dentry *base); 74 74 75 + void __init filename_init(void); 76 + 75 77 /* 76 78 * namespace.c 77 79 */
+28 -9
fs/namei.c
··· 125 125 126 126 #define EMBEDDED_NAME_MAX (PATH_MAX - offsetof(struct filename, iname)) 127 127 128 + /* SLAB cache for struct filename instances */ 129 + static struct kmem_cache *names_cachep __ro_after_init; 130 + 131 + void __init filename_init(void) 132 + { 133 + names_cachep = kmem_cache_create_usercopy("names_cache", PATH_MAX, 0, 134 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, 0, PATH_MAX, NULL); 135 + } 136 + 137 + static inline struct filename *alloc_filename(void) 138 + { 139 + return kmem_cache_alloc(names_cachep, GFP_KERNEL); 140 + } 141 + 142 + static inline void free_filename(struct filename *p) 143 + { 144 + kmem_cache_free(names_cachep, p); 145 + } 146 + 128 147 static inline void initname(struct filename *name) 129 148 { 130 149 name->aname = NULL; ··· 183 164 char *kname; 184 165 int len; 185 166 186 - result = __getname(); 167 + result = alloc_filename(); 187 168 if (unlikely(!result)) 188 169 return ERR_PTR(-ENOMEM); 189 170 ··· 200 181 */ 201 182 if (unlikely(len <= 0)) { 202 183 if (unlikely(len < 0)) { 203 - __putname(result); 184 + free_filename(result); 204 185 return ERR_PTR(len); 205 186 } 206 187 207 188 /* The empty path is special. */ 208 189 if (!(flags & LOOKUP_EMPTY)) { 209 - __putname(result); 190 + free_filename(result); 210 191 return ERR_PTR(-ENOENT); 211 192 } 212 193 } ··· 220 201 if (unlikely(len == EMBEDDED_NAME_MAX)) { 221 202 struct filename *p = getname_long(result, filename); 222 203 if (IS_ERR(p)) { 223 - __putname(result); 204 + free_filename(result); 224 205 return p; 225 206 } 226 207 result = p; ··· 261 242 struct filename *result; 262 243 int len = strlen(filename) + 1; 263 244 264 - result = __getname(); 245 + result = alloc_filename(); 265 246 if (unlikely(!result)) 266 247 return ERR_PTR(-ENOMEM); 267 248 ··· 273 254 274 255 tmp = kmalloc(size, GFP_KERNEL); 275 256 if (unlikely(!tmp)) { 276 - __putname(result); 257 + free_filename(result); 277 258 return ERR_PTR(-ENOMEM); 278 259 } 279 260 tmp->name = (char *)result; 280 261 result = tmp; 281 262 } else { 282 - __putname(result); 263 + free_filename(result); 283 264 return ERR_PTR(-ENAMETOOLONG); 284 265 } 285 266 memcpy((char *)result->name, filename, len); ··· 306 287 } 307 288 308 289 if (unlikely(name->name != name->iname)) { 309 - __putname(name->name); 290 + free_filename((struct filename *)name->name); 310 291 kfree(name); 311 292 } else 312 - __putname(name); 293 + free_filename(name); 313 294 } 314 295 EXPORT_SYMBOL(putname); 315 296
+2 -4
include/linux/fs.h
··· 2539 2539 extern void __init vfs_caches_init_early(void); 2540 2540 extern void __init vfs_caches_init(void); 2541 2541 2542 - extern struct kmem_cache *names_cachep; 2543 - 2544 - #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL) 2545 - #define __putname(name) kmem_cache_free(names_cachep, (void *)(name)) 2542 + #define __getname() kmalloc(PATH_MAX, GFP_KERNEL) 2543 + #define __putname(name) kfree(name) 2546 2544 2547 2545 void emergency_thaw_all(void); 2548 2546 extern int sync_filesystem(struct super_block *);