git: 1c7a65adb002 - main - cache: track calls to cache_symlink_alloc with unsupported size

Mateusz Guzik mjg at FreeBSD.org
Mon Jan 25 19:45:42 UTC 2021


The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=1c7a65adb002cf96bda1f72d9a26dd4237368263

commit 1c7a65adb002cf96bda1f72d9a26dd4237368263
Author:     Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-01-24 20:00:03 +0000
Commit:     Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-01-25 19:45:23 +0000

    cache: track calls to cache_symlink_alloc with unsupported size
    
    While here assert on size passed to free.
---
 sys/kern/vfs_cache.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index 03bafc75acaa..9d3b935a3047 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -122,6 +122,7 @@ SDT_PROBE_DEFINE2(vfs, namecache, zap_negative, done, "struct vnode *",
     "char *");
 SDT_PROBE_DEFINE2(vfs, namecache, evict_negative, done, "struct vnode *",
     "char *");
+SDT_PROBE_DEFINE1(vfs, namecache, symlink, alloc__fail, "size_t");
 
 SDT_PROBE_DEFINE3(vfs, fplookup, lookup, done, "struct nameidata", "int", "bool");
 SDT_PROBE_DECLARE(vfs, namei, lookup, entry);
@@ -477,6 +478,7 @@ STATNODE_COUNTER(fullpathfail2, numfullpathfail2,
     "Number of fullpath search errors (VOP_VPTOCNP failures)");
 STATNODE_COUNTER(fullpathfail4, numfullpathfail4, "Number of fullpath search errors (ENOMEM)");
 STATNODE_COUNTER(fullpathfound, numfullpathfound, "Number of successful fullpath calls");
+STATNODE_COUNTER(symlinktoobig, symlinktoobig, "Number of times symlink did not fit the cache");
 
 /*
  * Debug or developer statistics.
@@ -576,6 +578,8 @@ cache_symlink_alloc(size_t size, int flags)
 	if (size < CACHE_ZONE_LARGE_SIZE) {
 		return (uma_zalloc_smr(cache_zone_large, flags));
 	}
+	counter_u64_add(symlinktoobig, 1);
+	SDT_PROBE1(vfs, namecache, symlink, alloc__fail, size);
 	return (NULL);
 }
 
@@ -584,6 +588,8 @@ cache_symlink_free(char *string, size_t size)
 {
 
 	MPASS(string != NULL);
+	KASSERT(size < CACHE_ZONE_LARGE_SIZE,
+	    ("%s: size %zu too big", __func__, size));
 
 	if (size < CACHE_ZONE_SMALL_SIZE) {
 		uma_zfree_smr(cache_zone_small, string);


More information about the dev-commits-src-all mailing list