From patchwork Sun Mar 17 16:51:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13594768 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0672C54E67 for ; Sun, 17 Mar 2024 16:52:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F2B76B0083; Sun, 17 Mar 2024 12:52:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A2706B0087; Sun, 17 Mar 2024 12:52:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16A806B0088; Sun, 17 Mar 2024 12:52:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0462E6B0083 for ; Sun, 17 Mar 2024 12:52:04 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9A2EEA0BB0 for ; Sun, 17 Mar 2024 16:52:03 +0000 (UTC) X-FDA: 81907123326.26.3FCEB3D Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf27.hostedemail.com (Postfix) with ESMTP id 6139A40009 for ; Sun, 17 Mar 2024 16:52:00 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=naAqZ7eV; spf=pass (imf27.hostedemail.com: domain of djwong@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710694322; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CZr1E4oHCb6FH+/9RTdyliAeQWb9xlp2Yx/dmnl5n2o=; b=TEpAGYVusulTMs+ENZK++aS0RDzXUzz27BOWg87mmSWHJ6OuQwb3RNZmxVMGAr+jXIE1C1 wvdfRKyxEoprGKf13H76BLw3dyXGq7TP+qp2xgaQ8Ey6H2NIFyIfhWwE5OuYwsa7xMOh9z KMuZ9RDBdLaN2eyq7RnvL10UBA0T5+w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710694322; a=rsa-sha256; cv=none; b=S8ruPVRvXQiWj6hiPTAXFZ2ZETt0UfQRzCrbxTz3FlypQK8g5PWBYJZaT6BHdMfpNhMzn1 oPvSdiCeFQGDpewwnRcjabLjfyL+aMjRR00HjGDaaXAFhbzijT5jPCni5gG3M7kDpPqeHC a5nn84lIUi4/7Ces5G6k2jV2K7pK9fg= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=naAqZ7eV; spf=pass (imf27.hostedemail.com: domain of djwong@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 60F2FCE0174; Sun, 17 Mar 2024 16:51:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9858EC433C7; Sun, 17 Mar 2024 16:51:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710694317; bh=HxWfd1Znm4cUZamAM6TQvmubUOO81Xy3fg/jRpSm4BI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=naAqZ7eVFLhdBU/5dsNz+CCBzniVgBCPwpb/vhB4+sKkEMaIHcuYIIouHufDX7wLl qovkE+LrJgC/RmilV5mhExNDlSqFAHNEBC81/Y7zZ6SPOjYHU9uPTyN4qj0eWLsNru YVO7K7RHFgu3WF4w4Jl2nrcsRnyPYAvj7vf/EosSsTRArVe+IoKo0O4NHFpFjs2lJW OUhnOvvKy4rQd9op8CWgC8yyQeYmgIqRysmIMcV2wyVevAwEzUgEEjMrQ+zdsb/FQP G3pvf2VlekezVJlwgKWTAFHz8gGvHzfQW1x7x5JTSHy1iOfNPK2Kg+d6K3B0DpQAtT yQJaQhcY3KtOw== Date: Sun, 17 Mar 2024 09:51:57 -0700 From: "Darrick J. Wong" To: David Hildenbrand , djwong@kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, fstests , xfs Subject: [RFC PATCH] xfs_io: add linux madvise advice codes Message-ID: <20240317165157.GE1927156@frogsfrogsfrogs> References: <20240314161300.382526-1-david@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240314161300.382526-1-david@redhat.com> X-Rspamd-Queue-Id: 6139A40009 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zpuhk9fjk6wa4mbie765wp95i1g4jh3k X-HE-Tag: 1710694320-95051 X-HE-Meta: U2FsdGVkX19YzG4L+TQ1UZsMNMSfOrT7+keclcB3j4/hguvUqWa7gE46KpXZyL4XYISsQqJbIVdD1otwuyN6eQp9vSS7O/zzybDZQPs3eKRV6V2pY9vxx8rx+BBGdApOHbDzk54U80kzhkii46s4eAqlJ6KMrRNjvN4VuslzbBLVfm1eR3LCOXa1xBoBORHzK7SIYDgf1dJ4JpI5uNzNvxzxGDpSn4jYrIG1n9I1qhVSi1qidNhZLeesJueUYbvsYa7oW9JjueqO5ASAH0Iw23vdcQwHNE0lfdaCH9uebxYGuLdLPmIqcvFDt/p9Kcpm+S/TqPyEZwOWDlnIkuSFkVNjXy6a2vDN/Qj/GP4GEv2EeqpSw69KoZzEqUc3H2b4v/XfC4aIDKuy7hQMvOuX4M/cPFjWyFuWsfi5Rv4nJqhlcIhzsvGO/n/A1+DAt08IwYxKmzzxJdG8eC9TfkR3/ZnZ2+FpmkuG6vNSb6vTc3o59W7AtDfPW6uy/QvFo+4mgCRUjiblTUxUokiRdsiXj7SWE2GmtIegpGHvjA5YUx+o+Tqf/OeLsfQY/fob4XBOpDbCgvU4gW4q9VpkMDxOowVNWdqqFhtgxkQE17xcH2cuTharQfKivYWH/dsPzP+926KlNob+J0LHxfJ5iMmJy0nAg47dpwE/YfzEdcbuFiI3Gr2ySenj7NM+kBjKzgROPXJtRnI1XKTFoEKjnmx/hIO8eWRamGCR51YxdzzYwBgSmR8l89yJoAznf49+M2Zp//LLvZC+IPzDTvIlsoSpq/5m3o6qdJ6cBLnkqs7w+AmgA92RhkvYaW4cyP/OQM2Lxn/Wsc7h1UU40WRJddQ7JchISNhxJIUTnkIRIQH4No0qkOytoQpsQaPaezGSklVu0qtLWHmDqwV3TNYPPOUMHQyZRns+35JZC5n0PyylR7I6aTVFp3IfF55GSX2PZvq1iePQsjk+GpJqgLDlmu6 hF/LYhh2 3/ToExsMc6C92xagu8cBiFxBK1a0NvETXPSBbPcZnWPC3TwvsEuEYLZcXXdNxo0wy6/t+7ZHSUNFQHa5nyn91n7t/kzbGg5YqTcqwwmjJdZlPijHVZVNYzOcyo+HYgrPUB1b1b0v7l9aBfaiu/+ldmK6TudmyKlRfUO3ReEP7C3q5rRJ5sEVTZ+hNUIvXRXzWWzmgqXLEX7Iqkrh18ytCFsAmE6B8NfWIO0f8ksYDJq4+nbcY+b2YbkdAsgGFxFNqXAwA5g4TzkOuExkm8nQH17ytHpS9gmfT8oWj X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Darrick J. Wong Add all the Linux-specific madvise codes. We're going to need MADV_POPULATE_READ for a regression test. Signed-off-by: Darrick J. Wong --- configure.ac | 1 include/builddefs.in | 1 io/Makefile | 4 ++ io/madvise.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ m4/package_libcdev.m4 | 17 ++++++++ 5 files changed, 133 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 3786e44db6fd..723bdca506d1 100644 --- a/configure.ac +++ b/configure.ac @@ -187,6 +187,7 @@ AC_CONFIG_SYSTEMD_SYSTEM_UNIT_DIR AC_CONFIG_CROND_DIR AC_CONFIG_UDEV_DIR AC_HAVE_BLKID_TOPO +AC_HAVE_KERNEL_MADVISE_FLAGS if test "$enable_ubsan" = "yes" || test "$enable_ubsan" = "probe"; then AC_PACKAGE_CHECK_UBSAN diff --git a/include/builddefs.in b/include/builddefs.in index 07428206da45..a04f3e70f19d 100644 --- a/include/builddefs.in +++ b/include/builddefs.in @@ -193,6 +193,7 @@ HAVE_O_TMPFILE = @have_o_tmpfile@ HAVE_MKOSTEMP_CLOEXEC = @have_mkostemp_cloexec@ USE_RADIX_TREE_FOR_INUMS = @use_radix_tree_for_inums@ HAVE_FSVERITY_DESCR = @have_fsverity_descr@ +HAVE_KERNEL_MADVISE = @have_kernel_madvise@ GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall -Werror -Wextra -Wno-unused-parameter # -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl diff --git a/io/Makefile b/io/Makefile index 6f903e3df9a7..ce39fda0e82a 100644 --- a/io/Makefile +++ b/io/Makefile @@ -84,6 +84,10 @@ ifeq ($(HAVE_GETFSMAP),yes) CFILES += fsmap.c endif +ifeq ($(HAVE_KERNEL_MADVISE),yes) +LCFLAGS += -DHAVE_KERNEL_MADVISE +endif + default: depend $(LTCOMMAND) include $(BUILDRULES) diff --git a/io/madvise.c b/io/madvise.c index 6e9c5b121d72..081666f403bb 100644 --- a/io/madvise.c +++ b/io/madvise.c @@ -9,6 +9,9 @@ #include #include "init.h" #include "io.h" +#ifdef HAVE_KERNEL_MADVISE +# include +#endif static cmdinfo_t madvise_cmd; @@ -26,6 +29,47 @@ madvise_help(void) " -r -- expect random page references (POSIX_MADV_RANDOM)\n" " -s -- expect sequential page references (POSIX_MADV_SEQUENTIAL)\n" " -w -- will need these pages (POSIX_MADV_WILLNEED) [*]\n" +"\n" +"The following Linux-specific advise values are available:\n" +#ifdef MADV_COLLAPSE +" -c -- try to collapse range into transparent hugepages (MADV_COLLAPSE)\n" +#endif +#ifdef MADV_COLD +" -D -- deactivate the range (MADV_COLD)\n" +#endif +#ifdef MADV_FREE +" -f -- free the range (MADV_FREE)\n" +#endif +#ifdef MADV_NOHUGEPAGE +" -h -- disable transparent hugepages (MADV_NOHUGEPAGE)\n" +#endif +#ifdef MADV_HUGEPAGE +" -H -- enable transparent hugepages (MADV_HUGEPAGE)\n" +#endif +#ifdef MADV_MERGEABLE +" -m -- mark the range mergeable (MADV_MERGEABLE)\n" +#endif +#ifdef MADV_UNMERGEABLE +" -M -- mark the range unmergeable (MADV_UNMERGEABLE)\n" +#endif +#ifdef MADV_SOFT_OFFLINE +" -o -- mark the range offline (MADV_SOFT_OFFLINE)\n" +#endif +#ifdef MADV_REMOVE +" -p -- punch a hole in the file (MADV_REMOVE)\n" +#endif +#ifdef MADV_HWPOISON +" -P -- poison the page cache (MADV_HWPOISON)\n" +#endif +#ifdef MADV_POPULATE_READ +" -R -- prefault in the range for read (MADV_POPULATE_READ)\n" +#endif +#ifdef MADV_POPULATE_WRITE +" -W -- prefault in the range for write (MADV_POPULATE_WRITE)\n" +#endif +#ifdef MADV_PAGEOUT +" -X -- reclaim the range (MADV_PAGEOUT)\n" +#endif " Notes:\n" " NORMAL sets the default readahead setting on the file.\n" " RANDOM sets the readahead setting on the file to zero.\n" @@ -45,20 +89,85 @@ madvise_f( int advise = MADV_NORMAL, c; size_t blocksize, sectsize; - while ((c = getopt(argc, argv, "drsw")) != EOF) { + while ((c = getopt(argc, argv, "cdDfhHmMopPrRswWX")) != EOF) { switch (c) { +#ifdef MADV_COLLAPSE + case 'c': /* collapse to thp */ + advise = MADV_COLLAPSE; + break; +#endif case 'd': /* Don't need these pages */ advise = MADV_DONTNEED; break; +#ifdef MADV_COLD + case 'D': /* make more likely to be reclaimed */ + advise = MADV_COLD; + break; +#endif +#ifdef MADV_FREE + case 'f': /* page range out of memory */ + advise = MADV_FREE; + break; +#endif +#ifdef MADV_HUGEPAGE + case 'h': /* enable thp memory */ + advise = MADV_HUGEPAGE; + break; +#endif +#ifdef MADV_NOHUGEPAGE + case 'H': /* disable thp memory */ + advise = MADV_NOHUGEPAGE; + break; +#endif +#ifdef MADV_MERGEABLE + case 'm': /* enable merging */ + advise = MADV_MERGEABLE; + break; +#endif +#ifdef MADV_UNMERGEABLE + case 'M': /* disable merging */ + advise = MADV_UNMERGEABLE; + break; +#endif +#ifdef MADV_SOFT_OFFLINE + case 'o': /* offline */ + advise = MADV_SOFT_OFFLINE; + break; +#endif +#ifdef MADV_REMOVE + case 'p': /* punch hole */ + advise = MADV_REMOVE; + break; +#endif +#ifdef MADV_HWPOISON + case 'P': /* poison */ + advise = MADV_HWPOISON; + break; +#endif case 'r': /* Expect random page references */ advise = MADV_RANDOM; break; +#ifdef MADV_POPULATE_READ + case 'R': /* fault in pages for read */ + advise = MADV_POPULATE_READ; + break; +#endif case 's': /* Expect sequential page references */ advise = MADV_SEQUENTIAL; break; case 'w': /* Will need these pages */ advise = MADV_WILLNEED; break; +#ifdef MADV_POPULATE_WRITE + case 'W': /* fault in pages for write */ + advise = MADV_POPULATE_WRITE; + break; +#endif +#ifdef MADV_PAGEOUT + case 'X': /* reclaim memory */ + advise = MADV_PAGEOUT; + break; +#endif default: exitcode = 1; return command_usage(&madvise_cmd); diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4 index 84f288dfcfdb..064d050b2b55 100644 --- a/m4/package_libcdev.m4 +++ b/m4/package_libcdev.m4 @@ -322,3 +322,20 @@ struct fsverity_descriptor m = { }; AC_SUBST(have_fsverity_descr) ]) +# +# Check if asm/mman.h can be included +# +AC_DEFUN([AC_HAVE_KERNEL_MADVISE_FLAGS], + [ AC_MSG_CHECKING([for kernel madvise flags in asm/mman.h ]) + AC_COMPILE_IFELSE( + [ AC_LANG_PROGRAM([[ +#include + ]], [[ +int moo = MADV_COLLAPSE; + ]]) + ], have_kernel_madvise=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_kernel_madvise) + ]) +