Add tcp buffer size conduit to NetworkAgent.
bug: 16549611 Change-Id: I7d97dedea2c7c1aed2eccb185645889424508591
This commit is contained in:
@@ -55,6 +55,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
private ArrayList<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
|
private ArrayList<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
|
||||||
private ProxyInfo mHttpProxy;
|
private ProxyInfo mHttpProxy;
|
||||||
private int mMtu;
|
private int mMtu;
|
||||||
|
// in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max"
|
||||||
|
private String mTcpBufferSizes;
|
||||||
|
|
||||||
private static final int MIN_MTU = 68;
|
private static final int MIN_MTU = 68;
|
||||||
private static final int MIN_MTU_V6 = 1280;
|
private static final int MIN_MTU_V6 = 1280;
|
||||||
@@ -105,6 +107,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
addStackedLink(l);
|
addStackedLink(l);
|
||||||
}
|
}
|
||||||
setMtu(source.getMtu());
|
setMtu(source.getMtu());
|
||||||
|
mTcpBufferSizes = source.mTcpBufferSizes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,6 +354,29 @@ public final class LinkProperties implements Parcelable {
|
|||||||
return mMtu;
|
return mMtu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the tcp buffers sizes to be used when this link is the system default.
|
||||||
|
* Should be of the form "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max".
|
||||||
|
*
|
||||||
|
* @param tcpBufferSizes The tcp buffers sizes to use.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void setTcpBufferSizes(String tcpBufferSizes) {
|
||||||
|
mTcpBufferSizes = tcpBufferSizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the tcp buffer sizes.
|
||||||
|
*
|
||||||
|
* @return the tcp buffer sizes to use when this link is the system default.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public String getTcpBufferSizes() {
|
||||||
|
return mTcpBufferSizes;
|
||||||
|
}
|
||||||
|
|
||||||
private RouteInfo routeWithInterface(RouteInfo route) {
|
private RouteInfo routeWithInterface(RouteInfo route) {
|
||||||
return new RouteInfo(
|
return new RouteInfo(
|
||||||
route.getDestination(),
|
route.getDestination(),
|
||||||
@@ -509,6 +535,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
mHttpProxy = null;
|
mHttpProxy = null;
|
||||||
mStackedLinks.clear();
|
mStackedLinks.clear();
|
||||||
mMtu = 0;
|
mMtu = 0;
|
||||||
|
mTcpBufferSizes = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -534,6 +561,11 @@ public final class LinkProperties implements Parcelable {
|
|||||||
|
|
||||||
String mtu = " MTU: " + mMtu;
|
String mtu = " MTU: " + mMtu;
|
||||||
|
|
||||||
|
String tcpBuffSizes = "";
|
||||||
|
if (mTcpBufferSizes != null) {
|
||||||
|
tcpBuffSizes = " TcpBufferSizes: " + mTcpBufferSizes;
|
||||||
|
}
|
||||||
|
|
||||||
String routes = " Routes: [";
|
String routes = " Routes: [";
|
||||||
for (RouteInfo route : mRoutes) routes += route.toString() + ",";
|
for (RouteInfo route : mRoutes) routes += route.toString() + ",";
|
||||||
routes += "] ";
|
routes += "] ";
|
||||||
@@ -548,7 +580,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
stacked += "] ";
|
stacked += "] ";
|
||||||
}
|
}
|
||||||
return "{" + ifaceName + linkAddresses + routes + dns + domainName + mtu
|
return "{" + ifaceName + linkAddresses + routes + dns + domainName + mtu
|
||||||
+ proxy + stacked + "}";
|
+ tcpBuffSizes + proxy + stacked + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -756,6 +788,17 @@ public final class LinkProperties implements Parcelable {
|
|||||||
return getMtu() == target.getMtu();
|
return getMtu() == target.getMtu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares this {@code LinkProperties} Tcp buffer sizes against the target.
|
||||||
|
*
|
||||||
|
* @param target LinkProperties to compare.
|
||||||
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public boolean isIdenticalTcpBufferSizes(LinkProperties target) {
|
||||||
|
return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/**
|
||||||
* Compares this {@code LinkProperties} instance against the target
|
* Compares this {@code LinkProperties} instance against the target
|
||||||
@@ -788,7 +831,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
isIdenticalRoutes(target) &&
|
isIdenticalRoutes(target) &&
|
||||||
isIdenticalHttpProxy(target) &&
|
isIdenticalHttpProxy(target) &&
|
||||||
isIdenticalStackedLinks(target) &&
|
isIdenticalStackedLinks(target) &&
|
||||||
isIdenticalMtu(target);
|
isIdenticalMtu(target) &&
|
||||||
|
isIdenticalTcpBufferSizes(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -923,7 +967,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
+ mRoutes.size() * 41
|
+ mRoutes.size() * 41
|
||||||
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
|
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
|
||||||
+ mStackedLinks.hashCode() * 47)
|
+ mStackedLinks.hashCode() * 47)
|
||||||
+ mMtu * 51;
|
+ mMtu * 51
|
||||||
|
+ ((null == mTcpBufferSizes) ? 0 : mTcpBufferSizes.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -942,6 +987,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
}
|
}
|
||||||
dest.writeString(mDomains);
|
dest.writeString(mDomains);
|
||||||
dest.writeInt(mMtu);
|
dest.writeInt(mMtu);
|
||||||
|
dest.writeString(mTcpBufferSizes);
|
||||||
dest.writeInt(mRoutes.size());
|
dest.writeInt(mRoutes.size());
|
||||||
for(RouteInfo route : mRoutes) {
|
for(RouteInfo route : mRoutes) {
|
||||||
dest.writeParcelable(route, flags);
|
dest.writeParcelable(route, flags);
|
||||||
@@ -981,6 +1027,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
}
|
}
|
||||||
netProp.setDomains(in.readString());
|
netProp.setDomains(in.readString());
|
||||||
netProp.setMtu(in.readInt());
|
netProp.setMtu(in.readInt());
|
||||||
|
netProp.setTcpBufferSizes(in.readString());
|
||||||
addressCount = in.readInt();
|
addressCount = in.readInt();
|
||||||
for (int i=0; i<addressCount; i++) {
|
for (int i=0; i<addressCount; i++) {
|
||||||
netProp.addRoute((RouteInfo)in.readParcelable(null));
|
netProp.addRoute((RouteInfo)in.readParcelable(null));
|
||||||
|
|||||||
@@ -264,6 +264,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
private INetworkManagementService mNetd;
|
private INetworkManagementService mNetd;
|
||||||
private INetworkPolicyManager mPolicyManager;
|
private INetworkPolicyManager mPolicyManager;
|
||||||
|
|
||||||
|
private String mCurrentTcpBufferSizes;
|
||||||
|
|
||||||
private static final int ENABLED = 1;
|
private static final int ENABLED = 1;
|
||||||
private static final int DISABLED = 0;
|
private static final int DISABLED = 0;
|
||||||
|
|
||||||
@@ -1553,30 +1555,40 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static final String DEFAULT_TCP_BUFFER_SIZES = "4096,87380,110208,4096,16384,110208";
|
||||||
* Reads the network specific TCP buffer sizes from SystemProperties
|
|
||||||
* net.tcp.buffersize.[default|wifi|umts|edge|gprs] and set them for system
|
|
||||||
* wide use
|
|
||||||
*/
|
|
||||||
private void updateNetworkSettings(NetworkStateTracker nt) {
|
|
||||||
String key = nt.getTcpBufferSizesPropName();
|
|
||||||
String bufferSizes = key == null ? null : SystemProperties.get(key);
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(bufferSizes)) {
|
private void updateTcpBufferSizes(NetworkAgentInfo nai) {
|
||||||
if (VDBG) log(key + " not found in system properties. Using defaults");
|
if (isDefaultNetwork(nai) == false) {
|
||||||
|
return;
|
||||||
// Setting to default values so we won't be stuck to previous values
|
|
||||||
key = "net.tcp.buffersize.default";
|
|
||||||
bufferSizes = SystemProperties.get(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set values in kernel
|
String tcpBufferSizes = nai.linkProperties.getTcpBufferSizes();
|
||||||
if (bufferSizes.length() != 0) {
|
String[] values = null;
|
||||||
if (VDBG) {
|
if (tcpBufferSizes != null) {
|
||||||
log("Setting TCP values: [" + bufferSizes
|
values = tcpBufferSizes.split(",");
|
||||||
+ "] which comes from [" + key + "]");
|
|
||||||
}
|
}
|
||||||
setBufferSize(bufferSizes);
|
|
||||||
|
if (values == null || values.length != 6) {
|
||||||
|
if (VDBG) log("Invalid tcpBufferSizes string: " + tcpBufferSizes +", using defaults");
|
||||||
|
tcpBufferSizes = DEFAULT_TCP_BUFFER_SIZES;
|
||||||
|
values = tcpBufferSizes.split(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tcpBufferSizes.equals(mCurrentTcpBufferSizes)) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (VDBG) Slog.d(TAG, "Setting tx/rx TCP buffers to " + tcpBufferSizes);
|
||||||
|
|
||||||
|
final String prefix = "/sys/kernel/ipv4/tcp_";
|
||||||
|
FileUtils.stringToFile(prefix + "rmem_min", values[0]);
|
||||||
|
FileUtils.stringToFile(prefix + "rmem_def", values[1]);
|
||||||
|
FileUtils.stringToFile(prefix + "rmem_max", values[2]);
|
||||||
|
FileUtils.stringToFile(prefix + "wmem_min", values[3]);
|
||||||
|
FileUtils.stringToFile(prefix + "wmem_def", values[4]);
|
||||||
|
FileUtils.stringToFile(prefix + "wmem_max", values[5]);
|
||||||
|
mCurrentTcpBufferSizes = tcpBufferSizes;
|
||||||
|
} catch (IOException e) {
|
||||||
|
loge("Can't set TCP buffer sizes:" + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String defaultRwndKey = "net.tcp.default_init_rwnd";
|
final String defaultRwndKey = "net.tcp.default_init_rwnd";
|
||||||
@@ -1589,33 +1601,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes TCP buffer sizes to /sys/kernel/ipv4/tcp_[r/w]mem_[min/def/max]
|
|
||||||
* which maps to /proc/sys/net/ipv4/tcp_rmem and tcpwmem
|
|
||||||
*
|
|
||||||
* @param bufferSizes in the format of "readMin, readInitial, readMax,
|
|
||||||
* writeMin, writeInitial, writeMax"
|
|
||||||
*/
|
|
||||||
private void setBufferSize(String bufferSizes) {
|
|
||||||
try {
|
|
||||||
String[] values = bufferSizes.split(",");
|
|
||||||
|
|
||||||
if (values.length == 6) {
|
|
||||||
final String prefix = "/sys/kernel/ipv4/tcp_";
|
|
||||||
FileUtils.stringToFile(prefix + "rmem_min", values[0]);
|
|
||||||
FileUtils.stringToFile(prefix + "rmem_def", values[1]);
|
|
||||||
FileUtils.stringToFile(prefix + "rmem_max", values[2]);
|
|
||||||
FileUtils.stringToFile(prefix + "wmem_min", values[3]);
|
|
||||||
FileUtils.stringToFile(prefix + "wmem_def", values[4]);
|
|
||||||
FileUtils.stringToFile(prefix + "wmem_max", values[5]);
|
|
||||||
} else {
|
|
||||||
loge("Invalid buffersize string: " + bufferSizes);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
loge("Can't set tcp buffer sizes:" + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void flushVmDnsCache() {
|
private void flushVmDnsCache() {
|
||||||
/*
|
/*
|
||||||
* Tell the VMs to toss their DNS caches
|
* Tell the VMs to toss their DNS caches
|
||||||
@@ -1978,12 +1963,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
*/
|
*/
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NetworkStateTracker.EVENT_NETWORK_SUBTYPE_CHANGED: {
|
|
||||||
info = (NetworkInfo) msg.obj;
|
|
||||||
int type = info.getType();
|
|
||||||
if (mNetConfigs[type].isDefault()) updateNetworkSettings(mNetTrackers[type]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4152,6 +4131,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
|
|
||||||
updateInterfaces(newLp, oldLp, netId);
|
updateInterfaces(newLp, oldLp, netId);
|
||||||
updateMtu(newLp, oldLp);
|
updateMtu(newLp, oldLp);
|
||||||
|
updateTcpBufferSizes(networkAgent);
|
||||||
// TODO - figure out what to do for clat
|
// TODO - figure out what to do for clat
|
||||||
// for (LinkProperties lp : newLp.getStackedLinks()) {
|
// for (LinkProperties lp : newLp.getStackedLinks()) {
|
||||||
// updateMtu(lp, null);
|
// updateMtu(lp, null);
|
||||||
@@ -4377,6 +4357,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
loge("Exception setting default network :" + e);
|
loge("Exception setting default network :" + e);
|
||||||
}
|
}
|
||||||
handleApplyDefaultProxy(newNetwork.linkProperties.getHttpProxy());
|
handleApplyDefaultProxy(newNetwork.linkProperties.getHttpProxy());
|
||||||
|
updateTcpBufferSizes(newNetwork);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleConnectionValidated(NetworkAgentInfo newNetwork) {
|
private void handleConnectionValidated(NetworkAgentInfo newNetwork) {
|
||||||
@@ -4434,6 +4415,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
isNewDefault = true;
|
isNewDefault = true;
|
||||||
updateActiveDefaultNetwork(newNetwork);
|
updateActiveDefaultNetwork(newNetwork);
|
||||||
if (newNetwork.linkProperties != null) {
|
if (newNetwork.linkProperties != null) {
|
||||||
|
updateTcpBufferSizes(newNetwork);
|
||||||
setDefaultDnsSystemProperties(
|
setDefaultDnsSystemProperties(
|
||||||
newNetwork.linkProperties.getDnsServers());
|
newNetwork.linkProperties.getDnsServers());
|
||||||
} else {
|
} else {
|
||||||
@@ -4492,8 +4474,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
1000);
|
1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO - read the tcp buffer size config string from somewhere
|
|
||||||
// updateNetworkSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify battery stats service about this network, both the normal
|
// Notify battery stats service about this network, both the normal
|
||||||
|
|||||||
Reference in New Issue
Block a user