* [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures @ 2012-11-15 23:41 Eric Dumazet 2012-11-15 23:55 ` Joe Perches 2012-11-16 6:39 ` David Miller 0 siblings, 2 replies; 8+ messages in thread From: Eric Dumazet @ 2012-11-15 23:41 UTC (permalink / raw) To: David Miller; +Cc: netdev, Julien Tinnes From: Eric Dumazet <edumazet@google.com> order-5 allocations can fail with current kernels, we should try to reduce allocation sizes to allow network namespace creation. Reported-by: Julien Tinnes <jln@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> --- net/ipv4/tcp_metrics.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index 53bc584..15e93c4 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c @@ -1030,14 +1030,17 @@ static int __net_init tcp_net_metrics_init(struct net *net) else slots = 8 * 1024; } - +retry: net->ipv4.tcp_metrics_hash_log = order_base_2(slots); size = sizeof(struct tcpm_hash_bucket) << net->ipv4.tcp_metrics_hash_log; - net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL); - if (!net->ipv4.tcp_metrics_hash) - return -ENOMEM; - + net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); + if (!net->ipv4.tcp_metrics_hash) { + if (slots <= 16) + return -ENOMEM; + slots >>= 1; + goto retry; + } return 0; } ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures 2012-11-15 23:41 [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures Eric Dumazet @ 2012-11-15 23:55 ` Joe Perches 2012-11-16 0:47 ` Eric Dumazet 2012-11-16 6:39 ` David Miller 1 sibling, 1 reply; 8+ messages in thread From: Joe Perches @ 2012-11-15 23:55 UTC (permalink / raw) To: Eric Dumazet; +Cc: David Miller, netdev, Julien Tinnes On Thu, 2012-11-15 at 15:41 -0800, Eric Dumazet wrote: > From: Eric Dumazet <edumazet@google.com> > > order-5 allocations can fail with current kernels, we should > try to reduce allocation sizes to allow network namespace > creation. > > Reported-by: Julien Tinnes <jln@google.com> > Signed-off-by: Eric Dumazet <edumazet@google.com> > --- > net/ipv4/tcp_metrics.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c > index 53bc584..15e93c4 100644 > --- a/net/ipv4/tcp_metrics.c > +++ b/net/ipv4/tcp_metrics.c > @@ -1030,14 +1030,17 @@ static int __net_init tcp_net_metrics_init(struct net *net) > else > slots = 8 * 1024; > } > - > +retry: > net->ipv4.tcp_metrics_hash_log = order_base_2(slots); > size = sizeof(struct tcpm_hash_bucket) << net->ipv4.tcp_metrics_hash_log; > > - net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL); > - if (!net->ipv4.tcp_metrics_hash) > - return -ENOMEM; > - > + net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); > + if (!net->ipv4.tcp_metrics_hash) { > + if (slots <= 16) > + return -ENOMEM; maybe readd the warning for OOM reporting here? ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures 2012-11-15 23:55 ` Joe Perches @ 2012-11-16 0:47 ` Eric Dumazet 0 siblings, 0 replies; 8+ messages in thread From: Eric Dumazet @ 2012-11-16 0:47 UTC (permalink / raw) To: Joe Perches; +Cc: David Miller, netdev, Julien Tinnes On Thu, 2012-11-15 at 15:55 -0800, Joe Perches wrote: > maybe readd the warning for OOM reporting here? > Storing tcp metrics is a best effort, this can be silently ignored. And order-0 are going to work, unless machine is in critical state, that gives enough room. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures 2012-11-15 23:41 [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures Eric Dumazet 2012-11-15 23:55 ` Joe Perches @ 2012-11-16 6:39 ` David Miller 2012-11-16 15:31 ` Eric Dumazet 1 sibling, 1 reply; 8+ messages in thread From: David Miller @ 2012-11-16 6:39 UTC (permalink / raw) To: eric.dumazet; +Cc: netdev, jln From: Eric Dumazet <eric.dumazet@gmail.com> Date: Thu, 15 Nov 2012 15:41:04 -0800 > From: Eric Dumazet <edumazet@google.com> > > order-5 allocations can fail with current kernels, we should > try to reduce allocation sizes to allow network namespace > creation. > > Reported-by: Julien Tinnes <jln@google.com> > Signed-off-by: Eric Dumazet <edumazet@google.com> Indeed, this has to be done better. But this kind of retry solution results in non-deterministic behavior. Yes the tcp metrics cache is best effort, but it's size can influence behavior in a substantial way depending upon the workload. I would suggest that we instead use different limits, ones which the page allocator will satisfy for us always with GFP_KERNEL. 1) include linux/mmzone.h 2) Make the two limits based upon PAGE_ALLOC_COSTLY_ORDER. That is, make the larger table size PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER and the smaller one PAGE_SIZE << (PAGE_ALLOC_COSTLY_ORDER - 1). How about something like this? diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index 53bc584..d4b2d42 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c @@ -1,7 +1,6 @@ #include <linux/rcupdate.h> #include <linux/spinlock.h> #include <linux/jiffies.h> -#include <linux/bootmem.h> #include <linux/module.h> #include <linux/cache.h> #include <linux/slab.h> @@ -9,6 +8,7 @@ #include <linux/tcp.h> #include <linux/hash.h> #include <linux/tcp_metrics.h> +#include <linux/mmzone.h> #include <net/inet_connection_sock.h> #include <net/net_namespace.h> @@ -1025,10 +1025,12 @@ static int __net_init tcp_net_metrics_init(struct net *net) slots = tcpmhash_entries; if (!slots) { - if (totalram_pages >= 128 * 1024) - slots = 16 * 1024; - else - slots = 8 * 1024; + int order = PAGE_ALLOC_COSTLY_ORDER; + + if (totalram_pages < 128 * 1024) + order--; + slots = (PAGE_SIZE << order) / + sizeof(struct tcpm_hash_bucket); } net->ipv4.tcp_metrics_hash_log = order_base_2(slots); ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures 2012-11-16 6:39 ` David Miller @ 2012-11-16 15:31 ` Eric Dumazet 2012-11-16 18:37 ` David Miller 2012-11-16 18:51 ` Julien Tinnes 0 siblings, 2 replies; 8+ messages in thread From: Eric Dumazet @ 2012-11-16 15:31 UTC (permalink / raw) To: David Miller; +Cc: netdev, jln On Fri, 2012-11-16 at 01:39 -0500, David Miller wrote: > From: Eric Dumazet <eric.dumazet@gmail.com> > Date: Thu, 15 Nov 2012 15:41:04 -0800 > > > From: Eric Dumazet <edumazet@google.com> > > > > order-5 allocations can fail with current kernels, we should > > try to reduce allocation sizes to allow network namespace > > creation. > > > > Reported-by: Julien Tinnes <jln@google.com> > > Signed-off-by: Eric Dumazet <edumazet@google.com> > > Indeed, this has to be done better. > > But this kind of retry solution results in non-deterministic behavior. > Yes the tcp metrics cache is best effort, but it's size can influence > behavior in a substantial way depending upon the workload. > > I would suggest that we instead use different limits, ones which the > page allocator will satisfy for us always with GFP_KERNEL. > > 1) include linux/mmzone.h > > 2) Make the two limits based upon PAGE_ALLOC_COSTLY_ORDER. > > That is, make the larger table size PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER > and the smaller one PAGE_SIZE << (PAGE_ALLOC_COSTLY_ORDER - 1). Well, we dont really know what the size needs to be, and your proposal reduces the size by a 4 factor, even for the initial namespace. Julien report was about Chrome browser own netns, on a suspend/resume cycle (or something like that) If size can influence behavior, we could try a vmalloc() if kmalloc() fails... Thanks [PATCH v3] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures order-5 allocations can fail with current kernels, we should try vmalloc() as well. Reported-by: Julien Tinnes <jln@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> --- net/ipv4/tcp_metrics.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index 53bc584..f696d7c 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c @@ -1,7 +1,6 @@ #include <linux/rcupdate.h> #include <linux/spinlock.h> #include <linux/jiffies.h> -#include <linux/bootmem.h> #include <linux/module.h> #include <linux/cache.h> #include <linux/slab.h> @@ -9,6 +8,7 @@ #include <linux/tcp.h> #include <linux/hash.h> #include <linux/tcp_metrics.h> +#include <linux/vmalloc.h> #include <net/inet_connection_sock.h> #include <net/net_namespace.h> @@ -1034,7 +1034,10 @@ static int __net_init tcp_net_metrics_init(struct net *net) net->ipv4.tcp_metrics_hash_log = order_base_2(slots); size = sizeof(struct tcpm_hash_bucket) << net->ipv4.tcp_metrics_hash_log; - net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL); + net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); + if (!net->ipv4.tcp_metrics_hash) + net->ipv4.tcp_metrics_hash = vzalloc(size); + if (!net->ipv4.tcp_metrics_hash) return -ENOMEM; @@ -1055,7 +1058,10 @@ static void __net_exit tcp_net_metrics_exit(struct net *net) tm = next; } } - kfree(net->ipv4.tcp_metrics_hash); + if (is_vmalloc_addr(net->ipv4.tcp_metrics_hash)) + vfree(net->ipv4.tcp_metrics_hash); + else + kfree(net->ipv4.tcp_metrics_hash); } static __net_initdata struct pernet_operations tcp_net_metrics_ops = { ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures 2012-11-16 15:31 ` Eric Dumazet @ 2012-11-16 18:37 ` David Miller 2012-11-16 18:51 ` Julien Tinnes 1 sibling, 0 replies; 8+ messages in thread From: David Miller @ 2012-11-16 18:37 UTC (permalink / raw) To: eric.dumazet; +Cc: netdev, jln From: Eric Dumazet <eric.dumazet@gmail.com> Date: Fri, 16 Nov 2012 07:31:53 -0800 > Well, we dont really know what the size needs to be, and your proposal > reduces the size by a 4 factor, even for the initial namespace. > > Julien report was about Chrome browser own netns, on a suspend/resume > cycle (or something like that) > > If size can influence behavior, we could try a vmalloc() if kmalloc() > fails... Agreed. > [PATCH v3] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures > > order-5 allocations can fail with current kernels, we should > try vmalloc() as well. > > Reported-by: Julien Tinnes <jln@google.com> > Signed-off-by: Eric Dumazet <edumazet@google.com> This looks great, applied, thanks. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures 2012-11-16 15:31 ` Eric Dumazet 2012-11-16 18:37 ` David Miller @ 2012-11-16 18:51 ` Julien Tinnes 2012-11-16 19:08 ` Eric Dumazet 1 sibling, 1 reply; 8+ messages in thread From: Julien Tinnes @ 2012-11-16 18:51 UTC (permalink / raw) To: Eric Dumazet; +Cc: David Miller, netdev On Fri, Nov 16, 2012 at 7:31 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote: > On Fri, 2012-11-16 at 01:39 -0500, David Miller wrote: >> From: Eric Dumazet <eric.dumazet@gmail.com> >> Date: Thu, 15 Nov 2012 15:41:04 -0800 >> >> > From: Eric Dumazet <edumazet@google.com> >> > >> > order-5 allocations can fail with current kernels, we should >> > try to reduce allocation sizes to allow network namespace >> > creation. >> > >> > Reported-by: Julien Tinnes <jln@google.com> >> > Signed-off-by: Eric Dumazet <edumazet@google.com> >> >> Indeed, this has to be done better. >> >> But this kind of retry solution results in non-deterministic behavior. >> Yes the tcp metrics cache is best effort, but it's size can influence >> behavior in a substantial way depending upon the workload. >> >> I would suggest that we instead use different limits, ones which the >> page allocator will satisfy for us always with GFP_KERNEL. >> >> 1) include linux/mmzone.h >> >> 2) Make the two limits based upon PAGE_ALLOC_COSTLY_ORDER. >> >> That is, make the larger table size PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER >> and the smaller one PAGE_SIZE << (PAGE_ALLOC_COSTLY_ORDER - 1). > > Well, we dont really know what the size needs to be, and your proposal > reduces the size by a 4 factor, even for the initial namespace. > > Julien report was about Chrome browser own netns, on a suspend/resume > cycle (or something like that) It happens when users start Chrome. Chrome will create one new network NS (for the sandbox). This has been used for a few years now, but we had our first report in January of this year and we've been getting a few reports very recently at a rate that is starting to worry me (crbug.com/110756). Thanks a lot for helping with this! Julien ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures 2012-11-16 18:51 ` Julien Tinnes @ 2012-11-16 19:08 ` Eric Dumazet 0 siblings, 0 replies; 8+ messages in thread From: Eric Dumazet @ 2012-11-16 19:08 UTC (permalink / raw) To: Julien Tinnes; +Cc: David Miller, netdev On Fri, 2012-11-16 at 10:51 -0800, Julien Tinnes wrote: > It happens when users start Chrome. Chrome will create one new network > NS (for the sandbox). > > This has been used for a few years now, but we had our first report in > January of this year and we've been getting a few reports very > recently at a rate that is starting to worry me (crbug.com/110756). > > Thanks a lot for helping with this! Thanks for bringing this issue to our attention ! ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-11-16 19:08 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-11-15 23:41 [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures Eric Dumazet 2012-11-15 23:55 ` Joe Perches 2012-11-16 0:47 ` Eric Dumazet 2012-11-16 6:39 ` David Miller 2012-11-16 15:31 ` Eric Dumazet 2012-11-16 18:37 ` David Miller 2012-11-16 18:51 ` Julien Tinnes 2012-11-16 19:08 ` Eric Dumazet
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox