Make PageWriteback use the PageLocked optimisation
Subsystems (10)
Matthew Wilcox
maintainerv3 cover Make PageWriteback use the PageLocked optimisation
From: "Matthew Wilcox (Oracle)" <[email protected]>
PageWaiters is used by PageWriteback and PageLocked (and no other page flags), so it makes sense to use the same codepaths that have already been optimised for PageLocked, even if there's probably no real performance benefit to be had.
Unfortunately, clear_bit_unlock_is_negative_byte() isn't present on every architecture, and the default implementation is only available in filemap.c while I want to use it in page-writeback.c. Rather than move the default implementation to a header file, I've done optimised implementations for alpha and ia64. I can't figure out optimised implementations for m68k, mips, riscv and s390, so I've just replicated the effect of the generic implementation in them. I leave it to the experts to fix that (... or convert over to using asm-generic/bitops/lock.h ...)
v3:
- Added implementations of clear_bit_unlock_is_negative_byte() to architectures which need it
v2: Rebased to 5.7-rc1
- Split up patches better
- Moved the BUG() from end_page_writeback() to __clear_page_writeback() as requested by Jan Kara.
- Converted the BUG() to WARN_ON()
- Removed TestClearPageWriteback
Matthew Wilcox (Oracle) (11):
alpha: Add clear_bit_unlock_is_negative_byte implementation
ia64: Add clear_bit_unlock_is_negative_byte implementation
m68k: Add clear_bit_unlock_is_negative_byte implementation
mips: Add clear_bit_unlock_is_negative_byte implementation
riscv: Add clear_bit_unlock_is_negative_byte implementation
s390: Add clear_bit_unlock_is_negative_byte implementation
mm: Remove definition of clear_bit_unlock_is_negative_byte
mm: Move PG_writeback into the bottom byte
mm: Convert writeback BUG to WARN_ON
mm: Use clear_bit_unlock_is_negative_byte for PageWriteback
mm: Remove TestClearPageWriteback
arch/alpha/include/asm/bitops.h | 23 ++++++++++++++++++ arch/ia64/include/asm/bitops.h | 20 ++++++++++++++++ arch/m68k/include/asm/bitops.h | 7 ++++++ arch/mips/include/asm/bitops.h | 7 ++++++ arch/riscv/include/asm/bitops.h | 7 ++++++ arch/s390/include/asm/bitops.h | 9 +++++++ include/linux/page-flags.h | 8 +++---- mm/filemap.c | 41 ++++---------------------------- mm/page-writeback.c | 42 ++++++++++++++++++++------------- 9 files changed, 107 insertions(+), 57 deletions(-)
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerPATCH v3 1/11 alpha: Add clear_bit_unlock_is_negative_byte implementation
From: "Matthew Wilcox (Oracle)" <[email protected]>
Copy and paste the clear_bit_unlock() implementation, and test the temp variable to see if it has bit 7 set. Saves two instructions: a load and a compare:
860: 01 31 20 44 andnot t0,0x1,t0
864: 00 00 30 b8 stl_c t0,0(a0)
868: 67 1b 20 e4 beq t0,7608 <generic_file_write_iter+0x218>
- 86c: 00 00 30 a0 ldl t0,0(a0)
- 870: 01 10 30 44 and t0,0x80,t0
- 874: a1 03 e1 43 cmpult zero,t0,t0
- 878: 01 00 20 f4 bne t0,880 <unlock_page+0x40>
- 87c: 01 80 fa 6b ret
+ 86c: 01 10 30 44 and t0,0x80,t0
+ 870: 03 00 20 f4 bne t0,880 <unlock_page+0x40>
+ 874: 01 80 fa 6b ret--- arch/alpha/include/asm/bitops.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
arch/alpha/include/asm/bitops.h +23 -0
@@ -79,6 +79,29 @@ clear_bit_unlock(unsigned long nr, volatile void * addr)clear_bit (nr, addr); } +static inline bool clear_bit_unlock_is_negative_byte (unsigned int nr, +volatile unsigned long *p) +{ +unsigned long temp; +int *m = ((int *)p) + (nr >>5 ); + +smp_mb (); + __asm__ __volatile__( +"1: ldl_l %0,%3\n" +" bic %0,%2,%0\n" +" stl_c %0,%1\n" +" beq %0,2f\n" +".subsection 2\n" +"2: br 1b\n" +".previous" + :"=&r" (temp),"=m" (*m) + :"Ir" (1UL << (nr &31 )),"m" (*m)); + +return temp &128 ; +} +#define clear_bit_unlock_is_negative_byte \ + clear_bit_unlock_is_negative_byte +/* * WARNING: non atomic version. */
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerPATCH v3 2/11 ia64: Add clear_bit_unlock_is_negative_byte implementation
In reply to Matthew WilcoxFrom: "Matthew Wilcox (Oracle)" <[email protected]>
Copy and paste the clear_bit_unlock() implementation, and test the old variable to see if it has bit 7 set.
--- arch/ia64/include/asm/bitops.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
arch/ia64/include/asm/bitops.h +20 -0
@@ -117,6 +117,26 @@ clear_bit_unlock (int nr, volatile void *addr) }while (cmpxchg_rel (m, old, new) != old); } +static inline bool clear_bit_unlock_is_negative_byte (unsigned int nr, +volatile unsigned long *p) +{ +__u32 mask, old, new; +volatile __u32 *m; +CMPXCHG_BUGCHECK_DECL + + m = (volatile __u32 *) addr + (nr >>5 ); + mask = ~(1 << (nr &31 )); +do { +CMPXCHG_BUGCHECK (m); + old = *m; + new = old & mask; + }while (cmpxchg_rel (m, old, new) != old); + +return old & (1 <<7 ); +} +#define clear_bit_unlock_is_negative_byte \ + clear_bit_unlock_is_negative_byte +/** * __clear_bit_unlock - Non-atomically clears a bit in memory with release * @nr: Bit to clear
Signature · 1 line
2.25.1
kbuild test robot
build botRe: [PATCH v3 02/11] ia64: Add clear_bit_unlock_is_negative_byte implementation
Thank you for the patch! Yet something to improve:
Hi Matthew,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on ia64/next]
[also build test ERROR on m68k/for-next s390/features linus/master v5.7-rc1 next-20200416] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Matthew-Wilcox/Make-PageWriteback-use-the-PageLocked-optimisation/20200417-060442 base: https://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git next config: ia64-allmodconfig (attached as .config) compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=ia64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
WARNING: unmet direct dependencies detected for FRAME_POINTER
Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS
Selected by
- FAULT_INJECTION_STACKTRACE_FILTER && FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT && !X86_64 && !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM && !ARC && !X86 scripts/Makefile.build:59: 'arch/ia64/kernel/palinfo.ko' 'arch/ia64/kernel/mca_recovery.ko' 'arch/ia64/kernel/err_inject.ko' will not be built even though obj-m is specified. scripts/Makefile.build:60: You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.
In file included from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:19,
from arch/ia64/include/asm/bug.h:17,
from include/linux/bug.h:5,
from include/linux/page-flags.h:10,
from kernel/bounds.c:10:
arch/ia64/include/asm/bitops.h: In function 'clear_bit_unlock_is_negative_byte':
>> arch/ia64/include/asm/bitops.h:127:25: error: 'addr' undeclared (first use in this function)
127 | m = (volatile __u32 addr + (nr >> 5);
| ^~~~
arch/ia64/include/asm/bitops.h:127:25: note: each undeclared identifier is reported only once for each function it appears in
Makefile Module.symvers System.map arch block certs crypto drivers fs include init ipc kernel lib mm modules.builtin modules.builtin.modinfo modules.order net scripts security sound source usr virt vmlinux vmlinux.bin vmlinux.gz vmlinux.o [scripts/Makefile.build:101: kernel/bounds.s] Error 1 Target '__build' not remade because of errors.
Makefile Module.symvers System.map arch block certs crypto drivers fs include init ipc kernel lib mm modules.builtin modules.builtin.modinfo modules.order net scripts security sound source usr virt vmlinux vmlinux.bin vmlinux.gz vmlinux.o [Makefile:1113: prepare0] Error 2 Target 'prepare' not remade because of errors.
make: Makefile Module.symvers System.map arch block certs crypto drivers fs include init ipc kernel lib mm modules.builtin modules.builtin.modinfo modules.order net scripts security sound source usr virt vmlinux vmlinux.bin vmlinux.gz vmlinux.o [Makefile:180: sub-make] Error 2 16 real 4 user 7 sys 70.16% cpu make prepare
vim +/addr +127 arch/ia64/include/asm/bitops.h
119
120 static inline bool clear_bit_unlock_is_negative_byte(unsigned int nr,
121 volatile unsigned long *p)
122 {
123 __u32 mask, old, new;
124 volatile __u32 *m;
125 CMPXCHG_BUGCHECK_DECL
126
> 127 m = (volatile __u32 *) addr + (nr >> 5);
128 mask = ~(1 << (nr & 31));
129 do {
130 CMPXCHG_BUGCHECK(m);
131 old = *m;
132 new = old & mask;
133 } while (cmpxchg_rel(m, old, new) != old);
134
135 return old & (1 << 7);
136 }
137 #define clear_bit_unlock_is_negative_byte \
138 clear_bit_unlock_is_negative_byte
139
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Matthew Wilcox
maintainerRe: [PATCH v3 02/11] ia64: Add clear_bit_unlock_is_negative_byte implementation
Quoted 3 lines · kbuild test robot
Hi Matthew,
Thank you for the patch! Yet something to improve:
Build fixes for the reported errors pushed to
http://git.infradead.org/users/willy/linux-dax.git/shortlog/refs/heads/wb-page-flag
Matthew Wilcox
maintainerPATCH v3 3/11 m68k: Add clear_bit_unlock_is_negative_byte implementation
In reply to Matthew WilcoxFrom: "Matthew Wilcox (Oracle)" <[email protected]>
This is the generic implementation. Someone who knows m68k assembly can probably do better (the BFCLR instruction appears to set the N bit appropriately).
--- arch/m68k/include/asm/bitops.h | 7 +++++++ 1 file changed, 7 insertions(+)
arch/m68k/include/asm/bitops.h +7 -0
@@ -524,6 +524,13 @@ static inline int __fls(int x)#define clear_bit_unlock clear_bit#define __clear_bit_unlock clear_bit_unlock +static inline bool clear_bit_unlock_is_negative_byte (unsigned int nr, +volatile unsigned long *p) +{ +clear_bit_unlock (nr, p); +return test_bit (7 , p); +} +#include <asm-generic/bitops/ext2-atomic.h> #include <asm-generic/bitops/le.h> #include <asm-generic/bitops/fls64.h>
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerPATCH v3 4/11 mips: Add clear_bit_unlock_is_negative_byte implementation
In reply to Matthew WilcoxFrom: "Matthew Wilcox (Oracle)" <[email protected]>
This is the generic implementation. I can't figure out an optimised implementation for mips.
--- arch/mips/include/asm/bitops.h | 7 +++++++ 1 file changed, 7 insertions(+)
arch/mips/include/asm/bitops.h +7 -0
@@ -147,6 +147,13 @@ static inline void clear_bit_unlock(unsigned long nr, volatile unsigned long *adclear_bit (nr, addr); } +static inline bool clear_bit_unlock_is_negative_byte (unsigned int nr, +volatile unsigned long *p) +{ +clear_bit_unlock (nr, p); +return test_bit (7 , p); +} +/* * change_bit - Toggle a bit in memory * @nr: Bit to change
Signature · 1 line
2.25.1
kbuild test robot
build botRe: [PATCH v3 04/11] mips: Add clear_bit_unlock_is_negative_byte implementation
Thank you for the patch! Yet something to improve:
Hi Matthew,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on ia64/next]
[also build test ERROR on m68k/for-next s390/features linus/master v5.7-rc1 next-20200416] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Matthew-Wilcox/Make-PageWriteback-use-the-PageLocked-optimisation/20200417-060442 base: https://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git next config: mips-allyesconfig (attached as .config) compiler: mips-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=mips
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:19,
from arch/mips/include/asm/bug.h:42,
from include/linux/bug.h:5,
from include/linux/page-flags.h:10,
from kernel/bounds.c:10:
arch/mips/include/asm/bitops.h: In function 'clear_bit_unlock_is_negative_byte':
>> arch/mips/include/asm/bitops.h:154:9: error: implicit declaration of function 'test_bit'; did you mean 'set_bit'? [-Werror=implicit-function-declaration]
154 | return test_bit(7, p);
| ^~~~~~~~
| set_bit
In file included from arch/mips/include/asm/bitops.h:294,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:19,
from arch/mips/include/asm/bug.h:42,
from include/linux/bug.h:5,
from include/linux/page-flags.h:10,
from kernel/bounds.c:10:
include/asm-generic/bitops/non-atomic.h: At top level:
include/asm-generic/bitops/non-atomic.h:104:19: error: static declaration of 'test_bit' follows non-static declaration
104 | static inline int test_bit(int nr, const volatile unsigned long *addr)
| ^~~~~~~~
In file included from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:19,
from arch/mips/include/asm/bug.h:42,
from include/linux/bug.h:5,
from include/linux/page-flags.h:10,
from kernel/bounds.c:10:
arch/mips/include/asm/bitops.h:154:9: note: previous implicit declaration of 'test_bit' was here
154 | return test_bit(7, p);
| ^~~~~~~~ cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:101: kernel/bounds.s] Error 1 make[2]: Target '__build' not remade because of errors. make[1]: *** [Makefile:1113: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:180: sub-make] Error 2
23 real 7 user 10 sys 75.85% cpu make prepare
vim +154 arch/mips/include/asm/bitops.h
149
150 static inline bool clear_bit_unlock_is_negative_byte(unsigned int nr,
151 volatile unsigned long *p)
152 {
153 clear_bit_unlock(nr, p);
> 154 return test_bit(7, p);
155 }
156
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Matthew Wilcox
maintainerPATCH v3 5/11 riscv: Add clear_bit_unlock_is_negative_byte implementation
In reply to Matthew WilcoxFrom: "Matthew Wilcox (Oracle)" <[email protected]>
This is the generic implementation. I can't figure out an optimised implementation for riscv.
--- arch/riscv/include/asm/bitops.h | 7 +++++++ 1 file changed, 7 insertions(+)
arch/riscv/include/asm/bitops.h +7 -0
@@ -171,6 +171,13 @@ static inline void clear_bit_unlock( __op_bit_ord(and, __NOT, nr, addr, .rl); } +static inline bool clear_bit_unlock_is_negative_byte (unsigned int nr, +volatile unsigned long *p) +{ +clear_bit_unlock (nr, p); +return test_bit (7 , p); +} +/** * __clear_bit_unlock - Clear a bit in memory, for unlock * @nr: the bit to set
Signature · 1 line
2.25.1
kbuild test robot
build botRe: [PATCH v3 05/11] riscv: Add clear_bit_unlock_is_negative_byte implementation
Thank you for the patch! Yet something to improve:
Hi Matthew,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on ia64/next]
[also build test ERROR on m68k/for-next s390/features linus/master v5.7-rc1 next-20200416] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Matthew-Wilcox/Make-PageWriteback-use-the-PageLocked-optimisation/20200417-060442 base: https://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git next config: riscv-allyesconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:19,
from arch/riscv/include/asm/bug.h:75,
from include/linux/bug.h:5,
from include/linux/page-flags.h:10,
from kernel/bounds.c:10:
arch/riscv/include/asm/bitops.h: In function 'clear_bit_unlock_is_negative_byte':
arch/riscv/include/asm/bitops.h:178:9: error: implicit declaration of function 'test_bit'; did you mean 'set_bit'? [-Werror=implicit-function-declaration]
178 | return test_bit(7, p);
| ^~~~~~~~
| set_bit
In file included from arch/riscv/include/asm/bitops.h:208,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:19,
from arch/riscv/include/asm/bug.h:75,
from include/linux/bug.h:5,
from include/linux/page-flags.h:10,
from kernel/bounds.c:10:
include/asm-generic/bitops/non-atomic.h: At top level:
>> include/asm-generic/bitops/non-atomic.h:104:19: error: static declaration of 'test_bit' follows non-static declaration
104 | static inline int test_bit(int nr, const volatile unsigned long *addr)
| ^~~~~~~~
In file included from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:19,
from arch/riscv/include/asm/bug.h:75,
from include/linux/bug.h:5,
from include/linux/page-flags.h:10,
from kernel/bounds.c:10:
arch/riscv/include/asm/bitops.h:178:9: note: previous implicit declaration of 'test_bit' was here
178 | return test_bit(7, p);
| ^~~~~~~~ cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:101: kernel/bounds.s] Error 1 make[2]: Target '__build' not remade because of errors. make[1]: *** [Makefile:1113: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:180: sub-make] Error 2
34 real 4 user 6 sys 29.68% cpu make prepare
vim +/test_bit +104 include/asm-generic/bitops/non-atomic.h
4117b02132d1cf9 Akinobu Mita 2006-03-26 984117b02132d1cf9 Akinobu Mita 2006-03-26 99 /**
4117b02132d1cf9 Akinobu Mita 2006-03-26 100 * test_bit - Determine whether a bit is set
4117b02132d1cf9 Akinobu Mita 2006-03-26 101 * @nr: bit number to test
4117b02132d1cf9 Akinobu Mita 2006-03-26 102 * @addr: Address to start counting from
4117b02132d1cf9 Akinobu Mita 2006-03-26 103 */
4117b02132d1cf9 Akinobu Mita 2006-03-26 @104 static inline int test_bit(int nr, const volatile unsigned long *addr)
4117b02132d1cf9 Akinobu Mita 2006-03-26 105 {
d05be13bcc6ec61 Jiri Slaby 2007-10-18 106 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
4117b02132d1cf9 Akinobu Mita 2006-03-26 107 }4117b02132d1cf9 Akinobu Mita 2006-03-26 108
:::::: The code at line 104 was first introduced by commit
:::::: 4117b02132d1cf96a3e1c57148e302c4801c974d [PATCH] bitops: generic __{,test_and_}{set,clear,change}_bit() and test_bit()
:::::: TO: Akinobu Mita <[email protected]>
:::::: CC: Linus Torvalds <[email protected]>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kbuild test robot
build botRe: [PATCH v3 05/11] riscv: Add clear_bit_unlock_is_negative_byte implementation
In reply to Matthew WilcoxThank you for the patch! Yet something to improve:
Hi Matthew,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on ia64/next]
[also build test ERROR on m68k/for-next s390/features linus/master v5.7-rc1 next-20200416] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Matthew-Wilcox/Make-PageWriteback-use-the-PageLocked-optimisation/20200417-060442 base: https://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git next config: riscv-nommu_virt_defconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:19,
from arch/riscv/include/asm/bug.h:75,
from include/linux/bug.h:5,
from include/linux/page-flags.h:10,
from kernel/bounds.c:10:
arch/riscv/include/asm/bitops.h: In function 'clear_bit_unlock_is_negative_byte':
>> arch/riscv/include/asm/bitops.h:178:9: error: implicit declaration of function 'test_bit'; did you mean 'set_bit'? [-Werror=implicit-function-declaration]
178 | return test_bit(7, p);
| ^~~~~~~~
| set_bit
In file included from arch/riscv/include/asm/bitops.h:208,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:19,
from arch/riscv/include/asm/bug.h:75,
from include/linux/bug.h:5,
from include/linux/page-flags.h:10,
from kernel/bounds.c:10:
include/asm-generic/bitops/non-atomic.h: At top level:
include/asm-generic/bitops/non-atomic.h:104:19: error: static declaration of 'test_bit' follows non-static declaration
104 | static inline int test_bit(int nr, const volatile unsigned long *addr)
| ^~~~~~~~
In file included from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from include/asm-generic/bug.h:19,
from arch/riscv/include/asm/bug.h:75,
from include/linux/bug.h:5,
from include/linux/page-flags.h:10,
from kernel/bounds.c:10:
arch/riscv/include/asm/bitops.h:178:9: note: previous implicit declaration of 'test_bit' was here
178 | return test_bit(7, p);
| ^~~~~~~~ cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:101: kernel/bounds.s] Error 1 make[2]: Target '__build' not remade because of errors. make[1]: *** [Makefile:1113: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:180: sub-make] Error 2
25 real 6 user 17 sys 91.90% cpu make prepare
vim +178 arch/riscv/include/asm/bitops.h
173
174 static inline bool clear_bit_unlock_is_negative_byte(unsigned int nr,
175 volatile unsigned long *p)
176 {
177 clear_bit_unlock(nr, p);
> 178 return test_bit(7, p);
179 }
180
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Matthew Wilcox
maintainerPATCH v3 6/11 s390: Add clear_bit_unlock_is_negative_byte implementation
In reply to Matthew WilcoxFrom: "Matthew Wilcox (Oracle)" <[email protected]>
This is the generic implementation. I can't figure out an optimised implementation for s390.
--- arch/s390/include/asm/bitops.h | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/s390/include/asm/bitops.h +9 -0
@@ -241,6 +241,15 @@ static inline void arch___clear_bit_unlock(unsigned long nr,arch___clear_bit (nr, ptr); } +static inline bool arch_clear_bit_unlock_is_negative_byte (unsigned int nr, +volatile unsigned long *p) +{ +arch_clear_bit_unlock (nr, p); +return arch_test_bit (7 , p); +} +#define arch_clear_bit_unlock_is_negative_byte \ + arch_clear_bit_unlock_is_negative_byte +#include <asm-generic/bitops/instrumented-atomic.h> #include <asm-generic/bitops/instrumented-non-atomic.h> #include <asm-generic/bitops/instrumented-lock.h>
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerPATCH v3 7/11 mm: Remove definition of clear_bit_unlock_is_negative_byte
In reply to Matthew WilcoxFrom: "Matthew Wilcox (Oracle)" <[email protected]>
All architectures now have a definition of clear_bit_unlock_is_negative_byte(), either their own or through asm-generic/bitops/lock.h
--- mm/filemap.c | 23 ----------------------- 1 file changed, 23 deletions(-)
mm/filemap.c +0 -23
@@ -1248,29 +1248,6 @@ void add_page_wait_queue(struct page *page, wait_queue_entry_t *waiter) }EXPORT_SYMBOL_GPL (add_page_wait_queue); -#ifndef clear_bit_unlock_is_negative_byte - -/* -* PG_waiters is the high bit in the same byte as PG_lock. -* -* On x86 (and on many other architectures), we can clear PG_lock and -* test the sign bit at the same time. But if the architecture does -* not support that special operation, we just do this all by hand -* instead. -* -* The read of PG_waiters has to be after (or concurrently with) PG_locked -* being cleared, but a memory barrier should be unneccssary since it is -* in the same byte as PG_locked. -*/ -static inline bool clear_bit_unlock_is_negative_byte (long nr,volatile void *mem) -{ -clear_bit_unlock (nr, mem); -/* smp_mb__after_atomic(); */ -return test_bit (PG_waiters, mem); -} - -#endif -/** * unlock_page - unlock a locked page * @page: the page
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerPATCH v3 8/11 mm: Move PG_writeback into the bottom byte
In reply to Matthew WilcoxFrom: "Matthew Wilcox (Oracle)" <[email protected]>
By placing PG_writeback in the bottom byte along with PG_locked and PG_waiters, we will be able to use the same optimisation as PG_locked in the next patch. Add BUILD_BUGs to ensure that all three bits stay in the bottom byte.
--- include/linux/page-flags.h | 4 ++-- mm/filemap.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-)
include/linux/page-flags.h +2 -2
@@ -103,13 +103,14 @@*/ enum pageflags { PG_locked,/* Page is locked. Don't touch. */ + PG_writeback,/* Page is under writeback */ PG_referenced, PG_uptodate, PG_dirty, PG_lru, PG_active, + PG_waiters,/* Page has waiters, check its waitqueue */ PG_workingset, - PG_waiters,/* Page has waiters, check its waitqueue. Must be bit #7 and in the same byte as "PG_locked" */ PG_error, PG_slab, PG_owner_priv_1,/* Owner use. If pagecache, fs may use*/
@@ -117,7 +118,6 @@ enum pageflags { PG_reserved, PG_private,/* If pagecache, has fs-private data */ PG_private_2,/* If pagecache, has fs aux data */ - PG_writeback,/* Page is under writeback */ PG_head,/* A head page */ PG_mappedtodisk,/* Has blocks allocated on-disk */ PG_reclaim, /* To be reclaimed asap */
mm/filemap.c +3 -1
@@ -1266,6 +1266,7 @@ EXPORT_SYMBOL_GPL(add_page_wait_queue);void unlock_page (struct page *page) {BUILD_BUG_ON (PG_waiters !=7 ); +BUILD_BUG_ON (PG_locked >7 ); page =compound_head (page);VM_BUG_ON_PAGE (!PageLocked (page), page);if (clear_bit_unlock_is_negative_byte (PG_locked, &page->flags))
@@ -1279,12 +1280,13 @@ EXPORT_SYMBOL(unlock_page);*/ void end_page_writeback (struct page *page) { +BUILD_BUG_ON (PG_writeback >7 );/* * TestClearPageReclaim could be used here but it is an atomic * operation and overkill in this particular case. Failing to * shuffle a page marked for immediate reclaim is too mild to * justify taking an atomic operation penalty at the end of -* ever page writeback. +* every page writeback. */ if (PageReclaim (page)) {ClearPageReclaim (page);
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerPATCH v3 9/11 mm: Convert writeback BUG to WARN_ON
In reply to Matthew WilcoxFrom: "Matthew Wilcox (Oracle)" <[email protected]>
If this BUG() ever triggers, we'll have a dead system with no particular information. Dumping the page will give us a fighting chance of debugging the problem, and I think it's safe for us to just continue if we try to clear the writeback bit on a page which already has the writeback bit clear.
--- mm/filemap.c | 4 +--- mm/page-writeback.c | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-)
mm/filemap.c +1 -3
@@ -1293,9 +1293,7 @@ void end_page_writeback(struct page *page)rotate_reclaimable_page (page); } -if (!test_clear_page_writeback (page)) -BUG (); - +test_clear_page_writeback (page);smp_mb__after_atomic ();wake_up_page (page, PG_writeback); }
mm/page-writeback.c +5 -0
@@ -2718,6 +2718,11 @@ int test_clear_page_writeback(struct page *page)struct lruvec *lruvec;int ret; +if (WARN_ON (!PageWriteback (page))) { +dump_page (page,"!writeback" ); +return false; + } + memcg =lock_page_memcg (page); lruvec =mem_cgroup_page_lruvec (page,page_pgdat (page));if (mapping &&mapping_use_writeback_tags (mapping)) {
Signature · 1 line
2.25.1
Jan Kara
maintainerRe: [PATCH v3 09/11] mm: Convert writeback BUG to WARN_ON
Quoted 34 lines · Matthew Wilcox
From: "Matthew Wilcox (Oracle)" <[email protected]>
If this
BUG()ever triggers, we'll have a dead system with no particular information. Dumping the page will give us a fighting chance of debugging the problem, and I think it's safe for us to just continue if we try to clear the writeback bit on a page which already has the writeback bit clear.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- mm/filemap.c | 4 +--- mm/page-writeback.c | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-)mm/filemap.c +1
-3@@ -1293,9 +1293,7 @@ void end_page_writeback(struct page *page)rotate_reclaimable_page (page); } -if (!test_clear_page_writeback (page)) -BUG (); - +test_clear_page_writeback (page);smp_mb__after_atomic ();wake_up_page (page, PG_writeback); }mm/page-writeback.c +0
-0
mm/page-writeback.c int test_clear_page_writeback(struct page *page) · line 2725
Quoted 8 lines
mm/page-writeback.c +5
-0@@ -2718,6 +2718,11 @@ int test_clear_page_writeback(struct page *page)struct lruvec *lruvec;int ret; +if (WARN_ON (!PageWriteback (page))) { +dump_page (page,"!writeback" ); +return false; + } +
WARN_ON_ONCE() here perhaps? I don't think dumping more pages will bring that much value...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Matthew Wilcox
maintainerPATCH v3 10/11 mm: Use clear_bit_unlock_is_negative_byte for PageWriteback
In reply to Matthew WilcoxFrom: "Matthew Wilcox (Oracle)" <[email protected]>
We can use clear_bit_unlock_is_negative_byte() for writeback as well as the lock bit. wake_up_page() then has no more callers and can be removed.
Given the other code being executed between the clear and the test, this is not going to be as dramatic a win as it was for PageLocked, but symmetry between the two is nice and lets us remove some code.
--- include/linux/page-flags.h | 2 +- mm/filemap.c | 12 ++---------- mm/page-writeback.c | 37 ++++++++++++++++++++----------------- 3 files changed, 23 insertions(+), 28 deletions(-)
include/linux/page-flags.h +1 -1
@@ -545,7 +545,7 @@ static __always_inline void SetPageUptodate(struct page *page) CLEARPAGEFLAG(Uptodate, uptodate, PF_NO_TAIL) -int test_clear_page_writeback (struct page *page); +bool __clear_page_writeback (struct page *page);int __test_set_page_writeback (struct page *page,bool keep_write);#define test_set_page_writeback (page) \
mm/filemap.c +2 -10
@@ -1084,13 +1084,6 @@ static void wake_up_page_bit(struct page *page, int bit_nr)spin_unlock_irqrestore (&q->lock, flags); } -static void wake_up_page (struct page *page,int bit) -{ -if (!PageWaiters (page)) -return ; -wake_up_page_bit (page, bit); -} -/* * A choice of three behaviors for wait_on_page_bit_common(): */
@@ -1293,9 +1286,8 @@ void end_page_writeback(struct page *page)rotate_reclaimable_page (page); } -test_clear_page_writeback (page); -smp_mb__after_atomic (); -wake_up_page (page, PG_writeback); +if (__clear_page_writeback (page)) +wake_up_page_bit (page, PG_writeback); }EXPORT_SYMBOL (end_page_writeback);
mm/page-writeback.c +20 -17
@@ -595,7 +595,7 @@ static void wb_domain_writeout_inc(struct wb_domain *dom,/* * Increment @wb's writeout completion count and the global writeout -* completion count. Called from test_clear_page_writeback(). +* completion count. */ static inline void __wb_writeout_inc (struct bdi_writeback *wb) {
@@ -2711,12 +2711,19 @@ int clear_page_dirty_for_io(struct page *page) }EXPORT_SYMBOL (clear_page_dirty_for_io); -int test_clear_page_writeback (struct page *page) +#define clear_writeback_bit (page) \ + clear_bit_unlock_is_negative_byte(PG_writeback, &page->flags) + +/* +* The return value is whether there are waiters pending, not whether +* the flag was set. +*/ +bool __clear_page_writeback (struct page *page) {struct address_space *mapping =page_mapping (page);struct mem_cgroup *memcg;struct lruvec *lruvec; -int ret; +bool ret;if (WARN_ON (!PageWriteback (page))) {dump_page (page,"!writeback" );
@@ -2731,16 +2738,14 @@ int test_clear_page_writeback(struct page *page)unsigned long flags;xa_lock_irqsave (&mapping->i_pages, flags); - ret =TestClearPageWriteback (page); -if (ret) { -__xa_clear_mark (&mapping->i_pages,page_index (page), + ret =clear_writeback_bit (page); +__xa_clear_mark (&mapping->i_pages,page_index (page),PAGECACHE_TAG_WRITEBACK ); -if (bdi_cap_account_writeback (bdi)) { -struct bdi_writeback *wb =inode_to_wb (inode); +if (bdi_cap_account_writeback (bdi)) { +struct bdi_writeback *wb =inode_to_wb (inode); -dec_wb_stat (wb,WB_WRITEBACK ); -__wb_writeout_inc (wb); - } +dec_wb_stat (wb,WB_WRITEBACK ); +__wb_writeout_inc (wb); } if (mapping->host && !mapping_tagged(mapping,
@@ -2749,7 +2754,7 @@ int test_clear_page_writeback(struct page *page)xa_unlock_irqrestore (&mapping->i_pages, flags); }else { - ret =TestClearPageWriteback (page); + ret =clear_writeback_bit (page); }/* * NOTE: Page might be free now! Writeback doesn't hold a page
@@ -2757,11 +2762,9 @@ int test_clear_page_writeback(struct page *page)* the clearing of PG_writeback. The below can only access * page state that is static across allocation cycles. */ -if (ret) { -dec_lruvec_state (lruvec,NR_WRITEBACK ); -dec_zone_page_state (page,NR_ZONE_WRITE_PENDING ); -inc_node_page_state (page,NR_WRITTEN ); - } +dec_lruvec_state (lruvec,NR_WRITEBACK ); +dec_zone_page_state (page,NR_ZONE_WRITE_PENDING ); +inc_node_page_state (page,NR_WRITTEN );__unlock_page_memcg (memcg);return ret; }
Signature · 1 line
2.25.1
Matthew Wilcox
maintainerPATCH v3 11/11 mm: Remove TestClearPageWriteback
In reply to Matthew WilcoxFrom: "Matthew Wilcox (Oracle)" <[email protected]>
The last commit removed the only caller of TestClearPageWriteback(), so remove the definition.
--- include/linux/page-flags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/page-flags.h +1 -1
@@ -365,7 +365,7 @@ PAGEFLAG(OwnerPriv1, owner_priv_1, PF_ANY)* risky: they bypass page accounting. */ TESTPAGEFLAG(Writeback, writeback, PF_NO_TAIL) - TESTSCFLAG(Writeback, writeback, PF_NO_TAIL) + TESTSETFLAG(Writeback, writeback, PF_NO_TAIL)PAGEFLAG (MappedToDisk, mappedtodisk,PF_NO_TAIL )/* PG_readahead is only used for reads; PG_reclaim is only for writes */
Signature · 1 line
2.25.1
Geert Uytterhoeven
maintainerHi Matthew,
Quoted 15 lines · Matthew Wilcox
From: "Matthew Wilcox (Oracle)" <[email protected]> PageWaiters is used by PageWriteback and PageLocked (and no other page flags), so it makes sense to use the same codepaths that have already been optimised for PageLocked, even if there's probably no real performance benefit to be had.
Unfortunately,
clear_bit_unlock_is_negative_byte()isn't present on every architecture, and the default implementation is only available infilemap.cwhile I want to use it inpage-writeback.c. Rather than move the default implementation to a header file, I've done optimised implementations for alpha and ia64. I can't figure out optimised implementations for m68k, mips, riscv and s390, so I've just replicated the effect of the generic implementation in them. I leave it to the experts to fix that (... or convert over to usingasm-generic/bitops/lock.h...)
Quoted 3 lines
v3:
- Added implementations ofclear_bit_unlock_is_negative_byte()to architectures which need it
I have two questions here?
1. Why not implement arch_clear_bit_unlock_is_negative_byte() instead, so the kasan check in asm-generic is used everywhere?
2. Why not add the default implementation to include/asm-generic/bitops/instrumented-lock.h, in case an arch_*() variant is not provided yet?
Note that you did 1 for s390.
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Matthew Wilcox
maintainerQuoted 8 lines · Geert Uytterhoeven
Quoted 3 lines · Matthew Wilcox
v3:
- Added implementations ofclear_bit_unlock_is_negative_byte()to architectures which need itI have two questions here?
1. Why not implementarch_clear_bit_unlock_is_negative_byte()instead, so the kasan check in asm-generic is used everywhere?
That would be a larger change. As I understand it (and I may misunderstand it), I would need to rename all the clear_bit(), __clear_bit(), change_bit(), ... functions to have an 'arch_' prefix and then include instrumented-lock.h
Quoted 5 lines
2. Why not add the default implementation to
include/asm-generic/bitops/instrumented-lock.h, in case an arch_*() variant is not provided yet?Note that you did 1 for s390.
Well, s390 already uses instrumented-lock.h so I followed along with what they're doing. I don't think instrumented-lock.h is used at all on these other architectures, but the whole bitops header files are such a mess that I could easily have built a completely wrong mental model of what's going on.