[resource_quota] Periodically return memory to central quota (#30268)

* [resource_quota] Periodically return memory to central quota

* Automated change: Fix sanity tests

* Automated change: Fix sanity tests

* optionalize features

* fix periodic update behavior around initialization

* fix

* fix

* fix

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/30325/head
Craig Tiller 2 years ago committed by GitHub
parent a1d42f84ef
commit 6fc2511e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      BUILD
  2. 10
      CMakeLists.txt
  3. 2
      Makefile
  4. 20
      build_autogenerated.yaml
  5. 1
      config.m4
  6. 1
      config.w32
  7. 2
      gRPC-C++.podspec
  8. 3
      gRPC-Core.podspec
  9. 2
      grpc.gemspec
  10. 2
      grpc.gyp
  11. 2
      package.xml
  12. 23
      src/core/lib/resource_quota/memory_quota.cc
  13. 31
      src/core/lib/resource_quota/memory_quota.h
  14. 6
      src/core/lib/resource_quota/periodic_update.cc
  15. 3
      src/core/lib/resource_quota/periodic_update.h
  16. 1
      src/python/grpcio/grpc_core_dependencies.py
  17. 2
      tools/doxygen/Doxyfile.c++.internal
  18. 2
      tools/doxygen/Doxyfile.core.internal

@ -1860,11 +1860,13 @@ grpc_cc_library(
"loop", "loop",
"map", "map",
"orphanable", "orphanable",
"periodic_update",
"poll", "poll",
"race", "race",
"ref_counted_ptr", "ref_counted_ptr",
"resource_quota_trace", "resource_quota_trace",
"seq", "seq",
"time",
"useful", "useful",
], ],
) )

10
CMakeLists.txt generated

