From fd3bae1de25e92d631934ef3a53f13bb040103bd Mon Sep 17 00:00:00 2001 From: Jerry Jelinek Date: Wed, 18 Mar 2015 16:57:30 +0000 Subject: [PATCH] 7754 need tmpfs size support in percent Reviewed by: Hans Rosenfeld Reviewed by: Garrett D'Amore Approved by: Dan McDonald --- usr/src/man/man1m/mount_tmpfs.1m | 7 +++--- usr/src/uts/common/fs/tmpfs/tmp_subr.c | 40 ++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/usr/src/man/man1m/mount_tmpfs.1m b/usr/src/man/man1m/mount_tmpfs.1m index f01fa049b6..7ea64130bd 100644 --- a/usr/src/man/man1m/mount_tmpfs.1m +++ b/usr/src/man/man1m/mount_tmpfs.1m @@ -4,7 +4,7 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH MOUNT_TMPFS 1M "Mar 12, 2015" +.TH MOUNT_TMPFS 1M "Mar 18, 2015" .SH NAME mount_tmpfs \- mount tmpfs file systems .SH SYNOPSIS @@ -76,8 +76,9 @@ mode behaviour, as described above, applies. The \fIsz\fR argument controls the size of this particular \fBtmpfs\fR file system. If the argument is has a `k' suffix, the number will be interpreted as a number of kilobytes. An `m' suffix will be interpreted as a number of -megabytes. A `g' suffix will be interpreted as a number of gigabytes. -No suffix is interpreted as bytes. In all cases, the actual size of +megabytes. A `g' suffix will be interpreted as a number of gigabytes. A `%' +suffix will be interpreted as a percentage of the swap space available to the +zone. No suffix is interpreted as bytes. In all cases, the actual size of the file system is the number of bytes specified, rounded up to the physical pagesize of the system. .RE diff --git a/usr/src/uts/common/fs/tmpfs/tmp_subr.c b/usr/src/uts/common/fs/tmpfs/tmp_subr.c index 0a3c07b381..8723631555 100644 --- a/usr/src/uts/common/fs/tmpfs/tmp_subr.c +++ b/usr/src/uts/common/fs/tmpfs/tmp_subr.c @@ -52,6 +52,8 @@ #define VALIDMODEBITS 07777 +extern pgcnt_t swapfs_minfree; + int tmp_taccess(void *vtp, int mode, struct cred *cred) { @@ -82,7 +84,7 @@ tmp_taccess(void *vtp, int mode, struct cred *cred) */ int tmp_sticky_remove_access(struct tmpnode *dir, struct tmpnode *entry, - struct cred *cr) + struct cred *cr) { uid_t uid = crgetuid(cr); @@ -142,7 +144,9 @@ tmp_memfree(void *cp, size_t size) * namely, they cascade. For example, the caller may specify "2mk", which is * interpreted as 2 gigabytes. It would seem, at this late stage, that the * horse has left not only the barn but indeed the country, and possibly the - * entire planetary system. + * entire planetary system. Alternatively, the number may be followed by a + * single '%' sign, indicating the size is a percentage of either the zone's + * swap limit or the system's overall swap size. * * Parse and overflow errors are detected and a non-zero number returned on * error. @@ -180,6 +184,37 @@ tmp_convnum(char *str, pgcnt_t *maxpg) } /* + * Handle a size in percent. Anything other than a single percent + * modifier is invalid. We use either the zone's swap limit or the + * system's total available swap size as the initial value. Perform the + * intermediate calculation in pages to avoid overflow. + */ + if (*c == '%') { + u_longlong_t cap; + + if (*(c + 1) != '\0') + return (EINVAL); + + if (num > 100) + return (EINVAL); + + cap = (u_longlong_t)curproc->p_zone->zone_max_swap_ctl; + if (cap == UINT64_MAX) { + /* + * Use the amount of available physical and memory swap + */ + mutex_enter(&anoninfo_lock); + cap = TOTAL_AVAILABLE_SWAP; + mutex_exit(&anoninfo_lock); + } else { + cap = btop(cap); + } + + num = ptob(cap * num / 100); + goto done; + } + + /* * Apply the (potentially cascading) magnitude suffixes until an * invalid character is found, or the string comes to an end. */ @@ -213,6 +248,7 @@ valid_char: continue; } +done: /* * Since btopr() rounds up to page granularity, this round-up can * cause an overflow only if 'num' is between (max_bytes - PAGESIZE) -- 2.11.4.GIT