From owner-freebsd-current@FreeBSD.ORG Thu May 23 01:06:28 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 7F94B164 for ; Thu, 23 May 2013 01:06:28 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wi0-x235.google.com (mail-wi0-x235.google.com [IPv6:2a00:1450:400c:c05::235]) by mx1.freebsd.org (Postfix) with ESMTP id 1A4EF647 for ; Thu, 23 May 2013 01:06:27 +0000 (UTC) Received: by mail-wi0-f181.google.com with SMTP id hi5so1738889wib.8 for ; Wed, 22 May 2013 18:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-type:content-disposition:user-agent; bh=CvBD/fzLAJtAg2sSCUiRzXWVKQ0H2Az010Y1emr9IJo=; b=qEvEBDqrqrJa+fYr8V6anVaL+LGFpNQEwlz3Qj/ntN29e+lbVkokTg1nQTcRkrcFHZ ksijuDkuteZP2r2Desil3wR8OtLvvr8aKbIzu10zCigkADyF4TDQUERe1EL0jFuCyqKi sqmAzkqzMEGdpkj10wDO4nyxQt7iNFHj5b4KqvPi2FxJhLA5PJYxV4srS/vSw03CJBye U0nChuEvPAiNPhCoG/eg2T5GHZpW9XCS+NCahH6TaEfx+YVk2dMKkLPnDHxD64o6LV20 e1lGr34QpMFsN86kLIb+SRJD3TUVrkjEJoQpgtNRJiv8XCe+766jIw9KLJTIIN9rf8WS mGUg== X-Received: by 10.180.188.141 with SMTP id ga13mr39033570wic.9.1369271187174; Wed, 22 May 2013 18:06:27 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPSA id ay7sm32401909wib.9.2013.05.22.18.06.25 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 22 May 2013 18:06:26 -0700 (PDT) Date: Thu, 23 May 2013 03:06:23 +0200 From: Mateusz Guzik To: freebsd-current@freebsd.org Subject: acct: shared rlimit object for exiting processes Message-ID: <20130523010623.GB19960@dft-labs.eu> Mail-Followup-To: Mateusz Guzik , freebsd-current@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 May 2013 01:06:28 -0000 When a process is exiting accounting code always allocates new rlimit, copies old limits over and sets RLIMIT_FSIZE to RLIM_INFINITY. Since I don't see any good for keeping old limits with exception of RLIMIT_FSIZE, allocation each time looks unnecessary. Thus I propose the following: ========================= acct: create a special plimit object and set it for exiting processes instead of allocating new one each time We set all limits to RLIM_INFINITY which sould be ok (even though we care only about RLIMT_FSIZE). diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 3362112..af167d9 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -133,6 +133,7 @@ static int acct_configured; static int acct_suspended; static struct vnode *acct_vp; static struct ucred *acct_cred; +static struct plimit *acct_limit; static int acct_flags; static struct sx acct_sx; @@ -196,7 +197,7 @@ int sys_acct(struct thread *td, struct acct_args *uap) { struct nameidata nd; - int error, flags, replacing; + int error, flags, i, replacing; error = priv_check(td, PRIV_ACCT); if (error) @@ -267,6 +268,15 @@ sys_acct(struct thread *td, struct acct_args *uap) } /* + * Create our own rlimit object without limits. This is used with + * exiting processes to eliminate any file size limits. + */ + acct_limit = lim_alloc(); + for (i = 0; i < RLIM_NLIMITS; i++) + acct_limit->pl_rlimit[i].rlim_cur = + acct_limit->pl_rlimit[i].rlim_max = RLIM_INFINITY; + + /* * Save the new accounting file vnode, and schedule the new * free space watcher. */ @@ -314,6 +324,7 @@ acct_disable(struct thread *td, int logging) sx_assert(&acct_sx, SX_XLOCKED); error = vn_close(acct_vp, acct_flags, acct_cred, td); crfree(acct_cred); + lim_free(acct_limit); acct_configured = 0; acct_vp = NULL; acct_cred = NULL; @@ -334,7 +345,6 @@ acct_process(struct thread *td) { struct acctv2 acct; struct timeval ut, st, tmp; - struct plimit *newlim, *oldlim; struct proc *p; struct rusage ru; int t, ret; @@ -410,7 +420,6 @@ acct_process(struct thread *td) /* (8) The boolean flags that tell how the process terminated, etc. */ acct.ac_flagx = p->p_acflag; - PROC_UNLOCK(p); /* Setup ancillary structure fields. */ acct.ac_flagx |= ANVER; @@ -419,16 +428,11 @@ acct_process(struct thread *td) acct.ac_len = acct.ac_len2 = sizeof(acct); /* - * Eliminate any file size rlimit. + * Use our own rlimit to eliminate any file size limits. */ - newlim = lim_alloc(); - PROC_LOCK(p); - oldlim = p->p_limit; - lim_copy(newlim, oldlim); - newlim->pl_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; - p->p_limit = newlim; + lim_free(p->p_limit); + p->p_limit = lim_hold(acct_limit); PROC_UNLOCK(p); - lim_free(oldlim); /* * Write the accounting information to the file. -- Mateusz Guzik