From: Hideo AOKI <haoki@redhat.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
netdev <netdev@vger.kernel.org>
Cc: David Miller <davem@davemloft.net>,
Satoshi Oshima <satoshi.oshima.fk@hitachi.com>,
Bill Fink <billfink@mindspring.com>,
Andi Kleen <andi@firstfloor.org>,
Evgeniy Polyakov <johnpol@2ka.mipt.ru>,
Stephen Hemminger <shemminger@linux-foundation.org>,
yoshfuji@linux-ipv6.org,
Yumiko Sugita <yumiko.sugita.yf@hitachi.com>,
haoki@redhat.com
Subject: [PATCH 2/4] datagram: mem_scheudle functions
Date: Wed, 28 Nov 2007 13:52:59 -0500 [thread overview]
Message-ID: <474DB90B.9090107@redhat.com> (raw)
In-Reply-To: <474DB80E.5070403@redhat.com>
This patch introduces datagram memory accounting functions. Owing to
call memory schedule functions from IP layer, sk_wmem_schedule() is
also added.
Cc: Satoshi Oshima <satoshi.oshima.fk@hitachi.com>
signed-off-by: Hideo Aoki <haoki@redhat.com>
---
include/net/sock.h | 31 +++++++++++++++++++++++++++++++
net/core/datagram.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff -pruN net-2.6-udp-take9a2-p1/include/net/sock.h net-2.6-udp-take9a2-p2/include/net/sock.h
--- net-2.6-udp-take9a2-p1/include/net/sock.h 2007-11-20 10:29:40.000000000 -0500
+++ net-2.6-udp-take9a2-p2/include/net/sock.h 2007-11-27 11:11:38.000000000 -0500
@@ -778,6 +778,37 @@ static inline int sk_stream_wmem_schedul
sk_stream_mem_schedule(sk, size, 0);
}
+extern int sk_datagram_mem_schedule(struct sock *sk, int size, int kind);
+
+#define SK_DATAGRAM_MEM_QUANTUM ((unsigned int)PAGE_SIZE)
+
+static inline int sk_datagram_pages(int amt)
+{
+ /* Cast to unsigned as an optimization, since amt is always positive. */
+ return DIV_ROUND_UP((unsigned int)amt, SK_DATAGRAM_MEM_QUANTUM);
+}
+
+static inline int sk_datagram_rmem_schedule(struct sock *sk,
+ struct sk_buff *skb)
+{
+ return sk_datagram_mem_schedule(sk, skb->truesize, 1);
+}
+
+static inline int sk_datagram_wmem_schedule(struct sock *sk, int size)
+{
+ return sk_datagram_mem_schedule(sk, size, 0);
+}
+
+static inline int sk_wmem_schedule(struct sock *sk, int size)
+{
+ if (sk->sk_type == SOCK_STREAM)
+ return sk_stream_wmem_schedule(sk, size);
+ else if (sk->sk_type == SOCK_DGRAM)
+ return sk_datagram_wmem_schedule(sk, size);
+ else
+ return 1;
+}
+
/* Used by processes to "lock" a socket state, so that
* interrupts and bottom half handlers won't change it
* from under us. It essentially blocks any incoming
diff -pruN net-2.6-udp-take9a2-p1/net/core/datagram.c net-2.6-udp-take9a2-p2/net/core/datagram.c
--- net-2.6-udp-take9a2-p1/net/core/datagram.c 2007-11-14 10:49:06.000000000 -0500
+++ net-2.6-udp-take9a2-p2/net/core/datagram.c 2007-11-28 12:10:05.000000000 -0500
@@ -484,6 +484,39 @@ fault:
}
/**
+ * sk_datagram_mem_schedule - memory accounting for datagram protocls
+ * @sk: socket
+ * @size: memory size to allocate
+ * @kind: allocation type
+ *
+ * If kind is 0, it means wmem allocation. Otherwise it means rmem
+ * allocation.
+ */
+int sk_datagram_mem_schedule(struct sock *sk, int size, int kind)
+{
+ int amt;
+ struct proto *prot = sk->sk_prot;
+
+ /* Don't account and limit memory if protocol doesn't support. */
+ if (prot->memory_allocated == NULL)
+ return 1;
+
+ amt = sk_datagram_pages(size);
+ atomic_add(amt, prot->memory_allocated);
+ if (kind &&
+ (atomic_read(prot->memory_allocated) < prot->sysctl_mem[0] ||
+ atomic_read(&sk->sk_rmem_alloc) + size < prot->sysctl_rmem[0]))
+ return 1;
+ else if (atomic_read(prot->memory_allocated) < prot->sysctl_mem[0] ||
+ atomic_read(&sk->sk_wmem_alloc) + size < prot->sysctl_wmem[0])
+ return 1;
+
+ /* Undo changes. */
+ atomic_sub(amt, prot->memory_allocated);
+ return 0;
+}
+
+/**
* datagram_poll - generic datagram poll
* @file: file struct
* @sock: socket
@@ -542,3 +575,4 @@ EXPORT_SYMBOL(skb_copy_and_csum_datagram
EXPORT_SYMBOL(skb_copy_datagram_iovec);
EXPORT_SYMBOL(skb_free_datagram);
EXPORT_SYMBOL(skb_recv_datagram);
+EXPORT_SYMBOL(sk_datagram_mem_schedule);
--
Hitachi Computer Products (America) Inc.
next prev parent reply other threads:[~2007-11-28 18:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-28 18:48 [PATCH 0/4] UDP memory accounting and limitation (take 9) Hideo AOKI
2007-11-28 18:52 ` [PATCH 1/4] udp: fix send buffer check Hideo AOKI
2007-11-28 18:52 ` Hideo AOKI [this message]
2007-12-01 12:09 ` [PATCH 2/4] datagram: mem_scheudle functions Herbert Xu
2007-12-04 0:10 ` Hideo AOKI
2007-12-15 14:45 ` Herbert Xu
2007-12-18 17:02 ` Hideo AOKI
2007-11-28 18:53 ` [PATCH 3/4] udp: add udp_mem, udp_rmem_min and udp_wmem_min Hideo AOKI
2007-11-28 18:53 ` [PATCH 4/4] udp: memory accounting in IPv4 Hideo AOKI
2007-12-01 12:21 ` Herbert Xu
2007-12-01 13:08 ` Eric Dumazet
2007-12-01 13:16 ` Herbert Xu
2007-12-04 0:14 ` Hideo AOKI
2007-12-04 0:26 ` Herbert Xu
2007-12-06 4:28 ` Hideo AOKI
2007-12-10 9:22 ` Herbert Xu
2007-12-11 1:28 ` Hideo AOKI
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=474DB90B.9090107@redhat.com \
--to=haoki@redhat.com \
--cc=andi@firstfloor.org \
--cc=billfink@mindspring.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=johnpol@2ka.mipt.ru \
--cc=netdev@vger.kernel.org \
--cc=satoshi.oshima.fk@hitachi.com \
--cc=shemminger@linux-foundation.org \
--cc=yoshfuji@linux-ipv6.org \
--cc=yumiko.sugita.yf@hitachi.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.