Re: Big Swap...

From: Jakub Jelinek (jakub@redhat.com)
Date: Sat Jan 15 2000 - 08:49:25 EST


> > Well, I guess the symptoms clearly point at the following:
> >
> > A partition is accepted as swap space when it has a swap space signature.
> > This is meant as protection, so that one wouldnt start swapping over a
> > precious file system by a single typo.
> >
> > Where is this signature? In the last ten bytes of the first page.
> > A very unfortunate design, since nobody knows how large a page is.
> >
> > Earlier, mkswap used the constant PAGE_SIZE, but people complained
> > because this means that several binaries are required for the
> > same architecture, since different models may use a different PAGE_SIZE.
> > These days mkswap uses the system call getpagesize(), but as your example
> > shows that is no good either, since it may return the wrong value.
> >
> > (To be more precise, the kernel code
> >
> > asmlinkage unsigned long sys_getpagesize(void)
> > {
> > return PAGE_SIZE; /* Possibly older binaries want 8192 on sun4's? */
> > }
> >
> > is good enough, although the comment is a warning already, but the libc code
> >
> > size_t
> > DEFUN_VOID(__getpagesize)
> > {
> > #ifdef EXEC_PAGESIZE
> > return EXEC_PAGESIZE;
> > #else /* No EXEC_PAGESIZE. */
> > #ifdef NBPG
> > #ifndef CLSIZE
> > #define CLSIZE 1
> > #endif /* No CLSIZE. */
> > return NBPG * CLSIZE;
> > #else /* No NBPG. */
> > return NBPC;
> > #endif /* NBPG. */
> > #endif /* EXEC_PAGESIZE. */
> > }
> >
> > does not use a system call at all, but returns EXEC_PAGESIZE which is 8192.)
> > Thus, if I am not mistaken, if you change in mkswap.c, in the routine
> >
> > static void
> > init_signature_page() {
> > pagesize = getpagesize();
> >
> > #ifdef PAGE_SIZE
> > if (pagesize != PAGE_SIZE)
> > fprintf(stderr, _("Assuming pages of size %d\n"), pagesize);
> > #endif
> > signature_page = (int *) malloc(pagesize);
> > memset(signature_page,0,pagesize);
> > p = (struct swap_header_v1 *) signature_page;
> > }
> >
> > the assignment
> >
> > pagesize = getpagesize();
> >
> > into
> >
> > pagesize = PAGE_SIZE;
> >
> > then all will be well.
> >
> > Thanks for pointing out this problem. Will fix mkswap.
> >
> > Andries
>
> This DID make it work! Thank you!

What libc are you using?
glibc 2.1's getpagesize() should work correctly, have checked it.
If getpagesize() does not work correctly, then you should IMHO fix
getpagesize(), not break mkswap. Because if you just set pagesize =
PAGE_SIZE, then you're horribly broken because you'll have to use different
binaries for sun4, sun4c/d/m and sun4u.

Cheers,
    Jakub
___________________________________________________________________
Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj
Linux version 2.3.39 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Jan 15 2000 - 21:00:25 EST