
From: Murat Koc (murat.koc@frontsite.de)
Date: Sun 07 Jul 2002 - 15:22:03 EEST
        
Selam,
himm bakalim bakalim ne yazmisiz en son o.k memory struct i yazmisiz. 
O zaman simdi bunlari biraz daha acalim.
Tekrardan bir sunu alalim o zaman buraya.
------------------------------------------------------------------------------
/*
 * The in-memory structure used to track swap areas.
 */
struct swap_info_struct {
        unsigned int flags;
        kdev_t swap_device;
        spinlock_t sdev_lock;
        struct dentry * swap_file;
        struct vfsmount *swap_vfsmnt;
        unsigned short * swap_map;
        unsigned int lowest_bit;
        unsigned int highest_bit;
        unsigned int cluster_next;
        unsigned int cluster_nr;
        int prio;                       /* swap priority */
        int pages;
        unsigned long max;
        int next;                       /* next entry on swap list */
};
-------------------------------------------------------------------------------
Simdi bunlardan bazilarinin biraz daha acilmasi gerekiyor. kdev_t
swap_device in aciklanacak daha fazla birseyi yok sanirim:)  eveet simdi
flags ile baslayalim.
unsigned int flags:
------
simdi eger mm/swapfile.c i inceleyecek olursak burada gorecegemiz iki
tane deger vardir biri SWAP_USED digeri de SWAP_WRITEOK bunlarda zaten
yine swap.h da tanimlanmis vaziyette
#define SWP_USED        1
#define SWP_WRITEOK     3
yani eger swap alani aktif ise 1 degerini, degil ise 0 degerini alacak
demek. 
SWP_WRITEOK e bakacak olursak 3 gibi 2 bitlik bir deger aldigini
goruyoruz. Ilk bakista garip gibi geliyor degil mi niye 3 diye?
simdi swapfile.c e bakalim. Soyle birsey gorecegiz. 
if ((p->flags & SWP_WRITEOK) == SWP_WRITEOK) 
gibi seyler goreceksiniz burada baktiginiz zaman bunun aslinda SWP_OK
biti ile bir cakisma saglayarak swap alanina ancak aktif oldugu zaman
yazilabilmesini saglamak olacaktir. Yukardaki sadece bir ornek
amaclidir. 
spinlock_t sdev_lock:
---------------------
himm bunun amaci simdi locking islemi. Aslinda bu spinlock lar irq
islemleri icin kullaniliyor fakat burada spin_lock() ve spin_unlock()
ile data korumasi da yapabiliyoruz ki zaten swapfile.c de filan da
bunlar kullaniliyor. spin_lock(&lock) seklinde istediginiz data nin
korumasini yapiyorsunuz. Burada kullanim amaci ise eger bu locking
yapilmissa bir I/O transferinde page slot a access i korumak. 
unsigned short * swap_map: 
--------------------------
Bunun swap alanindaki her bir page slot icin bir counter dizisi
oldugundan bahsetmistim. Simdi eger bir page slot icin bu counter 0 ise
dogal olarak bu slot nedir free dir. Baska bunun alabilecegi degerler?
#define SWAP_MAP_MAX    0x7fff  (== 32767)
#define SWAP_MAP_BAD    0x8000  (== 32768)
hah simdi diyelim ki SWAP_MAP_MAX e esit. Bu durumda bakin soyle birsey
goruyoruz. 
* Note: if swap_map[] reaches SWAP_MAP_MAX the entries are treated as
 * "permanent", but will be reclaimed by the next swapoff.
 */
yani diyor ki eger bu degere erismisse bu slot taki page "permanent" dir
yani cikarilamaz bu slottan. Tabii buraya baska bir notu da eklemek
gerekiyor.
-------------------------------------------------------------------------------
/*
                 * How could swap count reach 0x7fff when the maximum
                 * pid is 0x7fff, and there's no way to repeat a swap
                 * page within an mm (except in shmem, where it's the
                 * shared object which takes the reference count)?
                 * We believe SWAP_MAP_MAX cannot occur in Linux 2.4.
                 *
                 * If that's wrong, then we should worry more about
                 * exit_mmap() and do_munmap() cases described above:
                 * we might be resetting SWAP_MAP_MAX too early here.
                 * We know "Undead"s can happen, they're okay, so don't
                 * report them; but do report if we reset SWAP_MAP_MAX.
                 */
                if (*swap_map == SWAP_MAP_MAX) {
                        swap_list_lock();
                        swap_device_lock(si);
                        nr_swap_pages++;
                        *swap_map = 1;
                        swap_device_unlock(si);
                        swap_list_unlock();
                        reset_overflow = 1;
                }
