[Devel] [PATCH rh7] tun: Silence allocation failer if user asked for too big header

2020-10-05 Thread Andrey Ryabinin
Userspace may ask tun device to send packet with ridiculously
big header and trigger this:

 [ cut here ]
 WARNING: CPU: 1 PID: 15366 at mm/page_alloc.c:3548 
__alloc_pages_nodemask+0x537/0x1200
 order 19 >= 11, gfp 0x2044d0
 Call Trace:
   dump_stack+0x19/0x1b
   __warn+0x17f/0x1c0
   warn_slowpath_fmt+0xad/0xe0
   __alloc_pages_nodemask+0x537/0x1200
   kmalloc_large_node+0x5f/0xd0
   __kmalloc_node_track_caller+0x425/0x630
   __kmalloc_reserve.isra.33+0x47/0xd0
   __alloc_skb+0xdd/0x5f0
   alloc_skb_with_frags+0x8f/0x540
   sock_alloc_send_pskb+0x5e5/0x940
   tun_get_user+0x38b/0x24a0 [tun]
   tun_chr_aio_write+0x13a/0x250 [tun]
   do_sync_readv_writev+0xdf/0x1c0
   do_readv_writev+0x1a5/0x850
   vfs_writev+0xba/0x190
   SyS_writev+0x17c/0x340
   system_call_fastpath+0x25/0x2a

Just add __GFP_NOWARN and silently return -ENOMEM to fix this.

https://jira.sw.ru/browse/PSBM-103639
Signed-off-by: Andrey Ryabinin 
---
 drivers/net/tun.c  | 4 ++--
 include/net/sock.h | 7 +++
 net/core/sock.c| 9 +
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index e95a89ba48b7..c0879c6a9703 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1142,8 +1142,8 @@ static struct sk_buff *tun_alloc_skb(struct tun_file 
*tfile,
if (prepad + len < PAGE_SIZE || !linear)
linear = len;
 
-   skb = sock_alloc_send_pskb(sk, prepad + linear, len - linear, noblock,
-  , 0);
+   skb = sock_alloc_send_pskb_flags(sk, prepad + linear, len - linear, 
noblock,
+   , 0, __GFP_NOWARN);
if (!skb)
return ERR_PTR(err);
 
diff --git a/include/net/sock.h b/include/net/sock.h
index 4136d2c3080c..1912d85ecc4d 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1626,6 +1626,13 @@ extern struct sk_buff
*sock_alloc_send_pskb(struct sock *sk,
  int noblock,
  int *errcode,
  int max_page_order);
+extern struct sk_buff  *sock_alloc_send_pskb_flags(struct sock *sk,
+ unsigned long header_len,
+ unsigned long data_len,
+ int noblock,
+ int *errcode,
+ int max_page_order,
+ gfp_t extra_flags);
 extern void *sock_kmalloc(struct sock *sk, int size,
  gfp_t priority);
 extern void sock_kfree_s(struct sock *sk, void *mem, int size);
diff --git a/net/core/sock.c b/net/core/sock.c
index 508fc6093a26..07ea42f976cf 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1964,6 +1964,15 @@ struct sk_buff *sock_alloc_send_pskb(struct sock *sk, 
unsigned long header_len,
 }
 EXPORT_SYMBOL(sock_alloc_send_pskb);
 
+struct sk_buff *sock_alloc_send_pskb_flags(struct sock *sk, unsigned long 
header_len,
+unsigned long data_len, int noblock,
+int *errcode, int max_page_order, gfp_t 
extra_flags)
+{
+   return __sock_alloc_send_pskb(sk, header_len, data_len, noblock,
+   errcode, max_page_order, extra_flags);
+}
+EXPORT_SYMBOL(sock_alloc_send_pskb_flags);
+
 struct sk_buff *sock_alloc_send_skb(struct sock *sk, unsigned long size,
int noblock, int *errcode)
 {
-- 
2.26.2

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH rh7] vmscan: don't report reclaim progress if there was no progress.

2020-10-05 Thread Andrey Ryabinin
__alloc_pages_slowpath relies on the direct reclaim and did_some_progress
as an indicator that it makes sense to retry allocation rather than
declaring OOM. shrink_zones checks if all zones reclaimable and if
shrink_zone didn't make any progress it prevents from a premature OOM
killer invocation by reporting the progress.
This might happen if the LRU is full of dirty or writeback pages
and direct reclaim cannot clean those up.

zone_reclaimable allows to rescan the reclaimable lists several times
and restart if a page is freed.  This is really subtle behavior and it
might lead to a livelock when a single freed page keeps allocator
looping but the current task will not be able to allocate that single
page.  OOM killer would be more appropriate than looping without any
progress for unbounded amount of time.

Report no progress even if zones are reclaimable as OOM is more appropiate
in that case.

https://jira.sw.ru/browse/PSBM-104900
Signed-off-by: Andrey Ryabinin 
---
 mm/vmscan.c | 24 
 1 file changed, 24 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 13ae9bd1e92e..85622f235e78 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2952,26 +2952,6 @@ static void snapshot_refaults(struct mem_cgroup 
*root_memcg, struct zone *zone)
} while ((memcg = mem_cgroup_iter(root_memcg, memcg, NULL)));
 }
 
