xref: /freebsd/sys/contrib/openzfs/include/os/linux/kernel/linux/mm_compat.h (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 
13 /*
14  * Copyright (c) 2023, 2024, Klara Inc.
15  * Copyright (c) 2024, Rob Norris <robn@despairlabs.com>
16  */
17 
18 #ifndef _ZFS_MM_COMPAT_H
19 #define	_ZFS_MM_COMPAT_H
20 
21 #include <linux/mm.h>
22 #include <linux/pagemap.h>
23 
24 /* 5.4 introduced page_size(). Older kernels can use a trivial macro instead */
25 #ifndef HAVE_MM_PAGE_SIZE
26 #define	page_size(p) ((unsigned long)(PAGE_SIZE << compound_order(p)))
27 #endif
28 
29 /* 6.11 removed page_mapping(). A simple wrapper around folio_mapping() works */
30 #ifndef HAVE_MM_PAGE_MAPPING
31 #define	page_mapping(p) folio_mapping(page_folio(p))
32 #endif
33 
34 /*
35  * 6.12 removed PG_error, SetPageError and ClearPageError, with no direct
36  * replacement, because page writeback errors are recorded elsewhere. Since we
37  * only use the page cache to assist with mmap(), never directly backing it
38  * with IO, it shouldn't be possible for this condition to occur on our pages
39  * anyway, even if this is the right way to report it. So it should be safe
40  * to remove, but for avoidance of doubt, we make it a no-op on 6.12 and leave
41  * it for everything else.
42  */
43 #ifndef HAVE_MM_PAGE_FLAG_ERROR
44 #define	SetPageError(p)		do {} while (0)
45 #define	ClearPageError(p)	do {} while (0)
46 #endif
47 
48 #endif /* _ZFS_MM_COMPAT_H */
49