Fix /tmp tmpfs handling and on machines with enough RAM default to
creating a /tmp tmpfs with 25% of ram size limit. Suggested by ad@.
This commit is contained in:
parent
d17a590668
commit
0e7fb040fb
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: bsddisklabel.c,v 1.34 2020/01/09 13:22:30 martin Exp $ */
|
/* $NetBSD: bsddisklabel.c,v 1.35 2020/01/16 16:47:19 martin Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 1997 Piermont Information Systems Inc.
|
* Copyright 1997 Piermont Information Systems Inc.
|
||||||
|
@ -236,8 +236,16 @@ draw_size_menu_line(menudesc *m, int opt, void *arg)
|
||||||
size / sizemult);
|
size / sizemult);
|
||||||
}
|
}
|
||||||
size = pset->infos[opt].size;
|
size = pset->infos[opt].size;
|
||||||
snprintf(psize, sizeof psize, "%" PRIu64 "%s",
|
if (pset->infos[opt].fs_type == FS_TMPFS) {
|
||||||
size / sizemult, inc_free);
|
if (pset->infos[opt].size < 0)
|
||||||
|
snprintf(psize, sizeof psize, "%" PRIu64 "%%", -size);
|
||||||
|
else
|
||||||
|
snprintf(psize, sizeof psize, "%" PRIu64 " %s", size,
|
||||||
|
msg_string(MSG_megname));
|
||||||
|
} else {
|
||||||
|
snprintf(psize, sizeof psize, "%" PRIu64 "%s",
|
||||||
|
size / sizemult, inc_free);
|
||||||
|
}
|
||||||
|
|
||||||
if (pset->infos[opt].type == PT_swap) {
|
if (pset->infos[opt].type == PT_swap) {
|
||||||
snprintf(swap, sizeof swap, "<%s>",
|
snprintf(swap, sizeof swap, "<%s>",
|
||||||
|
@ -521,6 +529,20 @@ find_part_at(struct disk_partitions *parts, daddr_t start)
|
||||||
return NO_PART;
|
return NO_PART;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static daddr_t
|
||||||
|
parse_ram_size(const char *str, bool *is_percent)
|
||||||
|
{
|
||||||
|
daddr_t val;
|
||||||
|
char *cp;
|
||||||
|
|
||||||
|
val = strtoull(str, &cp, 10);
|
||||||
|
while (*cp && isspace((unsigned char)*cp))
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
*is_percent = *cp == '%';
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
set_ptn_size(menudesc *m, void *arg)
|
set_ptn_size(menudesc *m, void *arg)
|
||||||
{
|
{
|
||||||
|
@ -531,7 +553,7 @@ set_ptn_size(menudesc *m, void *arg)
|
||||||
size_t i, root = ~0U;
|
size_t i, root = ~0U;
|
||||||
daddr_t size, old_size, new_size_val, mult;
|
daddr_t size, old_size, new_size_val, mult;
|
||||||
int rv;
|
int rv;
|
||||||
bool non_zero, extend;
|
bool non_zero, extend, is_ram_size, is_percent = false;
|
||||||
|
|
||||||
if (pset->cur_free_space == 0 && p->size == 0 &&
|
if (pset->cur_free_space == 0 && p->size == 0 &&
|
||||||
!(p->flags & PUIFLG_JUST_MOUNTPOINT))
|
!(p->flags & PUIFLG_JUST_MOUNTPOINT))
|
||||||
|
@ -561,22 +583,47 @@ set_ptn_size(menudesc *m, void *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_ram_size = (p->flags & PUIFLG_JUST_MOUNTPOINT)
|
||||||
|
&& p->fs_type == FS_TMPFS;
|
||||||
|
|
||||||
size = p->size;
|
size = p->size;
|
||||||
|
if (is_ram_size && size < 0) {
|
||||||
|
is_percent = true;
|
||||||
|
size = -size;
|
||||||
|
}
|
||||||
old_size = size;
|
old_size = size;
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
size = p->def_size;
|
size = p->def_size;
|
||||||
size /= sizemult;
|
if (!is_ram_size)
|
||||||
snprintf(dflt, sizeof dflt, "%" PRIu64 "%s",
|
size /= sizemult;
|
||||||
size, p->flags & PUIFLAG_EXTEND ? "+" : "");
|
|
||||||
|
if (is_ram_size) {
|
||||||
|
snprintf(dflt, sizeof dflt, "%" PRIu64 "%s",
|
||||||
|
size, is_percent ? "%" : "");
|
||||||
|
} else {
|
||||||
|
snprintf(dflt, sizeof dflt, "%" PRIu64 "%s",
|
||||||
|
size, p->flags & PUIFLAG_EXTEND ? "+" : "");
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
msg_fmt_prompt_win(MSG_askfssize, -1, 18, 0, 0,
|
msg_fmt_prompt_win(MSG_askfssize, -1, 18, 0, 0,
|
||||||
dflt, answer, sizeof answer, "%s%s", p->mount, multname);
|
dflt, answer, sizeof answer, "%s%s", p->mount,
|
||||||
|
is_ram_size ? msg_string(MSG_megname) : multname);
|
||||||
|
|
||||||
/* cp will be checked below */
|
if (is_ram_size) {
|
||||||
|
new_size_val = parse_ram_size(answer, &is_percent);
|
||||||
|
if (is_percent &&
|
||||||
|
(new_size_val < 0 || new_size_val > 100))
|
||||||
|
continue;
|
||||||
|
if (!is_percent && new_size_val < 0)
|
||||||
|
continue;
|
||||||
|
size = new_size_val;
|
||||||
|
extend = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
mult = sizemult;
|
mult = sizemult;
|
||||||
new_size_val = parse_disk_pos(answer, &mult, pm->dlcylsize,
|
new_size_val = parse_disk_pos(answer, &mult,
|
||||||
&extend);
|
pm->dlcylsize, &extend);
|
||||||
|
|
||||||
if (strcmp(answer, dflt) == 0)
|
if (strcmp(answer, dflt) == 0)
|
||||||
non_zero = p->def_size > 0;
|
non_zero = p->def_size > 0;
|
||||||
|
@ -613,7 +660,9 @@ set_ptn_size(menudesc *m, void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
daddr_t align = pset->parts->pscheme->get_part_alignment(pset->parts);
|
daddr_t align = pset->parts->pscheme->get_part_alignment(pset->parts);
|
||||||
size = NUMSEC(size, mult, align);
|
if (!is_ram_size) {
|
||||||
|
size = NUMSEC(size, mult, align);
|
||||||
|
}
|
||||||
if (p->flags & PUIFLAG_EXTEND)
|
if (p->flags & PUIFLAG_EXTEND)
|
||||||
p->flags &= ~PUIFLAG_EXTEND;
|
p->flags &= ~PUIFLAG_EXTEND;
|
||||||
if (extend && (p->limit == 0 || p->limit > p->size)) {
|
if (extend && (p->limit == 0 || p->limit > p->size)) {
|
||||||
|
@ -626,7 +675,7 @@ set_ptn_size(menudesc *m, void *arg)
|
||||||
adjust_free:
|
adjust_free:
|
||||||
if ((p->flags & (PUIFLG_IS_OUTER|PUIFLG_JUST_MOUNTPOINT)) == 0)
|
if ((p->flags & (PUIFLG_IS_OUTER|PUIFLG_JUST_MOUNTPOINT)) == 0)
|
||||||
pset->cur_free_space += p->size - size;
|
pset->cur_free_space += p->size - size;
|
||||||
p->size = size;
|
p->size = is_percent ? -size : size;
|
||||||
set_pset_exit_str(pset);
|
set_pset_exit_str(pset);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -879,6 +928,20 @@ fill_defaults(struct partition_usage_set *wanted, struct disk_partitions *parts,
|
||||||
|
|
||||||
memcpy(wanted->infos, default_parts_init, sizeof(default_parts_init));
|
memcpy(wanted->infos, default_parts_init, sizeof(default_parts_init));
|
||||||
|
|
||||||
|
#ifdef HAVE_TMPFS
|
||||||
|
if (get_ramsize() > 96) {
|
||||||
|
for (i = 0; i < wanted->num; i++) {
|
||||||
|
if (wanted->infos[i].type != PT_root ||
|
||||||
|
wanted->infos[i].fs_type != FS_TMPFS)
|
||||||
|
continue;
|
||||||
|
/* default tmpfs to 1/4 RAM */
|
||||||
|
wanted->infos[i].size = -25;
|
||||||
|
wanted->infos[i].def_size = -25;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MD_PART_DEFAULTS
|
#ifdef MD_PART_DEFAULTS
|
||||||
MD_PART_DEFAULTS(pm, wanted->infos, wanted->num);
|
MD_PART_DEFAULTS(pm, wanted->infos, wanted->num);
|
||||||
#endif
|
#endif
|
||||||
|
@ -918,11 +981,6 @@ fill_defaults(struct partition_usage_set *wanted, struct disk_partitions *parts,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((wanted->infos[i].flags & PUIFLG_JUST_MOUNTPOINT) &&
|
|
||||||
wanted->infos[i].size == 0)
|
|
||||||
/* default tmpfs to 1/4 RAM */
|
|
||||||
wanted->infos[i].def_size =
|
|
||||||
get_ramsize() * (MEG/512/4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1131,7 +1189,7 @@ sort_and_sync_parts(struct partition_usage_set *pset)
|
||||||
infos[pno].fs_version = info.fs_sub_type;
|
infos[pno].fs_version = info.fs_sub_type;
|
||||||
}
|
}
|
||||||
/* Add the non-partition entires after that */
|
/* Add the non-partition entires after that */
|
||||||
j = pset->num;
|
j = pset->parts->num_part;
|
||||||
for (i = 0; i < pset->num; i++) {
|
for (i = 0; i < pset->num; i++) {
|
||||||
if (j >= no)
|
if (j >= no)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: defs.h,v 1.50 2020/01/09 13:22:30 martin Exp $ */
|
/* $NetBSD: defs.h,v 1.51 2020/01/16 16:47:19 martin Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 1997 Piermont Information Systems Inc.
|
* Copyright 1997 Piermont Information Systems Inc.
|
||||||
|
@ -241,7 +241,10 @@ typedef struct distinfo {
|
||||||
* layout according to the partitioning scheme backend.
|
* layout according to the partitioning scheme backend.
|
||||||
*/
|
*/
|
||||||
struct part_usage_info {
|
struct part_usage_info {
|
||||||
daddr_t size; /* thumb guestimate of size [sec] */
|
daddr_t size; /* thumb guestimate of size,
|
||||||
|
* [sec if positive, %-of-ram
|
||||||
|
* if TMPFS and negative]
|
||||||
|
*/
|
||||||
daddr_t def_size; /* default size */
|
daddr_t def_size; /* default size */
|
||||||
daddr_t limit; /* max size */
|
daddr_t limit; /* max size */
|
||||||
char mount[MOUNTLEN]; /* where will we mount this? */
|
char mount[MOUNTLEN]; /* where will we mount this? */
|
||||||
|
@ -363,7 +366,6 @@ int partman_go; /* run extended partition manager */
|
||||||
FILE *logfp;
|
FILE *logfp;
|
||||||
FILE *script;
|
FILE *script;
|
||||||
|
|
||||||
daddr_t tmp_ramdisk_size;
|
|
||||||
#define MAX_DISKS 15
|
#define MAX_DISKS 15
|
||||||
|
|
||||||
daddr_t root_limit; /* BIOS (etc) read limit */
|
daddr_t root_limit; /* BIOS (etc) read limit */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: disks.c,v 1.59 2020/01/09 13:22:30 martin Exp $ */
|
/* $NetBSD: disks.c,v 1.60 2020/01/16 16:47:19 martin Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 1997 Piermont Information Systems Inc.
|
* Copyright 1997 Piermont Information Systems Inc.
|
||||||
|
@ -1299,7 +1299,11 @@ make_fstab(struct install_partition_desc *install)
|
||||||
if (ptn->size == 0)
|
if (ptn->size == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ptn->type != PT_swap &&
|
bool is_tmpfs = ptn->type == PT_root &&
|
||||||
|
ptn->fs_type == FS_TMPFS &&
|
||||||
|
(ptn->flags & PUIFLG_JUST_MOUNTPOINT);
|
||||||
|
|
||||||
|
if (!is_tmpfs && ptn->type != PT_swap &&
|
||||||
(ptn->instflags & PUIINST_MOUNT) == 0)
|
(ptn->instflags & PUIINST_MOUNT) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -1350,6 +1354,29 @@ make_fstab(struct install_partition_desc *install)
|
||||||
scripting_fprintf(f, "%s\t\tnone\tswap\tsw%s\t\t 0 0\n",
|
scripting_fprintf(f, "%s\t\tnone\tswap\tsw%s\t\t 0 0\n",
|
||||||
dev, dump_dev);
|
dev, dump_dev);
|
||||||
continue;
|
continue;
|
||||||
|
#ifdef HAVE_TMPFS
|
||||||
|
case FS_TMPFS:
|
||||||
|
if (ptn->size < 0)
|
||||||
|
scripting_fprintf(f,
|
||||||
|
"tmpfs\t\t/tmp\ttmpfs\trw,-m=1777,"
|
||||||
|
"-s=ram%%%" PRIu64 "\n", -ptn->size);
|
||||||
|
else
|
||||||
|
scripting_fprintf(f,
|
||||||
|
"tmpfs\t\t/tmp\ttmpfs\trw,-m=1777,"
|
||||||
|
"-s=%" PRIu64 "M\n", ptn->size);
|
||||||
|
continue;
|
||||||
|
#else
|
||||||
|
case FS_MFS:
|
||||||
|
if (swap_dev[0] != 0)
|
||||||
|
scripting_fprintf(f,
|
||||||
|
"%s\t\t/tmp\tmfs\trw,-s=%"
|
||||||
|
PRIu64 "\n", swap_dev, ptn->size);
|
||||||
|
else
|
||||||
|
scripting_fprintf(f,
|
||||||
|
"swap\t\t/tmp\tmfs\trw,-s=%"
|
||||||
|
PRIu64 "\n", ptn->size);
|
||||||
|
continue;
|
||||||
|
#endif
|
||||||
case FS_SYSVBFS:
|
case FS_SYSVBFS:
|
||||||
fstype = "sysvbfs";
|
fstype = "sysvbfs";
|
||||||
make_target_dir("/stand");
|
make_target_dir("/stand");
|
||||||
|
@ -1379,21 +1406,6 @@ make_fstab(struct install_partition_desc *install)
|
||||||
}
|
}
|
||||||
|
|
||||||
done_with_disks:
|
done_with_disks:
|
||||||
if (tmp_ramdisk_size > 0) {
|
|
||||||
#ifdef HAVE_TMPFS
|
|
||||||
scripting_fprintf(f, "tmpfs\t\t/tmp\ttmpfs\trw,-m=1777,-s=%"
|
|
||||||
PRIu64 "\n",
|
|
||||||
tmp_ramdisk_size * 512);
|
|
||||||
#else
|
|
||||||
if (swap_dev[0] != 0)
|
|
||||||
scripting_fprintf(f, "%s\t\t/tmp\tmfs\trw,-s=%"
|
|
||||||
PRIu64 "\n", swap_dev, tmp_ramdisk_size);
|
|
||||||
else
|
|
||||||
scripting_fprintf(f, "swap\t\t/tmp\tmfs\trw,-s=%"
|
|
||||||
PRIu64 "\n", tmp_ramdisk_size);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cdrom_dev[0] == 0)
|
if (cdrom_dev[0] == 0)
|
||||||
get_default_cdrom(cdrom_dev, sizeof(cdrom_dev));
|
get_default_cdrom(cdrom_dev, sizeof(cdrom_dev));
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: main.c,v 1.19 2019/12/11 15:08:45 martin Exp $ */
|
/* $NetBSD: main.c,v 1.20 2020/01/16 16:47:19 martin Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 1997 Piermont Information Systems Inc.
|
* Copyright 1997 Piermont Information Systems Inc.
|
||||||
|
@ -134,7 +134,6 @@ init(void)
|
||||||
const struct f_arg *arg;
|
const struct f_arg *arg;
|
||||||
|
|
||||||
sizemult = 1;
|
sizemult = 1;
|
||||||
tmp_ramdisk_size = 0;
|
|
||||||
clean_xfer_dir = 0;
|
clean_xfer_dir = 0;
|
||||||
mnt2_mounted = 0;
|
mnt2_mounted = 0;
|
||||||
fd_type = "msdos";
|
fd_type = "msdos";
|
||||||
|
|
Loading…
Reference in New Issue