-/* All zones in zonelist are unreclaimable? */
-static bool all_unreclaimable(struct zonelist *zonelist,
-   struct scan_control *sc)
-{
-   struct zoneref *z;
-   struct zone *zone;
-
-   for_each_zone_zonelist_nodemask(zone, z, zonelist,
-   gfp_zone(sc->gfp_mask), sc->nodemask) {
-   if (!populated_zone(zone))
-   continue;
-   if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL))
-   continue;
-   if (zone_reclaimable(zone))
-   return false;
-   }
-
-   return true;
-}
-
 static void shrink_tcrutches(struct scan_control *scan_ctrl)
 {
int nid;
@@ -3097,10 +3077,6 @@ out:
goto retry;
}
 
-   /* top priority shrink_zones still had more to do? don't OOM, then */
-   if (global_reclaim(sc) && !all_unreclaimable(zonelist, sc))
-   return 1;
-
return 0;
 }
 
-- 
2.26.2

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [PATCH vz8] kernel/sched/fair: Fix 'releasing a pinned lock'

2020-10-05 Thread Kirill Tkhai
On 05.10.2020 15:36, Andrey Ryabinin wrote:
> Lockdep complains that after rq_repin_lock() the lock wasn't unpinned
> before rq->lock release.
> 
> [ cut here ]
> releasing a pinned lock
> WARNING: CPU: 0 PID: 24 at kernel/locking/lockdep.c:4271 
> lock_release+0x939/0xee0
> Call Trace:
>  _raw_spin_unlock+0x1c/0x30
>  load_balance+0x1472/0x2e30
>  pick_next_task_fair+0x62c/0x2300
>  __schedule+0x481/0x1600
>  schedule+0xbf/0x240
>  worker_thread+0x1d5/0xb50
>  kthread+0x30e/0x3d0
>  ret_from_fork+0x3a/0x50
> 
> Add rq_unpin_lock(); call to fix this. Also for consistency use 'busiest'
> instead of 'env.src_rq' which is the same.
> 
> https://jira.sw.ru/browse/PSBM-120800
> Signed-off-by: Andrey Ryabinin 

Reviewed-by: Kirill Tkhai 

> ---
>  kernel/sched/fair.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index fc87dee4fd0e..23a2f2452474 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -9178,9 +9178,10 @@ static int load_balance(int this_cpu, struct rq 
> *this_rq,
>   env.loop = 0;
>   local_irq_save(rf.flags);
>   double_rq_lock(env.dst_rq, busiest);
> - rq_repin_lock(env.src_rq, );
> + rq_repin_lock(busiest, );
>   update_rq_clock(env.dst_rq);
>   cur_ld_moved = ld_moved = move_task_groups();
> + rq_unpin_lock(busiest, );
>   double_rq_unlock(env.dst_rq, busiest);
>   local_irq_restore(rf.flags);
>  }
> 

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH vz8] kernel/sched/fair: Fix 'releasing a pinned lock'

2020-10-05 Thread Andrey Ryabinin
Lockdep complains that after rq_repin_lock() the lock wasn't unpinned
before rq->lock release.

