Page MenuHomeFreeBSD

Halve the memory allocated by the blist allocator that is used for managing swap space
ClosedPublic

Authored by alc on Jun 2 2017, 4:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Jun 25, 2:00 PM
Unknown Object (File)
Mon, Jun 23, 10:49 PM
Unknown Object (File)
Mon, Jun 23, 10:32 AM
Unknown Object (File)
Sun, Jun 15, 5:50 AM
Unknown Object (File)
Tue, Jun 10, 4:49 AM
Unknown Object (File)
Jun 1 2025, 9:00 AM
Unknown Object (File)
May 16 2025, 4:23 PM
Unknown Object (File)
Apr 24 2025, 8:05 PM
Subscribers

Details

Summary

At the heart of the blist allocator is a union:

typedef struct blmeta {
        union {
            daddr_t     bmu_avail;      /* space available under us     */
            u_daddr_t   bmu_bitmap;     /* bitmap if we are a leaf      */
        } u;
        daddr_t         bm_bighint;     /* biggest contiguous block hint*/
} blmeta_t;

At some point in the distant past, daddr_t became a 64-bit integer, but u_daddr_t, which is defined locally by the blist allocator, was not extended from 32 to 64 bits. Consequently, the blist allocator started allocating twice as much memory to manage the same amount of swap space. This change updates the size of u_daddr_t to be 64 bits. This also requires a couple casts to be introduced where a 32-bit integer constant is being shifted to create a bit mask of type u_daddr_t.

Test Plan

I've tested this change locally on an amd64 machine. I'll ask Peter to stress test this change on both an amd64 and i386 machine.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

kib added inline comments.
sys/blist.h
59

Just curious, why do you use protected type name instead of uint64_t ? I suppose that it should be usable everywhere, because u_int32_t worked.

This revision is now accepted and ready to land.Jun 2 2017, 6:20 PM
sys/blist.h
59

I had no compelling reason. I'll change it tonight when I get home.

It looks like the comment above the MAX_PAGEOUT_CLUSTER definition should be updated too.

alc edited edge metadata.
This revision now requires review to proceed.Jun 3 2017, 4:27 PM

Peter, could you please test this patch on both amd64 and i386 under swap intensive workloads.

In D11028#228674, @alc wrote:

Peter, could you please test this patch on both amd64 and i386 under swap intensive workloads.

Sure. Glad to.

This revision is now accepted and ready to land.Jun 3 2017, 6:28 PM

I think that the old definition of u_daddr_t is responsible for this snippet:

    /*                                                                                          
     * If we go beyond this, we get overflows in the radix                                      
     * tree bitmap code.                                                                        
     */
    mblocks = 0x40000000 / BLIST_META_RADIX;
    if (nblks > mblocks) {
            printf(
"WARNING: reducing swap size to maximum of %luMB per unit\n",
                mblocks / 1024 / 1024 * PAGE_SIZE);
            nblks = mblocks;
    }

Specifically, the effect that the old definition has on this definition:

#define SWAPBLK_MASK    ((daddr_t)((u_daddr_t)-1 >> 1))         /* mask */

I ran all stress2 test with this patch. Half on i386 and the other half on amd64. I ran a -j 25 buildworld with 2 GB RAM on amd64.
No problems seen.

This revision was automatically updated to reflect the committed changes.