Unverified Commit 7719a68a authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!7098 [sync] PR-6818: mm: memcg: fix stale protection of reclaim target memcg

parents 9e7d953c 12ba5a90
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -745,28 +745,32 @@ static inline void mem_cgroup_protection(struct mem_cgroup *root,
void mem_cgroup_calculate_protection(struct mem_cgroup *root,
				     struct mem_cgroup *memcg);

static inline bool mem_cgroup_supports_protection(struct mem_cgroup *memcg)
static inline bool mem_cgroup_unprotected(struct mem_cgroup *target,
					  struct mem_cgroup *memcg)
{
	/*
	 * The root memcg doesn't account charges, and doesn't support
	 * protection.
	 * protection. The target memcg's protection is ignored, see
	 * mem_cgroup_calculate_protection() and mem_cgroup_protection()
	 */
	return !mem_cgroup_disabled() && !mem_cgroup_is_root(memcg);

	return mem_cgroup_disabled() || mem_cgroup_is_root(memcg) ||
		memcg == target;
}

static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg)
static inline bool mem_cgroup_below_low(struct mem_cgroup *target,
					struct mem_cgroup *memcg)
{
	if (!mem_cgroup_supports_protection(memcg))
	if (mem_cgroup_unprotected(target, memcg))
		return false;

	return READ_ONCE(memcg->memory.elow) >=
		page_counter_read(&memcg->memory);
}

static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg)
static inline bool mem_cgroup_below_min(struct mem_cgroup *target,
					struct mem_cgroup *memcg)
{
	if (!mem_cgroup_supports_protection(memcg))
	if (mem_cgroup_unprotected(target, memcg))
		return false;

	return READ_ONCE(memcg->memory.emin) >=
@@ -1351,12 +1355,19 @@ static inline void mem_cgroup_calculate_protection(struct mem_cgroup *root,
{
}

static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg)
static inline bool mem_cgroup_unprotected(struct mem_cgroup *target,
					  struct mem_cgroup *memcg)
{
	return true;
}
static inline bool mem_cgroup_below_low(struct mem_cgroup *target,
					struct mem_cgroup *memcg)
{
	return false;
}

static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg)
static inline bool mem_cgroup_below_min(struct mem_cgroup *target,
					struct mem_cgroup *memcg)
{
	return false;
}
+2 −2
Original line number Diff line number Diff line
@@ -2851,13 +2851,13 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc)

		mem_cgroup_calculate_protection(target_memcg, memcg);

		if (mem_cgroup_below_min(memcg)) {
		if (mem_cgroup_below_min(target_memcg, memcg)) {
			/*
			 * Hard protection.
			 * If there is no reclaimable memory, OOM.
			 */
			continue;
		} else if (mem_cgroup_below_low(memcg)) {
		} else if (mem_cgroup_below_low(target_memcg, memcg)) {
			/*
			 * Soft protection.
			 * Respect the protection only as long as