• Andrew Morton's avatar
    [PATCH] use spinlocking in the ext2 block allocator · c14c1a44
    Andrew Morton authored
    From Alex Tomas and myself
    
    ext2 currently uses lock_super() to protect the filesystem's in-core block
    allocation bitmaps.
    
    On big SMP machines the contention on that semaphore is causing high context
    switch rates, large amounts of idle time and reduced throughput.
    
    The context switch rate can also worsen block allocation: if several tasks
    are trying to allocate blocks inside the same blockgroup for different files,
    madly rotating between those tasks will cause the files' blocks to be
    intermingled.
    
    On SDET and dbench-style worloads (lots of tasks doing lots of allocation)
    this patch (and a similar one for the inode allocator) improve throughout on
    an 8-way by ~15%.  On 16-way NUMAQ the speedup is 150%.
    
    What wedo isto remove the lock altogether and just rely on the atomic
    semantics of test_and_set_bit(): if the allocator sees a block was free it
    runs test_and_set_bit().  If that fails, then we raced and the allocator will
    go and look for another block.
    
    Of course, we don't really use test_and_set_bit() because that
    isn'tendian-dependent.  New atomic endian-independent functions are
    introduced: ext2_set_bit_atomic() and ext2_clear_bit_atomic().  We do not
    need ext2_test_bit_atomic(), since even if ext2_test_bit() returns the wrong
    result, that error will be detected and naturally handled in the subsequent
    ext2_set_bit_atomic().
    
    For little-endian machines the new atomic ops map directly onto the
    test_and_set_bit(), etc.
    
    For big-endian machines we provide the architecture's impementation with the
    address of a spinlock whcih can be taken around the nonatomic ext2_set_bit().
     The spinlocks are hashed, and the hash is scaled according to the machine
    size.  Architectures are free to implement optimised versions of
    ext2_set_bit_atomic() and ext2_clear_bit_atomic().
    c14c1a44
bitops.h 11.4 KB