Re: [PATCH v5 1/2] fsx: support reads/writes from buffers backed by hugepages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Feb 3, 2025 at 10:59 AM Darrick J. Wong <djwong@xxxxxxxxxx> wrote:
>
> On Mon, Feb 03, 2025 at 10:04:04AM -0800, Joanne Koong wrote:
> > On Sun, Feb 2, 2025 at 6:25 AM Zorro Lang <zlang@xxxxxxxxxx> wrote:
> > >
> > > On Tue, Jan 21, 2025 at 01:56:40PM -0800, Joanne Koong wrote:
> > > > Add support for reads/writes from buffers backed by hugepages.
> > > > This can be enabled through the '-h' flag. This flag should only be used
> > > > on systems where THP capabilities are enabled.
> > > >
> > > > This is motivated by a recent bug that was due to faulty handling of
> > > > userspace buffers backed by hugepages. This patch is a mitigation
> > > > against problems like this in the future.
> > > >
> > > > Signed-off-by: Joanne Koong <joannelkoong@xxxxxxxxx>
> > > > Reviewed-by: Brian Foster <bfoster@xxxxxxxxxx>
> > > > Reviewed-by: Darrick J. Wong <djwong@xxxxxxxxxx>
> > > > ---
> > >
> > > Those two test cases fail on old system which doesn't support
> > > MADV_COLLAPSE:
> > >
> > >    fsx -N 10000 -l 500000 -h
> > >   -fsx -N 10000 -o 8192 -l 500000 -h
> > >   -fsx -N 10000 -o 128000 -l 500000 -h
> > >   +MADV_COLLAPSE not supported. Can't support -h
> > >
> > > and
> > >
> > >    fsx -N 10000 -l 500000 -r PSIZE -t BSIZE -w BSIZE -Z -R -W -h
> > >   -fsx -N 10000 -o 8192 -l 500000 -r PSIZE -t BSIZE -w BSIZE -Z -R -W -h
> > >   -fsx -N 10000 -o 128000 -l 500000 -r PSIZE -t BSIZE -w BSIZE -Z -R -W -h
> > >   +mapped writes DISABLED
> > >   +MADV_COLLAPSE not supported. Can't support -h
> > >
> > > I'm wondering ...
> > >
> > > >  ltp/fsx.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++-----
> > > >  1 file changed, 153 insertions(+), 13 deletions(-)
> > > >
> > > > diff --git a/ltp/fsx.c b/ltp/fsx.c
> > > > index 41933354..3be383c6 100644
> > > > --- a/ltp/fsx.c
> > > > +++ b/ltp/fsx.c
> > > >  static struct option longopts[] = {
> > > >       {"replay-ops", required_argument, 0, 256},
> > > >       {"record-ops", optional_argument, 0, 255},
> > > > @@ -2883,7 +3023,7 @@ main(int argc, char **argv)
> > > >       setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
> > > >
> > > >       while ((ch = getopt_long(argc, argv,
> > > > -                              "0b:c:de:fg:i:j:kl:m:no:p:qr:s:t:uw:xyABD:EFJKHzCILN:OP:RS:UWXZ",
> > > > +                              "0b:c:de:fg:hi:j:kl:m:no:p:qr:s:t:uw:xyABD:EFJKHzCILN:OP:RS:UWXZ",
> > > >                                longopts, NULL)) != EOF)
> > > >               switch (ch) {
> > > >               case 'b':
> > > > @@ -2916,6 +3056,14 @@ main(int argc, char **argv)
> > > >               case 'g':
> > > >                       filldata = *optarg;
> > > >                       break;
> > > > +             case 'h':
> > > > +#ifndef MADV_COLLAPSE
> > > > +                     fprintf(stderr, "MADV_COLLAPSE not supported. "
> > > > +                             "Can't support -h\n");
> > > > +                     exit(86);
> > > > +#endif
> > > > +                     hugepages = 1;
> > > > +                     break;
> > >
> > > ...
> > > if we could change this part to:
> > >
> > > #ifdef MADV_COLLAPSE
> > >         hugepages = 1;
> > > #endif
> > >         break;
> > >
> > > to avoid the test failures on old systems.
> > >
> > > Or any better ideas from you :)
> >
> > Hi Zorro,
> >
> > It looks like MADV_COLLAPSE was introduced in kernel version 6.1. What
> > do you think about skipping generic/758 and generic/759 if the kernel
> > version is older than 6.1? That to me seems more preferable than the
> > paste above, as the paste above would execute the test as if it did
> > test hugepages when in reality it didn't, which would be misleading.
>
> Now that I've gotten to try this out --
>
> There's a couple of things going on here.  The first is that generic/759
> and 760 need to check if invoking fsx -h causes it to spit out the
> "MADV_COLLAPSE not supported" error and _notrun the test.
>
> The second thing is that userspace programs can ensure the existence of
> MADV_COLLAPSE in multiple ways.  The first way is through sys/mman.h,
> which requires that the underlying C library headers are new enough to
> include a definition.  glibc 2.37 is new enough, but even things like
> Debian 12 and RHEL 9 aren't new enough to have that.  Other C libraries
> might not follow glibc's practice of wrapping and/or redefining symbols
> in a way that you hope is the same as...
>
> The second way is through linux/mman.h, which comes from the kernel
> headers package; and the third way is for the program to define it
> itself if nobody else does.
>
> So I think the easiest way to fix the fsx.c build is to include
> linux/mman.h in addition to sys/mman.h.  Sorry I didn't notice these

Thanks for your input. Do we still need sys/mman.h if linux/mman.h is added?

For generic/758 and 759, does it suffice to gate this on whether the
kernel version if 6.1+ and _notrun if not? My understanding is that
any kernel version 6.1 or newer will have MADV_COLLAPSE in its kernel
headers package and support the feature.


Thanks,
Joanne

> details when I reviewed your patch; I'm a little attention constrained
> ATM trying to get a large pile of bugfixes and redesigns reviewed so
> for-next can finally move forward again.
>
> --D
>
> >
> > Thanks,
> > Joanne
> >
> > >
> > > Thanks,
> > > Zorro
> > >
> > > >               case 'i':
> > > >                       integrity = 1;
> > > >                       logdev = strdup(optarg);
> > > > @@ -3229,15 +3377,7 @@ main(int argc, char **argv)
> > > >                       exit(95);
> > > >               }
> > > >       }
> > > > -     original_buf = (char *) malloc(maxfilelen);
> > > > -     for (i = 0; i < maxfilelen; i++)
> > > > -             original_buf[i] = random() % 256;
> > > > -     good_buf = (char *) malloc(maxfilelen + writebdy);
> > > > -     good_buf = round_ptr_up(good_buf, writebdy, 0);
> > > > -     memset(good_buf, '\0', maxfilelen);
> > > > -     temp_buf = (char *) malloc(maxoplen + readbdy);
> > > > -     temp_buf = round_ptr_up(temp_buf, readbdy, 0);
> > > > -     memset(temp_buf, '\0', maxoplen);
> > > > +     init_buffers();
> > > >       if (lite) {     /* zero entire existing file */
> > > >               ssize_t written;
> > > >
> > > > --
> > > > 2.47.1
> > > >
> > >





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux