Assorted tmpfs fixes

2001-05-15 Thread Christoph Rohland

Hi Alan,

would you mind to apply the accumulated tmpfs fixes to the -ac series?

Here the short descriptions:

2-SHMEM_I: 
Encapsulate all accesses to the private info structure with
macro. This was suggested by Al to later get rid of the
union in the inode struct. This is pretty straightforward
search and replace.
3-inline_symlink: 
For symlinks smaller than the private keep the
symlink directly there. This saves 4k per normal
symlink. This is a new feature which is quite simple.
4-accounting: 
This patch introduces accounting for in memory
tmpfs pages and modifies meminfo to subtract these pages from
the cached pages since they are not really cached. This makes
tuning memory requirement much easier and confuses less people.
5-accounting_shared:
Export the tmpfs memory count into the /shared/ field of
meminfo. This change does reuse the now unused field to get
some sensible data to the user. It is somewhat questionable
since it changes the semantics of the field against pre
2.4. But many people expect exactly this number here
6-accounting_uml:
The previous patch for uml
7-triple2:
redo the swap entry handling to do triple indirect
blocks. This is needed for s390x which has 4k page size and 64
bit. This limits tmpfs files and shm segments to ~1GB without
the patch.

I would really like to get this tested first in -ac before feeding
this to Linus.

Greetings
Christoph



diff -uNr 2.4.4-mmap_write/include/linux/shmem_fs.h 
2.4.4-mmap_write-SHMEM_I/include/linux/shmem_fs.h
--- 2.4.4-mmap_write/include/linux/shmem_fs.h   Tue May  1 20:02:00 2001
+++ 2.4.4-mmap_write-SHMEM_I/include/linux/shmem_fs.h   Tue May  1 20:06:10 2001
@@ -18,14 +18,15 @@
 } swp_entry_t;
 
 struct shmem_inode_info {
-   spinlock_t  lock;
-   struct semaphore sem;
-   unsigned long   max_index;
-   swp_entry_t i_direct[SHMEM_NR_DIRECT]; /* for the first blocks */
-   swp_entry_t   **i_indirect; /* doubly indirect blocks */
-   unsigned long   swapped;
-   int locked; /* into memory */
+   spinlock_t  lock;
+   struct semaphoresem;
+   unsigned long   max_index;
+   swp_entry_t i_direct[SHMEM_NR_DIRECT]; /* for the first blocks */
+   swp_entry_t   **i_indirect; /* doubly indirect blocks */
+   unsigned long   swapped;
+   int locked; /* into memory */
struct list_headlist;
+   struct inode   *inode;
 };
 
 struct shmem_sb_info {
@@ -35,5 +36,7 @@
unsigned long free_inodes;  /* How many are left for allocation */
spinlock_tstat_lock;
 };
+
+#define SHMEM_I(inode)  (>u.shmem_i)
 
 #endif
diff -uNr 2.4.4-mmap_write/ipc/shm.c 2.4.4-mmap_write-SHMEM_I/ipc/shm.c
--- 2.4.4-mmap_write/ipc/shm.c  Wed Apr 11 12:36:47 2001
+++ 2.4.4-mmap_write-SHMEM_I/ipc/shm.c  Tue May  1 20:06:10 2001
@@ -348,6 +348,7 @@
 
 static void shm_get_stat (unsigned long *rss, unsigned long *swp) 
 {
+   struct shmem_inode_info *info;
int i;
 
*rss = 0;
@@ -361,10 +362,11 @@
if(shp == NULL)
continue;
inode = shp->shm_file->f_dentry->d_inode;
-   spin_lock (>u.shmem_i.lock);
+   info = SHMEM_I(inode);
+   spin_lock (>lock);
*rss += inode->i_mapping->nrpages;
-   *swp += inode->u.shmem_i.swapped;
-   spin_unlock (>u.shmem_i.lock);
+   *swp += info->swapped;
+   spin_unlock (>lock);
}
 }
 
diff -uNr 2.4.4-mmap_write/mm/shmem.c 2.4.4-mmap_write-SHMEM_I/mm/shmem.c
--- 2.4.4-mmap_write/mm/shmem.c Tue May  1 20:02:00 2001
+++ 2.4.4-mmap_write-SHMEM_I/mm/shmem.c Wed May  2 16:46:00 2001
@@ -73,7 +73,7 @@
unsigned long freed;
 
