From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id A9C4180223 for ; Tue, 15 Sep 2026 17:24:37 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 68FHNDAJ006458; Tue, 15 Sep 2026 20:23:13 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 68FHNDAJ006458 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="Co+YVcL7" Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 68FHN4Pt006424 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 15 Sep 2026 20:23:04 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 68FHN4Pt006424 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-490a767b782so41345535e9.2 for ; Tue, 15 Sep 2026 10:23:04 -0700 (PDT) X-Gm-Message-State: AFuF++npYNCwL34rPv6FXzrYGbcHmzNx5ISRm59muYFwz4Wn9GRsWGnj CcFhp5RmceMOiEGhSUSbm1kL/YL8NnpDZ0Pf/VXY4pFS7DFI6eL3l/wmdZRARKodsiX5DN0zwF9 4ZrS3wD30XPwxH12J10chAF4Con8RuKaStsChaLI3lImYuEX/dKOe6g== X-Gm-Gg: AYBFou0j8oq2dsqdGMk+Qiv/R+cFBMdJro/KAZ/ze2cpeWGrP3iOE4hkfR+fHO3RrI1 A01ZwBQZvJ+R+EzVHEuvxFJ36ttLhCDu014hEjbwpqR3FfryDXcJmIfZwWuf4oa9FRdvfP2DE0u TO54I/n+DiY2zwgDGDK4A98fh43S3i3/3Y+bhM2MC6fS1yy1qZDyIOHXJrz1JrDXaTHGxQ3ZeMl 8hPEn/O03VUNaZdiATMq/slhpADfdo/lkQXQVxEvOEGOh93S1AoEDKnbxprwozdFkKXlABNckxR yCS9ECcL8ICM4klvkg+T1RUNgLfChdyIoACFGwMMkhaPKO4kTy+OQeZED/NzJOrYsRQGCM2gew/ nyCIWUT7LKPxTbr6mmy+08Bv1Ybsc X-Received: by 2002:a05:600d:8651:20b0:49c:fc6e:a3da with SMTP id 5b1f17b1804b1-49e82915984mr18958135e9.25.1789492984415; Tue, 15 Sep 2026 10:23:04 -0700 (PDT) X-Received: by 2002:a05:600d:8651:20b0:49c:fc6e:a3da with SMTP id 5b1f17b1804b1-49e82915984mr18957825e9.25.1789492983946; Tue, 15 Sep 2026 10:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1789492983; cv=none; d=google.com; s=arc-20260327; b=avLMXIuP0B/5jB21tnmPxRTiMzyPFBq/lbBGUZHF2mQJ296trTl2YwAxt8TiSWqlqs 2iyOPzka37nU0Iqsmfayyq0EE9r9Foxj2XuCPwKj75qyuH6T8LrMSlSAJj1FHtjK1yTx cDyjxOM6Dn5QyurHW9i7JanhNt8K+E1p1y1qC0pFUL564HJUsRpT0AhbR3i77vNPC/fQ Or0KFKZuMZnS9g36r/sRraaFLoJRBv6USnrrzuzVdnblooWMgTlE0lr64w8a3+qDDSYB 4ojAgOBvH+d6tW59VMO7B07VDR2YbDHwDHADNK9Svs62HwdSmOl0p/s/JtFPufERUsuj kkbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=c71I0kcZyryaT7Zz1M7hWK7XDUIim5jBe0NvFBB8cc0=; fh=QQvtjDaAlLft5IR2jnjma4lVp8TaaKU12WD0fWdFifQ=; b=AaHctksqKDlBP3WJDJrdBQT67IWdX+2h2Xe3HUQYAUuEBRGPlhTAFlzjnKdYLTsc9Y I9Mss/upcY8ilgj3iocSGKzzs8812kcsDPdOt68ag5wf0hDSeNc8a8D1Zr45FQ5bhm8/ vHWH+rzDfLHzYd5uqrYhkUujBxOhyZhaBJ6V2oslTQ/+dKFG8Ar/wV3KAFkD1vdKT3WQ EED1KmMEbBkicR/orMRD1G12Ny/PlfstWqRBHdnD3lxL4bSZdJu4eSYoN+n8fPYeAd63 jSkk64zOiede+SOx8FQOGkQQGUXrazTKpsFe7n13E5hpF9X6TG8m5qF31/97mdy2Irg2 UgWw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=Co+YVcL7; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4870bf7c68fsi421906f8f.494.2026.09.15.10.23.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 10:23:03 -0700 (PDT) Received-SPF: pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=Co+YVcL7; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=c71I0kcZyryaT7Zz1M7hWK7XDUIim5jBe0NvFBB8cc0=; b=Co+YVcL7MYqb d1tFEJpNLty8aQMlNC+zopWNGcsHmelE1Daq+pQ6iB8/pItm12OlecKDxg3zYjLWWP59QNmgkLYbP UoNLDvBVWSFyFPD3XK31bnv4cCsiupQPv9o7SsVbppcK1CEZ0B4Oymbt/zG1c0sZIUGrl5+trV0Lw PPHmzWDXMbF2CQ2byzaQTiYwzs8HiFDHhLLmaF/s0pElS8TuL9Zre29quFbUHR4yilhAGRJ6coeQp rAKm/N/gS92g19blj5vkrPM/mtIzh48PEbZ8sQSwuSq/xtxJvWhh8hvy7WB0tWYcE/9d6h8vQ0d3B F9CfhQMUXHpzKX8OW6O/Sw==; Received: from [130.117.225.5] (helo=dev012.aci.vzint.dev) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x6WpK-00GSrt-1j; Tue, 15 Sep 2026 19:22:53 +0200 From: Vladimir Riabchun To: devel@openvz.org Date: Tue, 15 Sep 2026 17:22:34 +0000 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 X-OZ-Fwd: true Subject: [Devel] [PATCH VZ10 v9 6/8] ve: Introduce per-VE failcount X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org It may be useful to have a history of resource limit hits for every VE, this may simplify debugging and provide some information about the resources usage. This information is provided by ve.failcount file, any write to it resets all failcounts. To add a new failcounter we need to create a new atomic_t field name_failcount in ve structure and add a new VE_FC_ENTRY in ve_failcounts array. One change, unrelated to failcounts: aio fields are now initialized in ve0. https://virtuozzo.atlassian.net/browse/VSTOR-135520 Feature: per-ve failcounters Signed-off-by: Vladimir Riabchun --- fs/aio.c | 1 + fs/namespace.c | 2 ++ include/linux/ve.h | 16 +++++++++ kernel/bpf/syscall.c | 1 + kernel/ve/ve.c | 70 ++++++++++++++++++++++++++++++++++++++++ net/core/dev.c | 10 ++---- net/core/neighbour.c | 3 +- net/core/net_namespace.c | 4 ++- 8 files changed, 96 insertions(+), 11 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index cb63416af135..4ae06bcd47f2 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -814,6 +814,7 @@ static struct kioctx *ioctx_alloc(unsigned nr_events) spin_lock(&ve->aio_nr_lock); if (ve->aio_nr + ctx->max_reqs > ve->aio_max_nr || ve->aio_nr + ctx->max_reqs < ve->aio_nr) { + ve_failcount_inc(ve, aio); spin_unlock(&ve->aio_nr_lock); err = -EAGAIN; goto err_ctx; diff --git a/fs/namespace.c b/fs/namespace.c index 1d6e66cd7174..ea01664ff5f2 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -3380,6 +3380,8 @@ static inline int ve_try_reserve_mount(struct ve_struct *ve) if (ret) get_ve(ve); + else + ve_failcount_inc(ve, mnt); return ret; } diff --git a/include/linux/ve.h b/include/linux/ve.h index fabc608e31f5..065129b42768 100644 --- a/include/linux/ve.h +++ b/include/linux/ve.h @@ -80,12 +80,15 @@ struct ve_struct { struct kmapset_key proc_perms_key; atomic_t netns_avail_nr; + atomic_t netns_failcount; int netns_max_nr; atomic_t netif_avail_nr; + atomic_t netif_failcount; int netif_max_nr; atomic_t bpf_prog_avail_nr; + atomic_t bpf_prog_failcount; int bpf_prog_max_nr; atomic64_t _uevent_seqnum; @@ -94,6 +97,7 @@ struct ve_struct { atomic_t arp_neigh_nr; atomic_t nd_neigh_nr; + atomic_t neigh_tbl_failcount; unsigned long meminfo_val; /* @@ -102,6 +106,7 @@ struct ve_struct { * other containers. */ atomic_t mnt_avail_nr; /* number of available VE mounts */ + atomic_t mnt_failcount; int mnt_max_nr; #ifdef CONFIG_COREDUMP @@ -129,6 +134,7 @@ struct ve_struct { spinlock_t aio_nr_lock; unsigned long aio_nr; unsigned long aio_max_nr; + atomic_t aio_failcount; #endif struct vfsmount *devtmpfs_mnt; }; @@ -151,6 +157,16 @@ extern int nr_ve; #define BPF_PROG_MAX_NR_DEFAULT 256 /* number of loaded BPF progs per-VE */ #define MNT_MAX_NR_DEFAULT 4096 /* number of mounts per-VE */ +#define ve_failcount_inc(ve, name) \ +do { \ + struct ve_struct *__ve = (ve); \ + \ + atomic_inc(&__ve->name##_failcount); \ + ve_pr_warn_ratelimited(VE_LOG_BOTH, "CT%s: hits the " #name \ + " limit, see the '" #name "' counter in ve.failcount " \ + "of the container's ve cgroup\n", ve_name(__ve)); \ +} while (0) + #ifdef CONFIG_VE static inline void ve_set_state(struct ve_struct *ve, int new_state) { diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index c94d4240e3d3..8498bc9df7ea 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2891,6 +2891,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size) if (!bpf_cap && type == BPF_PROG_TYPE_CGROUP_DEVICE) { load_ve = get_exec_env(); if (atomic_dec_if_positive(&load_ve->bpf_prog_avail_nr) < 0) { + ve_failcount_inc(load_ve, bpf_prog); load_ve = NULL; err = -ENOSPC; goto put_token; diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c index 5ebdb4b7baa7..9261565208e6 100644 --- a/kernel/ve/ve.c +++ b/kernel/ve/ve.c @@ -100,10 +100,13 @@ struct ve_struct ve0 = { .features = -1, .sched_lat_ve.cur = &ve0_lat_stats, .netns_avail_nr = ATOMIC_INIT(INT_MAX), + .netns_failcount = ATOMIC_INIT(0), .netns_max_nr = INT_MAX, .netif_avail_nr = ATOMIC_INIT(INT_MAX), + .netif_failcount = ATOMIC_INIT(0), .netif_max_nr = INT_MAX, .bpf_prog_avail_nr = ATOMIC_INIT(INT_MAX), + .bpf_prog_failcount = ATOMIC_INIT(0), .bpf_prog_max_nr = INT_MAX, .fsync_enable = FSYNC_FILTERED, ._randomize_va_space = @@ -115,8 +118,16 @@ struct ve_struct ve0 = { .arp_neigh_nr = ATOMIC_INIT(0), .nd_neigh_nr = ATOMIC_INIT(0), + .neigh_tbl_failcount = ATOMIC_INIT(0), .mnt_avail_nr = ATOMIC_INIT(INT_MAX), .mnt_max_nr = INT_MAX, + .mnt_failcount = ATOMIC_INIT(0), +#ifdef CONFIG_AIO + .aio_nr_lock = __SPIN_LOCK_UNLOCKED(aio_nr_lock), + .aio_nr = 0, + .aio_max_nr = AIO_MAX_NR_DEFAULT, + .aio_failcount = ATOMIC_INIT(0), +#endif .meminfo_val = VE_MEMINFO_SYSTEM, #ifdef CONFIG_X86 .umh_running_helpers = ATOMIC_INIT(0), @@ -787,12 +798,15 @@ static struct cgroup_subsys_state *ve_create(struct cgroup_subsys_state *parent_ ve->fsync_enable = FSYNC_FILTERED; atomic_set(&ve->netns_avail_nr, NETNS_MAX_NR_DEFAULT); + atomic_set(&ve->netns_failcount, 0); ve->netns_max_nr = NETNS_MAX_NR_DEFAULT; atomic_set(&ve->netif_avail_nr, NETIF_MAX_NR_DEFAULT); + atomic_set(&ve->netif_failcount, 0); ve->netif_max_nr = NETIF_MAX_NR_DEFAULT; atomic_set(&ve->bpf_prog_avail_nr, BPF_PROG_MAX_NR_DEFAULT); + atomic_set(&ve->bpf_prog_failcount, 0); ve->bpf_prog_max_nr = BPF_PROG_MAX_NR_DEFAULT; err = ve_log_init(ve); @@ -821,7 +835,9 @@ static struct cgroup_subsys_state *ve_create(struct cgroup_subsys_state *parent_ atomic_set(&ve->arp_neigh_nr, 0); atomic_set(&ve->nd_neigh_nr, 0); + atomic_set(&ve->neigh_tbl_failcount, 0); ve->mnt_max_nr = MNT_MAX_NR_DEFAULT; + atomic_set(&ve->mnt_failcount, 0); atomic_set(&ve->mnt_avail_nr, MNT_MAX_NR_DEFAULT); #ifdef CONFIG_COREDUMP @@ -834,6 +850,7 @@ static struct cgroup_subsys_state *ve_create(struct cgroup_subsys_state *parent_ spin_lock_init(&ve->aio_nr_lock); ve->aio_nr = 0; ve->aio_max_nr = AIO_MAX_NR_DEFAULT; + atomic_set(&ve->aio_failcount, 0); #endif return &ve->css; @@ -1074,6 +1091,53 @@ VE_RESOURCE(mnt); VE_RESOURCE(netif); VE_RESOURCE(bpf_prog); +static const struct ve_failcount_entry { + const char *name; + size_t offset; +} ve_failcounts[] = { +#define VE_FC_ENTRY(name) { #name, offsetof(struct ve_struct, name##_failcount) } + VE_FC_ENTRY(netns), + VE_FC_ENTRY(mnt), + VE_FC_ENTRY(netif), + VE_FC_ENTRY(bpf_prog), + VE_FC_ENTRY(neigh_tbl), +#ifdef CONFIG_AIO + VE_FC_ENTRY(aio), +#endif + {} +}; + +static int ve_failcount_read(struct seq_file *sf, void *v) +{ + struct ve_struct *ve = css_to_ve(seq_css(sf)); + const struct ve_failcount_entry *entry; + atomic_t *fc; + + for (entry = ve_failcounts; entry->name; entry++) { + fc = (void *)ve + entry->offset; + seq_printf(sf, "%s: %d\n", entry->name, atomic_read(fc)); + } + return 0; +} + +static ssize_t ve_failcount_write(struct kernfs_open_file *of, char *buf, + size_t nbytes, loff_t off) +{ + struct ve_struct *ve = css_to_ve(of_css(of)); + const struct ve_failcount_entry *entry; + atomic_t *fc; + + if (!ve_is_super(get_exec_env()) && !ve->is_pseudosuper) + return -EPERM; + + for (entry = ve_failcounts; entry->name; entry++) { + fc = (void *)ve + entry->offset; + atomic_set(fc, 0); + } + + return nbytes; +} + static int ve_os_release_read(struct seq_file *sf, void *v) { struct cgroup_subsys_state *css = seq_css(sf); @@ -1613,6 +1677,12 @@ static struct cftype ve_cftypes[] = { .flags = CFTYPE_NOT_ON_ROOT, .write_u64 = ve_rpc_kill_write, }, + { + .name = "failcount", + .flags = CFTYPE_NOT_ON_ROOT, + .seq_show = ve_failcount_read, + .write = ve_failcount_write, + }, { } }; diff --git a/net/core/dev.c b/net/core/dev.c index c7dddb200489..7632ad1fd015 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10997,10 +10997,7 @@ int register_netdevice(struct net_device *dev) ret = -ENOMEM; if (atomic_dec_if_positive(&net->owner_ve->netif_avail_nr) < 0) { - ve_pr_warn_ratelimited(VE_LOG_BOTH, - "CT%s: hits max number of network devices, " - "increase ve::netif_max_nr parameter\n", - ve_name(net->owner_ve)); + ve_failcount_inc(net->owner_ve, netif); return ret; } @@ -12211,10 +12208,7 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net, err = -ENOMEM; if (atomic_dec_if_positive(&net->owner_ve->netif_avail_nr) < 0) { - ve_pr_warn_ratelimited(VE_LOG_BOTH, - "CT%s: hits max number of network devices, " - "increase ve::netif_max_nr parameter\n", - ve_name(net->owner_ve)); + ve_failcount_inc(net->owner_ve, netif); goto out; } atomic_inc(&dev_net(dev)->owner_ve->netif_avail_nr); diff --git a/net/core/neighbour.c b/net/core/neighbour.c index f90deb17fb25..c7d5e6df50c2 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -520,8 +520,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl, (glob_entries >= READ_ONCE(tbl->gc_thresh2) && time_after(now, READ_ONCE(tbl->last_flush) + 5 * HZ))) { if (!neigh_forced_gc(tbl, ve) && entries >= gc_thresh3) { - net_info_ratelimited("%s: neighbor table overflow!\n", - tbl->id); + ve_failcount_inc(ve, neigh_tbl); NEIGH_CACHE_STAT_INC(tbl, table_fulls); goto out_entries; } diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index b3d54cad984a..328e1c96b6f4 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -486,8 +486,10 @@ void net_drop_ns(void *p) #ifdef CONFIG_VE static int dec_netns_avail(struct ve_struct *ve) { - if (atomic_dec_if_positive(&ve->netns_avail_nr) < 0) + if (atomic_dec_if_positive(&ve->netns_avail_nr) < 0) { + ve_failcount_inc(ve, netns); return -ENOSPC; + } return 0; } -- 2.47.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel