Re: Making tmpfs reserved memory configurable

2014-06-06 Thread Martin Husemann
On Thu, Jun 05, 2014 at 11:04:06PM +, Eduardo Horvath wrote:
 Maybe.  It's set in uvmpd_tune(), which may be called by the page daemon 
 in some circumstances.  Take a look at sys/uvm/uvm_pdaemon.c.

Hmm, should this be made more explicit in the mount_tmpfs documentation?
Under such low memory conditions, an unbound tmpfs might not behave
completely deterministially any more.

Martin


Re: Making tmpfs reserved memory configurable

2014-06-05 Thread Martin Husemann
On Fri, May 30, 2014 at 04:56:01PM +0200, Martin Husemann wrote:
 I have been on a quest to make the stock vax install CD (-image) usable on
 VAX machines with 8 MB recently. (8 MB is the lowest I could persuade simh
 to emulate, for 4 MB we will need a custom kernel anyway and for smaller
 even a custom /boot - I will cover installing on those machines in an
 upcoming improvement of the install docs).

Ok, this (much simpler) patch makes tmpfs work on low memory machines.
Comments?

Martin
Index: tmpfs.h
===
RCS file: /cvsroot/src/sys/fs/tmpfs/tmpfs.h,v
retrieving revision 1.49
diff -u -p -r1.49 tmpfs.h
--- tmpfs.h 30 Apr 2014 01:33:51 -  1.49
+++ tmpfs.h 5 Jun 2014 13:40:19 -
@@ -307,13 +307,6 @@ bool   tmpfs_strname_neqlen(struct compon
 KASSERT((node)-tn_size % sizeof(tmpfs_dirent_t) == 0);
 
 /*
- * Memory management stuff.
- */
-
-/* Amount of memory pages to reserve for the system. */
-#defineTMPFS_PAGES_RESERVED(4 * 1024 * 1024 / PAGE_SIZE)
-
-/*
  * Routines to convert VFS structures to tmpfs internal ones.
  */
 
Index: tmpfs_mem.c
===
RCS file: /cvsroot/src/sys/fs/tmpfs/tmpfs_mem.c,v
retrieving revision 1.5
diff -u -p -r1.5 tmpfs_mem.c
--- tmpfs_mem.c 30 Apr 2014 01:33:51 -  1.5
+++ tmpfs_mem.c 5 Jun 2014 13:40:19 -
@@ -89,7 +89,7 @@ tmpfs_mntmem_set(struct tmpfs_mount *mp,
  * = If 'total' is true, then return _total_ amount of pages.
  * = If false, then return the amount of _free_ memory pages.
  *
- * Remember to remove TMPFS_PAGES_RESERVED from the returned value to avoid
+ * Remember to remove uvmexp.freemin from the returned value to avoid
  * excessive memory usage.
  */
 size_t
@@ -118,10 +118,10 @@ tmpfs_bytes_max(struct tmpfs_mount *mp)
size_t freepages = tmpfs_mem_info(false);
uint64_t avail_mem;
 
-   if (freepages  TMPFS_PAGES_RESERVED) {
+   if (freepages  uvmexp.freemin) {
freepages = 0;
} else {
-   freepages -= TMPFS_PAGES_RESERVED;
+   freepages -= uvmexp.freemin;
}
avail_mem = round_page(mp-tm_bytes_used) + (freepages  PAGE_SHIFT);
return MIN(mp-tm_mem_limit, avail_mem);
Index: tmpfs_vfsops.c
===
RCS file: /cvsroot/src/sys/fs/tmpfs/tmpfs_vfsops.c,v
retrieving revision 1.61
diff -u -p -r1.61 tmpfs_vfsops.c
--- tmpfs_vfsops.c  30 Apr 2014 01:59:30 -  1.61
+++ tmpfs_vfsops.c  5 Jun 2014 13:40:19 -
@@ -132,7 +132,7 @@ tmpfs_mount(struct mount *mp, const char
 
 
/* Prohibit mounts if there is not enough memory. */
-   if (tmpfs_mem_info(true)  TMPFS_PAGES_RESERVED)
+   if (tmpfs_mem_info(true)  uvmexp.freemin)
return EINVAL;
 
/* Get the memory usage limit for this file-system. */
Index: mount_tmpfs.8
===
RCS file: /cvsroot/src/sbin/mount_tmpfs/mount_tmpfs.8,v
retrieving revision 1.17
diff -u -r1.17 mount_tmpfs.8
--- mount_tmpfs.8   4 Dec 2013 18:05:21 -   1.17
+++ mount_tmpfs.8   5 Jun 2014 13:41:09 -
@@ -83,7 +83,7 @@
 Specifies the total file system size in bytes.
 If zero is given (the default), the available amount of memory (including
 main memory and swap space) will be used.
-Note that four megabytes are always reserved for the system and cannot
+Note that some memory is always reserved for the system and cannot
 be assigned to the file system.
 .Ar Size
 can alternatively be specified as a percentage of the available


Re: Making tmpfs reserved memory configurable

2014-06-05 Thread Eduardo Horvath
On Thu, 5 Jun 2014, Martin Husemann wrote:

 On Fri, May 30, 2014 at 04:56:01PM +0200, Martin Husemann wrote:
  I have been on a quest to make the stock vax install CD (-image) usable on
  VAX machines with 8 MB recently. (8 MB is the lowest I could persuade simh
  to emulate, for 4 MB we will need a custom kernel anyway and for smaller
  even a custom /boot - I will cover installing on those machines in an
  upcoming improvement of the install docs).
 
 Ok, this (much simpler) patch makes tmpfs work on low memory machines.
 Comments?

Have you tested this?

The way the old scanner used to work, it started when the number of free 
pages hit freemin, and continued scanning until the number of free pages 
hit freetarg.

Looking at the code, it appears now the page scanner starts running when 
the number of free pages goes below uvmpd.freetarg.  I'm a bit concerned 
that if tmpfs allocates enough pages to put the system permanently below 
the uvmpd.freetarg threshold, the page scanner will never stop running.  
I'm not sure if this would be a problem or not, so it would be good to put 
a system into that condition to know for sure.

Eduardo


Re: Making tmpfs reserved memory configurable

2014-06-05 Thread Matt Thomas

On Jun 5, 2014, at 8:47 AM, Martin Husemann mar...@duskware.de wrote:

 On Thu, Jun 05, 2014 at 03:36:37PM +, Eduardo Horvath wrote:
 Have you tested this?
 
 I ran an install on a 8 MB simh VAX, and it worked good enough for that.
 No, I wouldn't call that serious testing.

can you try using freetarg?


Re: Making tmpfs reserved memory configurable

2014-06-05 Thread Martin Husemann
On Thu, Jun 05, 2014 at 03:36:37PM +, Eduardo Horvath wrote:
 Have you tested this?

I ran an install on a 8 MB simh VAX, and it worked good enough for that.
No, I wouldn't call that serious testing.

Martin


Re: Making tmpfs reserved memory configurable

2014-06-05 Thread Martin Husemann
On Thu, Jun 05, 2014 at 08:50:07AM -0700, Matt Thomas wrote:
 
 can you try using freetarg?

Did that and it worked as well.

Does freetarg ever change after boot?

Martin


Re: Making tmpfs reserved memory configurable

2014-06-05 Thread Eduardo Horvath
On Thu, 5 Jun 2014, Martin Husemann wrote:

 On Thu, Jun 05, 2014 at 08:50:07AM -0700, Matt Thomas wrote:
  
  can you try using freetarg?
 
 Did that and it worked as well.
 
 Does freetarg ever change after boot?

Maybe.  It's set in uvmpd_tune(), which may be called by the page daemon 
in some circumstances.  Take a look at sys/uvm/uvm_pdaemon.c.

Eduardo


Re: Making tmpfs reserved memory configurable

2014-05-30 Thread Rhialto
On Fri 30 May 2014 at 16:56:01 +0200, Martin Husemann wrote:
 One open issue is the name - I somehow thought reservee would be a proper
 noune for reserved memory, but apparently this does not work out well
 for native speakers, so it probably should be named something else.
 What about min_ram_free? Other suggestions?

I'm not a native speaker either, but it seems reserve (one fewer e)
would be good.

 --- sbin/mount_tmpfs/mount_tmpfs.84 Dec 2013 18:05:21 -   1.17
 +++ sbin/mount_tmpfs/mount_tmpfs.830 May 2014 13:42:46 -
 @@ -83,8 +83,12 @@
  Specifies the total file system size in bytes.
  If zero is given (the default), the available amount of memory (including
  main memory and swap space) will be used.
 -Note that four megabytes are always reserved for the system and cannot
 +Note that some memory (by default:
 +four megabytes) are always reserved for the system and cannot
  be assigned to the file system.

some memory (...) are - some memory is.

I'd split the lines as

| Note that some memory
| (by default: four megabytes)
| is always reserved for the system and cannot

-Olaf.
-- 
___ Olaf 'Rhialto' Seibert  -- The Doctor: No, 'eureka' is Greek for
\X/ rhialto/at/xs4all.nl-- 'this bath is too hot.'


pgprxAEQkY7q7.pgp
Description: PGP signature


Re: Making tmpfs reserved memory configurable

2014-05-30 Thread Eduardo Horvath
On Fri, 30 May 2014, Martin Husemann wrote:

 See mount_tmpfs(8), in the paragraph about the -s option:
 
Note that four megabytes are always reserved for the system and cannot
be assigned to the file system.
 
 Now, with a 3.2 MB text GENERIC kernel and 8 MB RAM, we certainly don't have
 4 MB available at all - so tmpfs is not usable.

This just doesn't sound right.  Why is tmpfs reserving a fixed amount of 
RAM?  Shouldn't it be using uvmexp.freemin?  That's basically what we're 
reserving for emergencies.

RAM scaling is always a pain in the posterior.  The choices made for a 
system with 16MB RAM don't make sense for a system with 16GB RAM, and visa 
versa.

Eduardo


Re: Making tmpfs reserved memory configurable

2014-05-30 Thread Mindaugas Rasiukevicius
Martin Husemann mar...@duskware.de wrote:
 ...
 
 See mount_tmpfs(8), in the paragraph about the -s option:
 
Note that four megabytes are always reserved for the system and cannot
be assigned to the file system.
 

This wording may be confusing.  tmpfs does not reserve the memory in a
sense of allocation.  It imposes a hard limit and, in addition, it checks
that there is at least 4MB left for the system (if not, it considers that
as hitting the limit and fails to allocate more memory).  Note that the
current mechanism of using the floating number of free memory is wrong.
It is not reliable and should not really be done that way.

The UVM itself has some reserved memory so that it could function if the
memory is exhausted (see reserve_pagedaemon and reserve_kernel in uvmexp).
I think that the assumptions about minimum memory requirements should be
made by UVM and if we want to keep a helper mechanism in tmpfs, then I
agree with Eduardo that it should rather be using uvmexp.freemin target.

-- 
Mindaugas