-------------------------------------------------------------------------------
peki ya SWAP_MAP_BAD ? sanirim acik eger counter bu degere ulasmis ise
bu slot kullanilamaz. Bunun icinde swapon() da ilgili yere bakarsak
-------------------------------------------------------------------------------
/* OK, set up the swap map and apply the bad block list */
                if (!(p->swap_map = vmalloc(maxpages * sizeof(short))))
{
                        error = -ENOMEM;
                        goto bad_swap;
                }
                error = 0;
                memset(p->swap_map, 0, maxpages * sizeof(short));
                for (i=0; i<swap_header->info.nr_badpages; i++) {
                        int page = swap_header->info.badpages[i];
                        if (page <= 0 || page >=
swap_header->info.last_page)
                                error = -EINVAL;
                        else
                                p->swap_map[page] = SWAP_MAP_BAD;
                }
                nr_good_pages = swap_header->info.last_page -
                                swap_header->info.nr_badpages -
                                1 /* header page */;
                if (error)
                        goto bad_swap;
        }
-------------------------------------------------------------------------------
Iste bu bir swap area descriptor un tanitimi. Sonrada su swap entry
filan onlara bakariz. 
/* Encode and de-code a swap entry */
#define SWP_TYPE(x)                     (((x).val >> 1) & 0x3f)
#define SWP_OFFSET(x)                   ((x).val >> 8)
#define SWP_ENTRY(type, offset)         ((swp_entry_t) { ((type) << 1) |
((offse
t) << 8) })
-- IYI CALISMALARMURAT KOC
-- Attached file included as plaintext by Ecartis -- -- File: signature.asc -- Desc: This is a digitally signed message part
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux)
iQIXAwUAPSgyab6uWt8ry/OwFALsWAgAmcG29AC3FtUay3EWD67vXCGpqea7llA0 /F76srsvmqYF4fA36NzyEQuY8ezOTzWrtbzjZ3s+sgmMR1Kw8q5ehkQTPny4h9xQ Y8v2mVp9j/YdTALg/Ik6D5S54tLu4LUNP+8WzXcIxahr7GhmMLnjMufxwLYQHBJk TB/oy7/BFNx29Rf6isZCXx8cYrUJrOVuUDZ+luMhemSxjvmnHb0+3LgUJWeVOmL6 0mM/f+S+j9Z2cwFCOQNE3R1Tt4Yx+jfyMis+kExKt6JPc+nphk803bEmQ/T2M2iM BgQSv9zuL4y6HfjhmdHx9/BL8m+r12Lmjbf2ZFSFoiIcufBJr7ER5ggAkfBlGxUM mPVsdJP4tqf1Cl5CpyeMKOLzzSdPNToRryuoNZ6O7eFSvxmj5zp9TgjlIvYQ3FMF 9RZv5rS1kU9p5ifJC7l2JHClyKYNtCy+2NZpux3yvC44/p9qxH9FoU0cqObaifFE FfpKDTSLUzmh2oq4BMnahPevEnaDa6PY5U9D9vn1o6ErGRg1WMizfG12l3LskvFg Ge+n6v/d5ly98RV8GUYFTEtDQYugXrxhN+fQLATwQUKDGjF6oVWvQLqf9qQ66mz8 cyWEtF/An8W4mkxeL1Sbf65pdP3L3XpX7XI9t10BbtSQzhpTlNRHSXxXmGABf8uL kzjALRMpgQLgfA== =k9Et -----END PGP SIGNATURE-----
----------------------------------------------------------------------- Liste üyeliğiniz ile ilgili her türlü işlem için http://liste.linux.org.tr adresindeki web arayüzünü kullanabilirsiniz. Listeden çıkmak için: 'linux-request@linux.org.tr' adresine, "Konu" kısmında "unsubscribe" yazan bir e-posta gönderiniz. -----------------------------------------------------------------------