[ cut here ]
releasing a pinned lock
WARNING: CPU: 0 PID: 24 at kernel/locking/lockdep.c:4271 
lock_release+0x939/0xee0
Call Trace:
 _raw_spin_unlock+0x1c/0x30
 load_balance+0x1472/0x2e30
 pick_next_task_fair+0x62c/0x2300
 __schedule+0x481/0x1600
 schedule+0xbf/0x240
 worker_thread+0x1d5/0xb50
 kthread+0x30e/0x3d0
 ret_from_fork+0x3a/0x50

Add rq_unpin_lock(); call to fix this. Also for consistency use 'busiest'
instead of 'env.src_rq' which is the same.

https://jira.sw.ru/browse/PSBM-120800
Signed-off-by: Andrey Ryabinin 
---
 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index fc87dee4fd0e..23a2f2452474 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9178,9 +9178,10 @@ static int load_balance(int this_cpu, struct rq *this_rq,
env.loop = 0;
local_irq_save(rf.flags);
double_rq_lock(env.dst_rq, busiest);
-   rq_repin_lock(env.src_rq, );
+   rq_repin_lock(busiest, );
update_rq_clock(env.dst_rq);
cur_ld_moved = ld_moved = move_task_groups();
+   rq_unpin_lock(busiest, );
double_rq_unlock(env.dst_rq, busiest);
local_irq_restore(rf.flags);
 }
-- 
2.26.2

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RHEL8 COMMIT] memcg: fixes accounting for allocations called in "disabled

2020-10-05 Thread Konstantin Khorenko
The commit is pushed to "branch-rh8-4.18.0-193.6.3.vz8.4.x-ovz" and will appear 
at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.11
-->
commit 060218e7064c3f370b0a8f6bbe8017971c15a89d
Author: Vasily Averin 
Date:   Mon Oct 5 13:20:48 2020 +0300

memcg: fixes accounting for allocations called in "disabled

BH" context #PSBM-120694
Message-ID: <49f823ed-279d-2bba-ed53-aebf362c8...@virtuozzo.com>
Date: Mon, 5 Oct 2020 10:47:46 +0300

in_interrupt() check includes "have BH disabled" case,
as result allocations called with disabled BH are not accounted to
proper memory cgroup.

https://jira.sw.ru/browse/PSBM-120694
Signed-off-by: Vasily Averin 
---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 71e0697ff838..df70c3bdd444 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2630,7 +2630,7 @@ static void memcg_schedule_kmem_cache_create(struct 
mem_cgroup *memcg,
 
 static inline bool memcg_kmem_bypass(void)
 {
-   if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD))
+   if (!in_task() || !current->mm || (current->flags & PF_KTHREAD))
return true;
return false;
 }
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RHEL8 COMMIT] mm, memcg: add oom counter to memory.stat memcgroup file

2020-10-05 Thread Konstantin Khorenko
The commit is pushed to "branch-rh8-4.18.0-193.6.3.vz8.4.x-ovz" and will appear 
at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.11
-->
commit 67a87abe411ef0fbea509e04c9115f23fbb072f2
Author: Andrey Ryabinin 
Date:   Mon Oct 5 13:18:40 2020 +0300

mm, memcg: add oom counter to memory.stat memcgroup file

Add oom counter to memory.stat file. oom shows amount of oom kills
triggered due to cgroup's memory limit. total_oom shows total sum of
oom kills triggered due to cgroup's and it's sub-groups memory limits.

memory.stat in the root cgroup counts global oom kills.

E.g:
 # mkdir /sys/fs/cgroup/memory/test/
 # echo 100M > /sys/fs/cgroup/memory/test/memory.limit_in_bytes
 # echo 100M > /sys/fs/cgroup/memory/test/memory.memsw.limit_in_bytes
 # echo $$ > /sys/fs/cgroup/memory/test/tasks
 # ./vm-scalability/usemem -O 200M
 # grep oom /sys/fs/cgroup/memory/test/memory.stat
   oom 1
   total_oom 1
 # echo -1 > /sys/fs/cgroup/memory/test/memory.memsw.limit_in_bytes
 # echo -1 > /sys/fs/cgroup/memory/test/memory.limit_in_bytes
 # ./vm-scalability/usemem -O 1000G
 # grep oom /sys/fs/cgroup/memory/memory.stat