freed = (inode->i_blocks/BLOCKS_PER_PAGE) -
-   (inode->i_mapping->nrpages + inode->u.shmem_i.swapped);
+   (inode->i_mapping->nrpages + SHMEM_I(inode)->swapped);
if (freed){
struct shmem_sb_info * info = >i_sb->u.shmem_sb;
inode->i_blocks -= freed*BLOCKS_PER_PAGE;
@@ -159,7 +159,7 @@
unsigned long index, start;
unsigned long freed = 0;
swp_entry_t **base, **ptr, **last;
-   struct shmem_inode_info * info = >u.shmem_i;
+   struct shmem_inode_info * info = SHMEM_I(inode);
 
down(>sem);
inode->i_ctime = inode->i_mtime = CURRENT_TIME;
@@ -206,7 +206,7 @@
struct shmem_sb_info *info = >i_sb->u.shmem_sb;
 
spin_lock (_ilock);
-   list_del (>u.shmem_i.list);
+   list_del (_I(inode)->list);
spin_unlock (_ilock);
inode->i_size = 0;
shmem_truncate (inode);
@@ -239,7 +239,7 @@
goto out;

inode = 

Assorted tmpfs fixes

2001-05-15 Thread Christoph Rohland

Hi Alan,

would you mind to apply the accumulated tmpfs fixes to the -ac series?

Here the short descriptions:

2-SHMEM_I: 
Encapsulate all accesses to the private info structure with
macro. This was suggested by Al to later get rid of the
union in the inode struct. This is pretty straightforward
search and replace.
3-inline_symlink: 
For symlinks smaller than the private keep the
symlink directly there. This saves 4k per normal
symlink. This is a new feature which is quite simple.
4-accounting: 
This patch introduces accounting for in memory
tmpfs pages and modifies meminfo to subtract these pages from
the cached pages since they are not really cached. This makes
tuning memory requirement much easier and confuses less people.
5-accounting_shared:
Export the tmpfs memory count into the /shared/ field of
meminfo. This change does reuse the now unused field to get
some sensible data to the user. It is somewhat questionable
since it changes the semantics of the field against pre
2.4. But many people expect exactly this number here
6-accounting_uml:
The previous patch for uml
7-triple2:
redo the swap entry handling to do triple indirect
blocks. This is needed for s390x which has 4k page size and 64
bit. This limits tmpfs files and shm segments to ~1GB without
the patch.

I would really like to get this tested first in -ac before feeding
this to Linus.

Greetings
Christoph



diff -uNr 2.4.4-mmap_write/include/linux/shmem_fs.h 
2.4.4-mmap_write-SHMEM_I/include/linux/shmem_fs.h
--- 2.4.4-mmap_write/include/linux/shmem_fs.h   Tue May  1 20:02:00 2001
+++ 2.4.4-mmap_write-SHMEM_I/include/linux/shmem_fs.h   Tue May  1 20:06:10 2001
@@ -18,14 +18,15 @@
 } swp_entry_t;
 
 struct shmem_inode_info {
-   spinlock_t  lock;
-   struct semaphore sem;
-   unsigned long   max_index;
-   swp_entry_t i_direct[SHMEM_NR_DIRECT]; /* for the first blocks */
-   swp_entry_t   **i_indirect; /* doubly indirect blocks */
-   unsigned long   swapped;
-   int locked; /* into memory */
+   spinlock_t  lock;
+   struct semaphoresem;
+   unsigned long   max_index;
+   swp_entry_t i_direct[SHMEM_NR_DIRECT]; /* for the first blocks */
+   swp_entry_t   **i_indirect; /* doubly indirect blocks */
+   unsigned long   swapped;
+   int locked; /* into memory */
struct list_headlist;
+   struct inode   *inode;
 };
 
 struct shmem_sb_info {
@@ -35,5 +36,7 @@
unsigned long free_inodes;  /* How many are left for allocation */
spinlock_tstat_lock;
 };
+
+#define SHMEM_I(inode)  (inode-u.shmem_i)
 
 #endif
diff -uNr 2.4.4-mmap_write/ipc/shm.c 2.4.4-mmap_write-SHMEM_I/ipc/shm.c
--- 2.4.4-mmap_write/ipc/shm.c  Wed Apr 11 12:36:47 2001
+++ 2.4.4-mmap_write-SHMEM_I/ipc/shm.c  Tue May  1 20:06:10 2001
@@ -348,6 +348,7 @@
 
 static void shm_get_stat (unsigned long *rss, unsigned long *swp) 
 {
+   struct shmem_inode_info *info;
int i;
 
*rss = 0;
@@ -361,10 +362,11 @@
if(shp == NULL)
continue;
inode = shp-shm_file-f_dentry-d_inode;
-   spin_lock (inode-u.shmem_i.lock);
+   info = SHMEM_I(inode);
+   spin_lock (info-lock);
*rss += inode-i_mapping-nrpages;
-   *swp += inode-u.shmem_i.swapped;
-   spin_unlock (inode-u.shmem_i.lock);
+   *swp += info-swapped;
+   spin_unlock (info-lock);
}
 }
 
diff -uNr 2.4.4-mmap_write/mm/shmem.c 2.4.4-mmap_write-SHMEM_I/mm/shmem.c
--- 2.4.4-mmap_write/mm/shmem.c Tue May  1 20:02:00 2001
+++ 2.4.4-mmap_write-SHMEM_I/mm/shmem.c Wed May  2 16:46:00 2001
@@ -73,7 +73,7 @@
unsigned long freed;
 
freed = (inode-i_blocks/BLOCKS_PER_PAGE) -
-   (inode-i_mapping-nrpages + inode-u.shmem_i.swapped);
+   (inode-i_mapping-nrpages + SHMEM_I(inode)-swapped);
if (freed){
struct shmem_sb_info * info = inode-i_sb-u.shmem_sb;
inode-i_blocks -= freed*BLOCKS_PER_PAGE;
@@ -159,7 +159,7 @@
unsigned long index, start;
unsigned long freed = 0;
swp_entry_t **base, **ptr, **last;
-   struct shmem_inode_info * info = inode-u.shmem_i;
+   struct shmem_inode_info * info = SHMEM_I(inode);
 
down(info-sem);
inode-i_ctime = inode-i_mtime = CURRENT_TIME;
@@ -206,7 +206,7 @@
struct shmem_sb_info *info = inode-i_sb-u.shmem_sb;
 
spin_lock (shmem_ilock);
-   list_del (inode-u.shmem_i.list);
+   list_del (SHMEM_I(inode)-list);
spin_unlock (shmem_ilock);
inode-i_size = 0;
shmem_truncate (inode);
@@ -239,7 +239,7 @@