Date: Sat, 19 Jun 2010 01:43:35 +0400 From: pluknet <pluknet@gmail.com> To: Gabor Kovesdan <gabor@freebsd.org> Cc: soc-status@freebsd.org Subject: Re: Collective resource limits status report #3 Message-ID: <AANLkTikwUYWCIvlDQ60L4L8gMcEeDFIV6850csEwuH8E@mail.gmail.com> In-Reply-To: <4C1BCB96.4040608@FreeBSD.org> References: <4C1BCB96.4040608@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 18 June 2010 23:40, Gabor Kovesdan <gabor@freebsd.org> wrote: > Hello, > > since the last report, I made my code compilable, although it doesn't > completely work yet. Now I'm working on finding what is going wrong. While I > spent time with buildworld/buildkernel compilations, I wrote manual pages > for the syscalls implemented and also extended the test utility a bit. For > next week, my goal is to make these totally work and start to work on actual > resource limits. First step to accomplish this is adding containers for > resource usage accounting. Edward's hrl code will be a big help for this and > I'll consider his work-in-progress project when doing this task, trying to > come up with a more general solution that is also useful for his work and > later improvements on resource limits. > > Bad news is that I've had some problems with Perforce. I used it many many > times, I know how it works but seems that recent client utility is either > buggy or developers broke compatibility and I experienced a very different > behaviour this time. I just sent a mail to developers@ about this, this is > something that we should look at. This made the history in my p4 repo a > total mess but supposedly code is there so you can check out. For easier > review, I'm also providing a patch for head with all the code I wrote. I > know this is not much but it took time to get into the kernel internals and > it also took time to compile the code and eliminating compile errors > one-by-one. Hopefully, as I'm getting into it, I'll progress more and more > quickly. The patch is here: http://kovesdan.org/patches/jobs_current.diff > First, thank you for doing this! Please, let me comment a little (that's rather a thinking aloud, don't take it too seriously). As I see, you decided to follow a bug-for-bug compatibility way and chose to bring in a new error type ENOPKG. That's sort of surprise since, as I know, ENOPKG is an IRIX specific error code meaning that a particular IRIX installation doesn't come with job limit feature installed, and that doesn't fit nicely in to the FreeBSD world. Does it make sense to define it at all? Also, I see no purpose to use it anywhere. Why don't define __jid_t as it's done for uid_t, gid_t, pid_t? Why do jid_t to be 64-bit capable? IMHO it should follow uid_t capacity, as far as jobs are created per uid (and that's noted in makenewjob(2)). I would make something like following (not important parts missed intentionally). [job limits are like struct plimit (both are based on BSD struct rlimit in my variant), so I decided to include jid_t limits (and name it struct ulimit here) into struct uidinfo since that's something similar to stuct plimit, but unlike plimit which is designed to be per process, an ulimit is per uid; hence its name: "user limit". Though I don't like that now there are excessively two new fields in struct uidinfo.] %%% Index: sys/sys/_types.h =================================================================== --- sys/sys/_types.h (revision 209037) +++ sys/sys/_types.h (working copy) @@ -42,7 +42,8 @@ typedef __uint64_t __fsblkcnt_t; typedef __uint64_t __fsfilcnt_t; typedef __uint32_t __gid_t; -typedef __int64_t __id_t; /* can hold a gid_t, pid_t, or uid_t */ +typedef __int64_t __id_t; /* can hold a gid_t, pid_t, + uid_t, or jid_t */ typedef __uint32_t __ino_t; /* inode number */ typedef long __key_t; /* IPC key (for Sys V IPC) */ typedef __int32_t __lwpid_t; /* Thread ID (a.k.a. LWP) */ @@ -61,6 +62,7 @@ typedef struct __timer *__timer_t; /* timer_gettime()... */ typedef struct __mq *__mqd_t; /* mq_open()... */ typedef __uint32_t __uid_t; +typedef __uint32_t __jid_t; typedef unsigned int __useconds_t; /* microseconds (unsigned) */ typedef int __cpuwhich_t; /* which parameter for cpuset. */ typedef int __cpulevel_t; /* level parameter for cpuset. */ Index: sys/sys/resource.h =================================================================== --- sys/sys/resource.h (revision 209037) +++ sys/sys/resource.h (working copy) @@ -130,6 +130,16 @@ #define _RLIM_T_DECLARED #endif +#ifndef _JID_T_DECLARED +typedef __jid_t jid_t; +#define _JID_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + struct rlimit { rlim_t rlim_cur; /* current (soft) limit */ rlim_t rlim_max; /* maximum value for rlim_cur */ @@ -154,6 +164,37 @@ #define CP_IDLE 4 #define CPUSTATES 5 +/* + * Job limits + */ +#define JLIMIT_CPU 0 +#define JLIMIT_DATA 1 +#define JLIMIT_NOFILE 2 +#define JLIMIT_NUMPROC 3 +#define JLIMIT_NUMTHR 4 +#define JLIMIT_VMEM 5 +#define JLIMIT_PMEM 6 +#define JLIMIT_RSS 7 + +#define JLIM_NLIMITS 8 + +/* + * Job limit string identifiers + */ + +#ifdef _JLIMIT_IDENT +static char *jlimit_ident[JLIM_NLIMITS] = { + "cputime", + "datasize", + "files", + "processes", + "threads", + "vmemory", + "physmem", + "ressetsize", +}; +#endif + #endif /* __BSD_VISIBLE */ #ifdef _KERNEL @@ -165,9 +206,13 @@ __BEGIN_DECLS /* XXX 2nd arg to [gs]etpriority() should be an id_t */ +int getjlimit(jid_t, int, struct rlimit *); int getpriority(int, int); int getrlimit(int, struct rlimit *); int getrusage(int, struct rusage *); +int killjob(jid_t, int); +jid_t makenewjob(jid_t, uid_t); +int setjlimit(jid_t, int, struct rlimit *); int setpriority(int, int, int); int setrlimit(int, const struct rlimit *); __END_DECLS Index: sys/sys/resourcevar.h =================================================================== --- sys/sys/resourcevar.h (revision 209037) +++ sys/sys/resourcevar.h (working copy) @@ -79,6 +79,11 @@ int pl_refcnt; /* number of references */ }; +struct ulimit { + struct rlimit ul_jlimit[JLIM_NLIMITS]; + int ul_refcnt; /* number of references */ +}; + /*- * Per uid resource consumption * @@ -97,6 +102,8 @@ long ui_ptscnt; /* (b) number of pseudo-terminals */ uid_t ui_uid; /* (a) uid */ u_int ui_ref; /* (b) reference count */ + jid_t ui_jid; /* (c) job in which this uid_t lives */ + struct ulimit *ui_limit; }; #define UIDINFO_VMSIZE_LOCK(ui) mtx_lock(&((ui)->ui_vmsize_mtx)) Index: sys/sys/types.h =================================================================== --- sys/sys/types.h (revision 209037) +++ sys/sys/types.h (working copy) @@ -181,7 +181,7 @@ #endif #ifndef _ID_T_DECLARED -typedef __id_t id_t; /* can hold a uid_t or pid_t */ +typedef __id_t id_t; /* can hold a uid_t, pid_t or jid_t */ #define _ID_T_DECLARED #endif @@ -271,6 +271,11 @@ #define _UID_T_DECLARED #endif +#ifndef _JID_T_DECLARED +typedef __jid_t jid_t; /* job id */ +#define _JID_T_DECLARED +#endif + #ifndef _USECONDS_T_DECLARED typedef __useconds_t useconds_t; /* microseconds (unsigned) */ #define _USECONDS_T_DECLARED %%% -- wbr, pluknet
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTikwUYWCIvlDQ60L4L8gMcEeDFIV6850csEwuH8E>