Theory
ભરેલી પણ ખાલી Lab
કલ્પના કરો એક group project માટે 5 મિત્રો સાથે LabOne server room માં પહોંચવું. ઓરડા ભરમાં 10 ખાલી seats વિખરાયેલી છે, પણ કોઈ 5 seats એક એકલી હરોળમાં સાથે નથી. lab assistant તમને કહે છે કે તમારું group કામ કરી શકતું નથી જ્યાં સુધી તમે બધા એક સતત line માં સાથે-સાથે ન બેસો. તમે રાહ જોવામાં ફસાયેલા છો, ભલે lab માં કુલ જગ્યા પુષ્કળ છે. એક operating system આ બિલકુલ માથાનો દુખાવો કેવી રીતે સામનો કરે છે જ્યારે 30 students એ જ સમયે પોતાનો code ચલાવવાનો પ્રયાસ કરે?
Theory
Cinema Hall વિરુદ્ધ વિખરાયેલું Cafeteria
contiguous allocation ને એક વ્યસ્ત cinema hall માં એક પરિવાર માટે tickets book કરવા જેવું વિચારો: બધાને સળંગ seat numbers માં સાથે બેસવું પડશે. જો seats નો એક અતૂટ block ગાયબ છે, પરિવારને પાછો કાઢી દેવાય છે. non contiguous allocation એક group ના એક college cafeteria માં ઘૂસવા જેવું છે. તમે વહેંચાઈ જાઓ છો, અલગ tables પર કોઈ પણ બેતરતીબ ખાલી ખુરશીઓ પકડી લો છો, અને તમારા mobile phones થી જોડાયેલા રહો છો. group તોય ખાઈ લે છે, ભલે એ ગમે ત્યાં બેસે.
Theory
Allocation Schemes વ્યાખ્યાયિત કરવી
એક operating system માં, contiguous memory allocation માટે જરૂરી છે કે દરેક process physical memory addresses નો એક એકલો, અતૂટ block ઘેરે. program ને સોંપાયેલા RAM addresses સળંગ હોય છે. બીજી બાજુ, non contiguous memory allocation એક process ને અનેક નાના ટુકડાઓમાં વહેંચવા અને physical RAM માં ગમે ત્યાં વિખરાયેલા ઉપલબ્ધ slots માં મૂકવાની પરવાનગી આપે છે. operating system દરેક ટુકડો ક્યાં છુપાયેલો છે એ track કરવા એક ભીતરી lookup map વાપરે છે.
At a glance
LabOne પર contiguous અને non-contiguous memory allocation વ્યૂહરચનાઓની સીધી સરખામણી.
| Feature | Contiguous Allocation | Non-Contiguous Allocation |
|---|---|---|
| RAM Layout | દરેક program માટે એક એકલો અતૂટ block | RAM માં વિખરાયેલા ટુકડાઓમાં વહેંચાયેલો |
| Fragmentation | external fragmentation થી ભારે નુકસાન ઝીલે છે | મુખ્યત્વે નાની internal fragmentation નો સામનો કરે છે |
| Execution Speed | ઝડપી કારણ કે addresses ક્રમિક હોય છે | address translation overhead ના કારણે ધીમો |
| Tracking Overhead | સરળ: માત્ર start address અને limit જોઈએ | જટિલ: page tables કે segment tables જોઈએ |
Theory
RAM Allocation ની દ્વિધા
આપણા LabOne server પર એક scenario ટ્રેસ કરીએ. RAM માં ત્રણ મફત slots છે: એક 20 MB block, એક 30 MB block, અને એક 10 MB block, સક્રિય programs થી અલગ કરેલા. એક student 45 MB memory માંગતી એક script ચલાવવા માંગે છે. contiguous નિયમો હેઠળ, OS 45 MB કે વધુ નો એક એકલો block શોધે છે. કારણ કે સૌથી મોટો block માત્ર 30 MB છે, script block થઈ જાય છે. non contiguous નિયમો હેઠળ, OS script ને નાના ટુકડાઓમાં વહેંચે છે જેથી 20 MB અને 30 MB slots ભરાય, એને સફળતાપૂર્વક load કરતાં.
Quiz
જો એક university exam પૂછે કે આધુનિક operating systems માં non-contiguous allocation ને કેમ પસંદ કરાય છે, કયું કારણ સૌથી સચોટ છે?
- એ address translation maps ની જરૂરને સંપૂર્ણપણે ખતમ કરી નાખે છે
- એ programs ના execution ને continuous blocks થી ખૂબ ઝડપી બનાવે છે
- એ વિખરાયેલા મફત memory spaces ને કાર્યક્ષમ રીતે વાપરે છે અને external fragmentation થી બચે છે
- એ LabOne પર અનેક student processes ને એક સાથે ચાલવાથી અટકાવે છે
Show the answer
એ વિખરાયેલા મફત memory spaces ને કાર્યક્ષમ રીતે વાપરે છે અને external fragmentation થી બચે છે
Non-contiguous allocation OS ને મફત RAM ના નાના, વિખરાયેલા pockets વાપરવા દે છે જે નહીંતર વેડફાઈ જાય. જોકે એ થોડું tracking overhead લાવે છે, એ external fragmentation ની સમસ્યાને સુંદરતાથી ઉકેલે છે.
Watch out
Fragmentation ની ગેરસમજ
semester exams માં એક classic ફાંદો એ લખવો છે કે non contiguous allocation બધા પ્રકારની fragmentation ખતમ કરી નાખે છે. આ તમારા marks લઈ લેશે. જોકે એ વિખરાયેલા blocks વાપરીને external fragmentation સંપૂર્ણપણે ખતમ કરે છે, એ હજુ પણ individual allocated chunks કે pages ની અંદર internal fragmentation લાવે છે. memory પ્રશ્નોનો જવાબ આપતી વખતે હંમેશા જણાવો કે કયા પ્રકારની fragmentation ઘટે કે પેદા થાય છે.
Think first
Address Translation નું વિશ્લેષણ
જો operating system એક program ને physical RAM ના અલગ ભાગોમાં વિખેરે છે, CPU ને કેવી રીતે ખબર પડે છે કે આગળનું instruction ક્યાં શોધવું? જવાબ પ્રગટ કરતાં પહેલાં સામેલ hardware ઘટકને યાદ કરવાનો પ્રયાસ કરો.
Show the answer
CPU હંમેશા logical addresses generate કરે છે. જ્યારે non-contiguous allocation વપરાય છે, hardware Memory Management Unit એક ભીતરી lookup table, જેમ એક page table કે segment table, વાપરે છે જેથી ક્રમિક logical address ને execution દરમિયાન તરત વિખરાયેલા physical coordinates માં અનુવાદિત કરે.
Theory
પછીના Semesters માં Paging અને Pointers
તમે આ બિલકુલ concept ને Unit 2 માં પૂર્ણ operational mechanisms માં ફેલાતું જોશો જ્યારે આપણે Paging અને Segmentation ભણીએ છીએ. વધુમાં, Semester 3 માં, જ્યારે તમે pointers વાપરતાં dynamic memory allocation સાથે જટિલ C++ programs લખો છો, તમે અંતર્ગત operating system kernel દ્વારા manage કરાયેલી એક non contiguous memory structure સાથે સીધી વાતચીત કરી રહ્યા છો.
Summary
Key takeaways
- Contiguous allocation એક process ને memory addresses ના એક એકલા, સળંગ block માં store કરે છે.
- Non-contiguous allocation એક process ને વિખરાયેલા RAM slots માં સ્થિત નાના chunks માં તોડે છે.
- Contiguous systems સરળ અને ઝડપી છે પણ ભારે external fragmentation બરબાદી પેદા કરે છે.
- Non-contiguous systems memory ઉપયોગ મહત્તમ કરે છે પણ translation tables અને hardware overhead માંગે છે.
- આધુનિક systems ડઝનબંધ student programs ને એક સાથે ચલાવવા non-contiguous methods પર આધાર રાખે છે.
- Memory hook: Contiguous એક મોટી chain છે, non-contiguous દર્દ તોડે છે!