Skip to content

Commit bd68a2a

Browse files
Eric Dumazetdavem330
authored andcommitted
net: set SK_MEM_QUANTUM to 4096
Systems with large pages (64KB pages for example) do not always have huge quantity of memory. A big SK_MEM_QUANTUM value leads to fewer interactions with the global counters (like tcp_memory_allocated) but might trigger memory pressure much faster, giving suboptimal TCP performance since windows are lowered to ridiculous values. Note that sysctl_mem units being in pages and in ABI, we also need to change sk_prot_mem_limits() accordingly. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a13925a commit bd68a2a

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

include/net/sock.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,11 +1162,6 @@ static inline void sk_enter_memory_pressure(struct sock *sk)
11621162
sk->sk_prot->enter_memory_pressure(sk);
11631163
}
11641164

1165-
static inline long sk_prot_mem_limits(const struct sock *sk, int index)
1166-
{
1167-
return sk->sk_prot->sysctl_mem[index];
1168-
}
1169-
11701165
static inline long
11711166
sk_memory_allocated(const struct sock *sk)
11721167
{
@@ -1281,11 +1276,27 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind);
12811276
void __sk_mem_reduce_allocated(struct sock *sk, int amount);
12821277
void __sk_mem_reclaim(struct sock *sk, int amount);
12831278

1284-
#define SK_MEM_QUANTUM ((int)PAGE_SIZE)
1279+
/* We used to have PAGE_SIZE here, but systems with 64KB pages
1280+
* do not necessarily have 16x time more memory than 4KB ones.
1281+
*/
1282+
#define SK_MEM_QUANTUM 4096
12851283
#define SK_MEM_QUANTUM_SHIFT ilog2(SK_MEM_QUANTUM)
12861284
#define SK_MEM_SEND 0
12871285
#define SK_MEM_RECV 1
12881286

1287+
/* sysctl_mem values are in pages, we convert them in SK_MEM_QUANTUM units */
1288+
static inline long sk_prot_mem_limits(const struct sock *sk, int index)
1289+
{
1290+
long val = sk->sk_prot->sysctl_mem[index];
1291+
1292+
#if PAGE_SIZE > SK_MEM_QUANTUM
1293+
val <<= PAGE_SHIFT - SK_MEM_QUANTUM_SHIFT;
1294+
#elif PAGE_SIZE < SK_MEM_QUANTUM
1295+
val >>= SK_MEM_QUANTUM_SHIFT - PAGE_SHIFT;
1296+
#endif
1297+
return val;
1298+
}
1299+
12891300
static inline int sk_mem_pages(int amt)
12901301
{
12911302
return (amt + SK_MEM_QUANTUM - 1) >> SK_MEM_QUANTUM_SHIFT;

0 commit comments

Comments
 (0)