[Patch] encapsulate shmem access to shmem_inode_info
Hi, On 24 Apr 2001, Christoph Rohland wrote: > Hi Al, > > On Tue, 24 Apr 2001, Alexander Viro wrote: >> So yes, IMO having such patches available _is_ a good thing. And in >> 2.5 we definitely want them in the tree. If encapsulation part gets >> there during 2.4 and separate allocation is available for all of >> them it will be easier to do without PITA in process. > > OK I will do that for tmpfs soon. And I will do the symlink inlining > with that patch. Here comes the patch to encapsulate all accesses to struct shmem_inode_info into a macro. It is now trivial to allocate the private part independently from the inode. Greetings Christoph P.S: The symlink inlining will come in a separate patch 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 = page->mapping->host; - info = >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 = >u.shmem_i; + info = SHMEM_I(inode); down (>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(>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 = >u.shmem_i; + struct
[Patch] encapsulate shmem access to shmem_inode_info
Hi, On 24 Apr 2001, Christoph Rohland wrote: Hi Al, On Tue, 24 Apr 2001, Alexander Viro wrote: So yes, IMO having such patches available _is_ a good thing. And in 2.5 we definitely want them in the tree. If encapsulation part gets there during 2.4 and separate allocation is available for all of them it will be easier to do without PITA in process. OK I will do that for tmpfs soon. And I will do the symlink inlining with that patch. Here comes the patch to encapsulate all accesses to struct shmem_inode_info into a macro. It is now trivial to allocate the private part independently from the inode. Greetings Christoph P.S: The symlink inlining will come in a separate patch 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 @@ 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 *