Assorted tmpfs fixes
Subsystems (14)
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
include/linux/shmem_fs.h +10 -7
@@ -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 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 */ struct list_head list; +struct inode *inode; };struct shmem_sb_info {
@@ -35,5 +36,7 @@unsigned long free_inodes;/* How many are left for allocation */ spinlock_t stat_lock; }; + +#define SHMEM_I (inode) (&inode->u.shmem_i)#endif
ipc/shm.c +5 -3
@@ -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); } }
mm/shmem.c +19 -19
@@ -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 @@ goto out; inode = page->mapping->host; - info = &inode->u.shmem_i; + info =SHMEM_I (inode); swap =__get_swap_page (2 ); error = -ENOMEM ;if (!swap.val)
@@ -407,7 +407,7 @@page_cache_release (*ptr); } - info = &inode->u.shmem_i; + info =SHMEM_I (inode);down (&info->sem);/* retest we may have slept */
@@ -415,7 +415,7 @@if (inode->i_size < (loff_t ) idx *PAGE_CACHE_SIZE ) goto failed; - *ptr =shmem_getpage_locked (&inode->u.shmem_i, inode, idx); + *ptr =shmem_getpage_locked (info, inode, idx);if (IS_ERR (*ptr)) goto failed;
@@ -462,7 +462,7 @@void shmem_lock (struct file * file,int lock) {struct inode * inode = file->f_dentry->d_inode; -struct shmem_inode_info * info = &inode->u.shmem_i; +struct shmem_inode_info * info =SHMEM_I (inode);struct page * page;unsigned long idx, size;
@@ -521,7 +521,8 @@ inode->i_rdev =to_kdev_t (dev); inode->i_mapping->a_ops = &shmem_aops; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ; - info = &inode->u.shmem_i; + info =SHMEM_I (inode); + info->inode = inode;spin_lock_init (&info->lock);sema_init (&info->sem,1 );switch (mode &S_IFMT ) {
@@ -542,7 +543,7 @@break ; }spin_lock (&shmem_ilock); -list_add (&inode->u.shmem_i.list, &shmem_inodes); +list_add (&SHMEM_I (inode)->list, &shmem_inodes);spin_unlock (&shmem_ilock); }return inode;
@@ -629,7 +630,7 @@__get_user (dummy, buf+bytes-1 ); } - info = &inode->u.shmem_i; + info =SHMEM_I (inode);down (&info->sem); page =shmem_getpage_locked (info, inode, index);up (&info->sem);
@@ -658,8 +659,8 @@ buf += bytes;if (pos > inode->i_size) inode->i_size = pos; -if (inode->u.shmem_i.max_index <= index) - inode->u.shmem_i.max_index = index+1 ; +if (info->max_index <= index) + info->max_index = index+1 ; } unlock:
@@ -940,7 +941,7 @@ inode = dentry->d_inode;down (&inode->i_sem); - page =shmem_getpage_locked (&inode->u.shmem_i, inode,0 ); + page =shmem_getpage_locked (SHMEM_I (inode), inode,0 );if (IS_ERR (page)) goto fail; kaddr =kmap (page);
@@ -1220,12 +1221,11 @@return -1 ; } -static int shmem_unuse_inode (struct inode *inode,swp_entry_t entry,struct page *page) +static int shmem_unuse_inode (struct shmem_inode_info *info,swp_entry_t entry,struct page *page) {swp_entry_t **base, **ptr;unsigned long idx;int offset; -struct shmem_inode_info *info = &inode->u.shmem_i; idx =0 ;spin_lock (&info->lock);
@@ -1246,7 +1246,7 @@spin_unlock (&info->lock);return 0 ; found: -add_to_page_cache (page, inode->i_mapping, offset + idx); +add_to_page_cache (page, info->inode->i_mapping, offset + idx);set_page_dirty (page);SetPageUptodate (page);UnlockPage (page);
@@ -1261,13 +1261,13 @@void shmem_unuse (swp_entry_t entry,struct page *page) {struct list_head *p; -struct inode * inode; +struct shmem_inode_info * info;spin_lock (&shmem_ilock);list_for_each (p, &shmem_inodes) { - inode = list_entry(p, struct inode, u.shmem_i.list); + info = list_entry(p, struct shmem_inode_info, list); -if (shmem_unuse_inode (inode, entry, page)) +if (shmem_unuse_inode (info, entry, page))break ; }spin_unlock (&shmem_ilock);
mm/shmem.c +61 -33
155 lines not on this page · raw message
fs/proc/proc_misc.c +14 -3
@@ -140,6 +140,17 @@ {struct sysinfo i;int len; +unsigned int cached, shmem; + +/* +* There may be some inconsistency because shmem_nrpages +* update is delayed to page_cache_size +* We make sure the cached value does not get below zero +*/ + cached =atomic_read (&page_cache_size); + shmem =atomic_read (&shmem_nrpages); +if (shmem < cached) + cached -= shmem;/* * display in kilobytes.
@@ -153,8 +164,8 @@"Swap: %8lu %8lu %8lu\n" ,B (i.totalram),B (i.totalram-i.freeram),B (i.freeram),B (i.sharedram),B (i.bufferram), -B (atomic_read (&page_cache_size)),B (i.totalswap), - B(i.totalswap-i.freeswap), B(i.freeswap)); +B (cached),B (i.totalswap), + B(i.totalswap-i.freeswap), B(i.freeswap));/* * Tagged format, for easy grepping and expansion. * The above will go away eventually, once the tools
@@ -180,7 +191,7 @@K (i.freeram),K (i.sharedram),K (i.bufferram), -K (atomic_read (&page_cache_size)), +K (cached),K (nr_active_pages),K (nr_inactive_dirty_pages), K(nr_inactive_clean_pages()),
include/linux/shmem_fs.h +2 -0
@@ -17,6 +17,8 @@unsigned long val; } swp_entry_t; +extern atomic_t shmem_nrpages; +struct shmem_inode_info {spinlock_t lock;struct semaphore sem;
mm/mmap.c +13 -2
@@ -55,13 +55,24 @@*/ long free; - +unsigned long cached, shmem; + +/* +* There may be some inconsistency because shmem_nrpages +* update is delayed to the page_cache_size +* We make sure the cached value does not get below zero +*/ + cached =atomic_read (&page_cache_size); + shmem =atomic_read (&shmem_nrpages); +if (cached > shmem) + cached -= shmem; +/* Sometimes we want to use more memory than we have. */ if (sysctl_overcommit_memory)return 1 ; free =atomic_read (&buffermem_pages); - free +=atomic_read (&page_cache_size); + free += cached; free +=nr_free_pages (); free += nr_swap_pages;
mm/shmem.c +15 -6
@@ -3,7 +3,8 @@* * Copyright (C) 2000 Linus Torvalds. * 2000 Transmeta Corp. -* 2000 Christoph Rohland +* 2000-2001 Christoph Rohland +* 2000-2001 SAP AG * * This file is released under the GPL. */
@@ -45,6 +46,7 @@LIST_HEAD (shmem_inodes);static spinlock_t shmem_ilock =SPIN_LOCK_UNLOCKED ; +atomic_t shmem_nrpages =ATOMIC_INIT (0 );#define BLOCKS_PER_PAGE (PAGE_SIZE/512)
@@ -52,6 +54,7 @@* shmem_recalc_inode - recalculate the size of an inode * * @inode: inode to recalc +* @swap: additional swap pages freed externally * * We have to calculate the free blocks since the mm can drop pages * behind our back
@@ -62,12 +65,14 @@* * So the mm freed * inodes->i_blocks/BLOCKS_PER_PAGE - -* (inode->i_mapping->nrpages + info->swapped) +* (inode->i_mapping->nrpages + info->swapped) * * It has to be called with the spinlock held. +* +* The swap parameter is a performance hack for truncate. */ -static void shmem_recalc_inode (struct inode * inode) +static void shmem_recalc_inode (struct inode * inode,unsigned long swap) {unsigned long freed;
@@ -79,6 +84,7 @@spin_lock (&info->stat_lock); info->free_blocks += freed;spin_unlock (&info->stat_lock); +atomic_sub (freed-swap, &shmem_nrpages); } }
@@ -195,7 +201,7 @@ out: info->max_index = index; info->swapped -= freed; -shmem_recalc_inode (inode); +shmem_recalc_inode (inode, freed);spin_unlock (&info->lock);up (&info->sem); }
@@ -250,14 +256,15 @@ entry =shmem_swp_entry (info, page->index);if (IS_ERR (entry))/* this had been allocted on page allocation */ BUG (); -shmem_recalc_inode (page->mapping->host); +shmem_recalc_inode (page->mapping->host,0 ); error = -EAGAIN ;if (entry->val)BUG (); *entry = swap; error =0 ; -/* Remove the from the page cache */ +/* Remove the page from the page cache */ +atomic_dec (&shmem_nrpages);lru_cache_del (page);remove_inode_page (page);
@@ -376,6 +383,7 @@ }/* We have the page */ +atomic_inc (&shmem_nrpages);SetPageUptodate (page);if (info->locked)page_cache_get (page);
@@ -1275,6 +1283,7 @@return 0 ; found:add_to_page_cache (page, info->inode->i_mapping, offset + idx); +atomic_inc (&shmem_nrpages);set_page_dirty (page);SetPageUptodate (page);UnlockPage (page);
arch/alpha/mm/init.c +1 -1
@@ -402,7 +402,7 @@ si_meminfo(struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh =0 ;
arch/arm/mm/init.c +1 -1
@@ -647,7 +647,7 @@void si_meminfo (struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh =0 ;
arch/cris/mm/init.c +1 -1
@@ -503,7 +503,7 @@ i = max_mapnr; val->totalram =0 ; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages);while (i-- >0 ) {
arch/i386/mm/init.c +1 -1
@@ -570,7 +570,7 @@void si_meminfo (struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh = totalhigh_pages;
arch/ia64/mm/init.c +1 -1
@@ -151,7 +151,7 @@ si_meminfo (struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh =0 ;
arch/m68k/mm/init.c +1 -1
@@ -217,7 +217,7 @@ i = max_mapnr; val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages);while (i-- >0 ) {
arch/mips/mm/init.c +1 -1
@@ -343,7 +343,7 @@void si_meminfo (struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh =0 ;
arch/mips64/mm/init.c +1 -1
@@ -411,7 +411,7 @@ si_meminfo(struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh =0 ;
arch/parisc/mm/init.c +1 -1
@@ -458,7 +458,7 @@ i = max_mapnr; val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages);#if 0
arch/ppc/mm/init.c +1 -1
@@ -336,7 +336,7 @@ i = max_mapnr; val->totalram =0 ; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages);while (i-- >0 ) {
arch/s390/mm/init.c +1 -1
@@ -271,7 +271,7 @@void si_meminfo (struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh =0 ;
arch/s390x/mm/init.c +1 -1
@@ -284,7 +284,7 @@void si_meminfo (struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh =0 ;
arch/sh/mm/init.c +1 -1
@@ -215,7 +215,7 @@void si_meminfo (struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh = totalhigh_pages;
arch/sparc/mm/init.c +1 -1
@@ -534,7 +534,7 @@void si_meminfo (struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh = totalhigh_pages;
arch/sparc64/mm/init.c +1 -1
@@ -1512,7 +1512,7 @@void si_meminfo (struct sysinfo *val) { val->totalram = num_physpages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages);
arch/um/kernel/mem.c +1 -1
@@ -77,7 +77,7 @@void si_meminfo (struct sysinfo *val) { val->totalram = totalram_pages; - val->sharedram =0 ; + val->sharedram =atomic_read (&shmem_nrpages); val->freeram =nr_free_pages (); val->bufferram =atomic_read (&buffermem_pages); val->totalhigh =0 ;
include/linux/shmem_fs.h +2 -2
@@ -22,9 +22,9 @@struct shmem_inode_info {spinlock_t lock;struct semaphore sem; -unsigned long max_index; +unsigned long next_index;swp_entry_t i_direct[SHMEM_NR_DIRECT ];/* for the first blocks */ -swp_entry_t **i_indirect;/* doubly indirect blocks */ +void **i_indirect;/* indirect blocks */ unsigned long swapped;int locked;/* into memory */ struct list_head list;
mm/shmem.c +201 -78
380 lines not on this page · raw message