2930
2931// for internal use only. returns the total memory available on the system.
2932static uint64_t WebMemorySize()
2933{
2934 glibtop_mem memory;
2935 glibtop_get_mem(&memory);
2936 return (uint64_t)memory.total;
2937}
2938
2939/**
2940 * webkit_web_view_set_cache_model:
2941 * @cache_model: a #WebKitCacheModel
2942 *
2943 * Sets the cache model all web views should follow. This cache model
2944 * determines the RAM and disk space to use for caching previously viewed
2945 * content.
2946 *
2947 * Since: 1.1.1
2948 */
2949void webkit_web_view_set_cache_model(WebKitCacheModel cacheModel)
2950{
2951 if (s_didSetCacheModel && cacheModel == s_cacheModel)
2952 return;
2953
2954 // mac version sets cache directory here
2955
2956 uint64_t memSize = WebMemorySize() / 1024 / 1000;
2957 // mac version gets disk size here
2958
2959 unsigned cacheTotalCapacity = 0;
2960 unsigned cacheMinDeadCapacity = 0;
2961 unsigned cacheMaxDeadCapacity = 0;
2962 double deadDecodedDataDeletionInterval = 0;
2963
2964 unsigned pageCacheCapacity = 0;
2965
2966 switch (cacheModel) {
2967 case WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER: {
2968 // Page cache capacity (in pages)
2969 pageCacheCapacity = 0;
2970
2971 // Object cache capacities (in bytes)
2972 if (memSize >= 2048)
2973 cacheTotalCapacity = 96 * 1024 * 1024;
2974 else if (memSize >= 1536)
2975 cacheTotalCapacity = 64 * 1024 * 1024;
2976 else if (memSize >= 1024)
2977 cacheTotalCapacity = 32 * 1024 * 1024;
2978 else if (memSize >= 512)
2979 cacheTotalCapacity = 16 * 1024 * 1024;
2980
2981 cacheMinDeadCapacity = 0;
2982 cacheMaxDeadCapacity = 0;
2983
2984 break;
2985 }
2986 case WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER: {
2987 // Page cache capacity (in pages)
2988 if (memSize >= 1024)
2989 pageCacheCapacity = 3;
2990 else if (memSize >= 512)
2991 pageCacheCapacity = 2;
2992 else if (memSize >= 256)
2993 pageCacheCapacity = 1;
2994 else
2995 pageCacheCapacity = 0;
2996
2997 // Object cache capacities (in bytes)
2998 if (memSize >= 2048)
2999 cacheTotalCapacity = 96 * 1024 * 1024;
3000 else if (memSize >= 1536)
3001 cacheTotalCapacity = 64 * 1024 * 1024;
3002 else if (memSize >= 1024)
3003 cacheTotalCapacity = 32 * 1024 * 1024;
3004 else if (memSize >= 512)
3005 cacheTotalCapacity = 16 * 1024 * 1024;
3006
3007 cacheMinDeadCapacity = cacheTotalCapacity / 8;
3008 cacheMaxDeadCapacity = cacheTotalCapacity / 4;
3009
3010 break;
3011 }
3012 case WEBKIT_CACHE_MODEL_WEB_BROWSER: {
3013 // Page cache capacity (in pages)
3014 // (Research indicates that value / page drops substantially after 3 pages.)
3015 if (memSize >= 2048)
3016 pageCacheCapacity = 5;
3017 else if (memSize >= 1024)
3018 pageCacheCapacity = 4;
3019 else if (memSize >= 512)
3020 pageCacheCapacity = 3;
3021 else if (memSize >= 256)
3022 pageCacheCapacity = 2;
3023 else
3024 pageCacheCapacity = 1;
3025
3026 // Object cache capacities (in bytes)
3027 // (Testing indicates that value / MB depends heavily on content and
3028 // browsing pattern. Even growth above 128MB can have substantial
3029 // value / MB for some content / browsing patterns.)
3030 if (memSize >= 2048)
3031 cacheTotalCapacity = 128 * 1024 * 1024;
3032 else if (memSize >= 1536)
3033 cacheTotalCapacity = 96 * 1024 * 1024;
3034 else if (memSize >= 1024)
3035 cacheTotalCapacity = 64 * 1024 * 1024;
3036 else if (memSize >= 512)
3037 cacheTotalCapacity = 32 * 1024 * 1024;
3038
3039 cacheMinDeadCapacity = cacheTotalCapacity / 4;
3040 cacheMaxDeadCapacity = cacheTotalCapacity / 2;
3041
3042 // This code is here to avoid a PLT regression. We can remove it if we
3043 // can prove that the overall system gain would justify the regression.
3044 cacheMaxDeadCapacity = max(24u, cacheMaxDeadCapacity);
3045
3046 deadDecodedDataDeletionInterval = 60;
3047
3048 break;
3049 }
3050 default:
3051 ASSERT_NOT_REACHED();
3052 }
3053
3054 WebCore::cache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
3055 WebCore::cache()->setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
3056 WebCore::pageCache()->setCapacity(pageCacheCapacity);
3057
3058 s_cacheModel = cacheModel;
3059 s_didSetCacheModel = true;
3060}
3061
3062/**
3063 * webkit_web_view_cache_model:
3064 *
3065 * Returns the current cache model.
3066 *
3067 * Return value: the current @webkit_cache_model.
3068 *
3069 * Since: 1.1.1
3070 */
3071WebKitCacheModel webkit_web_view_cache_model()
3072{
3073 return s_cacheModel;
3074}
3075
3076/**
3077 * webkit_web_view_did_set_cache_model:
3078 *
3079 * Returns whether or not we have set the cache model and are not just
3080 * using the default.
3081 *
3082 * Return value: a boolean value, with TRUE indicating that we have specified
3083 * a cache model.
3084 *
3085 * Since: 1.1.1
3086 */
3087gboolean webkit_web_view_did_set_cache_model()
3088{
3089 return s_didSetCacheModel ? TRUE : FALSE;
3090}
3091