net/netfilter/nf_conntrack_core.c
int nf_conntrack_init_start(void)
{
    int max_factor = 8;
    int i, ret, cpu;

    for (i = 0; i < CONNTRACK_LOCKS; i++)
        spin_lock_init(&nf_conntrack_locks[i]);

    if (!nf_conntrack_htable_size) {
        /* Idea from tcp.c: use 1/16384 of memory.
         * On i386: 32MB machine has 512 buckets.
         * >= 1GB machines have 16384 buckets.
         * >= 4GB machines have 65536 buckets.
         */
        nf_conntrack_htable_size
            = (((totalram_pages << PAGE_SHIFT) / 16384)
               / sizeof(struct hlist_head));
        if (totalram_pages > (4 * (1024 * 1024 * 1024 / PAGE_SIZE)))
            nf_conntrack_htable_size = 65536;
        else if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
            nf_conntrack_htable_size = 16384;
        if (nf_conntrack_htable_size < 32)
            nf_conntrack_htable_size = 32;

        /* Use a max. factor of four by default to get the same max as
         * with the old struct list_heads. When a table size is given
         * we use the old value of 8 to avoid reducing the max.
         * entries. */
        max_factor = 4;
    }
    nf_conntrack_max = max_factor * nf_conntrack_htable_size;
Comments
Write a Comment