xfs
[Top] [All Lists]

preallocation

To: linux-xfs@xxxxxxxxxxx
Subject: preallocation
From: Ying-Hung Chen <ying@xxxxxxxxxxxxxx>
Date: Thu, 29 Sep 2005 14:37:03 +0800
Cc: Ying-Hung Chen <ying@xxxxxxxxxxxxxx>
In-reply-to: <43381317.8040007@sgi.com>
References: <4337ADB7.3060700@yingternet.com> <43381317.8040007@sgi.com>
Sender: linux-xfs-bounce@xxxxxxxxxxx
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
Hi, I just tried the preallocation method Eric provided:

after run the xfs_allocate code to allocate 52MB each (see
xfs_preallocate.cpp)

[root@localhost hdb4]# xfs_bmap 00001.ivf
00001.ivf:
        0: [0..106495]: 96..106591

[root@localhost hdb4]# du -sh 00001.ivf
52M     00001.ivf

and when I writing data in it (see recorder_simulator.cpp) bascially i
am simulating 16 cocurrent streams (up to 50MB, so there are still space
left)

I got heavy fragmentations (shown below)

did I do anything wrong?

Thanks

-Ying

[root@localhost hdb4]# xfs_bmap 00001.ivf
00001.ivf:
        0: [0..639]: 96..735
        1: [640..1151]: 10336..10847
        2: [1152..2687]: 30048..31583
        3: [2688..3967]: 50528..51807
        4: [3968..17151]: 220768..233951
        5: [17152..19711]: 298080..300639
        6: [19712..20223]: 320608..321119
        7: [20224..20479]: 324704..324959
        8: [20480..20991]: 328312..328823
        9: [20992..21247]: 336304..336559
        10: [21248..21759]: 340704..341215
        11: [21760..22015]: 348640..348895
        12: [22016..22271]: 352480..352735
        13: [22272..22783]: 357088..357599
        14: [22784..23039]: 368096..368351
        15: [23040..23295]: 372192..372447
        16: [23296..23551]: 376288..376543
        17: [23552..24063]: 383712..384223
        18: [24064..24319]: 388576..388831
        19: [24320..24575]: 391904..392159
        20: [24576..24831]: 396000..396255
        21: [24832..25087]: 400352..400607
        22: [25088..25343]: 404448..404703
        23: [25344..25855]: 411360..411871
        24: [25856..26111]: 416480..416735
        25: [26112..26367]: 419296..419551
        26: [26368..26623]: 423904..424159
        27: [26624..26879]: 428000..428255
        28: [26880..27135]: 430304..430559
        29: [27136..27391]: 434400..434655
        30: [27392..27647]: 438496..438751
        31: [27648..27903]: 442592..442847
        32: [27904..28671]: 446688..447455
        33: [28672..28927]: 460256..460511
        34: [28928..29439]: 463072..463583
        35: [29440..29695]: 471264..471519
        36: [29696..29951]: 475360..475615
        37: [29952..30207]: 479456..479711
        38: [30208..30463]: 483552..483807
        39: [30464..30975]: 487648..488159
        40: [30976..31231]: 495840..496095
        41: [31232..31487]: 502752..503007
        42: [31488..31743]: 506848..507103
        43: [31744..31999]: 511200..511455
        44: [32000..32255]: 515296..515551
        45: [32256..32511]: 519392..519647
        46: [32512..32767]: 522464..522719
        47: [32768..33023]: 526560..526815
        48: [33024..33791]: 533088..533855
        49: [33792..34047]: 540512..540767
        50: [34048..34303]: 544480..544735
        51: [34304..34559]: 548320..548575
        52: [34560..34815]: 551648..551903
        53: [34816..35071]: 555488..555743
        54: [35072..35327]: 559328..559583
        55: [35328..36351]: 563168..564191
        56: [36352..39679]: 605664..608991
        57: [39680..42495]: 648416..651231
        58: [42496..44799]: 684000..686303
        59: [44800..47615]: 726240..729055
        60: [47616..50175]: 764384..766943
        61: [50176..52223]: 800736..802783
        62: [52224..54399]: 830560..832735
        63: [54400..55935]: 858592..860127
        64: [55936..57471]: 883040..884575
        65: [57472..58751]: 12200360..12201639
        66: [58752..62335]: 18281744..18285327
        67: [62336..70271]: 30493152..30501087
        68: [70272..76287]: 42713776..42719791
        69: [76288..84223]: 54900560..54908495
        70: [84224..91647]: 61045096..61052519
        71: [91648..100479]: 85444488..85453319
        72: [100480..102399]: 91550192..91552111
#include <xfs/libxfs.h>
#include <stdio.h>

void preallocate()
{
        int             fd, err;
        xfs_flock64_t   fl;

        fl.l_whence = 0;
    fl.l_start = 1;
    fl.l_len = (off64_t)(52 * 1024 * 1024); /* 52M */
        char str[10];
        memset(str, 0, 10);

        int count = 1;
        while(count < 900)
        {
                snprintf(str, 10, "%05d.ivf", count);
                fd = open(str, O_RDWR|O_CREAT, S_IRWXU);
        if (fd < 0) {
                perror("open: ");
                printf("open of file %s failed\n", str);
                exit(1);
        }

        err = xfsctl(str, fd, XFS_IOC_RESVSP64, &fl);
        if (err < 0) {
                perror("allocsp: ");
                printf("XFS_IOC_RESVSP64 failed\n");
                close(fd);
                exit(1);
                }

        close(fd);
                count++;
        }

}

int main(int argc, char **argv)
{
        //if(argc != 2)
    //  return fprintf(stderr, "Filename expected.\n"), 1;
        
        preallocate();
        return 0;
} 
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <unistd.h>

#include <ace/Task.h>

using namespace std;

const int WRITE_BLOCK=1024;

class RecorderSimulator : public ACE_Task_Base
{
public:
        RecorderSimulator()//:cuException(NULL)
        {
                //sprintf(test_file,"05%d.ivf", getcount());
        }

        int svc()
        {
                char data[WRITE_BLOCK];
                while(1)
                {
                        sprintf(test_file,"%05d.ivf", getcount());
                        
                        cout << "Writing to file "<< test_file<<endl;
                        FILE * f = fopen(test_file, "w+b");
                        assert(f);
                        int total_size = WRITE_BLOCK * 1024 * 50;//writing 50MB
                        int write_size = 0;
                        int r = 0;
                        while(write_size < total_size)
                        {
                                 r = fwrite(data, sizeof(char), WRITE_BLOCK, f);
                                 assert(r == WRITE_BLOCK);
                                write_size += WRITE_BLOCK;
                                ::usleep(50);
                        }
                        fclose(f);
                        ::usleep(5000);
                }
                return 0;
        }
        int wait()
        {
                int ret = ACE_Task_Base::wait();
                /*if(cuException != NULL)
                {
                        //printf("\nReaderthrow *cuException is 
here.................................\n");
                        throw *cuException;
                }*/
                return ret;
        }
private:
        static int count;
        static int getcount()
        {
                if(count > 900)
                        count = 1;
                else
                        count ++;
                return count;
        }
        //CppUnit::Exception* cuException;
        char test_file[20];
        /*void CatchException(CppUnit::Exception& e)
        {
                cuException = new CppUnit::Exception(e);
        }*/
};
int RecorderSimulator::count = 0;

int main(void)
{
        RecorderSimulator thread[16];
        for(int i=0; i<16; ++i)
                thread[i].activate();
        for(int i=0; i<16; ++i)
                thread[i].wait();
        return 0;
}
<Prev in Thread] Current Thread [Next in Thread>