Author: kib
Date: Mon Mar 30 21:50:51 2020
New Revision: 359468
URL: https://svnweb.freebsd.org/changeset/base/359468

Log:
  kern_sendfile.c: add specific malloc type.
  
  Now sfio leaks are more easily seen in the malloc statistics than
  e.g. just wired or busy pages leak.
  
  Reviewed by:  glebius, markj
  Tested by:    pho
  Sponsored by: The FreeBSD Foundation
  MFC after:    1 week
  Differential revision:        https://reviews.freebsd.org/D24038

Modified:
  head/sys/kern/kern_sendfile.c

Modified: head/sys/kern/kern_sendfile.c
==============================================================================
--- head/sys/kern/kern_sendfile.c       Mon Mar 30 21:48:47 2020        
(r359467)
+++ head/sys/kern/kern_sendfile.c       Mon Mar 30 21:50:51 2020        
(r359468)
@@ -65,6 +65,8 @@ __FBSDID("$FreeBSD$");
 #include <vm/vm_object.h>
 #include <vm/vm_pager.h>
 
+static MALLOC_DEFINE(M_SENDFILE, "sendfile", "sendfile dynamic memory");
+
 #define        EXT_FLAG_SYNC           EXT_FLAG_VENDOR1
 #define        EXT_FLAG_NOCACHE        EXT_FLAG_VENDOR2
 #define        EXT_FLAG_CACHE_LAST     EXT_FLAG_VENDOR3
@@ -283,7 +285,7 @@ sendfile_iodone(void *arg, vm_page_t *pg, int count, i
                 * to the socket yet.
                 */
                MPASS((curthread->td_pflags & TDP_KTHREAD) == 0);
-               free(sfio, M_TEMP);
+               free(sfio, M_SENDFILE);
                return;
        }
 
@@ -338,7 +340,7 @@ sendfile_iodone(void *arg, vm_page_t *pg, int count, i
 out_with_ref:
 #endif
        CURVNET_RESTORE();
-       free(sfio, M_TEMP);
+       free(sfio, M_SENDFILE);
 }
 
 /*
@@ -640,7 +642,7 @@ vn_sendfile(struct file *fp, int sockfd, struct uio *h
        SFSTAT_ADD(sf_rhpages_requested, SF_READAHEAD(flags));
 
        if (flags & SF_SYNC) {
-               sfs = malloc(sizeof *sfs, M_TEMP, M_WAITOK | M_ZERO);
+               sfs = malloc(sizeof(*sfs), M_SENDFILE, M_WAITOK | M_ZERO);
                mtx_init(&sfs->mtx, "sendfile", NULL, MTX_DEF);
                cv_init(&sfs->cv, "sendfile");
        }
@@ -826,7 +828,7 @@ retry_space:
                    npages, rhpages);
 
                sfio = malloc(sizeof(struct sf_io) +
-                   npages * sizeof(vm_page_t), M_TEMP, M_WAITOK);
+                   npages * sizeof(vm_page_t), M_SENDFILE, M_WAITOK);
                refcount_init(&sfio->nios, 1);
                sfio->obj = obj;
                sfio->error = 0;
@@ -1135,7 +1137,7 @@ out:
                KASSERT(sfs->count == 0, ("sendfile sync still busy"));
                cv_destroy(&sfs->cv);
                mtx_destroy(&sfs->mtx);
-               free(sfs, M_TEMP);
+               free(sfs, M_SENDFILE);
        }
 #ifdef KERN_TLS
        if (tls != NULL)
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to