OpenCloudOS-Kernel/fs
Roman Gushchin 6eff319e75 mm, memcg: rework remote charging API to support nesting
commit b87d8cefe4 upstream.

Currently the remote memcg charging API consists of two functions:
memalloc_use_memcg() and memalloc_unuse_memcg(), which set and clear the
memcg value, which overwrites the memcg of the current task.

  memalloc_use_memcg(target_memcg);
  <...>
  memalloc_unuse_memcg();

It works perfectly for allocations performed from a normal context,
however an attempt to call it from an interrupt context or just nest two
remote charging blocks will lead to an incorrect accounting.  On exit from
the inner block the active memcg will be cleared instead of being
restored.

  memalloc_use_memcg(target_memcg);

  memalloc_use_memcg(target_memcg_2);
    <...>
    memalloc_unuse_memcg();

    Error: allocation here are charged to the memcg of the current
    process instead of target_memcg.

  memalloc_unuse_memcg();

This patch extends the remote charging API by switching to a single
function: struct mem_cgroup *set_active_memcg(struct mem_cgroup *memcg),
which sets the new value and returns the old one.  So a remote charging
block will look like:

  old_memcg = set_active_memcg(target_memcg);
  <...>
  set_active_memcg(old_memcg);

This patch is heavily based on the patch by Johannes Weiner, which can be
found here: https://lkml.org/lkml/2020/5/28/806 .

Intel-SIG: commit b87d8cefe4 mm, memcg: rework remote charging API to
support nesting
Backport for SGX virtualization support on Intel Xeon platform.

