PERFORCE change 165412 for review
Edward Tomasz Napierala
trasz at FreeBSD.org
Mon Jun 29 17:10:51 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=165412
Change 165412 by trasz at trasz_victim on 2009/06/29 17:10:19
Kinda sorta working file descriptors accounting.
Affected files ...
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_descrip.c#8 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#18 edit
.. //depot/projects/soc2009/trasz_limits/sys/sys/hrl.h#13 edit
.. //depot/projects/soc2009/trasz_limits/sys/vm/vm_map.c#3 edit
Differences ...
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_descrip.c#8 (text+ko) ====
@@ -50,6 +50,7 @@
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/filio.h>
+#include <sys/hrl.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/limits.h>
@@ -279,7 +280,6 @@
td->td_retval[0] =
min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
PROC_UNLOCK(p);
- /* XXX: Use HRL? */
return (0);
}
@@ -722,7 +722,6 @@
return (flags & DUP_FCNTL ? EINVAL : EBADF);
PROC_LOCK(p);
maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
- /* XXX: Add HRL accounting. */
PROC_UNLOCK(p);
if (new >= maxfd)
return (flags & DUP_FCNTL ? EINVAL : EMFILE);
@@ -748,6 +747,12 @@
* out for a race.
*/
if (flags & DUP_FIXED) {
+ error = hrl_alloc_proc(p, HRL_RESOURCE_OPENFILES, 1);
+ if (error) {
+ FILEDESC_XUNLOCK(fdp);
+ fdrop(fp, td);
+ return (error);
+ }
if (new >= fdp->fd_nfiles)
fdgrowtable(fdp, new + 1);
if (fdp->fd_ofiles[new] == NULL)
@@ -770,6 +775,7 @@
if (fdp->fd_ofiles[new] == NULL)
fdunused(fdp, new);
FILEDESC_XUNLOCK(fdp);
+ hrl_free_proc(p, HRL_RESOURCE_OPENFILES, 1);
fdrop(fp, td);
return (EBADF);
}
@@ -814,6 +820,7 @@
*/
if (delfp != NULL) {
knote_fdclose(td, new);
+ hrl_free_proc(td->td_proc, HRL_RESOURCE_OPENFILES, 1);
if (delfp->f_type == DTYPE_MQUEUE)
mq_fdclose(td, new, delfp);
FILEDESC_XUNLOCK(fdp);
@@ -1112,6 +1119,7 @@
* added, and deleteing a knote for the new fd.
*/
knote_fdclose(td, fd);
+ hrl_free_proc(td->td_proc, HRL_RESOURCE_OPENFILES, 1);
if (fp->f_type == DTYPE_MQUEUE)
mq_fdclose(td, fd, fp);
FILEDESC_XUNLOCK(fdp);
@@ -1395,17 +1403,16 @@
{
struct proc *p = td->td_proc;
struct filedesc *fdp = p->p_fd;
- int fd = -1, maxfd;
+ int fd = -1, error;
FILEDESC_XLOCK_ASSERT(fdp);
if (fdp->fd_freefile > minfd)
minfd = fdp->fd_freefile;
- PROC_LOCK(p);
- maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
- /* XXX: Add HRL accounting. */
- PROC_UNLOCK(p);
+ error = hrl_alloc_proc(p, HRL_RESOURCE_OPENFILES, 1);
+ if (error)
+ return (EMFILE);
/*
* Search the bitmap for a free descriptor. If none is found, try
@@ -1415,11 +1422,9 @@
*/
for (;;) {
fd = fd_first_free(fdp, minfd, fdp->fd_nfiles);
- if (fd >= maxfd)
- return (EMFILE);
if (fd < fdp->fd_nfiles)
break;
- fdgrowtable(fdp, min(fdp->fd_nfiles * 2, maxfd));
+ fdgrowtable(fdp, fdp->fd_nfiles * 2);
}
/*
@@ -1452,7 +1457,6 @@
PROC_LOCK(p);
lim = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
- /* XXX: Add HRL accounting. */
PROC_UNLOCK(p);
if ((i = lim - fdp->fd_nfiles) > 0 && (n -= i) <= 0)
return (1);
@@ -1697,6 +1701,8 @@
if (fdp == NULL)
return;
+ hrl_allocated_proc(td->td_proc, HRL_RESOURCE_OPENFILES, 0);
+
/* Check for special need to clear POSIX style locks */
fdtol = td->td_proc->p_fdtol;
if (fdtol != NULL) {
@@ -1873,6 +1879,7 @@
struct file *fp;
knote_fdclose(td, i);
+ hrl_free_proc(td->td_proc, HRL_RESOURCE_OPENFILES, 1);
/*
* NULL-out descriptor prior to close to avoid
* a race while close blocks.
@@ -1937,6 +1944,7 @@
struct file *fp;
knote_fdclose(td, i);
+ hrl_free_proc(td->td_proc, HRL_RESOURCE_OPENFILES, 1);
/*
* NULL-out descriptor prior to close to avoid
* a race while close blocks.
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#18 (text+ko) ====
@@ -186,22 +186,17 @@
{
int i;
+ /*
+ * XXX: Free these two some other way.
+ */
+ hrl_allocated_proc(p, HRL_RESOURCE_FILESIZE, 0);
+ hrl_allocated_proc(p, HRL_RESOURCE_COREDUMPSIZE, 0);
+
mtx_lock(&hrl_lock);
for (i = 0; i < HRL_RESOURCE_MAX; i++) {
- if (p->p_accounting.ha_resources[i] != 0) {
-#if 0
+ if (p->p_accounting.ha_resources[i] != 0)
KASSERT(p->p_accounting.ha_resources == 0,
("dead process still holding resources"));
- printf("hrl_proc_exiting: %s = %lld\n",
- hrl_resource_name(i),
- p->p_accounting.ha_resources[i]);
-#else
- if (p->p_accounting.ha_resources[i] > 0)
- hrl_free_proc(p, i, p->p_accounting.ha_resources[i]);
- else
- p->p_accounting.ha_resources[i] = 0;
- }
-#endif
}
mtx_unlock(&hrl_lock);
}
@@ -257,8 +252,6 @@
KASSERT(amount > 0, ("hrl_alloc_proc: invalid amount for %s: %lld",
hrl_resource_name(resource), amount));
- if (amount <= 0)
- panic("bleh.");
mtx_lock(&hrl_lock);
p->p_accounting.ha_resources[resource] += amount;
@@ -290,7 +283,11 @@
mtx_unlock(&hrl_lock);
/*
- * XXX: When denying, return proper errno - EFSIZ, ENOMEM etc.
+ * XXX: When denying, return proper errno - EFSIZ, ENOMEM, EMFILE etc.
+ */
+
+ /*
+ * Check maxfilesperproc.
*/
return (0);
@@ -311,10 +308,8 @@
struct ucred *cred;
struct prison *pr;
- KASSERT(amount > 0, ("hrl_allocated_proc: invalid amount for %s: %lld",
+ KASSERT(amount >= 0, ("hrl_allocated_proc: invalid amount for %s: %lld",
hrl_resource_name(resource), amount));
- if (amount <= 0)
- panic("bleh.");
mtx_lock(&hrl_lock);
diff = amount - p->p_accounting.ha_resources[resource];
@@ -361,8 +356,6 @@
KASSERT(amount > 0, ("hrl_free_proc: invalid amount for %s: %lld",
hrl_resource_name(resource), amount));
- if (amount <= 0)
- panic("bleh.");
mtx_lock(&hrl_lock);
p->p_accounting.ha_resources[resource] -= amount;
==== //depot/projects/soc2009/trasz_limits/sys/sys/hrl.h#13 (text+ko) ====
==== //depot/projects/soc2009/trasz_limits/sys/vm/vm_map.c#3 (text+ko) ====
@@ -67,6 +67,7 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/hrl.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/mutex.h>
@@ -410,6 +411,11 @@
pmap_activate(td);
vmspace_dofree(vm);
}
+ hrl_allocated_proc(p, HRL_RESOURCE_DATASIZE, 0);
+ hrl_allocated_proc(p, HRL_RESOURCE_STACKSIZE, 0);
+ hrl_allocated_proc(p, HRL_RESOURCE_MEMORYUSE, 0);
+ hrl_allocated_proc(p, HRL_RESOURCE_MEMORYLOCKED, 0);
+ hrl_allocated_proc(p, HRL_RESOURCE_VMEMORYUSE, 0);
}
/* Acquire reference to vmspace owned by another process. */
More information about the p4-projects
mailing list