@ -2184,6 +2184,7 @@ add_library(grpc
src/core/lib/resource_quota/api.cc src/core/lib/resource_quota/api.cc
src/core/lib/resource_quota/arena.cc src/core/lib/resource_quota/arena.cc
src/core/lib/resource_quota/memory_quota.cc src/core/lib/resource_quota/memory_quota.cc
src/core/lib/resource_quota/periodic_update.cc
src/core/lib/resource_quota/resource_quota.cc src/core/lib/resource_quota/resource_quota.cc
src/core/lib/resource_quota/thread_quota.cc src/core/lib/resource_quota/thread_quota.cc
src/core/lib/resource_quota/trace.cc src/core/lib/resource_quota/trace.cc
@ -2810,6 +2811,7 @@ add_library(grpc_unsecure
src/core/lib/resource_quota/api.cc src/core/lib/resource_quota/api.cc
src/core/lib/resource_quota/arena.cc src/core/lib/resource_quota/arena.cc
src/core/lib/resource_quota/memory_quota.cc src/core/lib/resource_quota/memory_quota.cc
src/core/lib/resource_quota/periodic_update.cc
src/core/lib/resource_quota/resource_quota.cc src/core/lib/resource_quota/resource_quota.cc
src/core/lib/resource_quota/thread_quota.cc src/core/lib/resource_quota/thread_quota.cc
src/core/lib/resource_quota/trace.cc src/core/lib/resource_quota/trace.cc
@ -5959,6 +5961,7 @@ add_executable(arena_promise_test
src/core/lib/promise/activity.cc src/core/lib/promise/activity.cc
src/core/lib/resource_quota/arena.cc src/core/lib/resource_quota/arena.cc
src/core/lib/resource_quota/memory_quota.cc src/core/lib/resource_quota/memory_quota.cc
src/core/lib/resource_quota/periodic_update.cc
src/core/lib/resource_quota/resource_quota.cc src/core/lib/resource_quota/resource_quota.cc
src/core/lib/resource_quota/thread_quota.cc src/core/lib/resource_quota/thread_quota.cc
src/core/lib/resource_quota/trace.cc src/core/lib/resource_quota/trace.cc
@ -7587,6 +7590,7 @@ add_executable(chunked_vector_test
src/core/lib/promise/activity.cc src/core/lib/promise/activity.cc
src/core/lib/resource_quota/arena.cc src/core/lib/resource_quota/arena.cc
src/core/lib/resource_quota/memory_quota.cc src/core/lib/resource_quota/memory_quota.cc
src/core/lib/resource_quota/periodic_update.cc
src/core/lib/resource_quota/resource_quota.cc src/core/lib/resource_quota/resource_quota.cc
src/core/lib/resource_quota/thread_quota.cc src/core/lib/resource_quota/thread_quota.cc
src/core/lib/resource_quota/trace.cc src/core/lib/resource_quota/trace.cc
@ -9782,6 +9786,7 @@ add_executable(flow_control_test
src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_internal.cc
src/core/lib/promise/activity.cc src/core/lib/promise/activity.cc
src/core/lib/resource_quota/memory_quota.cc src/core/lib/resource_quota/memory_quota.cc
src/core/lib/resource_quota/periodic_update.cc
src/core/lib/resource_quota/resource_quota.cc src/core/lib/resource_quota/resource_quota.cc
src/core/lib/resource_quota/thread_quota.cc src/core/lib/resource_quota/thread_quota.cc
src/core/lib/resource_quota/trace.cc src/core/lib/resource_quota/trace.cc
@ -9847,6 +9852,7 @@ add_executable(for_each_test
src/core/lib/promise/activity.cc src/core/lib/promise/activity.cc
src/core/lib/resource_quota/arena.cc src/core/lib/resource_quota/arena.cc
src/core/lib/resource_quota/memory_quota.cc src/core/lib/resource_quota/memory_quota.cc
src/core/lib/resource_quota/periodic_update.cc
src/core/lib/resource_quota/resource_quota.cc src/core/lib/resource_quota/resource_quota.cc
src/core/lib/resource_quota/thread_quota.cc src/core/lib/resource_quota/thread_quota.cc
src/core/lib/resource_quota/trace.cc src/core/lib/resource_quota/trace.cc
@ -12724,6 +12730,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX)
src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_internal.cc
src/core/lib/promise/activity.cc src/core/lib/promise/activity.cc
src/core/lib/resource_quota/memory_quota.cc src/core/lib/resource_quota/memory_quota.cc
src/core/lib/resource_quota/periodic_update.cc
src/core/lib/resource_quota/trace.cc src/core/lib/resource_quota/trace.cc
src/core/lib/slice/percent_encoding.cc src/core/lib/slice/percent_encoding.cc
src/core/lib/slice/slice.cc src/core/lib/slice/slice.cc
@ -12784,6 +12791,7 @@ add_executable(memory_quota_test
src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_internal.cc
src/core/lib/promise/activity.cc src/core/lib/promise/activity.cc
src/core/lib/resource_quota/memory_quota.cc src/core/lib/resource_quota/memory_quota.cc
src/core/lib/resource_quota/periodic_update.cc
src/core/lib/resource_quota/trace.cc src/core/lib/resource_quota/trace.cc
src/core/lib/slice/percent_encoding.cc src/core/lib/slice/percent_encoding.cc
src/core/lib/slice/slice.cc src/core/lib/slice/slice.cc
@ -13821,6 +13829,7 @@ add_executable(pipe_test
src/core/lib/promise/activity.cc src/core/lib/promise/activity.cc
src/core/lib/resource_quota/arena.cc src/core/lib/resource_quota/arena.cc
src/core/lib/resource_quota/memory_quota.cc src/core/lib/resource_quota/memory_quota.cc
src/core/lib/resource_quota/periodic_update.cc
src/core/lib/resource_quota/resource_quota.cc src/core/lib/resource_quota/resource_quota.cc
src/core/lib/resource_quota/thread_quota.cc src/core/lib/resource_quota/thread_quota.cc
src/core/lib/resource_quota/trace.cc src/core/lib/resource_quota/trace.cc
@ -14678,6 +14687,7 @@ add_executable(resource_quota_test
src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_internal.cc
src/core/lib/promise/activity.cc src/core/lib/promise/activity.cc
src/core/lib/resource_quota/memory_quota.cc src/core/lib/resource_quota/memory_quota.cc
src/core/lib/resource_quota/periodic_update.cc
src/core/lib/resource_quota/resource_quota.cc src/core/lib/resource_quota/resource_quota.cc
src/core/lib/resource_quota/thread_quota.cc src/core/lib/resource_quota/thread_quota.cc
src/core/lib/resource_quota/trace.cc src/core/lib/resource_quota/trace.cc

2
Makefile generated

@ -1557,6 +1557,7 @@ LIBGRPC_SRC = \
src/core/lib/resource_quota/api.cc \ src/core/lib/resource_quota/api.cc \
src/core/lib/resource_quota/arena.cc \ src/core/lib/resource_quota/arena.cc \
src/core/lib/resource_quota/memory_quota.cc \ src/core/lib/resource_quota/memory_quota.cc \
src/core/lib/resource_quota/periodic_update.cc \
src/core/lib/resource_quota/resource_quota.cc \ src/core/lib/resource_quota/resource_quota.cc \
src/core/lib/resource_quota/thread_quota.cc \ src/core/lib/resource_quota/thread_quota.cc \
src/core/lib/resource_quota/trace.cc \ src/core/lib/resource_quota/trace.cc \
@ -2022,6 +2023,7 @@ LIBGRPC_UNSECURE_SRC = \
src/core/lib/resource_quota/api.cc \ src/core/lib/resource_quota/api.cc \
src/core/lib/resource_quota/arena.cc \ src/core/lib/resource_quota/arena.cc \
src/core/lib/resource_quota/memory_quota.cc \ src/core/lib/resource_quota/memory_quota.cc \
src/core/lib/resource_quota/periodic_update.cc \
src/core/lib/resource_quota/resource_quota.cc \ src/core/lib/resource_quota/resource_quota.cc \
src/core/lib/resource_quota/thread_quota.cc \ src/core/lib/resource_quota/thread_quota.cc \
src/core/lib/resource_quota/trace.cc \ src/core/lib/resource_quota/trace.cc \

@ -873,6 +873,7 @@ libs:
- src/core/lib/resource_quota/api.h - src/core/lib/resource_quota/api.h
- src/core/lib/resource_quota/arena.h - src/core/lib/resource_quota/arena.h
- src/core/lib/resource_quota/memory_quota.h - src/core/lib/resource_quota/memory_quota.h
- src/core/lib/resource_quota/periodic_update.h
- src/core/lib/resource_quota/resource_quota.h - src/core/lib/resource_quota/resource_quota.h
- src/core/lib/resource_quota/thread_quota.h - src/core/lib/resource_quota/thread_quota.h
- src/core/lib/resource_quota/trace.h - src/core/lib/resource_quota/trace.h
@ -1539,6 +1540,7 @@ libs:
- src/core/lib/resource_quota/api.cc - src/core/lib/resource_quota/api.cc
- src/core/lib/resource_quota/arena.cc - src/core/lib/resource_quota/arena.cc
- src/core/lib/resource_quota/memory_quota.cc - src/core/lib/resource_quota/memory_quota.cc
- src/core/lib/resource_quota/periodic_update.cc
- src/core/lib/resource_quota/resource_quota.cc - src/core/lib/resource_quota/resource_quota.cc
- src/core/lib/resource_quota/thread_quota.cc - src/core/lib/resource_quota/thread_quota.cc
- src/core/lib/resource_quota/trace.cc - src/core/lib/resource_quota/trace.cc
@ -2090,6 +2092,7 @@ libs:
- src/core/lib/resource_quota/api.h - src/core/lib/resource_quota/api.h
- src/core/lib/resource_quota/arena.h - src/core/lib/resource_quota/arena.h
- src/core/lib/resource_quota/memory_quota.h - src/core/lib/resource_quota/memory_quota.h
- src/core/lib/resource_quota/periodic_update.h
- src/core/lib/resource_quota/resource_quota.h - src/core/lib/resource_quota/resource_quota.h
- src/core/lib/resource_quota/thread_quota.h - src/core/lib/resource_quota/thread_quota.h
- src/core/lib/resource_quota/trace.h - src/core/lib/resource_quota/trace.h
@ -2397,6 +2400,7 @@ libs:
- src/core/lib/resource_quota/api.cc - src/core/lib/resource_quota/api.cc
- src/core/lib/resource_quota/arena.cc - src/core/lib/resource_quota/arena.cc
- src/core/lib/resource_quota/memory_quota.cc - src/core/lib/resource_quota/memory_quota.cc
- src/core/lib/resource_quota/periodic_update.cc
- src/core/lib/resource_quota/resource_quota.cc - src/core/lib/resource_quota/resource_quota.cc
- src/core/lib/resource_quota/thread_quota.cc - src/core/lib/resource_quota/thread_quota.cc
- src/core/lib/resource_quota/trace.cc - src/core/lib/resource_quota/trace.cc
@ -3922,6 +3926,7 @@ targets:
- src/core/lib/promise/seq.h - src/core/lib/promise/seq.h
- src/core/lib/resource_quota/arena.h - src/core/lib/resource_quota/arena.h
- src/core/lib/resource_quota/memory_quota.h - src/core/lib/resource_quota/memory_quota.h
- src/core/lib/resource_quota/periodic_update.h
- src/core/lib/resource_quota/resource_quota.h - src/core/lib/resource_quota/resource_quota.h
- src/core/lib/resource_quota/thread_quota.h - src/core/lib/resource_quota/thread_quota.h
- src/core/lib/resource_quota/trace.h - src/core/lib/resource_quota/trace.h
@ -3947,6 +3952,7 @@ targets:
- src/core/lib/promise/activity.cc - src/core/lib/promise/activity.cc
- src/core/lib/resource_quota/arena.cc - src/core/lib/resource_quota/arena.cc
- src/core/lib/resource_quota/memory_quota.cc - src/core/lib/resource_quota/memory_quota.cc
- src/core/lib/resource_quota/periodic_update.cc
- src/core/lib/resource_quota/resource_quota.cc - src/core/lib/resource_quota/resource_quota.cc
- src/core/lib/resource_quota/thread_quota.cc - src/core/lib/resource_quota/thread_quota.cc
- src/core/lib/resource_quota/trace.cc - src/core/lib/resource_quota/trace.cc
@ -4551,6 +4557,7 @@ targets:
- src/core/lib/promise/seq.h - src/core/lib/promise/seq.h
- src/core/lib/resource_quota/arena.h - src/core/lib/resource_quota/arena.h
- src/core/lib/resource_quota/memory_quota.h - src/core/lib/resource_quota/memory_quota.h
- src/core/lib/resource_quota/periodic_update.h
- src/core/lib/resource_quota/resource_quota.h - src/core/lib/resource_quota/resource_quota.h
- src/core/lib/resource_quota/thread_quota.h - src/core/lib/resource_quota/thread_quota.h
- src/core/lib/resource_quota/trace.h - src/core/lib/resource_quota/trace.h
@ -4575,6 +4582,7 @@ targets:
- src/core/lib/promise/activity.cc - src/core/lib/promise/activity.cc
- src/core/lib/resource_quota/arena.cc - src/core/lib/resource_quota/arena.cc
- src/core/lib/resource_quota/memory_quota.cc - src/core/lib/resource_quota/memory_quota.cc
- src/core/lib/resource_quota/periodic_update.cc
- src/core/lib/resource_quota/resource_quota.cc - src/core/lib/resource_quota/resource_quota.cc
- src/core/lib/resource_quota/thread_quota.cc - src/core/lib/resource_quota/thread_quota.cc
- src/core/lib/resource_quota/trace.cc - src/core/lib/resource_quota/trace.cc
@ -5481,6 +5489,7 @@ targets:
- src/core/lib/promise/race.h - src/core/lib/promise/race.h
- src/core/lib/promise/seq.h - src/core/lib/promise/seq.h
- src/core/lib/resource_quota/memory_quota.h - src/core/lib/resource_quota/memory_quota.h
- src/core/lib/resource_quota/periodic_update.h
- src/core/lib/resource_quota/resource_quota.h - src/core/lib/resource_quota/resource_quota.h
- src/core/lib/resource_quota/thread_quota.h - src/core/lib/resource_quota/thread_quota.h
- src/core/lib/resource_quota/trace.h - src/core/lib/resource_quota/trace.h
@ -5507,6 +5516,7 @@ targets:
- src/core/lib/iomgr/iomgr_internal.cc - src/core/lib/iomgr/iomgr_internal.cc
- src/core/lib/promise/activity.cc - src/core/lib/promise/activity.cc
- src/core/lib/resource_quota/memory_quota.cc - src/core/lib/resource_quota/memory_quota.cc
- src/core/lib/resource_quota/periodic_update.cc
- src/core/lib/resource_quota/resource_quota.cc - src/core/lib/resource_quota/resource_quota.cc
- src/core/lib/resource_quota/thread_quota.cc - src/core/lib/resource_quota/thread_quota.cc
- src/core/lib/resource_quota/trace.cc - src/core/lib/resource_quota/trace.cc
@ -5571,6 +5581,7 @@ targets:
- src/core/lib/promise/wait_set.h - src/core/lib/promise/wait_set.h
- src/core/lib/resource_quota/arena.h - src/core/lib/resource_quota/arena.h
- src/core/lib/resource_quota/memory_quota.h - src/core/lib/resource_quota/memory_quota.h
- src/core/lib/resource_quota/periodic_update.h
- src/core/lib/resource_quota/resource_quota.h - src/core/lib/resource_quota/resource_quota.h
- src/core/lib/resource_quota/thread_quota.h - src/core/lib/resource_quota/thread_quota.h
- src/core/lib/resource_quota/trace.h - src/core/lib/resource_quota/trace.h
@ -5596,6 +5607,7 @@ targets:
- src/core/lib/promise/activity.cc - src/core/lib/promise/activity.cc
- src/core/lib/resource_quota/arena.cc - src/core/lib/resource_quota/arena.cc
- src/core/lib/resource_quota/memory_quota.cc - src/core/lib/resource_quota/memory_quota.cc
- src/core/lib/resource_quota/periodic_update.cc
- src/core/lib/resource_quota/resource_quota.cc - src/core/lib/resource_quota/resource_quota.cc
- src/core/lib/resource_quota/thread_quota.cc - src/core/lib/resource_quota/thread_quota.cc
- src/core/lib/resource_quota/trace.cc - src/core/lib/resource_quota/trace.cc
@ -6638,6 +6650,7 @@ targets:
- src/core/lib/promise/race.h - src/core/lib/promise/race.h
- src/core/lib/promise/seq.h - src/core/lib/promise/seq.h
- src/core/lib/resource_quota/memory_quota.h - src/core/lib/resource_quota/memory_quota.h
- src/core/lib/resource_quota/periodic_update.h
- src/core/lib/resource_quota/trace.h - src/core/lib/resource_quota/trace.h
- src/core/lib/slice/percent_encoding.h - src/core/lib/slice/percent_encoding.h
- src/core/lib/slice/slice.h - src/core/lib/slice/slice.h
@ -6659,6 +6672,7 @@ targets:
- src/core/lib/iomgr/iomgr_internal.cc - src/core/lib/iomgr/iomgr_internal.cc
- src/core/lib/promise/activity.cc - src/core/lib/promise/activity.cc
- src/core/lib/resource_quota/memory_quota.cc - src/core/lib/resource_quota/memory_quota.cc
- src/core/lib/resource_quota/periodic_update.cc
- src/core/lib/resource_quota/trace.cc - src/core/lib/resource_quota/trace.cc
- src/core/lib/slice/percent_encoding.cc - src/core/lib/slice/percent_encoding.cc
- src/core/lib/slice/slice.cc - src/core/lib/slice/slice.cc
@ -6712,6 +6726,7 @@ targets:
- src/core/lib/promise/race.h - src/core/lib/promise/race.h
- src/core/lib/promise/seq.h - src/core/lib/promise/seq.h
- src/core/lib/resource_quota/memory_quota.h - src/core/lib/resource_quota/memory_quota.h
- src/core/lib/resource_quota/periodic_update.h
- src/core/lib/resource_quota/trace.h - src/core/lib/resource_quota/trace.h
- src/core/lib/slice/percent_encoding.h - src/core/lib/slice/percent_encoding.h
- src/core/lib/slice/slice.h - src/core/lib/slice/slice.h
@ -6734,6 +6749,7 @@ targets:
- src/core/lib/iomgr/iomgr_internal.cc - src/core/lib/iomgr/iomgr_internal.cc
- src/core/lib/promise/activity.cc - src/core/lib/promise/activity.cc
- src/core/lib/resource_quota/memory_quota.cc - src/core/lib/resource_quota/memory_quota.cc
- src/core/lib/resource_quota/periodic_update.cc
- src/core/lib/resource_quota/trace.cc - src/core/lib/resource_quota/trace.cc
- src/core/lib/slice/percent_encoding.cc - src/core/lib/slice/percent_encoding.cc
- src/core/lib/slice/slice.cc - src/core/lib/slice/slice.cc
@ -7200,6 +7216,7 @@ targets:
- src/core/lib/promise/seq.h - src/core/lib/promise/seq.h
- src/core/lib/resource_quota/arena.h - src/core/lib/resource_quota/arena.h
- src/core/lib/resource_quota/memory_quota.h - src/core/lib/resource_quota/memory_quota.h
- src/core/lib/resource_quota/periodic_update.h
- src/core/lib/resource_quota/resource_quota.h - src/core/lib/resource_quota/resource_quota.h
- src/core/lib/resource_quota/thread_quota.h - src/core/lib/resource_quota/thread_quota.h
- src/core/lib/resource_quota/trace.h - src/core/lib/resource_quota/trace.h
@ -7225,6 +7242,7 @@ targets:
- src/core/lib/promise/activity.cc - src/core/lib/promise/activity.cc
- src/core/lib/resource_quota/arena.cc - src/core/lib/resource_quota/arena.cc
- src/core/lib/resource_quota/memory_quota.cc - src/core/lib/resource_quota/memory_quota.cc
- src/core/lib/resource_quota/periodic_update.cc
- src/core/lib/resource_quota/resource_quota.cc - src/core/lib/resource_quota/resource_quota.cc
- src/core/lib/resource_quota/thread_quota.cc - src/core/lib/resource_quota/thread_quota.cc
- src/core/lib/resource_quota/trace.cc - src/core/lib/resource_quota/trace.cc
@ -7572,6 +7590,7 @@ targets:
- src/core/lib/promise/race.h - src/core/lib/promise/race.h
- src/core/lib/promise/seq.h - src/core/lib/promise/seq.h
- src/core/lib/resource_quota/memory_quota.h - src/core/lib/resource_quota/memory_quota.h
- src/core/lib/resource_quota/periodic_update.h
- src/core/lib/resource_quota/resource_quota.h - src/core/lib/resource_quota/resource_quota.h
- src/core/lib/resource_quota/thread_quota.h - src/core/lib/resource_quota/thread_quota.h
- src/core/lib/resource_quota/trace.h - src/core/lib/resource_quota/trace.h
@ -7595,6 +7614,7 @@ targets:
- src/core/lib/iomgr/iomgr_internal.cc - src/core/lib/iomgr/iomgr_internal.cc
- src/core/lib/promise/activity.cc - src/core/lib/promise/activity.cc
- src/core/lib/resource_quota/memory_quota.cc - src/core/lib/resource_quota/memory_quota.cc
- src/core/lib/resource_quota/periodic_update.cc
- src/core/lib/resource_quota/resource_quota.cc - src/core/lib/resource_quota/resource_quota.cc
- src/core/lib/resource_quota/thread_quota.cc - src/core/lib/resource_quota/thread_quota.cc
- src/core/lib/resource_quota/trace.cc - src/core/lib/resource_quota/trace.cc

1
config.m4 generated

@ -618,6 +618,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/resource_quota/api.cc \ src/core/lib/resource_quota/api.cc \
src/core/lib/resource_quota/arena.cc \ src/core/lib/resource_quota/arena.cc \
src/core/lib/resource_quota/memory_quota.cc \ src/core/lib/resource_quota/memory_quota.cc \
src/core/lib/resource_quota/periodic_update.cc \
src/core/lib/resource_quota/resource_quota.cc \ src/core/lib/resource_quota/resource_quota.cc \
src/core/lib/resource_quota/thread_quota.cc \ src/core/lib/resource_quota/thread_quota.cc \
src/core/lib/resource_quota/trace.cc \ src/core/lib/resource_quota/trace.cc \

1
config.w32 generated

@ -584,6 +584,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\resource_quota\\api.cc " + "src\\core\\lib\\resource_quota\\api.cc " +
"src\\core\\lib\\resource_quota\\arena.cc " + "src\\core\\lib\\resource_quota\\arena.cc " +
"src\\core\\lib\\resource_quota\\memory_quota.cc " + "src\\core\\lib\\resource_quota\\memory_quota.cc " +
"src\\core\\lib\\resource_quota\\periodic_update.cc " +
"src\\core\\lib\\resource_quota\\resource_quota.cc " + "src\\core\\lib\\resource_quota\\resource_quota.cc " +
"src\\core\\lib\\resource_quota\\thread_quota.cc " + "src\\core\\lib\\resource_quota\\thread_quota.cc " +
"src\\core\\lib\\resource_quota\\trace.cc " + "src\\core\\lib\\resource_quota\\trace.cc " +

2
gRPC-C++.podspec generated

@ -833,6 +833,7 @@ Pod::Spec.new do |s|
'src/core/lib/resource_quota/api.h', 'src/core/lib/resource_quota/api.h',
'src/core/lib/resource_quota/arena.h', 'src/core/lib/resource_quota/arena.h',
'src/core/lib/resource_quota/memory_quota.h', 'src/core/lib/resource_quota/memory_quota.h',
'src/core/lib/resource_quota/periodic_update.h',
'src/core/lib/resource_quota/resource_quota.h', 'src/core/lib/resource_quota/resource_quota.h',
'src/core/lib/resource_quota/thread_quota.h', 'src/core/lib/resource_quota/thread_quota.h',
'src/core/lib/resource_quota/trace.h', 'src/core/lib/resource_quota/trace.h',
@ -1676,6 +1677,7 @@ Pod::Spec.new do |s|
'src/core/lib/resource_quota/api.h', 'src/core/lib/resource_quota/api.h',
'src/core/lib/resource_quota/arena.h', 'src/core/lib/resource_quota/arena.h',
'src/core/lib/resource_quota/memory_quota.h', 'src/core/lib/resource_quota/memory_quota.h',
'src/core/lib/resource_quota/periodic_update.h',
'src/core/lib/resource_quota/resource_quota.h', 'src/core/lib/resource_quota/resource_quota.h',
'src/core/lib/resource_quota/thread_quota.h', 'src/core/lib/resource_quota/thread_quota.h',
'src/core/lib/resource_quota/trace.h', 'src/core/lib/resource_quota/trace.h',

3
gRPC-Core.podspec generated

@ -1349,6 +1349,8 @@ Pod::Spec.new do |s|
'src/core/lib/resource_quota/arena.h', 'src/core/lib/resource_quota/arena.h',
'src/core/lib/resource_quota/memory_quota.cc', 'src/core/lib/resource_quota/memory_quota.cc',
'src/core/lib/resource_quota/memory_quota.h', 'src/core/lib/resource_quota/memory_quota.h',
'src/core/lib/resource_quota/periodic_update.cc',
'src/core/lib/resource_quota/periodic_update.h',
'src/core/lib/resource_quota/resource_quota.cc', 'src/core/lib/resource_quota/resource_quota.cc',
'src/core/lib/resource_quota/resource_quota.h', 'src/core/lib/resource_quota/resource_quota.h',
'src/core/lib/resource_quota/thread_quota.cc', 'src/core/lib/resource_quota/thread_quota.cc',
@ -2291,6 +2293,7 @@ Pod::Spec.new do |s|
'src/core/lib/resource_quota/api.h', 'src/core/lib/resource_quota/api.h',
'src/core/lib/resource_quota/arena.h', 'src/core/lib/resource_quota/arena.h',
'src/core/lib/resource_quota/memory_quota.h', 'src/core/lib/resource_quota/memory_quota.h',
'src/core/lib/resource_quota/periodic_update.h',
'src/core/lib/resource_quota/resource_quota.h', 'src/core/lib/resource_quota/resource_quota.h',
'src/core/lib/resource_quota/thread_quota.h', 'src/core/lib/resource_quota/thread_quota.h',
'src/core/lib/resource_quota/trace.h', 'src/core/lib/resource_quota/trace.h',

2
grpc.gemspec generated

@ -1262,6 +1262,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/resource_quota/arena.h ) s.files += %w( src/core/lib/resource_quota/arena.h )
s.files += %w( src/core/lib/resource_quota/memory_quota.cc ) s.files += %w( src/core/lib/resource_quota/memory_quota.cc )
s.files += %w( src/core/lib/resource_quota/memory_quota.h ) s.files += %w( src/core/lib/resource_quota/memory_quota.h )
s.files += %w( src/core/lib/resource_quota/periodic_update.cc )
s.files += %w( src/core/lib/resource_quota/periodic_update.h )
s.files += %w( src/core/lib/resource_quota/resource_quota.cc ) s.files += %w( src/core/lib/resource_quota/resource_quota.cc )
s.files += %w( src/core/lib/resource_quota/resource_quota.h ) s.files += %w( src/core/lib/resource_quota/resource_quota.h )
s.files += %w( src/core/lib/resource_quota/thread_quota.cc ) s.files += %w( src/core/lib/resource_quota/thread_quota.cc )

2
grpc.gyp generated

@ -908,6 +908,7 @@
'src/core/lib/resource_quota/api.cc', 'src/core/lib/resource_quota/api.cc',
'src/core/lib/resource_quota/arena.cc', 'src/core/lib/resource_quota/arena.cc',
'src/core/lib/resource_quota/memory_quota.cc', 'src/core/lib/resource_quota/memory_quota.cc',
'src/core/lib/resource_quota/periodic_update.cc',
'src/core/lib/resource_quota/resource_quota.cc', 'src/core/lib/resource_quota/resource_quota.cc',
'src/core/lib/resource_quota/thread_quota.cc', 'src/core/lib/resource_quota/thread_quota.cc',
'src/core/lib/resource_quota/trace.cc', 'src/core/lib/resource_quota/trace.cc',
@ -1366,6 +1367,7 @@
'src/core/lib/resource_quota/api.cc', 'src/core/lib/resource_quota/api.cc',
'src/core/lib/resource_quota/arena.cc', 'src/core/lib/resource_quota/arena.cc',
'src/core/lib/resource_quota/memory_quota.cc', 'src/core/lib/resource_quota/memory_quota.cc',
'src/core/lib/resource_quota/periodic_update.cc',
'src/core/lib/resource_quota/resource_quota.cc', 'src/core/lib/resource_quota/resource_quota.cc',
'src/core/lib/resource_quota/thread_quota.cc', 'src/core/lib/resource_quota/thread_quota.cc',
'src/core/lib/resource_quota/trace.cc', 'src/core/lib/resource_quota/trace.cc',

2
package.xml generated

@ -1244,6 +1244,8 @@
<file baseinstalldir="/" name="src/core/lib/resource_quota/arena.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/resource_quota/arena.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/resource_quota/memory_quota.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/resource_quota/memory_quota.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/resource_quota/memory_quota.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/resource_quota/memory_quota.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/resource_quota/periodic_update.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/resource_quota/periodic_update.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/resource_quota/resource_quota.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/resource_quota/resource_quota.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/resource_quota/resource_quota.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/resource_quota/resource_quota.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/resource_quota/thread_quota.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/resource_quota/thread_quota.cc" role="src" />

@ -29,6 +29,7 @@
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/global_config_env.h"
#include "src/core/lib/gprpp/mpscq.h" #include "src/core/lib/gprpp/mpscq.h"
#include "src/core/lib/promise/exec_ctx_wakeup_scheduler.h" #include "src/core/lib/promise/exec_ctx_wakeup_scheduler.h"
#include "src/core/lib/promise/loop.h" #include "src/core/lib/promise/loop.h"
@ -37,6 +38,13 @@
#include "src/core/lib/promise/seq.h" #include "src/core/lib/promise/seq.h"
#include "src/core/lib/resource_quota/trace.h" #include "src/core/lib/resource_quota/trace.h"
GPR_GLOBAL_CONFIG_DEFINE_BOOL(
grpc_experimental_enable_periodic_resource_quota_reclamation, false,
"Enable experimental feature to reclaim resource quota periodically");
GPR_GLOBAL_CONFIG_DEFINE_INT32(
grpc_experimental_max_quota_buffer_size, 1024 * 1024,
"Maximum size for one memory allocators buffer size against a quota");
namespace grpc_core { namespace grpc_core {
// Maximum number of bytes an allocator will request from a quota in one step. // Maximum number of bytes an allocator will request from a quota in one step.
@ -249,11 +257,16 @@ absl::optional<size_t> GrpcMemoryAllocatorImpl::TryReserve(
void GrpcMemoryAllocatorImpl::MaybeDonateBack() { void GrpcMemoryAllocatorImpl::MaybeDonateBack() {
size_t free = free_bytes_.load(std::memory_order_relaxed); size_t free = free_bytes_.load(std::memory_order_relaxed);
const size_t kReduceToSize = kMaxQuotaBufferSize / 2; while (free > 0) {
while (true) { size_t ret = 0;
if (free <= kReduceToSize) return; if (max_quota_buffer_size() > 0 && free > max_quota_buffer_size() / 2) {
size_t ret = free - kReduceToSize; ret = std::max(ret, free - max_quota_buffer_size() / 2);
if (free_bytes_.compare_exchange_weak(free, kReduceToSize, }
if (periodic_donate_back()) {
ret = std::max(ret, free > 8192 ? free / 2 : free);
}
const size_t new_free = free - ret;
if (free_bytes_.compare_exchange_weak(free, new_free,
std::memory_order_acq_rel, std::memory_order_acq_rel,
std::memory_order_acquire)) { std::memory_order_acquire)) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) { if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {

@ -34,11 +34,18 @@
#include <grpc/event_engine/memory_request.h> #include <grpc/event_engine/memory_request.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/lib/gprpp/global_config_generic.h"
#include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/promise/activity.h" #include "src/core/lib/promise/activity.h"
#include "src/core/lib/promise/poll.h" #include "src/core/lib/promise/poll.h"
#include "src/core/lib/resource_quota/periodic_update.h"
GPR_GLOBAL_CONFIG_DECLARE_BOOL(
grpc_experimental_enable_periodic_resource_quota_reclamation);
GPR_GLOBAL_CONFIG_DECLARE_INT32(grpc_experimental_max_quota_buffer_size);
namespace grpc_core { namespace grpc_core {
@ -80,7 +87,6 @@ enum class ReclamationPass {
kDestructive = 3, kDestructive = 3,
}; };
static constexpr size_t kNumReclamationPasses = 4; static constexpr size_t kNumReclamationPasses = 4;
static constexpr size_t kMaxQuotaBufferSize = 1024 * 1024;
// For each reclamation function run we construct a ReclamationSweep. // For each reclamation function run we construct a ReclamationSweep.
// When this object is finally destroyed (it may be moved several times first), // When this object is finally destroyed (it may be moved several times first),
@ -299,7 +305,9 @@ class GrpcMemoryAllocatorImpl final : public EventEngineMemoryAllocatorImpl {
// from 0 to non-zero, then we have more to do, otherwise, we're actually // from 0 to non-zero, then we have more to do, otherwise, we're actually
// done. // done.
size_t prev_free = free_bytes_.fetch_add(n, std::memory_order_release); size_t prev_free = free_bytes_.fetch_add(n, std::memory_order_release);
if (prev_free + n > kMaxQuotaBufferSize) { if ((max_quota_buffer_size() > 0 &&
prev_free + n > max_quota_buffer_size()) ||
(periodic_donate_back() && donate_back_.Tick())) {
// Try to immediately return some free'ed memory back to the total quota. // Try to immediately return some free'ed memory back to the total quota.
MaybeDonateBack(); MaybeDonateBack();
} }
@ -328,13 +336,20 @@ class GrpcMemoryAllocatorImpl final : public EventEngineMemoryAllocatorImpl {
absl::string_view name() const { return name_; } absl::string_view name() const { return name_; }
private: private:
static bool periodic_donate_back() {
static const bool value = GPR_GLOBAL_CONFIG_GET(
grpc_experimental_enable_periodic_resource_quota_reclamation);
return value;
}
static size_t max_quota_buffer_size() {
static const size_t value =
GPR_GLOBAL_CONFIG_GET(grpc_experimental_max_quota_buffer_size);
return value;
}
// Primitive reservation function. // Primitive reservation function.
absl::optional<size_t> TryReserve(MemoryRequest request) GRPC_MUST_USE_RESULT; absl::optional<size_t> TryReserve(MemoryRequest request) GRPC_MUST_USE_RESULT;
// This function may be invoked during a memory release operation. If the // This function may be invoked during a memory release operation.
// total free_bytes in this allocator/local cache exceeds // It will try to return half of our free pool to the quota.
// kMaxQuotaBufferSize / 2, donate the excess free_bytes in this cache back
// to the total quota immediately. This helps prevent free bytes in any
// particular allocator from growing too large.
void MaybeDonateBack(); void MaybeDonateBack();
// Replenish bytes from the quota, without blocking, possibly entering // Replenish bytes from the quota, without blocking, possibly entering
// overcommit. // overcommit.
@ -359,6 +374,8 @@ class GrpcMemoryAllocatorImpl final : public EventEngineMemoryAllocatorImpl {
// Amount of memory taken from the quota by this allocator. // Amount of memory taken from the quota by this allocator.
std::atomic<size_t> taken_bytes_{sizeof(GrpcMemoryAllocatorImpl)}; std::atomic<size_t> taken_bytes_{sizeof(GrpcMemoryAllocatorImpl)};
std::atomic<bool> registered_reclaimer_{false}; std::atomic<bool> registered_reclaimer_{false};
// We try to donate back some memory periodically to the central quota.
PeriodicUpdate donate_back_{Duration::Seconds(10)};
Mutex reclaimer_mu_; Mutex reclaimer_mu_;
bool shutdown_ ABSL_GUARDED_BY(reclaimer_mu_) = false; bool shutdown_ ABSL_GUARDED_BY(reclaimer_mu_) = false;
// Indices into the various reclaimer queues, used so that we can cancel // Indices into the various reclaimer queues, used so that we can cancel

@ -19,10 +19,16 @@
#include <atomic> #include <atomic>
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h"
namespace grpc_core { namespace grpc_core {
bool PeriodicUpdate::MaybeEndPeriod() { bool PeriodicUpdate::MaybeEndPeriod() {
if (period_start_ == Timestamp::ProcessEpoch()) {
period_start_ = ExecCtx::Get()->Now();
updates_remaining_.store(1, std::memory_order_release);
return false;
}
// updates_remaining_ just reached 0 and the thread calling this function was // updates_remaining_ just reached 0 and the thread calling this function was
// the decrementer that got us there. // the decrementer that got us there.
// We can now safely mutate any non-atomic mutable variables (we've got a // We can now safely mutate any non-atomic mutable variables (we've got a

@ -22,7 +22,6 @@
#include <atomic> #include <atomic>
#include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/exec_ctx.h"
namespace grpc_core { namespace grpc_core {
@ -60,7 +59,7 @@ class PeriodicUpdate {
// this is fine because they'll observe an ignorable negative value. // this is fine because they'll observe an ignorable negative value.
const Duration period_; const Duration period_;
Timestamp period_start_ = ExecCtx::Get()->Now(); Timestamp period_start_ = Timestamp::ProcessEpoch();
int64_t expected_updates_per_period_ = 1; int64_t expected_updates_per_period_ = 1;
std::atomic<int64_t> updates_remaining_{1}; std::atomic<int64_t> updates_remaining_{1};
}; };

@ -593,6 +593,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/resource_quota/api.cc', 'src/core/lib/resource_quota/api.cc',
'src/core/lib/resource_quota/arena.cc', 'src/core/lib/resource_quota/arena.cc',
'src/core/lib/resource_quota/memory_quota.cc', 'src/core/lib/resource_quota/memory_quota.cc',
'src/core/lib/resource_quota/periodic_update.cc',
'src/core/lib/resource_quota/resource_quota.cc', 'src/core/lib/resource_quota/resource_quota.cc',
'src/core/lib/resource_quota/thread_quota.cc', 'src/core/lib/resource_quota/thread_quota.cc',
'src/core/lib/resource_quota/trace.cc', 'src/core/lib/resource_quota/trace.cc',

@ -2245,6 +2245,8 @@ src/core/lib/resource_quota/arena.cc \
src/core/lib/resource_quota/arena.h \ src/core/lib/resource_quota/arena.h \
src/core/lib/resource_quota/memory_quota.cc \ src/core/lib/resource_quota/memory_quota.cc \
src/core/lib/resource_quota/memory_quota.h \ src/core/lib/resource_quota/memory_quota.h \
src/core/lib/resource_quota/periodic_update.cc \
src/core/lib/resource_quota/periodic_update.h \
src/core/lib/resource_quota/resource_quota.cc \ src/core/lib/resource_quota/resource_quota.cc \
src/core/lib/resource_quota/resource_quota.h \ src/core/lib/resource_quota/resource_quota.h \
src/core/lib/resource_quota/thread_quota.cc \ src/core/lib/resource_quota/thread_quota.cc \

@ -2039,6 +2039,8 @@ src/core/lib/resource_quota/arena.cc \
src/core/lib/resource_quota/arena.h \ src/core/lib/resource_quota/arena.h \
src/core/lib/resource_quota/memory_quota.cc \ src/core/lib/resource_quota/memory_quota.cc \
src/core/lib/resource_quota/memory_quota.h \ src/core/lib/resource_quota/memory_quota.h \
src/core/lib/resource_quota/periodic_update.cc \
src/core/lib/resource_quota/periodic_update.h \
src/core/lib/resource_quota/resource_quota.cc \ src/core/lib/resource_quota/resource_quota.cc \
src/core/lib/resource_quota/resource_quota.h \ src/core/lib/resource_quota/resource_quota.h \
src/core/lib/resource_quota/thread_quota.cc \ src/core/lib/resource_quota/thread_quota.cc \

Loading…
Cancel
Save