Signed-off-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Dan Schatzberg <dschatzberg@fb.com>
Link: https://lkml.kernel.org/r/20200821212056.3769116-1-guro@fb.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[ Zhiquan Li: amend commit log and resolve the conflict.
  The memalloc_use_memcg/memalloc_unuse_memcg() call in mm/memcontrol.c
  have not been introduced in v5.4, so discards the changes.
  Since the APIs have been changed to set_active_memcg(), it will be
  noticed if old APIs call be backported in future.
]
Signed-off-by: Zhiquan Li <zhiquan1.li@intel.com>
2024-06-11 21:23:42 +08:00
..
9p ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
adfs Merge branch 'work.adfs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-07-19 11:33:22 -07:00
affs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
afs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
autofs autofs: fix a leak in autofs_expire_indirect() 2019-10-25 00:03:11 -04:00
befs fs: Fill in max and min timestamps in superblock 2019-08-30 07:27:17 -07:00
bfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
btrfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
cachefiles ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ceph ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
cgroupfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
cifs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
coda y2038: add inode timestamp clamping 2019-09-19 09:42:37 -07:00
configfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
cramfs cramfs: fix usage on non-MTD device 2019-11-23 21:44:49 -05:00
crypto ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
debugfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
devpts devpts_pty_kill(): don't bother with d_delete() 2019-09-03 09:30:56 -04:00
dlm ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ecryptfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
efivarfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
efs fs: Fill in max and min timestamps in superblock 2019-08-30 07:27:17 -07:00
erofs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
exportfs exportfs_decode_fh(): negative pinned may become positive without the parent locked 2019-11-10 11:56:05 -05:00
ext2 ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ext4 ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
f2fs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
fat compat_ioctl: move drivers to compat_ptr_ioctl 2024-06-11 21:14:45 +08:00
freevxfs fs: Fill in max and min timestamps in superblock 2019-08-30 07:27:17 -07:00
fscache Revert "Merge tag 'keys-acl-20190703' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs" 2019-07-10 18:43:43 -07:00
fuse fuse: fix one null ptr issue in fuse_dev_ioctl 2024-06-11 21:18:45 +08:00
gfs2 ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
hfs treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
hfsplus ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
hostfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
hpfs fs: hpfs: Initialize filesystem timestamp ranges 2019-08-30 08:11:25 -07:00
hugetlbfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
iomap Intel: generic_perform_write()/iomap_write_actor(): saner logics for short copy 2024-06-11 21:18:20 +08:00
isofs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
jbd2 ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
jffs2 ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
jfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
kernfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
lockd ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
minix ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
nfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
nfs_common ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
nfsd ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
nilfs2 ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
nls treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
notify mm, memcg: rework remote charging API to support nesting 2024-06-11 21:23:42 +08:00
ntfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ocfs2 ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
omfs fs: omfs: Initialize filesystem timestamp ranges 2019-08-30 08:11:25 -07:00
openpromfs Merge branch 'work.mount0' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-07-19 10:42:02 -07:00
orangefs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
overlayfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
proc x86/resctrl: Add task resctrl information display 2024-06-11 21:12:54 +08:00
pstore ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
qnx4 fs: Fill in max and min timestamps in superblock 2019-08-30 07:27:17 -07:00
qnx6 fs: Fill in max and min timestamps in superblock 2019-08-30 07:27:17 -07:00
quota ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ramfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
reiserfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
romfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
squashfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
sysfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
sysv fs: sysv: Initialize filesystem timestamp ranges 2019-08-30 07:27:18 -07:00
tracefs tracing: Do not create tracefs files if tracefs lockdown is in effect 2019-10-12 20:49:07 -04:00
ubifs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
udf ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ufs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
unicode unicode: make array 'token' static const, makes object smaller 2019-09-17 11:48:24 -04:00
verity fs-verity: support builtin file signatures 2019-08-12 19:33:50 -07:00
xfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
Kconfig ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
Kconfig.binfmt binfmt_flat: make support for old format binaries optional 2019-06-24 09:16:47 +10:00
Makefile ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
aio.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
anon_inodes.c Merge branch 'work.mount0' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-07-19 10:42:02 -07:00
attr.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
bad_inode.c
binfmt_aout.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
binfmt_elf.c introduction of regset ->get() wrappers, switching ELF coredumps to those 2024-06-11 21:05:54 +08:00
binfmt_elf_fdpic.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
binfmt_em86.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
binfmt_flat.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
binfmt_misc.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
binfmt_script.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
block_dev.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
buffer.c mm, memcg: rework remote charging API to support nesting 2024-06-11 21:23:42 +08:00
char_dev.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
compat.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
compat_binfmt_elf.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
compat_ioctl.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
coredump.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
d_path.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
dax.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
dcache.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
dcookies.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
direct-io.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
drop_caches.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
eventfd.c eventfd: Export eventfd_ctx_do_read() 2024-06-11 21:15:04 +08:00
eventpoll.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
exec.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
fcntl.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
fhandle.c fs/handle.c - fix up kerneldoc 2019-08-07 21:51:47 -04:00
file.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
file_table.c vfs: Export flush_delayed_fput for use by knfsd. 2019-08-19 11:00:39 -04:00
filesystems.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
fs-writeback.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
fs_context.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
fs_parser.c vfs: Make fs_parse() handle fs_param_is_fd-type params better 2019-09-12 21:06:14 -04:00
fs_pin.c switch the remnants of releasing the mountpoint away from fs_pin 2019-07-16 22:52:37 -04:00
fs_struct.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
fs_types.c
fsopen.c Merge branch 'work.mount0' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-07-19 10:42:02 -07:00
inode.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
internal.h tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
io_uring.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ioctl.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
libfs.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
locks.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
mbcache.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
mount.h switch the remnants of releasing the mountpoint away from fs_pin 2019-07-16 22:52:37 -04:00
mpage.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
namei.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
namespace.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
no-block.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
nsfs.c vfs: Convert nsfs to use the new mount API 2019-05-25 18:00:06 -04:00
open.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
pipe.c vfs: Convert pipe to use the new mount API 2019-05-25 18:00:07 -04:00
pnode.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
pnode.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
posix_acl.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
proc_namespace.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
read_write.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
readdir.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
select.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
seq_file.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
signalfd.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
splice.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
stack.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
stat.c
statfs.c vfs: Fix EOVERFLOW testing in put_compat_statfs64 2019-10-03 14:21:35 -07:00
super.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
sync.c fs/sync.c: sync_file_range(2) may use WB_SYNC_ALL writeback 2019-05-14 09:47:50 -07:00
timerfd.c timerfd: Prepare for PREEMPT_RT 2019-08-01 20:51:23 +02:00
userfaultfd.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
utimes.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
xattr.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00