Messages in this thread Patch in this message | | | Date | Tue, 15 Jul 1997 00:45:41 +0200 (MET DST) | From | Uwe Ohse <> | Subject | Small patch for si_swapinfo() |
| |
Hello,
this patch improves the performance of si_swapinfo. si_swapinfo is called if some application reads /proc/meminfo or calls sysinfo, like top oder procinfo do. This patchs increases the speed of si_swapinfo by some orders of magnitude if you have a large swap space. [this is measurable on a P133 with 300MB swap and a 486/66 with 50MB of swap. si_swapinfo was deadslow on the pentium as that machine had even more spap] Drawback: Allocation and deallocation of a single swap page is slower (around 2 or 3 assembly instructions). This hasn't had any measurable effect (on my machines, if no programs call sysinfo or read /proc/meminfo. YMMV).
sidenote: has anybody thought about writing a daemon which adjusts the priority of swap devices? Using hard drice load and speed, and swap partition (file) utilization as input parameters?
The patch is against 2.0.31-pre2 with Werner Finks buffer patch and + some local hacks (which only influence line numbers here).
Uwe -----------------------------------------------------------------------
--- include/linux/swap.h.old Sun Jun 8 10:22:13 1997 +++ include/linux/swap.h Sun Jul 13 10:18:49 1997 @@ -28,6 +28,8 @@ int cluster_nr; int prio; /* swap priority */ int pages; + int total; /* statistics */ + int free; /* statistics */ unsigned long max; int next; /* next entry on swap list */ }; --- mm/swapfile.c.old Sun Jun 8 10:22:14 1997 +++ mm/swapfile.c Sun Jul 13 10:24:54 1997 @@ -64,6 +64,7 @@ si->lowest_bit = offset; got_page: si->swap_map[offset] = 1; + si->free--; nr_swap_pages--; if (offset == si->highest_bit) si->highest_bit--; @@ -147,8 +148,10 @@ if (!p->swap_map[offset]) printk("swap_free: swap-space map bad (entry %08lx)\n",entry); else - if (!--p->swap_map[offset]) + if (!--p->swap_map[offset]) { + p->free++; nr_swap_pages++; + } if (p->prio > swap_info[swap_list.next].prio) { swap_list.next = swap_list.head; } @@ -432,6 +435,7 @@ p->highest_bit = 0; p->cluster_nr = 0; p->max = 1; + p->free = 0; p->next = -1; if (swap_flags & SWAP_FLAG_PREFER) { p->prio = @@ -509,11 +513,13 @@ goto bad_swap; } for (i = 1 ; i < p->max ; i++) { - if (test_bit(i,p->swap_lockmap)) + if (test_bit(i,p->swap_lockmap)) { p->swap_map[i] = 0; - else + p->free++; + } else p->swap_map[i] = 0x80; } + p->total=p->free; p->swap_map[0] = 0x80; memset(p->swap_lockmap,0,PAGE_SIZE); p->flags = SWP_WRITEOK; @@ -554,21 +560,14 @@ void si_swapinfo(struct sysinfo *val) { - unsigned int i, j; + unsigned int i; val->freeswap = val->totalswap = 0; for (i = 0; i < nr_swapfiles; i++) { if ((swap_info[i].flags & SWP_WRITEOK) != SWP_WRITEOK) continue; - for (j = 0; j < swap_info[i].max; ++j) - switch (swap_info[i].swap_map[j]) { - case 128: - continue; - case 0: - ++val->freeswap; - default: - ++val->totalswap; - } + val->freeswap+=swap_info[i].free; + val->totalswap+=swap_info[i].total; } val->freeswap += nr_swap_cache_pages; val->freeswap <<= PAGE_SHIFT; --- init/patches/si-swapinfo.info Tue Mar 25 01:43:05 1997 +++ init/patches/si-swapinfo.info Sun Jul 13 21:59:21 1997 @@ -0,0 +1 @@ +si_swapinfo performance patch (Uwe Ohse)
| |