diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2008-04-24 04:02:16 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-04-24 04:02:16 -0400 |
commit | 5e659e4cb0eedacdc1f621a61e400a4611ddef8a (patch) | |
tree | fa3c8743010dd640c48584a6fa8a910d27350c01 /net/ipv4/tcp_ipv4.c | |
parent | 3d36696024499aef19dbf24a781e91a24fbbe4af (diff) |
[NET]: Fix heavy stack usage in seq_file output routines.
Plan C: we can follow the Al Viro's proposal about %n like in this patch.
The same applies to udp, fib (the /proc/net/route file), rt_cache and
sctp debug. This is minus ~150-200 bytes for each.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_ipv4.c')
-rw-r--r-- | net/ipv4/tcp_ipv4.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 776615180b93..0e9bc120707d 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -2255,13 +2255,13 @@ void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo) | |||
2255 | } | 2255 | } |
2256 | 2256 | ||
2257 | static void get_openreq4(struct sock *sk, struct request_sock *req, | 2257 | static void get_openreq4(struct sock *sk, struct request_sock *req, |
2258 | char *tmpbuf, int i, int uid) | 2258 | struct seq_file *f, int i, int uid, int *len) |
2259 | { | 2259 | { |
2260 | const struct inet_request_sock *ireq = inet_rsk(req); | 2260 | const struct inet_request_sock *ireq = inet_rsk(req); |
2261 | int ttd = req->expires - jiffies; | 2261 | int ttd = req->expires - jiffies; |
2262 | 2262 | ||
2263 | sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" | 2263 | seq_printf(f, "%4d: %08X:%04X %08X:%04X" |
2264 | " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p", | 2264 | " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n", |
2265 | i, | 2265 | i, |
2266 | ireq->loc_addr, | 2266 | ireq->loc_addr, |
2267 | ntohs(inet_sk(sk)->sport), | 2267 | ntohs(inet_sk(sk)->sport), |
@@ -2276,10 +2276,11 @@ static void get_openreq4(struct sock *sk, struct request_sock *req, | |||
2276 | 0, /* non standard timer */ | 2276 | 0, /* non standard timer */ |
2277 | 0, /* open_requests have no inode */ | 2277 | 0, /* open_requests have no inode */ |
2278 | atomic_read(&sk->sk_refcnt), | 2278 | atomic_read(&sk->sk_refcnt), |
2279 | req); | 2279 | req, |
2280 | len); | ||
2280 | } | 2281 | } |
2281 | 2282 | ||
2282 | static void get_tcp4_sock(struct sock *sk, char *tmpbuf, int i) | 2283 | static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len) |
2283 | { | 2284 | { |
2284 | int timer_active; | 2285 | int timer_active; |
2285 | unsigned long timer_expires; | 2286 | unsigned long timer_expires; |
@@ -2305,8 +2306,8 @@ static void get_tcp4_sock(struct sock *sk, char *tmpbuf, int i) | |||
2305 | timer_expires = jiffies; | 2306 | timer_expires = jiffies; |
2306 | } | 2307 | } |
2307 | 2308 | ||
2308 | sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX " | 2309 | seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX " |
2309 | "%08X %5d %8d %lu %d %p %u %u %u %u %d", | 2310 | "%08X %5d %8d %lu %d %p %u %u %u %u %d%n", |
2310 | i, src, srcp, dest, destp, sk->sk_state, | 2311 | i, src, srcp, dest, destp, sk->sk_state, |
2311 | tp->write_seq - tp->snd_una, | 2312 | tp->write_seq - tp->snd_una, |
2312 | sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog : | 2313 | sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog : |
@@ -2322,11 +2323,12 @@ static void get_tcp4_sock(struct sock *sk, char *tmpbuf, int i) | |||
2322 | icsk->icsk_ack.ato, | 2323 | icsk->icsk_ack.ato, |
2323 | (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, | 2324 | (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, |
2324 | tp->snd_cwnd, | 2325 | tp->snd_cwnd, |
2325 | tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh); | 2326 | tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh, |
2327 | len); | ||
2326 | } | 2328 | } |
2327 | 2329 | ||
2328 | static void get_timewait4_sock(struct inet_timewait_sock *tw, | 2330 | static void get_timewait4_sock(struct inet_timewait_sock *tw, |
2329 | char *tmpbuf, int i) | 2331 | struct seq_file *f, int i, int *len) |
2330 | { | 2332 | { |
2331 | __be32 dest, src; | 2333 | __be32 dest, src; |
2332 | __u16 destp, srcp; | 2334 | __u16 destp, srcp; |
@@ -2340,11 +2342,11 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw, | |||
2340 | destp = ntohs(tw->tw_dport); | 2342 | destp = ntohs(tw->tw_dport); |
2341 | srcp = ntohs(tw->tw_sport); | 2343 | srcp = ntohs(tw->tw_sport); |
2342 | 2344 | ||
2343 | sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" | 2345 | seq_printf(f, "%4d: %08X:%04X %08X:%04X" |
2344 | " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p", | 2346 | " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n", |
2345 | i, src, srcp, dest, destp, tw->tw_substate, 0, 0, | 2347 | i, src, srcp, dest, destp, tw->tw_substate, 0, 0, |
2346 | 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0, | 2348 | 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0, |
2347 | atomic_read(&tw->tw_refcnt), tw); | 2349 | atomic_read(&tw->tw_refcnt), tw, len); |
2348 | } | 2350 | } |
2349 | 2351 | ||
2350 | #define TMPSZ 150 | 2352 | #define TMPSZ 150 |
@@ -2352,7 +2354,7 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw, | |||
2352 | static int tcp4_seq_show(struct seq_file *seq, void *v) | 2354 | static int tcp4_seq_show(struct seq_file *seq, void *v) |
2353 | { | 2355 | { |
2354 | struct tcp_iter_state* st; | 2356 | struct tcp_iter_state* st; |
2355 | char tmpbuf[TMPSZ + 1]; | 2357 | int len; |
2356 | 2358 | ||
2357 | if (v == SEQ_START_TOKEN) { | 2359 | if (v == SEQ_START_TOKEN) { |
2358 | seq_printf(seq, "%-*s\n", TMPSZ - 1, | 2360 | seq_printf(seq, "%-*s\n", TMPSZ - 1, |
@@ -2366,16 +2368,16 @@ static int tcp4_seq_show(struct seq_file *seq, void *v) | |||
2366 | switch (st->state) { | 2368 | switch (st->state) { |
2367 | case TCP_SEQ_STATE_LISTENING: | 2369 | case TCP_SEQ_STATE_LISTENING: |
2368 | case TCP_SEQ_STATE_ESTABLISHED: | 2370 | case TCP_SEQ_STATE_ESTABLISHED: |
2369 | get_tcp4_sock(v, tmpbuf, st->num); | 2371 | get_tcp4_sock(v, seq, st->num, &len); |
2370 | break; | 2372 | break; |
2371 | case TCP_SEQ_STATE_OPENREQ: | 2373 | case TCP_SEQ_STATE_OPENREQ: |
2372 | get_openreq4(st->syn_wait_sk, v, tmpbuf, st->num, st->uid); | 2374 | get_openreq4(st->syn_wait_sk, v, seq, st->num, st->uid, &len); |
2373 | break; | 2375 | break; |
2374 | case TCP_SEQ_STATE_TIME_WAIT: | 2376 | case TCP_SEQ_STATE_TIME_WAIT: |
2375 | get_timewait4_sock(v, tmpbuf, st->num); | 2377 | get_timewait4_sock(v, seq, st->num, &len); |
2376 | break; | 2378 | break; |
2377 | } | 2379 | } |
2378 | seq_printf(seq, "%-*s\n", TMPSZ - 1, tmpbuf); | 2380 | seq_printf(seq, "%*s\n", TMPSZ - 1 - len, ""); |
2379 | out: | 2381 | out: |
2380 | return 0; | 2382 | return 0; |
2381 | } | 2383 | } |