diff options
| author | Christoph Hellwig <hch@lst.de> | 2002-11-02 18:45:55 -0800 |
|---|---|---|
| committer | Christoph Hellwig <hch@lst.de> | 2002-11-02 18:45:55 -0800 |
| commit | abcb2f165501ff80e738748a29625b71fe7e6293 (patch) | |
| tree | 7f26059a9f2aee3a151a312a3af55610373039f3 | |
| parent | 0a541971fe1821ee8659ec0f8496d1fd2e9fec84 (diff) | |
[PATCH] make swap code conditional
Make the swap code conditional on CONFIG_SWAP. This is mostly for
uClinux, but !CONFIG_SWAP compiles and boots fine for i386, too -
the only problem I've seen is that X doesn't starts, it's probably
shm-related, thus it's disabled unconditionally for "normal" arches.
The patch makes three files in mm/ conditional on CONFIG_SWAP, reorganzies
include/linux/swap.h big time to provide stubs for the !CONFIG_SWAP case,
moves the remaining /proc/swaps code to swapfile.c and cleans up some
more MM code to compile fine without CONFIG_SWAP
| -rw-r--r-- | fs/proc/proc_misc.c | 14 | ||||
| -rw-r--r-- | include/linux/mm.h | 3 | ||||
| -rw-r--r-- | include/linux/page-flags.h | 4 | ||||
| -rw-r--r-- | include/linux/swap.h | 141 | ||||
| -rw-r--r-- | kernel/sys.c | 2 | ||||
| -rw-r--r-- | mm/Makefile | 11 | ||||
| -rw-r--r-- | mm/mmap.c | 2 | ||||
| -rw-r--r-- | mm/swapfile.c | 26 | ||||
| -rw-r--r-- | mm/vmscan.c | 15 |
9 files changed, 133 insertions, 85 deletions
diff --git a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c index 7ab0958a7bd6..8b6f9370d187 100644 --- a/fs/proc/proc_misc.c +++ b/fs/proc/proc_misc.c @@ -62,7 +62,6 @@ extern int get_filesystem_list(char *); extern int get_exec_domain_list(char *); extern int get_dma_list(char *); extern int get_locks_status (char *, char **, off_t, int); -extern int get_swaparea_info (char *); #ifdef CONFIG_SGI_DS1286 extern int get_ds1286_status(char *); #endif @@ -296,18 +295,6 @@ static struct file_operations proc_partitions_operations = { .release = seq_release, }; -extern struct seq_operations swaps_op; -static int swaps_open(struct inode *inode, struct file *file) -{ - return seq_open(file, &swaps_op); -} -static struct file_operations proc_swaps_operations = { - .open = swaps_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, -}; - #ifdef CONFIG_MODULES extern struct seq_operations modules_op; static int modules_open(struct inode *inode, struct file *file) @@ -641,7 +628,6 @@ void __init proc_misc_init(void) entry->proc_fops = &proc_kmsg_operations; create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations); create_seq_entry("partitions", 0, &proc_partitions_operations); - create_seq_entry("swaps", 0, &proc_swaps_operations); #if !defined(CONFIG_ARCH_S390) create_seq_entry("interrupts", 0, &proc_interrupts_operations); #endif diff --git a/include/linux/mm.h b/include/linux/mm.h index 961892ae2842..bef259292073 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -444,9 +444,6 @@ extern void si_meminfo_node(struct sysinfo *val, int nid); #endif extern void swapin_readahead(swp_entry_t); -extern int can_share_swap_page(struct page *); -extern int remove_exclusive_swap_page(struct page *); - /* mmap.c */ extern void insert_vm_struct(struct mm_struct *, struct vm_area_struct *); extern void build_mmap_rb(struct mm_struct *); diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 9b3496e2aac5..44480d80952f 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -237,8 +237,12 @@ extern void get_full_page_state(struct page_state *ret); * The PageSwapCache predicate doesn't use a PG_flag at this time, * but it may again do so one day. */ +#ifdef CONFIG_SWAP extern struct address_space swapper_space; #define PageSwapCache(page) ((page)->mapping == &swapper_space) +#else +#define PageSwapCache(page) 0 +#endif struct page; /* forward declaration */ diff --git a/include/linux/swap.h b/include/linux/swap.h index 421e6a327fa2..8ad50c284b45 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -1,11 +1,13 @@ #ifndef _LINUX_SWAP_H #define _LINUX_SWAP_H +#include <linux/config.h> #include <linux/spinlock.h> #include <linux/kdev_t.h> #include <linux/linkage.h> #include <linux/mmzone.h> #include <linux/list.h> +#include <asm/atomic.h> #include <asm/page.h> #define SWAP_FLAG_PREFER 0x8000 /* set if swap priority specified */ @@ -36,13 +38,11 @@ * bootbits... */ union swap_header { - struct - { + struct { char reserved[PAGE_SIZE - 10]; char magic[10]; /* SWAP-SPACE or SWAPSPACE2 */ } magic; - struct - { + struct { char bootbits[1024]; /* Space for disklabel etc. */ unsigned int version; unsigned int last_page; @@ -62,6 +62,10 @@ typedef struct { #ifdef __KERNEL__ +struct sysinfo; +struct address_space; +struct zone; + /* * A swap extent maps a range of a swapfile's PAGE_SIZE pages onto a range of * disk blocks. A list of swap extents maps the entire swapfile. (Where the @@ -84,8 +88,6 @@ struct swap_extent { #define MAX_SWAP_BADPAGES \ ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int)) -#include <asm/atomic.h> - enum { SWP_USED = (1 << 0), /* is slot in swap_info[] used? */ SWP_WRITEOK = (1 << 1), /* ok to write to this swap? */ @@ -122,27 +124,40 @@ struct swap_info_struct { int next; /* next entry on swap list */ }; -struct inode; -extern int nr_swap_pages; +struct swap_list_t { + int head; /* head of priority-ordered swapfile list */ + int next; /* swapfile to be used next */ +}; /* Swap 50% full? Release swapcache more aggressively.. */ #define vm_swap_full() (nr_swap_pages*2 < total_swap_pages) +/* linux/mm/page_alloc.c */ extern unsigned long totalram_pages; extern unsigned long totalhigh_pages; +extern int nr_swap_pages; /* XXX: shouldn't this be ulong? --hch */ extern unsigned int nr_free_pages(void); -#ifdef CONFIG_NUMA extern unsigned int nr_free_pages_pgdat(pg_data_t *pgdat); -#endif extern unsigned int nr_free_buffer_pages(void); extern unsigned int nr_free_pagecache_pages(void); -/* Incomplete types for prototype declarations: */ -struct task_struct; -struct vm_area_struct; -struct sysinfo; -struct address_space; -struct zone; +/* linux/mm/filemap.c */ +extern void FASTCALL(mark_page_accessed(struct page *)); + +/* linux/mm/swap.c */ +extern void FASTCALL(lru_cache_add(struct page *)); +extern void FASTCALL(lru_cache_add_active(struct page *)); +extern void FASTCALL(activate_page(struct page *)); +extern void lru_add_drain(void); +extern void swap_setup(void); + +/* linux/mm/vmscan.c */ +extern int try_to_free_pages(struct zone *, unsigned int, unsigned int); +extern int shrink_all_memory(int); +extern int vm_swappiness; + +/* linux/mm/oom_kill.c */ +extern void out_of_memory(void); /* linux/mm/rmap.c */ extern int FASTCALL(page_referenced(struct page *)); @@ -157,43 +172,31 @@ extern int FASTCALL(page_over_rsslimit(struct page *)); #define SWAP_FAIL 2 #define SWAP_ERROR 3 -/* linux/mm/swap.c */ -extern void FASTCALL(lru_cache_add(struct page *)); -extern void FASTCALL(lru_cache_add_active(struct page *)); -extern void FASTCALL(activate_page(struct page *)); -void lru_add_drain(void); - -extern void swap_setup(void); - -/* linux/mm/vmscan.c */ -extern int try_to_free_pages(struct zone *, unsigned int, unsigned int); -int shrink_all_memory(int nr_pages); -extern int vm_swappiness; +/* linux/mm/shmem.c */ +extern int shmem_unuse(swp_entry_t entry, struct page *page); +#ifdef CONFIG_SWAP /* linux/mm/page_io.c */ -int swap_readpage(struct file *file, struct page *page); -int swap_writepage(struct page *page); -int rw_swap_page_sync(int rw, swp_entry_t entry, struct page *page); - -/* linux/mm/page_alloc.c */ +extern int swap_readpage(struct file *, struct page *); +extern int swap_writepage(struct page *); +extern int rw_swap_page_sync(int, swp_entry_t, struct page *); /* linux/mm/swap_state.c */ +extern struct address_space swapper_space; +#define total_swapcache_pages swapper_space.nrpages extern void show_swap_cache_info(void); extern int add_to_swap_cache(struct page *, swp_entry_t); extern int add_to_swap(struct page *); -extern void __delete_from_swap_cache(struct page *page); -extern void delete_from_swap_cache(struct page *page); -extern int move_to_swap_cache(struct page *page, swp_entry_t entry); -extern int move_from_swap_cache(struct page *page, unsigned long index, - struct address_space *mapping); -extern void free_page_and_swap_cache(struct page *page); -extern void free_pages_and_swap_cache(struct page **pages, int nr); +extern void __delete_from_swap_cache(struct page *); +extern void delete_from_swap_cache(struct page *); +extern int move_to_swap_cache(struct page *, swp_entry_t); +extern int move_from_swap_cache(struct page *, unsigned long, + struct address_space *); +extern void free_page_and_swap_cache(struct page *); +extern void free_pages_and_swap_cache(struct page **, int); extern struct page * lookup_swap_cache(swp_entry_t); extern struct page * read_swap_cache_async(swp_entry_t); -/* linux/mm/oom_kill.c */ -extern void out_of_memory(void); - /* linux/mm/swapfile.c */ extern int total_swap_pages; extern unsigned int nr_swapfiles; @@ -204,19 +207,12 @@ extern int swap_duplicate(swp_entry_t); extern int valid_swaphandles(swp_entry_t, unsigned long *); extern void swap_free(swp_entry_t); extern void free_swap_and_cache(swp_entry_t); -sector_t map_swap_page(struct swap_info_struct *p, pgoff_t offset); -struct swap_info_struct *get_swap_info_struct(unsigned type); +extern sector_t map_swap_page(struct swap_info_struct *, pgoff_t); +extern struct swap_info_struct *get_swap_info_struct(unsigned); +extern int can_share_swap_page(struct page *); +extern int remove_exclusive_swap_page(struct page *); -struct swap_list_t { - int head; /* head of priority-ordered swapfile list */ - int next; /* swapfile to be used next */ -}; extern struct swap_list_t swap_list; -asmlinkage long sys_swapoff(const char *); -asmlinkage long sys_swapon(const char *, int); - -extern void FASTCALL(mark_page_accessed(struct page *)); - extern spinlock_t swaplock; #define swap_list_lock() spin_lock(&swaplock) @@ -224,8 +220,39 @@ extern spinlock_t swaplock; #define swap_device_lock(p) spin_lock(&p->sdev_lock) #define swap_device_unlock(p) spin_unlock(&p->sdev_lock) -extern int shmem_unuse(swp_entry_t entry, struct page *page); - +#else /* CONFIG_SWAP */ + +#define total_swap_pages 0 +#define total_swapcache_pages 0UL + +#define si_swapinfo(val) \ + do { (val)->freeswap = (val)->totalswap = 0; } while (0) +#define free_page_and_swap_cache(page) \ + page_cache_release(page) +#define free_pages_and_swap_cache(pages, nr) \ + release_pages((pages), (nr), 0); + +#define show_swap_cache_info() /*NOTHING*/ +#define free_swap_and_cache(swp) /*NOTHING*/ +#define swap_duplicate(swp) /*NOTHING*/ +#define swap_free(swp) /*NOTHING*/ +#define read_swap_cache_async(swp) NULL +#define lookup_swap_cache(swp) NULL +#define valid_swaphandles(swp, off) 0 +#define can_share_swap_page(p) 0 +#define remove_exclusive_swap_page(p) 0 +#define move_to_swap_cache(p, swp) 1 +#define move_from_swap_cache(p, i, m) 1 +#define __delete_from_swap_cache(p) /*NOTHING*/ +#define delete_from_swap_cache(p) /*NOTHING*/ + +static inline swp_entry_t get_swap_page(void) +{ + swp_entry_t entry; + entry.val = 0; + return entry; +} + +#endif /* CONFIG_SWAP */ #endif /* __KERNEL__*/ - #endif /* _LINUX_SWAP_H */ diff --git a/kernel/sys.c b/kernel/sys.c index 3c2992ac68f2..22c1c93ec6da 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -204,6 +204,8 @@ cond_syscall(sys_nfsservctl) cond_syscall(sys_quotactl) cond_syscall(sys_acct) cond_syscall(sys_lookup_dcookie) +cond_syscall(sys_swapon) +cond_syscall(sys_swapoff) static int set_one_prio(struct task_struct *p, int niceval, int error) { diff --git a/mm/Makefile b/mm/Makefile index c2c873068a41..060e761a3864 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -5,10 +5,11 @@ export-objs := shmem.o filemap.o mempool.o page_alloc.o page-writeback.o obj-y := memory.o mmap.o filemap.o fremap.o mprotect.o mlock.o mremap.o \ - vmalloc.o slab.o bootmem.o swap.o vmscan.o page_io.o \ - page_alloc.o swap_state.o swapfile.o oom_kill.o \ - shmem.o highmem.o mempool.o msync.o mincore.o readahead.o \ - pdflush.o page-writeback.o rmap.o madvise.o vcache.o \ - truncate.o + vmalloc.o slab.o bootmem.o swap.o vmscan.o page_alloc.o \ + oom_kill.o shmem.o highmem.o mempool.o msync.o mincore.o \ + readahead.o pdflush.o page-writeback.o rmap.o madvise.o \ + vcache.o truncate.o + +obj-$(CONFIG_SWAP) += page_io.o swap_state.o swapfile.o include $(TOPDIR)/Rules.make diff --git a/mm/mmap.c b/mm/mmap.c index 472a9208bf91..205ba003d746 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -96,7 +96,7 @@ int vm_enough_memory(long pages) * this compensates for the swap-space over-allocation * (ie "nr_swap_pages" being too small). */ - free += swapper_space.nrpages; + free += total_swapcache_pages; /* * The code below doesn't account for free space in the diff --git a/mm/swapfile.c b/mm/swapfile.c index 628a97140a73..16d0698c3b2b 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -16,6 +16,7 @@ #include <linux/shm.h> #include <linux/blkdev.h> #include <linux/buffer_head.h> +#include <linux/proc_fs.h> #include <linux/seq_file.h> #include <asm/pgtable.h> @@ -1121,12 +1122,35 @@ static int swap_show(struct seq_file *swap, void *v) return 0; } -struct seq_operations swaps_op = { +static struct seq_operations swaps_op = { .start = swap_start, .next = swap_next, .stop = swap_stop, .show = swap_show }; + +static int swaps_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &swaps_op); +} + +static struct file_operations proc_swaps_operations = { + .open = swaps_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + +static int __init procswaps_init(void) +{ + struct proc_dir_entry *entry; + + entry = create_proc_entry("swaps", 0, NULL); + if (entry) + entry->proc_fops = &proc_swaps_operations; + return 0; +} +__initcall(procswaps_init); #endif /* CONFIG_PROC_FS */ /* diff --git a/mm/vmscan.c b/mm/vmscan.c index a2ae04f94ee7..b0cd7ff6265e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -249,6 +249,7 @@ shrink_list(struct list_head *page_list, unsigned int gfp_mask, mapping = page->mapping; +#ifdef CONFIG_SWAP /* * Anonymous process memory without backing store. Try to * allocate it some swap space here. @@ -281,6 +282,7 @@ shrink_list(struct list_head *page_list, unsigned int gfp_mask, } } pte_chain_unlock(page); +#endif /* CONFIG_SWAP */ /* * FIXME: this is CPU-inefficient for shared mappings. @@ -376,16 +378,21 @@ shrink_list(struct list_head *page_list, unsigned int gfp_mask, goto keep_locked; } +#ifdef CONFIG_SWAP if (PageSwapCache(page)) { swp_entry_t swap = { .val = page->index }; __delete_from_swap_cache(page); write_unlock(&mapping->page_lock); swap_free(swap); - } else { - __remove_from_page_cache(page); - write_unlock(&mapping->page_lock); + __put_page(page); /* The pagecache ref */ + goto free_it; } - __put_page(page); /* The pagecache ref */ +#endif /* CONFIG_SWAP */ + + __remove_from_page_cache(page); + write_unlock(&mapping->page_lock); + __put_page(page); + free_it: unlock_page(page); ret++; |