oom 1
total_oom 2

https://jira.sw.ru/browse/PSBM-108287
Signed-off-by: Andrey Ryabinin 

khorenko@ notes:
1) non-root memcg:
   * oom - number of OOMs caused by limit exceeded by this particular memcg
   * total_oom - number of OOMs caused by limit exceeded by this particular
 memcg and all nested memory cgroups.

   Note: as the current memcg is not root, then it's "local" OOM,
   thus processes were killed in the same memcg which caused it.

2) root memcg:
   * oom - the number of global OOMs happened
   * total_oom - the number of global OOMs + number of OOMs caused by limit
 exceeded in all nested memory cgroups

Note: root memory cgroup cannot be limited => no OOMs can be cause by its 
limit.
---
 include/linux/memcontrol.h |  2 ++
 mm/memcontrol.c| 33 ++---
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index b097f137a3df..eb8634128a81 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -75,6 +75,8 @@ struct accumulated_stats {
unsigned long stat[MEMCG_NR_STAT];
unsigned long events[NR_VM_EVENT_ITEMS];
unsigned long lru_pages[NR_LRU_LISTS];
+   unsigned long oom;
+   unsigned long oom_kill;
const unsigned int *stats_array;
const unsigned int *events_array;
int stats_size;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a2d9f74ef77c..71e0697ff838 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3144,6 +3144,8 @@ void accumulate_memcg_tree(struct mem_cgroup *memcg,
for (i = 0; i < NR_LRU_LISTS; i++)
acc->lru_pages[i] +=
mem_cgroup_nr_lru_pages(mi, BIT(i));
+   acc->oom += atomic_long_read(>memory_events[MEMCG_OOM]);
+   acc->oom_kill += 
atomic_long_read(>memory_events[MEMCG_OOM_KILL]);
 
cond_resched();
}
@@ -3899,6 +3901,13 @@ static int memcg_stat_show(struct seq_file *m, void *v)
BUILD_BUG_ON(ARRAY_SIZE(memcg1_stat_names) != ARRAY_SIZE(memcg1_stats));
BUILD_BUG_ON(ARRAY_SIZE(mem_cgroup_lru_names) != NR_LRU_LISTS);
 
+   memset(, 0, sizeof(acc));
+   acc.stats_size = ARRAY_SIZE(memcg1_stats);
+   acc.stats_array = memcg1_stats;
+   acc.events_size = ARRAY_SIZE(memcg1_events);
+   acc.events_array = memcg1_events;
+   accumulate_memcg_tree(memcg, );
+
for (i = 0; i < ARRAY_SIZE(memcg1_stats); i++) {
if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
continue;
@@ -3911,6 +3920,18 @@ static int memcg_stat_show(struct seq_file *m, void *v)
seq_printf(m, "%s %lu\n", memcg1_event_names[i],
   memcg_sum_events(memcg, memcg1_events[i]));
 
+   /*
+* For root_mem_cgroup we want to account global ooms as well.
+* The diff between allo MEMCG_OOM_KILL and MEMCG_OOM events
+* should give us the glogbal ooms count.
+*/
+   if (memcg == root_mem_cgroup)
+   seq_printf(m, "oom %lu\n", acc.oom_kill - acc.oom +
+   atomic_long_read(>memory_events[MEMCG_OOM]));
+   else
+   seq_printf(m, "oom %lu\n",
+   atomic_long_read(>memory_events[MEMCG_OOM]));
+
for (i = 0; i < NR_LRU_LISTS; i++)
seq_printf(m, "%s %lu\n", mem_cgroup_lru_names[i],
   mem_cgroup_nr_lru_pages(memcg, BIT(i)) * PAGE_SIZE);
@@ -3927,13 +3948,6 @@ static int memcg_stat_show(struct seq_file *m, void *v)
seq_printf(m, 

[Devel] [PATCH RHEL8 COMMIT] mm/memcg: reclaim memory.cache.limit_in_bytes from background

2020-10-05 Thread Konstantin Khorenko
The commit is pushed to "branch-rh8-4.18.0-193.6.3.vz8.4.x-ovz" and will appear 
at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.11
-->
commit 6fd293dbf5518d786f325db3b0f352385795f4bf
Author: Andrey Ryabinin 
Date:   Mon Oct 5 12:00:58 2020 +0300

mm/memcg: reclaim memory.cache.limit_in_bytes from background

Reclaiming memory above memory.cache.limit_in_bytes always in direct
reclaim mode adds to much of a cost for vstorage. Instead of direct
reclaim allow to overflow memory.cache.limit_in_bytes but launch
the reclaim in background task.

https://pmc.acronis.com/browse/VSTOR-24395
https://jira.sw.ru/browse/PSBM-94761
Signed-off-by: Andrey Ryabinin 
---
 mm/memcontrol.c | 42 ++
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ee09f5f6da6c..14727037bcd0 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2211,11 +2211,16 @@ static void reclaim_high(struct mem_cgroup *memcg,
 unsigned int nr_pages,
 gfp_t gfp_mask)
 {
+
do {
-   if (page_counter_read(>memory) <= memcg->high)
-   continue;
-   memcg_memory_event(memcg, MEMCG_HIGH);
-   try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, true);
+
+   if (page_counter_read(>memory) > memcg->high) {
+   memcg_memory_event(memcg, MEMCG_HIGH);
+   try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, 
true);
+   }
+
+   if (page_counter_read(>cache) > memcg->cache.max)
+   try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, 
false);
} while ((memcg = parent_mem_cgroup(memcg)));
 }
 
