Re: where to release proc.p_stats

From: John Baldwin <jhb_at_freebsd.org>
Date: Fri, 21 Oct 2005 12:39:33 -0400
On Friday 21 October 2005 09:13 am, nocool wrote:
> freebsd-hackers,hello
>
> 	Question about 5.4 kernel source code.
> 	I have some question about strust proc's initialize. Kernel use proc_zone
> to allocate proc items and initialize them with proc_init
> (sys\kern\kern_proc.c) function. In this function, we can find the field
> proc.p_stats is allocated with pstats_alloc(), as
>
> p->p_stats = pstats_alloc();
>
> and pstats_alloc is realized as
>
> malloc(sizeof(struct pstats), M_SUBPROC, M_ZERO|M_WAITOK);
>
> But I can't find where this field is freed. If it will not be release, will
> there be memory leakage?

Heh, das_at_ forgot to call pstats_free() when he did the changes.  The reason 
is probably because proc_fini() doesn't do anything useful because we never 
recycle proc structs.  We should probably at least add the operations there 
though for documentation purposes.  Something like this would work I think:

Index: kern_proc.c
===================================================================
RCS file: /usr/cvs/src/sys/kern/kern_proc.c,v
retrieving revision 1.232
diff -u -r1.232 kern_proc.c
--- kern_proc.c 2 Oct 2005 23:27:56 -0000       1.232
+++ kern_proc.c 21 Oct 2005 16:38:45 -0000
_at__at_ -197,7 +197,14 _at__at_
 proc_fini(void *mem, int size)
 {

+#ifdef notnow
+       pstats_free(p->p_stats);
+       mtx_destroy(&p->p_mtx);
+       ksegrp_free(FIRST_KSEGRP_IN_PROC(p));
+       thread_free(FIRST_THREAD_IN_PROC(p));
+#else
        panic("proc reclaimed");
+#endif
 }

 /*


-- 
John Baldwin <jhb_at_FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org
Received on Fri Oct 21 2005 - 14:43:55 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:46 UTC