linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Baxter, Jim" <jim_baxter@mentor.com>
To: David Miller <davem@davemloft.net>, <oneukum@suse.com>
Cc: <bjorn@mork.no>, <linux-usb@vger.kernel.org>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [RFC V1 1/1] net: cdc_ncm: Reduce memory use when kernel memory low
Date: Tue, 23 May 2017 20:06:53 +0100	[thread overview]
Message-ID: <97db8a45-55ec-b68f-6f88-e934f67d31fc@mentor.com> (raw)
In-Reply-To: <20170523.112625.33559883707681029.davem@davemloft.net>

From: David S. Miller (davem@davemloft.net)
Sent: Tue, 23 May 2017 11:26:25 -0400 
> From: Oliver Neukum <oneukum@suse.com>
> Date: Tue, 23 May 2017 10:42:48 +0200
> 
>>
>> We could use a counter. After the first failure, do it once, after the
>> second twice and so on. And reset the counter as a higher order
>> allocation works. (just bound it somewhere)
> 
> So an exponential backoff, that might work.
> 

As an idea I have created this patch as an addition to the original patch
in this series.

Would this be acceptable?

At the moment I have capped the value at 10, does anyone think it needs to
be much higher then that?

Regards,
Jim


diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index c06d20f..0e40603 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -89,6 +89,8 @@ struct cdc_ncm_stats {
        CDC_NCM_SIMPLE_STAT(rx_ntbs),
 };
 
+#define CDC_NCM_LOW_MEM_MAX_CNT 10
+
 static int cdc_ncm_get_sset_count(struct net_device __always_unused *netdev, int sset)
 {
        switch (sset) {
@@ -1111,8 +1113,13 @@ struct sk_buff *
 
        /* allocate a new OUT skb */
        if (!skb_out) {
-               ctx->tx_curr_size = ctx->tx_max;
-               skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC);
+               if (ctx->tx_low_mem_val == 0) {
+                       ctx->tx_curr_size = ctx->tx_max;
+                       skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC);
+                       if (skb_out == NULL) {
+                               ctx->tx_low_mem_max_cnt = min(ctx->tx_low_mem_max_cnt + 1, CDC_NCM_LOW_MEM_MAX_CNT);
+                               ctx->tx_low_mem_val = ctx->tx_low_mem_max_cnt;
+               }
                if (skb_out == NULL) {
                        /* See if a very small allocation is possible.
                         * We will send this packet immediately and hope
@@ -1127,12 +1134,13 @@ struct sk_buff *
 
                        /* No allocation possible so we will abort */
                        if (skb_out == NULL) {
-                               if (skb != NULL) {
+                               if (skb) {
                                        dev_kfree_skb_any(skb);
                                        dev->net->stats.tx_dropped++;
                                }
                                goto exit_no_skb;
                        }
+                       ctx->tx_low_mem_val--;
                }
                /* fill out the initial 16-bit NTB header */
                nth16 = (struct usb_cdc_ncm_nth16 *)memset(skb_put(skb_out, sizeof(struct usb_cdc_ncm_nth16)), 0, sizeof(struct usb_cdc_ncm_nth16));
diff --git a/include/linux/usb/cdc_ncm.h b/include/linux/usb/cdc_ncm.h
index 5162f38..25a0aed 100644
--- a/include/linux/usb/cdc_ncm.h
+++ b/include/linux/usb/cdc_ncm.h
@@ -118,6 +118,8 @@ struct cdc_ncm_ctx {
        u32 rx_max;
        u32 tx_max;
        u32 tx_curr_size;
+       u32 tx_low_mem_max_cnt;
+       u32 tx_low_mem_val;
        u32 max_datagram_size;
        u16 tx_max_datagrams;
        u16 tx_remainder;

  reply	other threads:[~2017-05-23 19:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-16 17:41 [RFC V1 0/1] Reduce cdc_ncm memory use when kernel memory low Jim Baxter
2017-05-16 17:41 ` [RFC V1 1/1] net: cdc_ncm: Reduce " Jim Baxter
2017-05-16 18:24   ` Bjørn Mork
2017-05-17  7:44     ` Oliver Neukum
2017-05-17 10:56       ` Baxter, Jim
2017-05-17 18:18     ` David Miller
2017-05-18 10:01       ` Oliver Neukum
2017-05-22 15:45       ` Baxter, Jim
2017-05-22 15:54         ` David Miller
2017-05-23  8:42           ` Oliver Neukum
2017-05-23 15:26             ` David Miller
2017-05-23 19:06               ` Baxter, Jim [this message]
     [not found]                 ` <1497263047.15677.13.camel@suse.com>
2017-06-12 12:32                   ` Baxter, Jim
2017-05-19 11:10   ` David Laight
2017-05-19 13:55     ` Bjørn Mork
2017-05-19 14:46       ` David Laight
2017-05-22 13:27         ` Oliver Neukum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=97db8a45-55ec-b68f-6f88-e934f67d31fc@mentor.com \
    --to=jim_baxter@mentor.com \
    --cc=bjorn@mork.no \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oneukum@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).