@@ -2270,13 +2275,8 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t 
gfp_mask, bool kmem_charge
refill_stock(memcg, nr_pages);
goto charge;
}
-
-   if (cache_charge && !page_counter_try_charge(
-   >cache, nr_pages, )) {
-   refill_stock(memcg, nr_pages);
-   goto charge;
-   }
-   return 0;
+   css_get_many(>css, batch);
+   goto done;
}
 
 charge:
@@ -2301,19 +2301,6 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t 
gfp_mask, bool kmem_charge
}
}
 
-   if (!mem_over_limit && cache_charge) {
-   if (page_counter_try_charge(>cache, nr_pages, ))
-   goto done_restock;
-
-   may_swap = false;
-   mem_over_limit = mem_cgroup_from_counter(counter, cache);
-   page_counter_uncharge(>memory, batch);
-   if (do_memsw_account())
-   page_counter_uncharge(>memsw, batch);
-   if (kmem_charge)
-   page_counter_uncharge(>kmem, nr_pages);
-   }
-
if (!mem_over_limit)
goto done_restock;
 
@@ -2437,6 +2424,9 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t 
gfp_mask, bool kmem_charge
css_get_many(>css, batch);
if (batch > nr_pages)
refill_stock(memcg, batch - nr_pages);
+done:
+   if (cache_charge)
+   page_counter_charge(>cache, nr_pages);
 
/*
 * If the hierarchy is above the normal consumption range, schedule
@@ -2457,7 +2447,11 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t 
gfp_mask, bool kmem_charge
current->memcg_nr_pages_over_high += batch;
set_notify_resume(current);
break;
+   } else if (page_counter_read(>cache) > memcg->cache.max) 
{
+   if (!work_pending(>high_work))
+   schedule_work(>high_work);
}
+
} while ((memcg = parent_mem_cgroup(memcg)));
 
return 0;
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RHEL8 COMMIT] mm/memcg: fix cache growth above cache.limit_in_bytes

2020-10-05 Thread Konstantin Khorenko
The commit is pushed to "branch-rh8-4.18.0-193.6.3.vz8.4.x-ovz" and will appear 
at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.11
-->
commit e9a22ab1de9d9904945a5ed4abbbc9dff1bef6b1
Author: Andrey Ryabinin 
Date:   Mon Oct 5 12:00:58 2020 +0300

mm/memcg: fix cache growth above cache.limit_in_bytes

Exceeding cache above cache.limit_in_bytes schedules high_work_func()
which tries to reclaim 32 pages. If cache generated fast enough or it allows
cgroup to steadily grow above cache.limit_in_bytes because we don't reclaim
enough. Try to reclaim exceeded amount of cache instead.

https://jira.sw.ru/browse/PSBM-106384
Signed-off-by: Andrey Ryabinin 
---
 mm/memcontrol.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 14727037bcd0..a2d9f74ef77c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2213,14 +2213,18 @@ static void reclaim_high(struct mem_cgroup *memcg,
 {
 
do {
+   long cache_overused;
 
if (page_counter_read(>memory) > memcg->high) {
memcg_memory_event(memcg, MEMCG_HIGH);
try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, 
true);
}
 
-   if (page_counter_read(>cache) > memcg->cache.max)
-   try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, 
false);
+   cache_overused = page_counter_read(>cache) -
+   memcg->cache.max;
+
+   if (cache_overused > 0)
+   try_to_free_mem_cgroup_pages(memcg, cache_overused, 
gfp_mask, false);
} while ((memcg = parent_mem_cgroup(memcg)));
 }
 
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RH8] memcg: fixes accounting for allocations called in "disabled BH" context

2020-10-05 Thread Vasily Averin
in_interrupt() check includes "have BH disabled" case,
as result allocations called with disabled BH are not accounted to
proper memory cgroup.

https://jira.sw.ru/browse/PSBM-120694
Signed-off-by: Vasily Averin 
---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 68242a72be4d..09351bb08883 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2632,7 +2632,7 @@ static void memcg_schedule_kmem_cache_create(struct 
mem_cgroup *memcg,
 
 static inline bool memcg_kmem_bypass(void)
 {
-   if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD))
+   if (!in_task() || !current->mm || (current->flags & PF_KTHREAD))
return true;
return false;
 }
-- 
2.17.1

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RHEL7 COMMIT] memcg: fixes accounting for allocations called in "disabled BH" context

2020-10-05 Thread Vasily Averin
The commit is pushed to "branch-rh7-3.10.0-1127.18.2.vz7.163.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.18.2.vz7.163.32
-->
commit bdd0719de2dc72afa136ec5907aede4ab1db94cb
Author: Vasily Averin 
Date:   Mon Oct 5 10:36:38 2020 +0300

memcg: fixes accounting for allocations called in "disabled BH" context

in_interrupt() check includes "have BH disabled" case,
as result allocations called with disabled BH are not accounted to
proper memory cgroup.

https://jira.sw.ru/browse/PSBM-108292
Signed-off-by: Vasily Averin 
---
 include/linux/memcontrol.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 485a3d3..5e16658 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -644,7 +644,7 @@ memcg_kmem_newpage_charge(struct page *page, gfp_t gfp, int 
order)
 */
if (gfp & __GFP_NOFAIL)
return true;
-   if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD))
+   if (!in_task() || (!current->mm) || (current->flags & PF_KTHREAD))
return true;
 
/* If the test is dying, just let it go. */
@@ -682,7 +682,7 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
return cachep;
if (gfp & __GFP_NOFAIL)
return cachep;
-   if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD))
+   if (!in_task() || (!current->mm) || (current->flags & PF_KTHREAD))
return cachep;
if (unlikely(fatal_signal_pending(current)))
return cachep;
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RH7] memcg: fixes accounting for allocations called in "disabled BH" context

2020-10-05 Thread Vasily Averin
in_interrupt() check includes "have BH disabled" case,
as result allocations called with disabled BH are not accounted to
proper memory cgroup.
https://jira.sw.ru/browse/PSBM-108292
Signed-off-by: Vasily Averin 
---
 include/linux/memcontrol.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 485a3d354b78..5e16658a356f 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -644,7 +644,7 @@ memcg_kmem_newpage_charge(struct page *page, gfp_t gfp, int 
order)
 */
if (gfp & __GFP_NOFAIL)
return true;
-   if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD))
+   if (!in_task() || (!current->mm) || (current->flags & PF_KTHREAD))
return true;
 
/* If the test is dying, just let it go. */
@@ -682,7 +682,7 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
return cachep;
if (gfp & __GFP_NOFAIL)
return cachep;
-   if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD))
+   if (!in_task() || (!current->mm) || (current->flags & PF_KTHREAD))
return cachep;
if (unlikely(fatal_signal_pending(current)))
return cachep;
-- 
2.17.1

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel